Skip to content

Commit

Permalink
protoc-gen-swagger: remove boolean format (grpc-ecosystem#1597)
Browse files Browse the repository at this point in the history
* protoc-gen-swagger: remove boolean format

* update examples for test
  • Loading branch information
algas authored Aug 13, 2020
1 parent f3b7d47 commit 26da007
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
8 changes: 0 additions & 8 deletions examples/internal/clients/abe/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ paths:
in: "query"
required: false
type: "boolean"
format: "boolean"
x-exportParamName: "BoolValue"
x-optionalDataType: "Bool"
- name: "string_value"
Expand Down Expand Up @@ -487,7 +486,6 @@ paths:
in: "query"
required: false
type: "boolean"
format: "boolean"
x-exportParamName: "BoolValue"
x-optionalDataType: "Bool"
- name: "string_value"
Expand Down Expand Up @@ -768,7 +766,6 @@ paths:
in: "query"
required: false
type: "boolean"
format: "boolean"
x-exportParamName: "BoolValue"
x-optionalDataType: "Bool"
- name: "bytes_value"
Expand Down Expand Up @@ -1064,7 +1061,6 @@ paths:
in: "query"
required: false
type: "boolean"
format: "boolean"
x-exportParamName: "BoolValue"
x-optionalDataType: "Bool"
- name: "string_value"
Expand Down Expand Up @@ -1335,7 +1331,6 @@ paths:
in: "path"
required: true
type: "boolean"
format: "boolean"
x-exportParamName: "BoolValue"
- name: "string_value"
in: "path"
Expand Down Expand Up @@ -1662,7 +1657,6 @@ paths:
type: "array"
items:
type: "boolean"
format: "boolean"
collectionFormat: "csv"
minItems: 1
x-exportParamName: "PathRepeatedBoolValue"
Expand Down Expand Up @@ -2357,7 +2351,6 @@ definitions:
format: "int64"
bool_value:
type: "boolean"
format: "boolean"
string_value:
type: "string"
bytes_value:
Expand Down Expand Up @@ -2496,7 +2489,6 @@ definitions:
type: "array"
items:
type: "boolean"
format: "boolean"
path_repeated_string_value:
type: "array"
items:
Expand Down
24 changes: 8 additions & 16 deletions examples/internal/proto/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@
"name": "bool_value",
"in": "query",
"required": false,
"type": "boolean",
"format": "boolean"
"type": "boolean"
},
{
"name": "string_value",
Expand Down Expand Up @@ -577,8 +576,7 @@
"name": "bool_value",
"in": "query",
"required": false,
"type": "boolean",
"format": "boolean"
"type": "boolean"
},
{
"name": "string_value",
Expand Down Expand Up @@ -886,8 +884,7 @@
"name": "bool_value",
"in": "query",
"required": false,
"type": "boolean",
"format": "boolean"
"type": "boolean"
},
{
"name": "bytes_value",
Expand Down Expand Up @@ -1208,8 +1205,7 @@
"name": "bool_value",
"in": "query",
"required": false,
"type": "boolean",
"format": "boolean"
"type": "boolean"
},
{
"name": "string_value",
Expand Down Expand Up @@ -1512,8 +1508,7 @@
"name": "bool_value",
"in": "path",
"required": true,
"type": "boolean",
"format": "boolean"
"type": "boolean"
},
{
"name": "string_value",
Expand Down Expand Up @@ -1946,8 +1941,7 @@
"required": true,
"type": "array",
"items": {
"type": "boolean",
"format": "boolean"
"type": "boolean"
},
"collectionFormat": "csv",
"minItems": 1
Expand Down Expand Up @@ -2846,8 +2840,7 @@
"format": "int64"
},
"bool_value": {
"type": "boolean",
"format": "boolean"
"type": "boolean"
},
"string_value": {
"type": "string"
Expand Down Expand Up @@ -3049,8 +3042,7 @@
"path_repeated_bool_value": {
"type": "array",
"items": {
"type": "boolean",
"format": "boolean"
"type": "boolean"
}
},
"path_repeated_string_value": {
Expand Down
3 changes: 1 addition & 2 deletions examples/internal/proto/examplepb/stream.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,7 @@
"format": "int64"
},
"bool_value": {
"type": "boolean",
"format": "boolean"
"type": "boolean"
},
"string_value": {
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
},
"access": {
"type": "boolean",
"format": "boolean",
"title": "Whether you have access or not"
}
}
Expand Down
10 changes: 6 additions & 4 deletions protoc-gen-swagger/genswagger/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,10 @@ func primitiveSchema(t pbdescriptor.FieldDescriptorProto_Type) (ftype, format st
// Ditto.
return "integer", "int64", true
case pbdescriptor.FieldDescriptorProto_TYPE_BOOL:
return "boolean", "boolean", true
// NOTE: in swagger specification, format should be empty on boolean type
return "boolean", "", true
case pbdescriptor.FieldDescriptorProto_TYPE_STRING:
// NOTE: in swagger specifition, format should be empty on string type
// NOTE: in swagger specification, format should be empty on string type
return "string", "", true
case pbdescriptor.FieldDescriptorProto_TYPE_BYTES:
return "string", "byte", true
Expand Down Expand Up @@ -1919,13 +1920,14 @@ func protoJSONSchemaTypeToFormat(in []swagger_options.JSONSchema_JSONSchemaSimpl
case swagger_options.JSONSchema_ARRAY:
return "array", ""
case swagger_options.JSONSchema_BOOLEAN:
return "boolean", "boolean"
// NOTE: in swagger specification, format should be empty on boolean type
return "boolean", ""
case swagger_options.JSONSchema_INTEGER:
return "integer", "int32"
case swagger_options.JSONSchema_NUMBER:
return "number", "double"
case swagger_options.JSONSchema_STRING:
// NOTE: in swagger specifition, format should be empty on string type
// NOTE: in swagger specification, format should be empty on string type
return "string", ""
default:
// Maybe panic?
Expand Down

0 comments on commit 26da007

Please sign in to comment.