Skip to content

Commit

Permalink
applied pr fix oapi-codegen#717
Browse files Browse the repository at this point in the history
  • Loading branch information
MMorsell committed Sep 27, 2024
1 parent 2b72548 commit 9700a3c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
21 changes: 8 additions & 13 deletions pkg/codegen/merge_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,23 @@ import (

// MergeSchemas merges all the fields in the schemas supplied into one giant schema.
// The idea is that we merge all fields together into one schema.
func MergeSchemas(allOf []*openapi3.SchemaRef, path []string) (Schema, error) {
func MergeSchemas(schema *openapi3.Schema, path []string) (Schema, error) {
// If someone asked for the old way, for backward compatibility, return the
// old style result.
if globalState.options.Compatibility.OldMergeSchemas {
return mergeSchemasV1(allOf, path)
return mergeSchemasV1(schema.AllOf, path)
}
return mergeSchemas(allOf, path)
return mergeSchemas(schema, path)
}

func mergeSchemas(allOf []*openapi3.SchemaRef, path []string) (Schema, error) {
func mergeSchemas(baseSchema *openapi3.Schema, path []string) (Schema, error) {
allOf := baseSchema.AllOf
n := len(allOf)

if n == 1 {
return GenerateGoSchema(allOf[0], path)
}

schema, err := valueWithPropagatedRef(allOf[0])
if err != nil {
return Schema{}, err
}
schema := *baseSchema
schema.AllOf = nil

for i := 1; i < n; i++ {
for i := 0; i < n; i++ {
var err error
oneOfSchema, err := valueWithPropagatedRef(allOf[i])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func GenerateGoSchema(sref *openapi3.SchemaRef, path []string) (Schema, error) {
// so that in a RESTful paradigm, the Create operation can return
// (object, id), so that other operations can refer to (id)
if schema.AllOf != nil {
mergedSchema, err := MergeSchemas(schema.AllOf, path)
mergedSchema, err := MergeSchemas(schema, path)
if err != nil {
return Schema{}, fmt.Errorf("error merging schemas: %w", err)
}
Expand Down

0 comments on commit 9700a3c

Please sign in to comment.