Skip to content

Commit 3207a66

Browse files
committed
refactor: logic improvment to response item support
1 parent 6460088 commit 3207a66

File tree

3 files changed

+262
-252
lines changed

3 files changed

+262
-252
lines changed

Diff for: protoc-gen-openapiv2/internal/genopenapi/template.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,10 @@ func getFieldBehaviorOption(reg *descriptor.Registry, fd *descriptor.Field) ([]a
26222622
func protoJSONSchemaToOpenAPISchemaCore(j *openapi_options.JSONSchema, reg *descriptor.Registry, refs refMap) schemaCore {
26232623
ret := schemaCore{}
26242624

2625+
if j == nil {
2626+
return ret
2627+
}
2628+
26252629
if j.GetRef() != "" {
26262630
openapiName, ok := fullyQualifiedNameToOpenAPIName(j.GetRef(), reg)
26272631
if ok {
@@ -2633,13 +2637,15 @@ func protoJSONSchemaToOpenAPISchemaCore(j *openapi_options.JSONSchema, reg *desc
26332637
ret.Ref += j.GetRef()
26342638
}
26352639
} else {
2636-
f, t := protoJSONSchemaTypeToFormat(j.GetType())
2640+
typ := j.GetType()
26372641

2638-
if items := j.GetItems(); items != nil && f == "array" {
2642+
if len(typ) > 0 && typ[0] == openapi_options.JSONSchema_ARRAY {
26392643
ret.Items = &openapiItemsObject{
2640-
schemaCore: protoJSONSchemaToOpenAPISchemaCore(items, reg, refs),
2644+
schemaCore: protoJSONSchemaToOpenAPISchemaCore(j.GetItems(), reg, refs),
26412645
}
26422646
} else {
2647+
f, t := protoJSONSchemaTypeToFormat(typ)
2648+
26432649
ret.Format = f
26442650
ret.Type = t
26452651
}

0 commit comments

Comments
 (0)