fix: add extra deref step for anyOf/oneOf variants

fixes #810
This commit is contained in:
Roman Hotsiy 2019-03-15 11:22:38 +02:00
parent 869a91ae4d
commit d81b63147c
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0

View File

@ -161,7 +161,15 @@ export class SchemaModel {
private initOneOf(oneOf: OpenAPISchema[], parser: OpenAPIParser) { private initOneOf(oneOf: OpenAPISchema[], parser: OpenAPIParser) {
this.oneOf = oneOf!.map((variant, idx) => { this.oneOf = oneOf!.map((variant, idx) => {
const merged = parser.mergeAllOf(variant, this.pointer + '/oneOf/' + idx); const derefVariant = parser.deref(variant);
const merged = parser.mergeAllOf(derefVariant, this.pointer + '/oneOf/' + idx);
// try to infer title
const title =
isNamedDefinition(variant.$ref) && !merged.title
? JsonPointer.baseName(variant.$ref)
: merged.title;
const schema = new SchemaModel( const schema = new SchemaModel(
parser, parser,
@ -169,12 +177,14 @@ export class SchemaModel {
{ {
// variant may already have allOf so merge it to not get overwritten // variant may already have allOf so merge it to not get overwritten
...merged, ...merged,
title,
allOf: [{ ...this.schema, oneOf: undefined, anyOf: undefined }], allOf: [{ ...this.schema, oneOf: undefined, anyOf: undefined }],
} as OpenAPISchema, } as OpenAPISchema,
this.pointer + '/oneOf/' + idx, this.pointer + '/oneOf/' + idx,
this.options, this.options,
); );
parser.exitRef(variant);
// each oneOf should be independent so exiting all the parent refs // each oneOf should be independent so exiting all the parent refs
// otherwise it will cause false-positive recursive detection // otherwise it will cause false-positive recursive detection
parser.exitParents(merged); parser.exitParents(merged);