swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

arrays cause the UI to fail if items aren't present in the schema

Open paulhill opened this issue 12 years ago • 2 comments

This function throws a null pointer error if items isn't present for an array type.

var Property = function(name, obj, required) {
  this.schema = obj;
  this.required = required;
  if(obj['$ref']) {
    var refType = obj['$ref'];
    refType = refType.indexOf('#/definitions') === -1 ? refType : refType.substring('#/definitions').length;
    this['$ref'] = refType;
  }
  else if (obj.type === 'array') {
    if(obj.items['$ref'])
      this['$ref'] = obj.items['$ref'];
    else
      obj = obj.items;
  }
  this.name = name;
  this.obj = obj;
  this.optional = true;
  this.example = obj.example || null;
}

But json schema does not require items: http://json-schema.org/latest/json-schema-validation.html#anchor36

Is this a case of swagger-ui does require it, or just a bug?

paulhill avatar Oct 16 '14 23:10 paulhill

We definitely need items if it's an array, we're not supporting anonymous inner types. Granted an error isn't the right way to handle it.

Btw you filed bug #666. Nice job :-/

fehguy avatar Oct 17 '14 01:10 fehguy

Please track this here:

https://github.com/swagger-api/swagger-js/issues/190

fehguy avatar Dec 29 '14 19:12 fehguy