From 11247b1b3c347d892e27b857fabd4846de230b2b Mon Sep 17 00:00:00 2001 From: Chris Reeves Date: Wed, 23 Nov 2022 11:12:23 +0000 Subject: [PATCH] refactor: logic improvment to response item support --- protoc-gen-openapiv2/internal/genopenapi/template.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/protoc-gen-openapiv2/internal/genopenapi/template.go b/protoc-gen-openapiv2/internal/genopenapi/template.go index 249f7e8bbe4..80675ccbe3e 100644 --- a/protoc-gen-openapiv2/internal/genopenapi/template.go +++ b/protoc-gen-openapiv2/internal/genopenapi/template.go @@ -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 { @@ -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 }