Open chameleon82 opened 4 years ago
You need to add quotes around the example value:
type: string
format: date
example: '2019-02-01' # <----
Without the quotes, the value is parsed as a YAML timestamp which is a different data type than string.
YAML timestamp is exactly i expected to be applied here.
There is example under the link date (00:00:00Z): 2002-12-14
and i expecting swagger will format json string from parsed timestamp as a date with specified format format: date
and type type:string
and as output i will have:
{
"checkInDate": "2019-02-01"
}
This behaviour i expect as well in the swagger-core
/swagger-annotations
, for example i can define next code:
@io.swagger.v3.oas.annotations.Operation(
...
requestBody = new RequestBody(
content = Array(
new Content(
schema = new Schema(implementation = classOf[MyDto]),
examples = Array(
new ExampleObject(
name = "example",
value =
"{\n \"checkInDate\": \"2019-02-01\"\n }"
)
)
)
)
),
where example body is
{
"checkInDate": "2019-02-01"
}
and class is
class MyDto {
@Schema(required = true, title = "Date in ISO8201 format", example = "2019-02-01")
public java.time.LocalDate invoiceDate;
}
and from swagger-core
i see expected output
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyDto'
examples:
example:
description: example
value:
checkInDate: 2019-02-01
MyDto:
properties:
checkInDate:
title: Date in ISO8201 format
type: string
format: date
example: 2019-02-01
Hi!
We just encountered the same problem with date/datetime examples.
I know that workaround is to use quotes/double-quotes, but in our case swagger bundle is auto-generated and it correctly doesn't have any quotes (as per https://yaml.org/spec/1.2/spec.html#id2788859 only combination of symbols ": " requires quoting). As a result all our date/date-time examples are displayed as {}
.
As far as I understand this is a problem with js-yaml library (without quotes vs with quotes).
best regards, ty
Hi!
I experienced the same issue with dates in examples. The workaround with putting quotes (either ' or " ) does not work for me as well. It always shows the date value as {}
.
Kind regards, Christian
@typhoon2k I think js-yaml
correctly parse date/date-time as JavaScript Date object. Seems problem that Swagger cannot convert it to string properly
You need to add quotes around the example value:
type: string format: date example: '2019-02-01' # <----
Without the quotes, the value is parsed as a YAML timestamp which is a different data type than string.
Quotes solution doesn't work, please fix.
We are having the same problem with this. Quotes fixes it, but the spec is auto-generated and they'd have to manually update a bunch of params every time.
Same problem here. I use Spring boot and my request model has field birthDate like:
@NotNull
@Schema(description = "User birthdate.", example = "19680228", format = "yyyyMMdd", required = true, nullable = false)
private OffsetDateTime birthDate;
I would expect this to work, however, in SwaggerUI, none of this really helps. This is what I get it for that request model and also as example for the request body:
btw - it looks working fine on https://editor.swagger.io/ now...
For me it seems that the problem only occurs when a $ref is used
paths:
/pet/{petId}:
get:
parameters:
# does not work
- $ref: components/parameters/date.yaml
# does work
- name: date
in: query
schema:
title: Date
type: string
format: date
examples:
example1:
value: 2022-10-12
responses:
'200':
description: successful operation
components/parameters/date.yaml looks like:
name: date-ref
in: query
schema:
title: Date
type: string
format: date
examples:
example1:
value: 2022-10-12
Any update on it? I've got same issue as @Zepryit mentioned above All date example are formed as date-time when $ref is used.
I have the same issue with dates. the pattern and example I provided in the @Schema, is ignored!!!
I have the same issue with dates. the pattern and example I provided in the @Schema, is ignored!!!
me 2
Q&A (please complete the following information)
Content & configuration
Example Swagger/OpenAPI definition:
Describe the bug you're encountering
Following the specification i should see correct example in UI
"checkInDate": "2019-02-01"
but instead i see"checkInDate": {}
In schema block i see:
example: OrderedMap {}
Expected behavior
Correct property example in dto object in request body
"checkInDate": "2019-02-01"