Using $ref to refer to schema that has $ref in example treats $ref as a property
See original GitHub issueQ&A (please complete the following information)
- OS: macOS
- Browser: chrome
- Version: 66.0.3359.181
- Method of installation: homebrew
- Swagger-UI version: https://editor.swagger.io/ and swagger-editor-dist@^3.3.1 using swagger-ui@^3.12.0
- Swagger/OpenAPI version: OpenAPI 3.0.1
Content & configuration
Example Swagger/OpenAPI definition:
openapi: '3.0.1'
info:
title: 'Title'
version: 1.0.0
components:
schemas:
object:
type: object
example:
a:
$ref: '#/components/schemas/object/properties/a/example'
properties:
a:
type: string
example: 'aString'
paths:
'/path':
post:
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/object'
responses:
'201':
description: 'description'
Swagger-UI configuration options:
I don’t know the configuration. This bug happens on https://editor.swagger.io/ and also on swagger-ui-watcher.
Describe the bug you’re encountering
To reproduce…
Steps to reproduce the behavior:
- Go to https://editor.swagger.io/
- Paste in the Swagger/OpenAPI definition yaml above.
- Expand the POST /path route
- Paste in the yaml again. This bug seems to only happen when you update the yaml. So it might be a bug with swagger-editor instead.
- Look a the rendered swagger-ui on the right.
- The JSON example for the request body has a bug. It treats the
$ref
as a property of the JSON.
This is what you should see:
{
"a": {
"$ref": "#/components/schemas/object/properties/a/example"
}
}
Expected behavior
The JSON should be:
{
"a": "aString"
}
Screenshots
Additional context or thoughts
If you go to the Model, it will show example: aString
, which is correct.
If you embed the schema within the requestBody
schema
manually, everything works as expected:
openapi: '3.0.1'
info:
title: 'Title'
version: 1.0.0
components:
schemas:
object:
type: object
example:
a:
$ref: '#/components/schemas/object/properties/a/example'
properties:
a:
type: string
example: 'aString'
paths:
'/path':
post:
requestBody:
required: true
content:
application/json:
schema:
type: object
example:
a:
$ref: '#/components/schemas/object/properties/a/example'
properties:
a:
type: string
example: 'aString'
responses:
'201':
description: 'description'
Result:
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Using $ref - Swagger
To reference a definition, use the $ref keyword: $ref: 'reference to definition'. For example, suppose you have the following schema object, which you...
Read more >Structuring a complex schema — Understanding JSON ...
A schema can reference another schema using the $ref keyword. The value of $ref is a URI-reference that is resolved against the schema's...
Read more >json - Can a property of an allOf item contain a $ref to another ...
Your schema is mostly right, although you've set an $id in a subschema. The "$id" keyword defines a URI for the schema, and...
Read more >How to use JSON references ($refs) - Redocly
How to use JSON references ($refs) ; a multi-file structure; re-use of schemas or other content ; empty (to refer to the current...
Read more >17.7.0 API Reference - joi.dev
First, a schema is constructed using the provided types and constraints: const schema = Joi.object({ a: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks, @webron - closing this 😄
Sorry for the delay here. The way it works right now is as expected. As @shockey mentioned, there’s no support for
$ref
for examples inside the Schema Object. As such, it should treat the$ref
as the example itself.