I have redoc-cli
installed via npm
$ redoc-cli --version
0.13.20
Now I use it to build docs with the following
openapi: 3.1.0
info:
title: Sample API
version: '1.0'
contact:
email: some@email.com
description: Api description.
tags:
- name: sample tag
description: tag description
servers:
- url: http://localhost:3000
paths:
/int/methods/list:
post:
summary: Sample op
operationId: sample-op
description: Op description.
requestBody:
content:
application/json:
schema:
type: object
properties:
test:
$ref: '#/components/schemas/test'
tags:
- sample tag
components:
schemas:
test1:
title: Test
type: object
properties:
testType:
type: string
testOne:
type: string
test2:
title: Test 2
type: object
properties:
testType:
type: string
testTwo:
type: number
test:
title: Test Polymorph
oneOf:
- $ref: '#/components/schemas/test1'
- $ref: '#/components/schemas/test2'
discriminator:
propertyName: testType
mapping:
ONE: '#/components/schemas/test1'
TWO: '#/components/schemas/test2'
Still attempting to
$ redoc-cli build 04_interface/test.yaml
Prerendering docs
🎉 bundled successfully in: redoc-static.html (1061 KiB) [⏱ 0.179s]
Gives me a result as-if the whole discriminator
was missing, ie
...instaed of the expected select box, as documented in redocly
I know redocly
and redoc-cli
are not the same, but redoc-cli used to support discriminators in the past, just at some point it seems to me that it stopped working - or there is some syntax niche I am missing.
So i found what the turning point is. Look at this example.
openapi: 3.1.0
info:
title: Sample API
version: '1.0'
contact:
email: some@email.com
description: Api description.
tags:
- name: sample tag
description: tag description
servers:
- url: http://localhost:3000
paths:
/sample-path:
post:
summary: Sample op
operationId: sample-op
description: Op description.
requestBody:
content:
application/json:
schema:
title: Test
type: object
properties:
prop1:
title: Test Polymorph
oneOf:
- $ref: '#/components/schemas/test1'
- $ref: '#/components/schemas/test2'
discriminator:
propertyName: testType
mapping:
ONE: '#/components/schemas/test1'
TWO: '#/components/schemas/test2'
prop2:
$ref: '#/components/schemas/testPolymorph'
tags:
- sample tag
/another-path:
post:
summary: Another op
operationId: another-op
description: Another op description.
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/testPolymorph'
tags:
- sample tag
components:
schemas:
test1:
title: Test - Variant 1
type: object
properties:
testType:
type: string
testOne:
type: string
test2:
title: Test Variant 2
type: object
properties:
testType:
type: string
testTwo:
type: number
testPolymorph:
title: Test Polymorph
discriminator:
propertyName: testType
mapping:
ONE: '#/components/schemas/test1'
TWO: '#/components/schemas/test2'
oneOf:
- $ref: '#/components/schemas/test1'
- $ref: '#/components/schemas/test2'
This specs yields the following visualization
It seems the discriminator doesnt work for $refs, only if the $ref is on the top schema level.
I started an issue here https://github.com/Redocly/redoc/issues/2252
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.