wework / json-schema-to-openapi-schema

A little NodeJS package to convert JSON Schema to OpenAPI Schema Objects
214 stars 44 forks source link

types in definitions are not converted #5

Closed hugomallet closed 6 years ago

hugomallet commented 6 years ago

Hi,

Types are not converted if they are defined in the definitions field.

Simple example to reproduce :

const toOpenApi = require('json-schema-to-openapi-schema');
const { inspect } = require('util');

const successfulSchema = {
    $schema: 'http://json-schema.org/draft-04/schema#',
    type: 'object',
    properties: {
        issue: {
            type: ['string', 'null']
        }
    }
};

const failingSchema = {
    $schema: 'http://json-schema.org/draft-04/schema#',
    type: 'object',
    properties: {
        issue: { $ref: '#/definitions/issue' }
    },
    definitions: {
        issue: {
            type: ['string', 'null']
        }
    }
};

const successfullyConvertedSchema = toOpenApi(successfulSchema);
const failedConvertedSchema = toOpenApi(failingSchema);

console.log('SUCCESS');
console.log(inspect(successfullyConvertedSchema, { compact: false, depth: 3 }));
console.log('FAILURE');
console.log(inspect(failedConvertedSchema, { compact: false, depth: 3 }));

Expected result : failingSchema should be converted

Hugo

philsturgeon commented 6 years ago

Hey there! Sorry but its not about definitions, it's just that this tool does not resolve $ref. There are tools around that do, and you should use those before passing the result to this document.