From 20e56d2f8ed3312ff284e04f96925023d51fdb31 Mon Sep 17 00:00:00 2001 From: Anders Cassidy Date: Wed, 19 Jan 2022 11:54:00 +0000 Subject: [PATCH] Pass through required properties to allOf children --- src/schema.js | 2 +- tests/generated/v3.0/allof-example.ts | 2 +- tests/schemas/v3.0/allof-example.yaml | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/schema.js b/src/schema.js index fa1ce669f..4b944f2c2 100644 --- a/src/schema.js +++ b/src/schema.js @@ -188,7 +188,7 @@ const complexSchemaParsers = { }, [SCHEMA_TYPES.COMPLEX_ALL_OF]: (schema) => { // T1 & T2 - const combined = _.map(schema.allOf, complexTypeGetter); + const combined = _.map(schema.allOf.map(s => _.merge({ required: schema.required }, s)), complexTypeGetter); return checkAndAddNull( schema, filterContents(combined, [...JS_EMPTY_TYPES, ...JS_PRIMITIVE_TYPES, TS_KEYWORDS.ANY]).join( diff --git a/tests/generated/v3.0/allof-example.ts b/tests/generated/v3.0/allof-example.ts index 2c94a295c..4627b7be3 100644 --- a/tests/generated/v3.0/allof-example.ts +++ b/tests/generated/v3.0/allof-example.ts @@ -13,7 +13,7 @@ export interface Pet { pet_type: string; } -export type Dog = Pet & { bark?: boolean; breed?: "Dingo" | "Husky" | "Retriever" | "Shepherd" }; +export type Dog = Pet & { bark?: boolean; breed: "Dingo" | "Husky" | "Retriever" | "Shepherd" }; export type Cat = Pet & { hunts?: boolean; age?: number }; diff --git a/tests/schemas/v3.0/allof-example.yaml b/tests/schemas/v3.0/allof-example.yaml index 20085b326..470f2c8a3 100644 --- a/tests/schemas/v3.0/allof-example.yaml +++ b/tests/schemas/v3.0/allof-example.yaml @@ -29,7 +29,9 @@ components: discriminator: propertyName: pet_type Dog: # "Dog" is a value for the pet_type property (the discriminator value) - allOf: # Combines the main `Pet` schema with `Dog`-specific properties + required: + - breed + allOf: # Combines the main `Pet` schema with `Dog`-specific properties - $ref: '#/components/schemas/Pet' - type: object # all other properties specific to a `Dog` @@ -48,4 +50,4 @@ components: hunts: type: boolean age: - type: integer \ No newline at end of file + type: integer