openapi: 3.1.0
info:
title: Union Import Demo
version: 1.0.0
servers:
- url: https://example.com/api
components:
schemas:
Cat:
type: object
required: [id, lives]
properties:
id:
type: string
format: uuid
lives:
type: integer
Dog:
type: object
required: [id, breed]
properties:
id:
type: string
format: uuid
breed:
type: string
Animal:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
CardCheckout:
type: object
required: [method, cardLast4]
properties:
method:
type: string
const: card
cardLast4:
type: string
minLength: 4
maxLength: 4
BankCheckout:
type: object
required: [method, accountId]
properties:
method:
type: string
const: bank
accountId:
type: string
minLength: 6
Checkout:
oneOf:
- $ref: '#/components/schemas/CardCheckout'
- $ref: '#/components/schemas/BankCheckout'
discriminator:
propertyName: method
mapping:
card: '#/components/schemas/CardCheckout'
bank: '#/components/schemas/BankCheckout'
Result:
oneOf:
- $ref: '#/components/schemas/Animal'
- $ref: '#/components/schemas/Checkout'
paths:
/checkout:
post:
operationId: createCheckout
requestBody:
required: true
content:
application/json:
schema:
discriminator:
propertyName: method
oneOf:
- type: object
required: [method, cardLast4]
properties:
method:
type: string
const: card
cardLast4:
type: string
minLength: 4
maxLength: 4
- type: object
required: [method, accountId]
properties:
method:
type: string
const: bank
accountId:
type: string
minLength: 6
responses:
'200':
description: Created checkout or animal payload
content:
application/json:
schema:
$ref: '#/components/schemas/Result'