-
-
Notifications
You must be signed in to change notification settings - Fork 351
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
Support for union type #551
Comments
That would be great, also when using OpenAPI's openapi: 3.0.3
info:
title: Sample API
description: Sample
version: '1.0'
paths:
/pets:
get:
responses:
'200':
description: Pets
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
components:
schemas:
Dog:
type: object
properties:
kind:
type: string
enum: [dog]
Cat:
type: object
properties:
kind:
type: string
enum: [cat] would generate: interface Dog {
kind: 'dog';
}
interface Cat {
kind: 'cat';
}
type PetsResponse = Dog | Cat which is a discriminated union. The whole thing would be like |
FYI this is not a valid OpenAPI specification, see https://swagger.io/specification/#schema-object
The correct way to model this would be Example:
type: object
oneOf:
- type: object
properties:
prop:
type: string
- type: object
properties:
prop:
type: number |
@DominicBach I updated the snipped to be complete (now it validates) and replaced the confusing double use of |
@DominicBach Type arrays are supported in OpenAPI 3.1: https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0 |
I added a PR for nullability that should fix this one as well: #645 |
The following schema:
Will yield the following type:
While the appropriate type would be:
It seems a property with more than one type is being treated as
unknown
.This is especially apparent when trying to document nullable properties.
Package Version: 6.9.6
The text was updated successfully, but these errors were encountered: