@@ -18,6 +18,14 @@ export class ComplexSchemaParser extends MonoSchemaParser {
1818 complexType
1919 ] ( this . schema ) ;
2020
21+ // A $ref alongside `not`, `allOf` and friends is a sibling in OpenAPI 3.1: the
22+ // keywords apply on top of the referenced schema. Parsing the reference too keeps
23+ // the type, which would otherwise be lost with the complex keyword that cannot be
24+ // expressed in TypeScript.
25+ const shouldParseSimpleSchema =
26+ this . schemaUtils . getInternalSchemaType ( simpleSchema ) ===
27+ SCHEMA_TYPES . OBJECT || this . schemaUtils . isRefSchema ( simpleSchema ) ;
28+
2129 return {
2230 ...( typeof this . schema === "object" ? this . schema : { } ) ,
2331 $schemaPath : this . schemaPath . slice ( ) ,
@@ -33,19 +41,21 @@ export class ComplexSchemaParser extends MonoSchemaParser {
3341 ) ,
3442 content :
3543 this . config . Ts . IntersectionType (
36- compact ( [
37- this . config . Ts . ExpressionGroup ( complexSchemaContent ) ,
38- this . schemaUtils . getInternalSchemaType ( simpleSchema ) ===
39- SCHEMA_TYPES . OBJECT &&
40- this . config . Ts . ExpressionGroup (
41- this . schemaParserFabric
42- . createSchemaParser ( {
43- schema : simpleSchema ,
44- schemaPath : this . schemaPath ,
45- } )
46- . getInlineParseContent ( ) ,
47- ) ,
48- ] ) ,
44+ this . schemaUtils
45+ . filterSchemaContents (
46+ compact ( [
47+ complexSchemaContent ,
48+ shouldParseSimpleSchema &&
49+ this . schemaParserFabric
50+ . createSchemaParser ( {
51+ schema : simpleSchema ,
52+ schemaPath : this . schemaPath ,
53+ } )
54+ . getInlineParseContent ( ) ,
55+ ] ) ,
56+ ( content ) => content !== this . config . Ts . Keyword . Any ,
57+ )
58+ . map ( ( content ) => this . config . Ts . ExpressionGroup ( content ) ) ,
4959 ) || this . config . Ts . Keyword . Any ,
5060 } ;
5161 }
0 commit comments