Skip to content

Commit

Permalink
refactor: logic improvment to response item support
Browse files Browse the repository at this point in the history
  • Loading branch information
krak3n committed Nov 23, 2022
1 parent 6460088 commit 3207a66
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 252 deletions.
12 changes: 9 additions & 3 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2622,6 +2622,10 @@ func getFieldBehaviorOption(reg *descriptor.Registry, fd *descriptor.Field) ([]a
func protoJSONSchemaToOpenAPISchemaCore(j *openapi_options.JSONSchema, reg *descriptor.Registry, refs refMap) schemaCore {
ret := schemaCore{}

if j == nil {
return ret
}

if j.GetRef() != "" {
openapiName, ok := fullyQualifiedNameToOpenAPIName(j.GetRef(), reg)
if ok {
Expand All @@ -2633,13 +2637,15 @@ func protoJSONSchemaToOpenAPISchemaCore(j *openapi_options.JSONSchema, reg *desc
ret.Ref += j.GetRef()
}
} else {
f, t := protoJSONSchemaTypeToFormat(j.GetType())
typ := j.GetType()

if items := j.GetItems(); items != nil && f == "array" {
if len(typ) > 0 && typ[0] == openapi_options.JSONSchema_ARRAY {
ret.Items = &openapiItemsObject{
schemaCore: protoJSONSchemaToOpenAPISchemaCore(items, reg, refs),
schemaCore: protoJSONSchemaToOpenAPISchemaCore(j.GetItems(), reg, refs),
}
} else {
f, t := protoJSONSchemaTypeToFormat(typ)

ret.Format = f
ret.Type = t
}
Expand Down
Loading

0 comments on commit 3207a66

Please sign in to comment.