Skip to content

Commit

Permalink
protoc-gen-openapiv2: Fix schema types for Value and Empty well-k…
Browse files Browse the repository at this point in the history
…nown types (#2719)

* protoc-gen-openapiv2: Don't generate object schemas for `google.protobuf.Value`

* protoc-gen-openapiv2: Generate object schemas for `google.protobuf.Empty`

* Regenerate files
  • Loading branch information
haines authored May 27, 2022
1 parent f3fa3ce commit 0de16aa
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 33 deletions.
39 changes: 26 additions & 13 deletions examples/internal/clients/abe/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -1718,7 +1719,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -1790,7 +1792,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2237,7 +2240,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2288,7 +2292,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2418,7 +2423,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2449,7 +2455,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2525,7 +2532,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2556,7 +2564,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2598,7 +2607,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2637,7 +2647,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2681,7 +2692,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down Expand Up @@ -2720,7 +2732,8 @@ paths:
responses:
200:
description: "A successful response."
schema: {}
schema:
type: "object"
403:
description: "Returned when the user does not have permission to access\
\ the resource."
Expand Down
8 changes: 3 additions & 5 deletions examples/internal/clients/echo/api/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,12 @@ definitions:
structField:
type: "object"
properties: {}
valueField:
type: "object"
properties: {}
valueField: {}
description: "DynamicMessage represents a message which can have its structure\n\
built dynamically using Struct and Values."
example:
structField: "{}"
valueField: "{}"
valueField: ""
examplepbDynamicMessageUpdate:
type: "object"
properties:
Expand All @@ -603,7 +601,7 @@ definitions:
example:
body:
structField: "{}"
valueField: "{}"
valueField: ""
updateMask: "updateMask"
examplepbEmbedded:
type: "object"
Expand Down
19 changes: 19 additions & 0 deletions examples/internal/proto/examplepb/a_bit_of_everything.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -1915,6 +1916,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -2055,6 +2057,7 @@
}
},
"oneofEmpty": {
"type": "object",
"properties": {}
},
"oneofString": {
Expand Down Expand Up @@ -2225,6 +2228,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -2734,6 +2738,7 @@
}
},
"oneofEmpty": {
"type": "object",
"properties": {}
},
"oneofString": {
Expand Down Expand Up @@ -3019,6 +3024,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -3160,6 +3166,7 @@
}
},
"oneofEmpty": {
"type": "object",
"properties": {}
},
"oneofString": {
Expand Down Expand Up @@ -3284,6 +3291,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -3425,6 +3433,7 @@
}
},
"oneofEmpty": {
"type": "object",
"properties": {}
},
"oneofString": {
Expand Down Expand Up @@ -3689,6 +3698,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -3734,6 +3744,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -3827,6 +3838,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -3888,6 +3900,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -3933,6 +3946,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -3994,6 +4008,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -4051,6 +4066,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -4194,6 +4210,7 @@
}
},
"oneofEmpty": {
"type": "object",
"properties": {}
},
"oneofString": {
Expand Down Expand Up @@ -4326,6 +4343,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -4517,6 +4535,7 @@
}
},
"oneofEmpty": {
"type": "object",
"properties": {}
},
"oneofString": {
Expand Down
4 changes: 1 addition & 3 deletions examples/internal/proto/examplepb/echo_service.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,7 @@
"structField": {
"type": "object"
},
"valueField": {
"type": "object"
}
"valueField": {}
},
"description": "DynamicMessage represents a message which can have its structure\nbuilt dynamically using Struct and Values."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -189,6 +190,7 @@
}
},
"oneofEmpty": {
"type": "object",
"properties": {}
},
"oneofString": {
Expand Down
2 changes: 2 additions & 0 deletions examples/internal/proto/examplepb/stream.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand Down Expand Up @@ -316,6 +317,7 @@
}
},
"oneofEmpty": {
"type": "object",
"properties": {}
},
"oneofString": {
Expand Down
2 changes: 2 additions & 0 deletions examples/internal/proto/examplepb/wrappers.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
"200": {
"description": "A successful response.",
"schema": {
"type": "object",
"properties": {}
}
},
Expand All @@ -171,6 +172,7 @@
"in": "body",
"required": true,
"schema": {
"type": "object",
"properties": {}
}
}
Expand Down
1 change: 1 addition & 0 deletions protoc-gen-openapiv2/internal/genopenapi/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ go_test(
"@org_golang_google_protobuf//types/descriptorpb",
"@org_golang_google_protobuf//types/known/anypb",
"@org_golang_google_protobuf//types/known/durationpb",
"@org_golang_google_protobuf//types/known/emptypb",
"@org_golang_google_protobuf//types/known/structpb",
"@org_golang_google_protobuf//types/known/timestamppb",
"@org_golang_google_protobuf//types/known/wrapperspb",
Expand Down
6 changes: 3 additions & 3 deletions protoc-gen-openapiv2/internal/genopenapi/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ var wktSchemas = map[string]schemaCore{
".google.protobuf.BoolValue": {
Type: "boolean",
},
".google.protobuf.Empty": {},
".google.protobuf.Struct": {
".google.protobuf.Empty": {
Type: "object",
},
".google.protobuf.Value": {
".google.protobuf.Struct": {
Type: "object",
},
".google.protobuf.Value": {},
".google.protobuf.ListValue": {
Type: "array",
Items: (*openapiItemsObject)(&schemaCore{
Expand Down
Loading

0 comments on commit 0de16aa

Please sign in to comment.