Skip to content

Commit e707445

Browse files
committed
protoc-gen-openapi: remove duplicate body params
When a request has both path parameters and body = "*", the path parameters were being repeated in the body. But according to the docs: the special name `*` is used to define that every field not bound by the path template should be mapped to the request body. This commit does exactly that, when the body is `*` and there are some path parameters, then the a new message schema is created that does not include the path parameters. The name of the schema is the same as the message name, with the `_Body` suffix. fixes google#323
1 parent ad271d5 commit e707445

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1754
-225
lines changed

cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi.yaml

+6-18
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ paths:
335335
content:
336336
application/json:
337337
schema:
338-
$ref: '#/components/schemas/MoveBookRequest'
338+
$ref: '#/components/schemas/MoveBookRequest_Body'
339339
required: true
340340
responses:
341341
"200":
@@ -374,7 +374,7 @@ paths:
374374
content:
375375
application/json:
376376
schema:
377-
$ref: '#/components/schemas/MergeShelvesRequest'
377+
$ref: '#/components/schemas/MergeShelvesRequest_Body'
378378
required: true
379379
responses:
380380
"200":
@@ -469,36 +469,24 @@ components:
469469
field in the subsequent call to `ListShelves` method to retrieve the next
470470
page of results.
471471
description: Response message for LibraryService.ListShelves.
472-
MergeShelvesRequest:
472+
MergeShelvesRequest_Body:
473473
required:
474-
- name
475474
- other_shelf_name
476475
type: object
477476
properties:
478-
name:
479-
type: string
480-
description: The name of the shelf we're adding books to.
481477
other_shelf_name:
482478
type: string
483479
description: The name of the shelf we're removing books from and deleting.
484-
description: |-
485-
Describes the shelf being removed (other_shelf_name) and updated
486-
(name) in this merge.
487-
MoveBookRequest:
480+
description: The body of LibraryService_MergeShelves
481+
MoveBookRequest_Body:
488482
required:
489-
- name
490483
- other_shelf_name
491484
type: object
492485
properties:
493-
name:
494-
type: string
495-
description: The name of the book to move.
496486
other_shelf_name:
497487
type: string
498488
description: The name of the destination shelf.
499-
description: |-
500-
Describes what book to move (name) and what shelf we're moving it
501-
to (other_shelf_name).
489+
description: The body of LibraryService_MoveBook
502490
Shelf:
503491
required:
504492
- name

cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_default_response.yaml

+6-18
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ paths:
335335
content:
336336
application/json:
337337
schema:
338-
$ref: '#/components/schemas/MoveBookRequest'
338+
$ref: '#/components/schemas/MoveBookRequest_Body'
339339
required: true
340340
responses:
341341
"200":
@@ -374,7 +374,7 @@ paths:
374374
content:
375375
application/json:
376376
schema:
377-
$ref: '#/components/schemas/MergeShelvesRequest'
377+
$ref: '#/components/schemas/MergeShelvesRequest_Body'
378378
required: true
379379
responses:
380380
"200":
@@ -469,36 +469,24 @@ components:
469469
field in the subsequent call to `ListShelves` method to retrieve the next
470470
page of results.
471471
description: Response message for LibraryService.ListShelves.
472-
MergeShelvesRequest:
472+
MergeShelvesRequest_Body:
473473
required:
474-
- name
475474
- otherShelfName
476475
type: object
477476
properties:
478-
name:
479-
type: string
480-
description: The name of the shelf we're adding books to.
481477
otherShelfName:
482478
type: string
483479
description: The name of the shelf we're removing books from and deleting.
484-
description: |-
485-
Describes the shelf being removed (other_shelf_name) and updated
486-
(name) in this merge.
487-
MoveBookRequest:
480+
description: The body of LibraryService_MergeShelves
481+
MoveBookRequest_Body:
488482
required:
489-
- name
490483
- otherShelfName
491484
type: object
492485
properties:
493-
name:
494-
type: string
495-
description: The name of the book to move.
496486
otherShelfName:
497487
type: string
498488
description: The name of the destination shelf.
499-
description: |-
500-
Describes what book to move (name) and what shelf we're moving it
501-
to (other_shelf_name).
489+
description: The body of LibraryService_MoveBook
502490
Shelf:
503491
required:
504492
- name

cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_fq_schema_naming.yaml

+6-18
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ paths:
335335
content:
336336
application/json:
337337
schema:
338-
$ref: '#/components/schemas/google.example.library.v1.MoveBookRequest'
338+
$ref: '#/components/schemas/google.example.library.v1.MoveBookRequest_Body'
339339
required: true
340340
responses:
341341
"200":
@@ -374,7 +374,7 @@ paths:
374374
content:
375375
application/json:
376376
schema:
377-
$ref: '#/components/schemas/google.example.library.v1.MergeShelvesRequest'
377+
$ref: '#/components/schemas/google.example.library.v1.MergeShelvesRequest_Body'
378378
required: true
379379
responses:
380380
"200":
@@ -461,36 +461,24 @@ components:
461461
field in the subsequent call to `ListShelves` method to retrieve the next
462462
page of results.
463463
description: Response message for LibraryService.ListShelves.
464-
google.example.library.v1.MergeShelvesRequest:
464+
google.example.library.v1.MergeShelvesRequest_Body:
465465
required:
466-
- name
467466
- otherShelfName
468467
type: object
469468
properties:
470-
name:
471-
type: string
472-
description: The name of the shelf we're adding books to.
473469
otherShelfName:
474470
type: string
475471
description: The name of the shelf we're removing books from and deleting.
476-
description: |-
477-
Describes the shelf being removed (other_shelf_name) and updated
478-
(name) in this merge.
479-
google.example.library.v1.MoveBookRequest:
472+
description: The body of LibraryService_MergeShelves
473+
google.example.library.v1.MoveBookRequest_Body:
480474
required:
481-
- name
482475
- otherShelfName
483476
type: object
484477
properties:
485-
name:
486-
type: string
487-
description: The name of the book to move.
488478
otherShelfName:
489479
type: string
490480
description: The name of the destination shelf.
491-
description: |-
492-
Describes what book to move (name) and what shelf we're moving it
493-
to (other_shelf_name).
481+
description: The body of LibraryService_MoveBook
494482
google.example.library.v1.Shelf:
495483
required:
496484
- name

cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_json.yaml

+6-18
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ paths:
335335
content:
336336
application/json:
337337
schema:
338-
$ref: '#/components/schemas/MoveBookRequest'
338+
$ref: '#/components/schemas/MoveBookRequest_Body'
339339
required: true
340340
responses:
341341
"200":
@@ -374,7 +374,7 @@ paths:
374374
content:
375375
application/json:
376376
schema:
377-
$ref: '#/components/schemas/MergeShelvesRequest'
377+
$ref: '#/components/schemas/MergeShelvesRequest_Body'
378378
required: true
379379
responses:
380380
"200":
@@ -469,36 +469,24 @@ components:
469469
field in the subsequent call to `ListShelves` method to retrieve the next
470470
page of results.
471471
description: Response message for LibraryService.ListShelves.
472-
MergeShelvesRequest:
472+
MergeShelvesRequest_Body:
473473
required:
474-
- name
475474
- otherShelfName
476475
type: object
477476
properties:
478-
name:
479-
type: string
480-
description: The name of the shelf we're adding books to.
481477
otherShelfName:
482478
type: string
483479
description: The name of the shelf we're removing books from and deleting.
484-
description: |-
485-
Describes the shelf being removed (other_shelf_name) and updated
486-
(name) in this merge.
487-
MoveBookRequest:
480+
description: The body of LibraryService_MergeShelves
481+
MoveBookRequest_Body:
488482
required:
489-
- name
490483
- otherShelfName
491484
type: object
492485
properties:
493-
name:
494-
type: string
495-
description: The name of the book to move.
496486
otherShelfName:
497487
type: string
498488
description: The name of the destination shelf.
499-
description: |-
500-
Describes what book to move (name) and what shelf we're moving it
501-
to (other_shelf_name).
489+
description: The body of LibraryService_MoveBook
502490
Shelf:
503491
required:
504492
- name

cmd/protoc-gen-openapi/examples/google/example/library/v1/openapi_string_enum.yaml

+6-18
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ paths:
335335
content:
336336
application/json:
337337
schema:
338-
$ref: '#/components/schemas/MoveBookRequest'
338+
$ref: '#/components/schemas/MoveBookRequest_Body'
339339
required: true
340340
responses:
341341
"200":
@@ -374,7 +374,7 @@ paths:
374374
content:
375375
application/json:
376376
schema:
377-
$ref: '#/components/schemas/MergeShelvesRequest'
377+
$ref: '#/components/schemas/MergeShelvesRequest_Body'
378378
required: true
379379
responses:
380380
"200":
@@ -469,36 +469,24 @@ components:
469469
field in the subsequent call to `ListShelves` method to retrieve the next
470470
page of results.
471471
description: Response message for LibraryService.ListShelves.
472-
MergeShelvesRequest:
472+
MergeShelvesRequest_Body:
473473
required:
474-
- name
475474
- otherShelfName
476475
type: object
477476
properties:
478-
name:
479-
type: string
480-
description: The name of the shelf we're adding books to.
481477
otherShelfName:
482478
type: string
483479
description: The name of the shelf we're removing books from and deleting.
484-
description: |-
485-
Describes the shelf being removed (other_shelf_name) and updated
486-
(name) in this merge.
487-
MoveBookRequest:
480+
description: The body of LibraryService_MergeShelves
481+
MoveBookRequest_Body:
488482
required:
489-
- name
490483
- otherShelfName
491484
type: object
492485
properties:
493-
name:
494-
type: string
495-
description: The name of the book to move.
496486
otherShelfName:
497487
type: string
498488
description: The name of the destination shelf.
499-
description: |-
500-
Describes what book to move (name) and what shelf we're moving it
501-
to (other_shelf_name).
489+
description: The body of LibraryService_MoveBook
502490
Shelf:
503491
required:
504492
- name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Generated with protoc-gen-openapi
2+
# https://github.com/google/gnostic/tree/master/cmd/protoc-gen-openapi
3+
4+
openapi: 3.0.3
5+
info:
6+
title: Messaging API
7+
version: 0.0.1
8+
paths:
9+
/v1/messages:
10+
patch:
11+
tags:
12+
- Messaging
13+
operationId: Messaging_UpdateMessage
14+
requestBody:
15+
content:
16+
application/json:
17+
schema:
18+
$ref: '#/components/schemas/Message'
19+
required: true
20+
responses:
21+
"200":
22+
description: OK
23+
content:
24+
application/json:
25+
schema:
26+
$ref: '#/components/schemas/Message'
27+
default:
28+
description: Default error response
29+
content:
30+
application/json:
31+
schema:
32+
$ref: '#/components/schemas/Status'
33+
/v1/messages/{messageId}:
34+
patch:
35+
tags:
36+
- Messaging
37+
operationId: Messaging_UpdateMessage
38+
parameters:
39+
- name: messageId
40+
in: path
41+
required: true
42+
schema:
43+
type: string
44+
requestBody:
45+
content:
46+
application/json:
47+
schema:
48+
type: string
49+
required: true
50+
responses:
51+
"200":
52+
description: OK
53+
content:
54+
application/json:
55+
schema:
56+
$ref: '#/components/schemas/Message'
57+
default:
58+
description: Default error response
59+
content:
60+
application/json:
61+
schema:
62+
$ref: '#/components/schemas/Status'
63+
components:
64+
schemas:
65+
GoogleProtobufAny:
66+
type: object
67+
properties:
68+
'@type':
69+
type: string
70+
description: The type of the serialized message.
71+
additionalProperties: true
72+
description: Contains an arbitrary serialized message along with a @type that describes the type of the serialized message.
73+
Message:
74+
type: object
75+
properties:
76+
messageId:
77+
type: string
78+
text:
79+
type: string
80+
Status:
81+
type: object
82+
properties:
83+
code:
84+
type: integer
85+
description: The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code].
86+
format: int32
87+
message:
88+
type: string
89+
description: A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client.
90+
details:
91+
type: array
92+
items:
93+
$ref: '#/components/schemas/GoogleProtobufAny'
94+
description: A list of messages that carry the error details. There is a common set of message types for APIs to use.
95+
description: 'The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).'
96+
tags:
97+
- name: Messaging

0 commit comments

Comments
 (0)