@@ -102,6 +102,53 @@ describe('generate-python-dict', () => {
102102 expect ( content ) . toMatchSnapshot ( ) ;
103103 } ) ;
104104
105+ it ( 'handles oneOf with refs' , ( ) => {
106+ const doc : OpenAPI . Document = {
107+ openapi : '3.1.0' ,
108+ info : { title : 't' , version : '1' } ,
109+ paths : { } ,
110+ components : {
111+ schemas : {
112+ A : { type : 'object' , properties : { id : { type : 'string' } } } ,
113+ B : { type : 'object' , properties : { value : { type : 'number' } } } ,
114+ Message : { oneOf : [ { $ref : '#/components/schemas/A' } , { $ref : '#/components/schemas/B' } ] }
115+ }
116+ }
117+ } ;
118+ const schemas = extractSchemas ( doc , null ) ;
119+ const { definition, typingImports } = convertToTypedDict ( 'Message' , schemas . Message as OpenAPI . SchemaObject ) ;
120+ const typingLine = `from typing import ${ Array . from ( typingImports ) . join ( ', ' ) } ` ;
121+ const content = [ typingLine , '' , definition , '' ] . filter ( Boolean ) . join ( '\n' ) ;
122+ const tmp = path . join ( __dirname , 'tmp_oneof.py' ) ;
123+ fs . writeFileSync ( tmp , content ) ;
124+ child_process . execSync ( `python3 -m py_compile ${ tmp } ` ) ;
125+ fs . unlinkSync ( tmp ) ;
126+ expect ( content ) . toMatchSnapshot ( ) ;
127+ } ) ;
128+
129+ it ( 'handles oneOf with a single ref' , ( ) => {
130+ const doc : OpenAPI . Document = {
131+ openapi : '3.1.0' ,
132+ info : { title : 't' , version : '1' } ,
133+ paths : { } ,
134+ components : {
135+ schemas : {
136+ A : { type : 'object' , properties : { id : { type : 'string' } } } ,
137+ MessageSingle : { oneOf : [ { $ref : '#/components/schemas/A' } ] }
138+ }
139+ }
140+ } ;
141+ const schemas = extractSchemas ( doc , null ) ;
142+ const { definition, typingImports } = convertToTypedDict ( 'MessageSingle' , schemas . MessageSingle as OpenAPI . SchemaObject ) ;
143+ const typingLine = `from typing import ${ Array . from ( typingImports ) . join ( ', ' ) } ` ;
144+ const content = [ typingLine , '' , definition , '' ] . filter ( Boolean ) . join ( '\n' ) ;
145+ const tmp = path . join ( __dirname , 'tmp_oneof_single.py' ) ;
146+ fs . writeFileSync ( tmp , content ) ;
147+ child_process . execSync ( `python3 -m py_compile ${ tmp } ` ) ;
148+ fs . unlinkSync ( tmp ) ;
149+ expect ( content ) . toMatchSnapshot ( ) ;
150+ } ) ;
151+
105152 it ( 'handles inline object properties' , ( ) => {
106153 const doc : OpenAPI . Document = {
107154 openapi : '3.1.0' ,
0 commit comments