Skip to content

Commit

Permalink
Handle anyOf definition for property types (#156)
Browse files Browse the repository at this point in the history
* Handle anyOf definition for property types

* Update pkg/openapi.go

* Update pkg/openapi.go
  • Loading branch information
praneetloke authored May 24, 2024
1 parent abb383f commit a16d5fc
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,18 @@ func (ctx *resourceContext) propertyTypeSpec(parentName string, propSchema opena
valType = propSchema.Value.AnyOf[0].Value.Type
}

if len(propSchema.Value.AnyOf) > 1 {
unionTypes := make([]pschema.TypeSpec, 0, len(propSchema.Value.AnyOf))
for _, schemaRef := range propSchema.Value.AnyOf {
typeSpec, _, err := ctx.propertyTypeSpec(parentName, *schemaRef)
if err != nil {
return nil, false, errors.Wrap(err, "generating type spec from anyOf definition")
}
unionTypes = append(unionTypes, *typeSpec)
}
return &pschema.TypeSpec{OneOf: unionTypes}, false, nil
}

// All other types.
switch {
case valType.Is(openapi3.TypeInteger):
Expand Down

0 comments on commit a16d5fc

Please sign in to comment.