_From @specialtactics on May 16, 2018 10:03_
Swagger/OpenAPI version: OpenAPI 3.0
Swagger/OpenAPI definition:
yaml
components:
examples:
exampleModel:
value:
{
"name": "Adam Jacobson",
"email": null,
}
YAML is a superset of JSON and hence supports "null" as a value of a json property. It is actually a fairly common use-case for a field to be null (for example, patch a property as null to remove it, default values being null).
However the editor will display a null value in a json example as empty object { }, which is not accurate and is very annoying.
Editor to print json null as null in the example dialogues - for instance, as it would appear in postman.
I have not, I think it should be consistent with the json standard and other tools.
None
Thank you
_Copied from original issue: swagger-api/swagger-editor#1758_
Hey @specialtactics, this is actually because we aren't currently respecting example values at all, so the type: object schema definition for the property is creating that empty object you see, I believe.
Here's what I tested with, based on your snippet:
openapi: "3.0.0"
paths:
/:
post:
requestBody:
content:
application/json:
schema:
type: object
properties:
name:
type: string
email:
type: object
example:
$ref: "#/components/examples/exampleModel"
components:
examples:
exampleModel:
value:
name: "Adam Jacobson"
email: null
As luck would have it, example/examples support is up for work very soon, so this will be fixed in short order 馃槃
Good to hear @shockey, thanks !
@shockey Actually the issue is not specific to media type examples - example: null also does not work properly in schema examples.
openapi: 3.0.0
info:
title: test
version: 0.0.1
paths:
/foo:
get:
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
foo:
type: string
nullable: true
example: null
# object-level example
#example:
# foo: null
Expected result:
{
"foo": null
}
Actual result:
{
"foo": {}
}
Locking due to inactivity.
This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.
If you think you're experiencing something similar to what you've found here: please open a new issue, follow the template, and reference this issue in your report.
Thanks!
Most helpful comment
@shockey Actually the issue is not specific to media type examples -
example: nullalso does not work properly in schema examples.Expected result:
Actual result: