Skip to content

Commit 6628de3

Browse files
mromaszewiczdanicc097
authored andcommitted
Revert "Updated code to find AdditionalTypes under AdditionalPropertiesType key as well. (oapi-codegen#1017)"
This reverts commit 71bd050. Unit tests fail with this change, because some fields in additional properties become duplicated
1 parent 053808c commit 6628de3

3 files changed

Lines changed: 0 additions & 564 deletions

File tree

pkg/codegen/codegen_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -201,49 +201,6 @@ 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-
247204
func TestGoTypeImport(t *testing.T) {
248205
packageName := "api"
249206
opts := Configuration{
@@ -352,8 +309,5 @@ func (t *ExampleSchema_Item) FromExternalRef0NewPet(v externalRef0.NewPet) error
352309

353310
}
354311

355-
//go:embed test_schema_additional_properties_types.yaml
356-
var testSchemaArrayTypes string
357-
358312
//go:embed test_spec.yaml
359313
var testOpenAPIDefinition string

pkg/codegen/schema.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ func (s Schema) GetAdditionalTypeDefs() []TypeDefinition {
7171
for _, p := range s.Properties {
7272
result = append(result, p.Schema.GetAdditionalTypeDefs()...)
7373
}
74-
// Some schema definitions may be used for key/value and not specify any properties, but provide properties
75-
// within the additionalProperties. See test_schema_array_types.yaml in tests.
76-
if s.AdditionalPropertiesType != nil {
77-
result = append(result, s.AdditionalPropertiesType.GetAdditionalTypeDefs()...)
78-
}
7974
result = append(result, s.AdditionalTypes...)
8075
return result
8176
}

0 commit comments

Comments
 (0)