@@ -518,14 +518,24 @@ func renderEnumerationsAsDefinition(enums enumMap, d swaggerDefinitionsObject, r
518518
519519// Take in a FQMN or FQEN and return a swagger safe version of the FQMN
520520func fullyQualifiedNameToSwaggerName (fqn string , reg * descriptor.Registry ) string {
521+ ret , _ := fullyQualifiedNameToSwaggerNameOk (fqn , reg )
522+ return ret
523+ }
524+
525+ // Take in a FQMN or FQEN and return a swagger safe version of the FQMN and
526+ // a boolean indicating if FQMN was properly resolved.
527+ // TODO utrack: bad name?
528+ func fullyQualifiedNameToSwaggerNameOk (fqn string , reg * descriptor.Registry ) (string , bool ) {
521529 registriesSeenMutex .Lock ()
522530 defer registriesSeenMutex .Unlock ()
523531 if mapping , present := registriesSeen [reg ]; present {
524- return mapping [fqn ]
532+ ret , ok := mapping [fqn ]
533+ return ret , ok
525534 }
526535 mapping := resolveFullyQualifiedNameToSwaggerNames (append (reg .GetAllFQMNs (), reg .GetAllFQENs ()... ), reg .GetUseFQNForSwaggerName ())
527536 registriesSeen [reg ] = mapping
528- return mapping [fqn ]
537+ ret , ok := mapping [fqn ]
538+ return ret , ok
529539}
530540
531541// registriesSeen is used to memoise calls to resolveFullyQualifiedNameToSwaggerNames so
@@ -849,7 +859,8 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
849859 desc += "(streaming responses)"
850860 responseSchema .Type = "object"
851861 responseSchema .Title = fmt .Sprintf ("Stream result of %s" , fullyQualifiedNameToSwaggerName (meth .ResponseType .FQMN (), reg ))
852- responseSchema .Properties = & swaggerSchemaObjectProperties {
862+
863+ props := swaggerSchemaObjectProperties {
853864 keyVal {
854865 Key : "result" ,
855866 Value : swaggerSchemaObject {
@@ -858,14 +869,18 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
858869 },
859870 },
860871 },
861- keyVal {
872+ }
873+ streamErrDef , hasStreamError := fullyQualifiedNameToSwaggerNameOk (".grpc.gateway.runtime.StreamError" , reg )
874+ if hasStreamError {
875+ props = append (props , keyVal {
862876 Key : "error" ,
863877 Value : swaggerSchemaObject {
864878 schemaCore : schemaCore {
865- Ref : fmt .Sprintf ("#/definitions/%s" , fullyQualifiedNameToSwaggerName ( ".grpc.gateway.runtime.StreamError" , reg ) )},
879+ Ref : fmt .Sprintf ("#/definitions/%s" , streamErrDef )},
866880 },
867- },
881+ })
868882 }
883+ responseSchema .Properties = & props
869884 responseSchema .Ref = ""
870885 }
871886
@@ -885,14 +900,17 @@ func renderServices(services []*descriptor.Service, paths swaggerPathsObject, re
885900 },
886901 }
887902 if ! reg .GetDisableDefaultErrors () {
888- // https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#responses-object
889- operationObject .Responses ["default" ] = swaggerResponseObject {
890- Description : "An unexpected error response" ,
891- Schema : swaggerSchemaObject {
892- schemaCore : schemaCore {
893- Ref : fmt .Sprintf ("#/definitions/%s" , fullyQualifiedNameToSwaggerName (".grpc.gateway.runtime.Error" , reg )),
903+ errDef , hasErrDef := fullyQualifiedNameToSwaggerNameOk (".grpc.gateway.runtime.Error" , reg )
904+ if hasErrDef {
905+ // https://github.com/OAI/OpenAPI-Specification/blob/3.0.0/versions/2.0.md#responses-object
906+ operationObject .Responses ["default" ] = swaggerResponseObject {
907+ Description : "An unexpected error response" ,
908+ Schema : swaggerSchemaObject {
909+ schemaCore : schemaCore {
910+ Ref : fmt .Sprintf ("#/definitions/%s" , errDef ),
911+ },
894912 },
895- },
913+ }
896914 }
897915 }
898916 if bIdx == 0 {
0 commit comments