Last active
February 19, 2024 08:54
-
-
Save snigdhasjg/3b07e1bb1a58658c92ef6904055067e5 to your computer and use it in GitHub Desktop.
Shows how discriminator can be used
This file contains hidden or 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.3 | |
info: | |
title: Unit of measure | |
description: Gives ratio | |
version: "0.0.1" | |
servers: | |
- url: 'https://uom.com/v1' | |
tags: | |
- name: UOM | |
description: Unit of measure | |
paths: | |
/uom/convert/{systemOfMeasurement}: | |
post: | |
tags: | |
- UOM | |
summary: Convert Reading | |
description: Convert a reading | |
operationId: convertReading | |
parameters: | |
- $ref: '#/components/parameters/systemOfMeasurement' | |
requestBody: | |
description: Reading to convert. | |
required: true | |
content: | |
application/json: | |
schema: | |
$ref: '#/components/schemas/Reading' | |
responses: | |
200: | |
description: OK | |
content: | |
application/json: | |
schema: | |
$ref: '#/components/schemas/Reading' | |
components: | |
parameters: | |
systemOfMeasurement: | |
name: systemOfMeasurement | |
in: path | |
description: system of measurement | |
required: true | |
schema: | |
type: string | |
enum: | |
- metric | |
- usStandard | |
example: metric | |
schemas: | |
UnitOfMeasure: | |
type: object | |
description: Base model for all units of measure in the platform. | |
properties: | |
type: | |
type: string | |
description: Available types of measurements. | |
enum: | |
- distance | |
- volume | |
DistanceUoM: | |
description: | | |
Distance unit of measure. Supported values are: | |
* mi (mile); | |
* km (kilometer). | |
allOf: | |
- $ref: '#/components/schemas/UnitOfMeasure' | |
- type: object | |
properties: | |
value: | |
type: string | |
description: Unit of measure values. | |
enum: [ km, mi ] | |
example: | |
type: 'distance' | |
value: 'km' | |
VolumeUoM: | |
description: | | |
Volume unit of measure. Supported values are: | |
* L (liter); | |
* gal (gallon). | |
allOf: | |
- $ref: '#/components/schemas/UnitOfMeasure' | |
- type: object | |
properties: | |
value: | |
type: string | |
description: Allowed values for volume unit of measure. | |
enum: [ L, gal ] | |
example: | |
type: volume | |
value: L | |
Reading: | |
type: object | |
description: Represent reading. | |
properties: | |
value: | |
type: integer | |
description: Reading data. | |
example: 7 | |
unitOfMeasure: | |
oneOf: | |
- $ref: '#/components/schemas/DistanceUoM' | |
- $ref: '#/components/schemas/VolumeUoM' | |
discriminator: | |
propertyName: type | |
mapping: | |
distance: '#/components/schemas/DistanceUoM' | |
volume: '#/components/schemas/VolumeUoM' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment