Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ bracket form most form APIs read, Stripe's among them: a bracket per level, an i
| `[{price: p1}]` | `items[0][price]=p1` |
| `{a: {b: [1]}}` | `filter[a][b][0]=1` |
| `https://x.test`, one value | `url=https%3A%2F%2Fx.test` |
| a union, `{gte: 1}` or `1` | `created[gte]=1` or `created=1` |

Brackets are shown as they read. On the wire they are `%5B` and `%5D`.

Expand Down
6 changes: 5 additions & 1 deletion docs/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,17 @@ OpenAPI defines `deepObject` for an object of scalars only. Lists, nesting and s
[the bracket form](client.md#deepobject-past-an-object) of the client. The server also reads `[]`
and a repeated bare name: `expand[]=a`, `expand=a&expand=b`.

A union reads keys with brackets as an object member and a bare name as one value: `created[gte]=1`
and `created=1` both work. A `deepObject` parameter that comes both ways, `created=1&created[gte]=1`,
is a 400.

### Parameters without a field

Some parameters cannot be read, so they get no field. Generation warns about each one.

| Parameter | Warning |
|---|---|
| a query, header or cookie parameter whose union has an object or array variant, or a list or map of such unions. No style writes it as text. | `param-unsupported` |
| a query, header or cookie parameter whose union has an object or array variant, or a list or map of such unions. No style but `deepObject` writes it. | `param-unsupported` |
| a parameter or response header in a style the OpenAPI style table does not define for its location or value. See below. | `param-unsupported` |
| a form-style cookie that holds a list or object with `explode: true`. OpenAPI says it writes the wrong delimiter for cookies. `style: cookie` writes it. | `param-unsupported` |
| nesting the table above does not list | `param-unsupported` |
Expand Down
6 changes: 4 additions & 2 deletions docs/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ type Device struct {
a union takes any JSON for it.
- A parameter or header of such a type needs one that implements `encoding.TextMarshaler` and
`encoding.TextUnmarshaler`.
- A union parameter with such a member gets no field, with a warning.
- A union parameter with such a member gets no field, with a warning, unless its style is
`deepObject`.

## Pointers

Expand Down Expand Up @@ -489,7 +490,8 @@ A union of strings, numbers and booleans with no shared properties also gets `Ma
- Text that reads as a JSON number or boolean is tried as one first, then as a string.
- A union with nothing set has no text: sending it is an error.
- A query, header or cookie parameter whose union has an object or array variant gets no field,
with a warning. So does a list or map of such unions.
with a warning. So does a list or map of such unions. A `deepObject` query parameter is the
exception: it is written with brackets, `created[gte]=1` or `created=1`.

#### Forms

Expand Down
6 changes: 6 additions & 0 deletions examples/client/params/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ paths:
in: query
schema: {type: object, properties: {reference: {type: string}, status: {type: array, items: {type: string}}}}
- {name: id, in: query, schema: {oneOf: [{type: integer}, {type: string}]}}
- {name: created, in: query, style: deepObject, schema: {anyOf: [{$ref: '#/components/schemas/Range'}, {type: integer}]}}
- {name: ids, in: query, allowReserved: true, schema: {type: string}}
- {name: needed, in: query, required: true, schema: {type: string}}
responses:
Expand Down Expand Up @@ -92,6 +93,11 @@ paths:
application/json: {schema: {$ref: '#/components/schemas/Echo'}}
components:
schemas:
Range:
type: object
properties:
gte: {type: integer}
lt: {type: integer}
Point:
type: object
properties:
Expand Down
67 changes: 67 additions & 0 deletions examples/client/params/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions examples/client/params/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ func TestQueryStyles(t *testing.T) {
query: &QueryStylesQuery{ID: &QueryStylesQueryID{String: new("a7")}, Needed: "yes"},
want: "id=a7&needed=yes",
},
{
name: "A deepObject union writes an object variant under brackets",
query: &QueryStylesQuery{Created: &QueryStylesQueryCreated{Range: &Range{Gte: new(1), Lt: new(2)}}, Needed: "yes"},
want: "created%5Bgte%5D=1&created%5Blt%5D=2&needed=yes",
},
{
name: "A deepObject union writes one value under its name",
query: &QueryStylesQuery{Created: &QueryStylesQueryCreated{Int: new(5)}, Needed: "yes"},
want: "created=5&needed=yes",
},
{
name: "A space and a comma inside an item are escaped, reserved characters kept where allowed",
query: &QueryStylesQuery{Csv: []string{"a b", "c,d"}, IDs: new("List(1,2)"), Needed: "x y"},
Expand Down
6 changes: 6 additions & 0 deletions examples/server/beego/params/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ paths:
- {name: flat, in: query, explode: false, schema: {$ref: '#/components/schemas/Point'}}
- {name: json, in: query, content: {application/json: {schema: {$ref: '#/components/schemas/Point'}}}}
- {name: id, in: query, schema: {oneOf: [{type: integer}, {type: string}]}}
- {name: created, in: query, style: deepObject, schema: {anyOf: [{$ref: '#/components/schemas/Range'}, {type: integer}]}}
- {name: needed, in: query, required: true, schema: {type: string}}
- {name: limit, in: query, schema: {type: integer, default: 20}}
responses:
Expand Down Expand Up @@ -77,6 +78,11 @@ paths:
application/json: {schema: {$ref: '#/components/schemas/Echo'}}
components:
schemas:
Range:
type: object
properties:
gte: {type: integer}
lt: {type: integer}
Point:
type: object
properties:
Expand Down
90 changes: 80 additions & 10 deletions examples/server/beego/params/gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions examples/server/chi/params/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ paths:
- {name: flat, in: query, explode: false, schema: {$ref: '#/components/schemas/Point'}}
- {name: json, in: query, content: {application/json: {schema: {$ref: '#/components/schemas/Point'}}}}
- {name: id, in: query, schema: {oneOf: [{type: integer}, {type: string}]}}
- {name: created, in: query, style: deepObject, schema: {anyOf: [{$ref: '#/components/schemas/Range'}, {type: integer}]}}
- {name: needed, in: query, required: true, schema: {type: string}}
- {name: limit, in: query, schema: {type: integer, default: 20}}
responses:
Expand Down Expand Up @@ -77,6 +78,11 @@ paths:
application/json: {schema: {$ref: '#/components/schemas/Echo'}}
components:
schemas:
Range:
type: object
properties:
gte: {type: integer}
lt: {type: integer}
Point:
type: object
properties:
Expand Down
Loading
Loading