From 00a850336b5d406980bbaa8e21223e2990040484 Mon Sep 17 00:00:00 2001 From: kainpets Date: Fri, 7 Jun 2024 12:45:35 +0200 Subject: [PATCH 1/3] update flatten obj schema to include sub oneOfs --- lib/interact-for-open-api-object.ts | 5 +++++ lib/openapi/flatten-obj-schema.ts | 20 ++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/interact-for-open-api-object.ts b/lib/interact-for-open-api-object.ts index 52020a5..fb3ca9e 100644 --- a/lib/interact-for-open-api-object.ts +++ b/lib/interact-for-open-api-object.ts @@ -40,6 +40,11 @@ export const interactForOpenApiObject = async ( // Clone args and args params so that we can mutate it args = { ...args, params: { ...args.params } } + if (!args.schema || typeof args.schema.type === 'undefined') { + console.error(`Schema type is undefined for command: ${args.command.join("/")}`) + return + } + const schema: OpenApiSchema = flattenObjSchema(args.schema) const { properties = {}, required = [] } = schema diff --git a/lib/openapi/flatten-obj-schema.ts b/lib/openapi/flatten-obj-schema.ts index 378ddd6..b53a464 100644 --- a/lib/openapi/flatten-obj-schema.ts +++ b/lib/openapi/flatten-obj-schema.ts @@ -4,6 +4,7 @@ type AllOfSchema = any type ObjSchema = any type PrimitiveSchema = any type PropertySchema = any +type ArraySchema = any import lodash from "lodash" @@ -15,6 +16,9 @@ export const flattenObjSchema = ( | { oneOf: Array } + | { + allOf: Array + } ): ObjSchema => { if ("type" in s && s.type === "object") return s @@ -40,6 +44,11 @@ export const flattenObjSchema = ( } return super_obj as ObjSchema } + + if ("allOf" in s) { + return deepFlattenAllOfSchema(s) as ObjSchema + } + throw new Error(`Unknown schema type "${s.type}"`) } @@ -58,7 +67,7 @@ export const deepFlattenAllOfSchema = ( const properties: Record = {} const required = new Set() - const primitives: PrimitiveSchema[] = [] + const primitives: (PrimitiveSchema | ArraySchema)[] = [] for (let subschema of s.allOf) { if ("allOf" in subschema) { @@ -69,8 +78,11 @@ export const deepFlattenAllOfSchema = ( } if ("oneOf" in subschema) { - console.error("oneOf not currently supported when flattening allOf") - continue + subschema = flattenObjSchema( + subschema as { + oneOf: Array + } + ) } if ("$ref" in subschema) { @@ -122,4 +134,4 @@ export const deepFlattenAllOfSchema = ( } return undefined -} +} \ No newline at end of file From 9212d4682065c17e24ce00988d13ee0ecc193645 Mon Sep 17 00:00:00 2001 From: kainpets Date: Fri, 7 Jun 2024 13:00:21 +0200 Subject: [PATCH 2/3] remove undefined schema check --- lib/interact-for-open-api-object.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/interact-for-open-api-object.ts b/lib/interact-for-open-api-object.ts index fb3ca9e..52020a5 100644 --- a/lib/interact-for-open-api-object.ts +++ b/lib/interact-for-open-api-object.ts @@ -40,11 +40,6 @@ export const interactForOpenApiObject = async ( // Clone args and args params so that we can mutate it args = { ...args, params: { ...args.params } } - if (!args.schema || typeof args.schema.type === 'undefined') { - console.error(`Schema type is undefined for command: ${args.command.join("/")}`) - return - } - const schema: OpenApiSchema = flattenObjSchema(args.schema) const { properties = {}, required = [] } = schema From b82d0c51fb9a6e21f2d0f415523a83ffc120313e Mon Sep 17 00:00:00 2001 From: Seam Bot Date: Fri, 7 Jun 2024 11:00:50 +0000 Subject: [PATCH 3/3] ci - format code --- lib/openapi/flatten-obj-schema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/openapi/flatten-obj-schema.ts b/lib/openapi/flatten-obj-schema.ts index b53a464..740b4db 100644 --- a/lib/openapi/flatten-obj-schema.ts +++ b/lib/openapi/flatten-obj-schema.ts @@ -134,4 +134,4 @@ export const deepFlattenAllOfSchema = ( } return undefined -} \ No newline at end of file +}