openapi-contrib / openapi-schema-to-json-schema

Due to the OpenAPI v3.0 and JSON Schema discrepancy, you can use this JS library to convert OpenAPI Schema objects to proper JSON Schema.
https://www.npmjs.com/package/@openapi-contrib/openapi-schema-to-json-schema
MIT License
242 stars 20 forks source link

JSON? #48

Closed LeighYCompton closed 1 year ago

LeighYCompton commented 2 years ago

Perhaps I don't understand, but the converted schema doesn't appear to be proper JSON.

In the output to the console, I see:

{
  type: 'object',
  properties: {
    details: { type: 'object', additionalProperties: [Object] },
    error: { type: 'string' },
    healthy: { type: 'boolean' },
    message: { type: 'string' },
    timestamp: { type: 'string' }
  }
}
But I would have expected
{
  "type": "object",
  "properties": {
    "details": { "type": "object", "additionalProperties": "[Object]" },
    "error": { "type": "string" },
    "healthy": { "type": "boolean" },
    "message": { "type": "string" },
    "timestamp": { "type": "string" }
  }
}

This was a very simple schema -- if I were converting a large/complex schema there would be quite a bit of manual editing required to turn the result into proper JSON.

WazzaJB commented 2 years ago

Hey Leigh,

You should be able to convert the object to a JSON string using JSON.stringify(schema), if you want to format it you can use JSON.stringify(schema, undefined, 2) where '2' is the number of spaces to use.

philsturgeon commented 1 year ago

Yeah you're seeing the JavaScript output whilst JSON is a little different.