diff --git a/internal/test/issues/issue-1476/issue1476.gen.go b/internal/test/issues/issue-1476/issue1476.gen.go index fb5d75386..757181c12 100644 --- a/internal/test/issues/issue-1476/issue1476.gen.go +++ b/internal/test/issues/issue-1476/issue1476.gen.go @@ -1,6 +1,6 @@ // Package issue1476 provides primitives to interact with the openapi HTTP API. // -// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version (devel) DO NOT EDIT. +// Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.0.0-00010101000000-000000000000 DO NOT EDIT. package issue1476 // Dog defines model for Dog. @@ -9,7 +9,7 @@ type Dog struct { Pet *struct { Id int64 `json:"id"` Tag *string `json:"tag,omitempty"` - } `json:"-"` + } `json:"pet,omitempty"` PetId *int64 `json:"petId,omitempty"` } diff --git a/pkg/codegen/schema.go b/pkg/codegen/schema.go index f8fe22d51..92854e4d5 100644 --- a/pkg/codegen/schema.go +++ b/pkg/codegen/schema.go @@ -392,15 +392,6 @@ func GenerateGoSchema(sref *openapi3.SchemaRef, path []string) (Schema, error) { for _, pName := range SortedSchemaKeys(schema.Properties) { p := schema.Properties[pName] - // Merge allOf in property - if p.Value.AllOf != nil { - val, err := mergeAllOf(p.Value.AllOf) - if err != nil { - return Schema{}, fmt.Errorf("error generating Go schema from allOf for property '%s': %w", pName, err) - } - p.Value = &val - } - propertyPath := append(path, pName) pSchema, err := GenerateGoSchema(p, propertyPath) if err != nil { @@ -446,6 +437,11 @@ func GenerateGoSchema(sref *openapi3.SchemaRef, path []string) (Schema, error) { } } + if schema.AllOf != nil { + if err := generateUnion(&outSchema, schema.AllOf, schema.Discriminator, path); err != nil { + return Schema{}, fmt.Errorf("error generating type for allOf: %w", err) + } + } if schema.AnyOf != nil { if err := generateUnion(&outSchema, schema.AnyOf, schema.Discriminator, path); err != nil { return Schema{}, fmt.Errorf("error generating type for anyOf: %w", err)