Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

feat: add discriminator example from redocly #112

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 137 additions & 0 deletions 3.0/json/discriminators.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,38 @@
}
}
},
"/redocly-discriminator-madness": {
"patch": {
"operationId": "redoclyQuirk",
"summary": "Discriminator without `anyOf` or `oneOf` that Redocly supports",
"description": "Redocly allows users to define [a discriminator mapping without an `anyOf` or `oneOf` that contains the discriminated objects](https://redocly.com/docs/resources/discriminator#allof-for-inheritance). This endpoint demonstrates that.",
"tags": ["Quirks"],
"requestBody": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"vehicle": {
"$ref": "#/components/schemas/BaseVehicle"
},
"some_other_property": {
"type": "string",
"description": "Some other property that should render alongside the discriminated property",
"default": "default-value"
}
}
}
}
}
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/potentially-undefined-formData": {
"post": {
"summary": "Handling for potentially undefined formData",
Expand Down Expand Up @@ -626,6 +658,111 @@
}
},
"required": ["event_type", "event_id"]
},
"BaseVehicle": {
"type": "object",
"description": "Vehicle (from [Redocly example](https://redocly.com/docs/resources/discriminator#when-to-use-the-openapi-discriminator))",
"discriminator": {
"propertyName": "powerSource",
"mapping": {
"electricity": "#/components/schemas/ElectricVehicle",
"gasoline": "#/components/schemas/FueledVehicle",
"human-energy": "#/components/schemas/PedaledVehicle"
}
},
"properties": {
"vehicleType": {
"description": "The type of vehicle.",
"type": "string",
"example": "bicycle"
},
"idealTerrain": {
"description": "A road, river, air... Where does this vehicle thrive?",
"type": "string",
"example": "roads"
},
"powerSource": {
"description": "How is the vehicle powered.",
"type": "string",
"example": "pedaling"
},
"topSpeed": {
"description": "The top speed in kilometers per hour rounded to the nearest integer.",
"type": "integer",
"example": 83
},
"range": {
"description": "The 95th percentile range of a trip in kilometers.",
"type": "integer",
"example": 100
}
}
},
"ElectricVehicle": {
"allOf": [
{
"$ref": "#/components/schemas/BaseVehicle"
},
{
"type": "object",
"description": "Electric Vehicle",
"properties": {
"chargeSpeed": {
"description": "In range kilometers per hour.",
"type": "integer"
},
"chargeAmps": {
"description": "Amps recommended for charging.",
"type": "integer"
},
"chargeVoltage": {
"description": "Voltage recommended for charging.",
"type": "integer"
}
}
}
]
},
"FueledVehicle": {
"allOf": [
{
"$ref": "#/components/schemas/BaseVehicle"
},
{
"type": "object",
"title": "Gas-powered Vehicle",
"properties": {
"tankCapacity": {
"type": "number",
"format": "double",
"description": "Capacity of the fuel tank in gallons."
},
"milesPerGallon": {
"type": "number",
"format": "double",
"description": "Miles per gallon on the highway."
}
}
}
]
},
"PedaledVehicle": {
"allOf": [
{
"$ref": "#/components/schemas/BaseVehicle"
},
{
"type": "object",
"description": "Pedaled Vehicle",
"properties": {
"handlebars": {
"type": "string",
"description": "Type of handlebars",
"enum": ["flat", "riser", "bullhorn", "drop", "aero", "cruiser"]
}
}
}
]
}
}
}
Expand Down
97 changes: 97 additions & 0 deletions 3.0/yaml/discriminators.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ paths:
responses:
'200':
description: OK
'/redocly-discriminator-madness':
patch:
operationId: redoclyQuirk
summary: Discriminator without `anyOf` or `oneOf` that Redocly supports
description: Redocly allows users to define [a discriminator mapping without an `anyOf` or `oneOf` that contains the discriminated objects](https://redocly.com/docs/resources/discriminator#allof-for-inheritance). This endpoint demonstrates that.
tags:
- Quirks
requestBody:
content:
application/json:
schema:
type: object
properties:
vehicle:
$ref: '#/components/schemas/BaseVehicle'
some_other_property:
type: string
description: Some other property that should render alongside the discriminated property
default: 'default-value'
responses:
'200':
description: OK
'/potentially-undefined-formData':
post:
summary: Handling for potentially undefined formData
Expand Down Expand Up @@ -402,3 +424,78 @@ components:
required:
- event_type
- event_id
BaseVehicle:
type: object
description: Vehicle (from [Redocly example](https://redocly.com/docs/resources/discriminator#when-to-use-the-openapi-discriminator))
discriminator:
propertyName: powerSource
mapping:
electricity: '#/components/schemas/ElectricVehicle'
gasoline: '#/components/schemas/FueledVehicle'
human-energy: '#/components/schemas/PedaledVehicle'
properties:
vehicleType:
description: The type of vehicle.
type: string
example: bicycle
idealTerrain:
description: A road, river, air... Where does this vehicle thrive?
type: string
example: roads
powerSource:
description: How is the vehicle powered.
type: string
example: pedaling
topSpeed:
description: The top speed in kilometers per hour rounded to the nearest integer.
type: integer
example: 83
range:
description: The 95th percentile range of a trip in kilometers.
type: integer
example: 100
ElectricVehicle:
allOf:
- $ref: '#/components/schemas/BaseVehicle'
- type: object
description: Electric Vehicle
properties:
chargeSpeed:
description: In range kilometers per hour.
type: integer
chargeAmps:
description: Amps recommended for charging.
type: integer
chargeVoltage:
description: Voltage recommended for charging.
type: integer
FueledVehicle:
allOf:
- $ref: '#/components/schemas/BaseVehicle'
- type: object
title: Gas-powered Vehicle
properties:
tankCapacity:
type: number
format: double
description: Capacity of the fuel tank in gallons.
milesPerGallon:
type: number
format: double
description: Miles per gallon on the highway.
PedaledVehicle:
allOf:
- $ref: '#/components/schemas/BaseVehicle'
- type: object
description: Pedaled Vehicle
properties:
handlebars:
type: string
description: Type of handlebars
enum:
- flat
- riser
- bullhorn
- drop
- aero
- cruiser
Loading