Skip to content

Instantly share code, notes, and snippets.

@johannes-riecken
Last active July 18, 2023 11:28
Show Gist options
  • Save johannes-riecken/868da658988170c5ddf5113b18ed7cfe to your computer and use it in GitHub Desktop.
Save johannes-riecken/868da658988170c5ddf5113b18ed7cfe to your computer and use it in GitHub Desktop.
openapi: 3.0.0
info:
title: "foo"
version: "0.0.1"
license:
url: "https://www.example.com"
name: "MIT"
servers:
- url: "http://localhost:8080"
paths:
/circles:
get:
responses:
200:
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Shape'
/rectangles:
get:
responses:
200:
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Shape'
/shapes:
get:
responses:
200:
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Shape'
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Shape'
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Shape'
404:
description: 'shape not found'
/shapes/{shapeId}:
get:
parameters:
- name: shapeId
in: path
required: true
schema:
type: integer
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Shape'
404:
description: 'shape not found'
components:
schemas:
Shape:
type: object
oneOf:
- $ref: '#/components/schemas/Circle'
- $ref: '#/components/schemas/Rectangle'
discriminator:
propertyName: kind
mapping:
Circle: '#/components/schemas/Circle'
Rectangle: '#/components/schemas/Rectangle'
example:
kind: circle
x: 1
y: 2
r: 3
ShapeBase:
type: object
properties:
id:
type: integer
kind:
type: string
x:
type: integer
y:
type: integer
required: ['kind', 'x', 'y']
Circle:
type: object
allOf:
- type: object
properties:
r:
type: integer
required: ['r']
- $ref: '#/components/schemas/ShapeBase'
Rectangle:
type: object
allOf:
- properties:
w:
type: integer
h:
type: integer
required: ['w', 'h']
- $ref: '#/components/schemas/ShapeBase'
requestBodies:
Shape:
content:
application/json:
schema:
$ref: '#/components/schemas/Shape'
openapi: 3.0.0
info:
title: "foo"
version: "0.0.1"
license:
url: "https://www.example.com"
name: "MIT"
servers:
- url: "http://localhost:8080"
paths:
/circles:
get:
responses:
200:
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Shape'
/rectangles:
get:
responses:
200:
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Shape'
/shapes:
get:
responses:
200:
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Shape'
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Shape'
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Shape'
404:
description: 'shape not found'
/shapes/{shapeId}:
get:
parameters:
- name: shapeId
in: path
required: true
schema:
type: integer
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Shape'
404:
description: 'shape not found'
components:
schemas:
Shape:
type: object
oneOf:
- $ref: '#/components/schemas/Circle'
- $ref: '#/components/schemas/Rectangle'
discriminator:
propertyName: kind
example:
kind: circle
x: 1
y: 2
r: 3
ShapeBase:
type: object
properties:
id:
type: integer
kind:
type: string
x:
type: integer
y:
type: integer
required: ['kind', 'x', 'y']
Circle:
type: object
allOf:
- type: object
properties:
r:
type: integer
required: ['r']
- $ref: '#/components/schemas/ShapeBase'
Rectangle:
type: object
allOf:
- properties:
w:
type: integer
h:
type: integer
required: ['w', 'h']
- $ref: '#/components/schemas/ShapeBase'
requestBodies:
Shape:
content:
application/json:
schema:
$ref: '#/components/schemas/Shape'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment