Skip to content

Commit 96fb53b

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 #323
1 parent ad271d5 commit 96fb53b

Some content is hidden

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

45 files changed

+1756
-227
lines changed

COMPILE-PROTOS.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
# limitations under the License.
1616
#
1717

18-
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
18+
go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.34.1
1919

2020
protoc -I . -I ./third_party --go_out=. --go_opt=paths=source_relative plugins/*.proto
2121
protoc -I . -I ./third_party --go_out=. --go_opt=paths=source_relative surface/*.proto
22-
protoc -I . -I ./third_party --go_out=. --go_opt=paths=source_relative metrics/*.proto
22+
protoc -I . -I ./third_party --go_out=. --go_opt=paths=source_relative metrics/*.proto

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

Lines changed: 6 additions & 18 deletions
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

Lines changed: 6 additions & 18 deletions
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

Lines changed: 6 additions & 18 deletions
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

Lines changed: 6 additions & 18 deletions
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

Lines changed: 6 additions & 18 deletions
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

0 commit comments

Comments
 (0)