From 8fc0d37a1f44d84563593ab3383738fb9ea557b9 Mon Sep 17 00:00:00 2001 From: Kiri111enz Date: Tue, 6 Feb 2024 11:03:48 +0300 Subject: [PATCH] fix: properties + oneOf --- src/__snapshots__/combiners/complex.test.ts.snap | 8 ++++++-- src/__snapshots__/combiners/oneOf.test.ts.snap | 16 ++++++++++++---- src/includer/traverse/tables.ts | 7 +++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/__snapshots__/combiners/complex.test.ts.snap b/src/__snapshots__/combiners/complex.test.ts.snap index b9dd472..8a22d44 100644 --- a/src/__snapshots__/combiners/complex.test.ts.snap +++ b/src/__snapshots__/combiners/complex.test.ts.snap @@ -35,7 +35,9 @@ Generated server url{.openapi__request__description} "name": "b", "age": { "c": "c" - } + }, + "type": "string", + "bar": "string" } \`\`\` @@ -92,7 +94,9 @@ Base 200 response "name": "b", "age": { "c": "c" - } + }, + "type": "string", + "bar": "string" } \`\`\` diff --git a/src/__snapshots__/combiners/oneOf.test.ts.snap b/src/__snapshots__/combiners/oneOf.test.ts.snap index 0e4ae25..fed73d6 100644 --- a/src/__snapshots__/combiners/oneOf.test.ts.snap +++ b/src/__snapshots__/combiners/oneOf.test.ts.snap @@ -137,7 +137,9 @@ Generated server url{.openapi__request__description} \`\`\`json { "name": "string", - "age": 0 + "age": 0, + "type": "string", + "baz": "string" } \`\`\` @@ -190,7 +192,9 @@ Cat class \`\`\`json { "name": "string", - "age": 0 + "age": 0, + "type": "string", + "baz": "string" } \`\`\` @@ -251,7 +255,9 @@ Generated server url{.openapi__request__description} "pet": { "type": "string", "baz": "string" - } + }, + "type": "string", + "baz": "string" } \`\`\` @@ -305,7 +311,9 @@ Cat class "pet": { "type": "string", "baz": "string" - } + }, + "type": "string", + "baz": "string" } \`\`\` diff --git a/src/includer/traverse/tables.ts b/src/includer/traverse/tables.ts index dd5172c..2c744c0 100644 --- a/src/includer/traverse/tables.ts +++ b/src/includer/traverse/tables.ts @@ -235,6 +235,13 @@ function findNonNullOneOfElement(schema: OpenJSONSchema): OpenJSONSchema { const merged = RefsService.merge(v); if (Object.keys(merged.properties || {}).length) { + if (v.oneOf?.length) { + const option = v.oneOf[0]; + if (typeof option === 'object' && option.properties) { + v.properties = {...v.properties, ...option.properties}; + } + delete v.oneOf; + } return v; }