Created
February 16, 2018 15:19
-
-
Save vrialland/7031316121cb8e025dfca9dccfc226b1 to your computer and use it in GitHub Desktop.
Example OpenAPI 3 polymorphism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
openapi: "3.0.0" | |
info: | |
version: 1.0.0 | |
title: Vehicles | |
description: Polymorphism example | |
paths: | |
/vehicles: | |
get: | |
summary: List all vehicles | |
tags: | |
- vehicles | |
responses: | |
'200': | |
description: An paged array of vehicles | |
content: | |
application/json: | |
schema: | |
$ref: "#/components/schemas/Vehicle" | |
default: | |
description: unexpected error | |
content: | |
application/json: | |
schema: | |
$ref: "#/components/schemas/Error" | |
/vehicles/{id}: | |
get: | |
summary: Info for a specific vehicle | |
tags: | |
- vehicles | |
parameters: | |
- name: id | |
in: path | |
required: true | |
description: The id of vehicle to retrieve | |
schema: | |
type: string | |
responses: | |
'200': | |
description: Expected response to a valid request | |
content: | |
application/json: | |
schema: | |
oneOf: | |
- $ref: "#/components/schemas/Car" | |
- $ref: "#/components/schemas/Plane" | |
discriminator: | |
propertyName: type | |
default: | |
description: unexpected error | |
content: | |
application/json: | |
schema: | |
$ref: "#/components/schemas/Error" | |
components: | |
schemas: | |
Vehicle: | |
type: object | |
required: | |
- id | |
- type | |
properties: | |
id: | |
type: integer | |
type: | |
type: string | |
model: | |
type: string | |
name: | |
type: string | |
discriminator: | |
propertyName: type | |
Car: | |
allOf: | |
- $ref: "#/components/schemas/Vehicle" | |
- type: object | |
properties: | |
type: | |
enum: | |
- car | |
has_4_wheel_drive: | |
type: boolean | |
Plane: | |
allOf: | |
- $ref: "#/components/schemas/Vehicle" | |
- type: object | |
properties: | |
type: | |
enum: | |
- plane | |
has_reactor: | |
type: boolean | |
nb_passengers: | |
type: integer | |
Error: | |
required: | |
- code | |
- message | |
properties: | |
code: | |
type: integer | |
format: int32 | |
message: | |
type: string |
I have the same issue. Trying to implement a polymorphic API using connexion and openapi 3.0. Have you made any progress?
Kind regards,
Jeroen
Same thing happens with me. :|
requestBody:
content:
application/json:
schema:
discriminator:
propertyName: type
mapping:
Car: "#/components/schemas/Car"
Plane: "#/components/schemas/Plane"
anyOf:
- $ref: "#/components/schemas/Car"
- $ref: "#/components/schemas/Plane"
summary: List all vehicles
tags:
- vehicles
responses:
'200':
description: An paged array of vehicles
content:
application/json:
schema:
$ref: "#/components/schemas/Vehicle"
default:
description: unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error
i made some changes on your configuration. It's working now.
@EmineKarakayali
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm struggling to validate against polymorphic models in the request body of a POST. I tried this:
Then, when I post
connexion tells me that the post body doesn't validate against the schema.
Do you know of an example that demonstrates POST and GET of polymorphic models?