Skip to content

Instantly share code, notes, and snippets.

@vrialland
Created February 16, 2018 15:19
Show Gist options
  • Select an option

  • Save vrialland/7031316121cb8e025dfca9dccfc226b1 to your computer and use it in GitHub Desktop.

Select an option

Save vrialland/7031316121cb8e025dfca9dccfc226b1 to your computer and use it in GitHub Desktop.
Example OpenAPI 3 polymorphism
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
@jeroenvdm

Copy link
Copy Markdown

@reece,

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

@third-bank-of-the-river

Copy link
Copy Markdown

Same thing happens with me. :|

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment