@@ -201,6 +201,49 @@ type GetTestByNameResponse struct {
201201 checkLint (t , "test.gen.go" , []byte (code ))
202202}
203203
204+ // Validate any types nested under AdditionalPropertiesTypes is propagated up as with normal Property AdditionalTypes
205+ func TestExampleOpenAPICodeGenerationSchemaAdditionalPropertyTypes (t * testing.T ) {
206+
207+ // Input vars for code generation:
208+ packageName := "testswagger"
209+ opts := Configuration {
210+ PackageName : packageName ,
211+ Generate : GenerateOptions {
212+ EchoServer : false ,
213+ Client : false ,
214+ Models : true ,
215+ EmbeddedSpec : false ,
216+ },
217+ }
218+
219+ loader := openapi3 .NewLoader ()
220+ loader .IsExternalRefsAllowed = true
221+
222+ // Get a spec from the test definition in this file:
223+ swagger , err := loader .LoadFromData ([]byte (testSchemaArrayTypes ))
224+ assert .NoError (t , err )
225+
226+ // Run our code generation:
227+ code , err := Generate (swagger , opts )
228+ assert .NoError (t , err )
229+ assert .NotEmpty (t , code )
230+
231+ // Check that we have valid (formattable) code:
232+ _ , err = format .Source ([]byte (code ))
233+ assert .NoError (t , err )
234+
235+ // Check that we have a package:
236+ assert .Contains (t , code , "package testswagger" )
237+
238+ // Check that AdditionalPropertyTypes structs are propagated up properly:
239+ assert .Contains (t , code , "[]PatchedBulkWritableCircuitTerminationRequest_Relationships_Destination_Objects_Item" )
240+ assert .Contains (t , code , "type PatchedBulkWritableCircuitTerminationRequest_Relationships_Destination_Objects_Item struct {" )
241+ assert .Contains (t , code , "[]BulkWritableCircuitTerminationRequest_Relationships_Destination_Objects_Item" )
242+ assert .Contains (t , code , "type BulkWritableCircuitTerminationRequest_Relationships_Destination_Objects_Item struct {" )
243+ assert .Contains (t , code , "[]WritableCircuitTerminationRequest_Relationships_Destination_Objects_Item " )
244+ assert .Contains (t , code , "type WritableCircuitTerminationRequest_Relationships_Destination_Objects_Item struct {" )
245+ }
246+
204247func TestGoTypeImport (t * testing.T ) {
205248 packageName := "api"
206249 opts := Configuration {
@@ -309,5 +352,8 @@ func (t *ExampleSchema_Item) FromExternalRef0NewPet(v externalRef0.NewPet) error
309352
310353}
311354
355+ //go:embed test_schema_additional_properties_types.yaml
356+ var testSchemaArrayTypes string
357+
312358//go:embed test_spec.yaml
313359var testOpenAPIDefinition string
0 commit comments