Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cosnicolaou authored Dec 17, 2022
1 parent be3354e commit 597fa8d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/codegen/merge_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func mergeSchemas(allOf []*openapi3.SchemaRef, path []string) (Schema, error) {
if err != nil {
return Schema{}, err
}
schema, err = mergeOpenapiSchemas(schema, oneOfSchema)
schema, err = mergeOpenapiSchemas(schema, oneOfSchema, true)
if err != nil {
return Schema{}, fmt.Errorf("error merging schemas for AllOf: %w", err)
}
Expand Down Expand Up @@ -74,7 +74,7 @@ func mergeAllOf(allOf []*openapi3.SchemaRef) (openapi3.Schema, error) {
var schema openapi3.Schema
for _, schemaRef := range allOf {
var err error
schema, err = mergeOpenapiSchemas(schema, *schemaRef.Value)
schema, err = mergeOpenapiSchemas(schema, *schemaRef.Value, true)
if err != nil {
return openapi3.Schema{}, fmt.Errorf("error merging schemas for AllOf: %w", err)
}
Expand All @@ -84,7 +84,7 @@ func mergeAllOf(allOf []*openapi3.SchemaRef) (openapi3.Schema, error) {

// mergeOpenapiSchemas merges two openAPI schemas and returns the schema
// all of whose fields are composed.
func mergeOpenapiSchemas(s1, s2 openapi3.Schema) (openapi3.Schema, error) {
func mergeOpenapiSchemas(s1, s2 openapi3.Schema, allOf bool) (openapi3.Schema, error) {
var result openapi3.Schema
if s1.Extensions != nil || s2.Extensions != nil {
result.Extensions = make(map[string]interface{})
Expand Down Expand Up @@ -219,8 +219,8 @@ func mergeOpenapiSchemas(s1, s2 openapi3.Schema) (openapi3.Schema, error) {
result.AdditionalProperties = s2.AdditionalProperties
}

// Unhandled for now
if s1.Discriminator != nil || s2.Discriminator != nil {
// Allow discriminators for allOf merges, but disallow for one/anyOfs.
if !allOf && (s1.Discriminator != nil || s2.Discriminator != nil) {
return openapi3.Schema{}, errors.New("merging two schemas with discriminators is not supported")
}

Expand Down

0 comments on commit 597fa8d

Please sign in to comment.