Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oneOf/anyOf support (including discriminator) #471

Merged
merged 13 commits into from May 31, 2022
32 changes: 15 additions & 17 deletions README.md
Expand Up @@ -315,6 +315,21 @@ define types for inner fields which themselves support additionalProperties, and
all of them are tested via the `internal/test/components` schemas and tests. Please
look through those tests for more usage examples.

#### oneOf/anyOf/allOf support

- `oneOf` and `anyOf` are implemented using delayed parsing with the help of `json.RawMessage`.
The following schema will result in a type that has methods such as `AsCat`, `AsDog`, `FromCat`, `FromDog`. If the schema also includes a discriminator the generated code will also have methods such as `Discriminator`, `ValueByDiscriminator` and will force discriminator value in `From` methods.
```yaml
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
```
- `allOf` is supported, by taking the union of all the fields in all the
component schemas. This is the most useful of these operations, and is
commonly used to merge objects with an identifier, as in the
`petstore-expanded` example.

## Generated Client Boilerplate

Once your server is up and running, you probably want to make requests to it. If
Expand Down Expand Up @@ -608,23 +623,6 @@ by comma separating them in the form `key1:value1,key2:value2`.
This code is still young, and not complete, since we're filling it in as we
need it. We've not yet implemented several things:

- `oneOf`, `anyOf` are not supported with strong Go typing. This schema:

schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'

will result in a Go type of `interface{}`. It will be up to you
to validate whether it conforms to `Cat` and/or `Dog`, depending on the
keyword. It's not clear if we can do anything much better here given the
limits of Go typing.

`allOf` is supported, by taking the union of all the fields in all the
component schemas. This is the most useful of these operations, and is
commonly used to merge objects with an identifier, as in the
`petstore-expanded` example.

- `patternProperties` isn't yet supported and will exit with an error. Pattern
properties were defined in JSONSchema, and the `kin-openapi` Swagger object
knows how to parse them, but they're not part of OpenAPI 3.0, so we've left
Expand Down