From 8926dd457c440ecb5aff3cd8ea191183d4d047a0 Mon Sep 17 00:00:00 2001 From: Roman Hotsiy Date: Mon, 5 Mar 2018 13:47:04 +0200 Subject: [PATCH] fix: merge inner properties of allOf --- .../DiscriminatorDropdown.test.tsx.snap | 4 ++++ src/services/OpenAPIParser.ts | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/components/Schema/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap b/src/components/Schema/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap index b54d4f3e..0daf93a6 100644 --- a/src/components/Schema/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap +++ b/src/components/Schema/__tests__/__snapshots__/DiscriminatorDropdown.test.tsx.snap @@ -76,12 +76,16 @@ exports[`Components SchemaView discriminator should correctly render discriminat "options": "<<>>", "pattern": undefined, "rawSchema": Object { + "allOf": undefined, "default": undefined, + "parentRefs": Array [], "type": "string", }, "readOnly": false, "schema": Object { + "allOf": undefined, "default": undefined, + "parentRefs": Array [], "type": "string", }, "title": "", diff --git a/src/services/OpenAPIParser.ts b/src/services/OpenAPIParser.ts index 618bc1ee..3bad8a5a 100644 --- a/src/services/OpenAPIParser.ts +++ b/src/services/OpenAPIParser.ts @@ -212,11 +212,18 @@ export class OpenAPIParser { } if (subSchema.properties !== undefined) { - // TODO: merge properties contents - receiver.properties = { - ...(receiver.properties || {}), - ...subSchema.properties, - }; + receiver.properties = receiver.properties || {}; + for (let prop in subSchema.properties) { + if (!receiver.properties[prop]) { + receiver.properties[prop] = subSchema.properties[prop]; + } else { + // merge inner properties + receiver.properties[prop] = this.mergeAllOf( + { allOf: [receiver.properties[prop], subSchema.properties[prop]] }, + $ref + '/properties/' + prop, + ); + } + } } if (subSchema.required !== undefined) {