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
36 changes: 36 additions & 0 deletions examples/union/anyof-query-params/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Union Query Parameters Example

This example demonstrates parameters whose schema is a union with two or more non-null variants.

## Behavior

A parameter union is generated as a named type with its own marshaler, so the value reaches the request. A single non-null variant next to `null` still collapses to a plain pointer.

```yaml
# two non-null variants and null
- name: parentID
in: query
schema:
anyOf:
- $ref: '#/components/schemas/WidgetID'
- type: string
enum: ["null"]
- type: "null"
```
Generates: `ParentID *ListGadgetsQuery_ParentID`, which wraps the `anyOf` and encodes as `parentID=w1`.

```yaml
# one non-null variant and null
- name: order
in: query
schema:
anyOf:
- type: string
enum: ["asc", "desc"]
- type: "null"
```
Generates: `Order *ListGizmosQueryOrderAnyOf` (no wrapper).

The same applies to path and header parameters.

The config also generates a `std-http` handler, so the request adapter has to parse into the same named type; the example would not compile otherwise.
57 changes: 57 additions & 0 deletions examples/union/anyof-query-params/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
openapi: 3.1.0
info: {title: t, version: 0.0.0}
paths:
/widgets:
get:
operationId: listWidgets
parameters:
- name: parentID
in: query
schema:
anyOf:
- anyOf:
- $ref: '#/components/schemas/WidgetID'
- type: string
enum: ["null"]
- type: "null"
responses:
"200": {description: OK, content: {application/json: {schema: {type: array, items: {type: string}}}}}
/gadgets:
get:
operationId: listGadgets
parameters:
- name: parentID
in: query
schema:
anyOf:
- $ref: '#/components/schemas/WidgetID'
- type: string
enum: ["null"]
- type: "null"
responses:
"200": {description: OK, content: {application/json: {schema: {type: array, items: {type: string}}}}}
/gizmos:
get:
operationId: listGizmos
parameters:
- name: order
in: query
schema:
anyOf:
- type: string
enum: ["asc", "desc"]
- type: "null"
- name: statuses
in: query
schema:
type: array
items:
oneOf:
- $ref: '#/components/schemas/WidgetID'
- type: string
enum: ["unpublished"]
responses:
"200": {description: OK, content: {application/json: {schema: {type: array, items: {type: string}}}}}
components:
schemas:
WidgetID: {type: string}
5 changes: 5 additions & 0 deletions examples/union/anyof-query-params/cfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package: gen
generate:
client: true
handler:
kind: std-http
Loading
Loading