Commit c61f60e
authored
fix(openapiv2): Invalid entries in body parameter schema required array when using
* fix(openapiv2): remove invalid body field name from schema required array
When generating OpenAPI schemas for body parameters with body: "field_name"
and path parameters extracted from nested fields, the body field name was
incorrectly added to the schema's required array via updateSwaggerObjectFromFieldBehavior.
For example, with UpdateCommentRequest containing a required Comment field,
and Comment having a required "comment" field, when using path parameter
{comment.name} and body: "comment", the generated body schema incorrectly had:
required: ["comment", "resource", "author", "comment"]
Or when the field name doesn't exist as a property:
required: ["title", "direction"] where "direction" is not a property
This fix filters the required array after calling renderFieldAsDefinition to:
1. Remove duplicate entries of the body field name
2. Remove the body field name if it's not actually a property of the schema
The body parameter's required status is already correctly set via the
parameter's required: true attribute.
* chore(openapiv2): regenerate examples with body parameter required fix
The fix in template.go correctly removes invalid body field names from the
required array when they are not properties of the schema. This regeneration
updates a_bit_of_everything.swagger.json to remove the incorrectly included
'book' field from the required array in the UpdateBookRequest body parameter.
Related to body parameter schema generation fix.body: "field_name" (#6088)1 parent 7403f9c commit c61f60e
File tree
3 files changed
+510
-4
lines changed- examples/internal/proto/examplepb
- protoc-gen-openapiv2/internal/genopenapi
3 files changed
+510
-4
lines changedLines changed: 1 addition & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5071 | 5071 | | |
5072 | 5072 | | |
5073 | 5073 | | |
5074 | | - | |
5075 | | - | |
5076 | | - | |
5077 | | - | |
| 5074 | + | |
5078 | 5075 | | |
5079 | 5076 | | |
5080 | 5077 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1565 | 1565 | | |
1566 | 1566 | | |
1567 | 1567 | | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
1568 | 1601 | | |
1569 | 1602 | | |
1570 | 1603 | | |
| |||
0 commit comments