Skip to content

Commit

Permalink
Simplify extensions merge in mergeOpenapiSchemas (#1424)
Browse files Browse the repository at this point in the history
From the Go specification [1]:

  "3. If the map is nil, the number of iterations is 0."

Therefore, an additional nil check for before the loop is unnecessary.

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
  • Loading branch information
Juneezee committed May 18, 2024
1 parent c8ba965 commit bf8962d
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions pkg/codegen/merge_schemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,14 @@ func mergeAllOf(allOf []*openapi3.SchemaRef) (openapi3.Schema, error) {
// all of whose fields are composed.
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{})
if s1.Extensions != nil {
for k, v := range s1.Extensions {
result.Extensions[k] = v
}
}
if s2.Extensions != nil {
for k, v := range s2.Extensions {
// TODO: Check for collisions
result.Extensions[k] = v
}
}

result.Extensions = make(map[string]interface{})
for k, v := range s1.Extensions {
result.Extensions[k] = v
}
for k, v := range s2.Extensions {
// TODO: Check for collisions
result.Extensions[k] = v
}

result.OneOf = append(s1.OneOf, s2.OneOf...)
Expand Down

0 comments on commit bf8962d

Please sign in to comment.