mikunn / openapi-schema-to-json-schema

Converts OpenAPI Schema Object to JSON Schema
76 stars 6 forks source link

Alternative types #29

Closed ozum closed 6 years ago

ozum commented 6 years ago

Hi,

If type property is an array of alternative types, throws error.

Example

const openAPItoJsonSchema = require("openapi-schema-to-json-schema");

const a = {
  type: "object",
  properties: {
    street: {
      type: ["string", "null"], // <--- Reason of the error
      maxLength: 50,
    },
  },
};

console.log(openAPItoJsonSchema(a));

Actual Result

.../node_modules/openapi-schema-to-json-schema/index.js:134
                throw new InvalidTypeError('Type "' + type + '" is not a valid type');

Error
    at Object.<anonymous> (...)

Expected Result

No error, because alternative types are valid JSON Schema.

Additional Notes

Thrown error does not have any message. I see the message from code but not in actual error.

index.js Line 10: InvalidTypeError.prototype = new Error();

Did you intend: InvalidTypeError.prototype = Error;

Kind Regards,

mikunn commented 6 years ago

Hi ozum,

It throws an error, because OpenAPI 3 does not support alternative types.

Thanks for pointing out the error message issue. It will be fixed in the next release.

ozum commented 6 years ago

@mikunn Thanks for pointing reference document. I always confuse Json Schema and OpenAPI validation part. I don't understand why OpenAPI does not implement Json Schema as it is, it is widely accepted.