spectral
spectral copied to clipboard
content Type XML and example not property handle
Describe the bug give an API Spec with a return content type set to application/xml spectral raise an error stating that example must be an object
notice that the file looks correct , and is correctly rendered by editor.swagger.io
To Reproduce given the API spec below
{
"openapi": "3.0.0",
"info": {
"title": "Kitten",
"version": "1.0.0"
},
"paths": {
"/pet": {
"get": {
"responses": {
"200": {
"description": "cat",
"content": {
"application/xml": {
"schema": {
"$ref": "#/components/schemas/niceCatResult"
},
"example": "<Cat><nice>true</nice></Cat>"
}
}
}
}
}
}
},
"components": {
"schemas": {
"niceCatResult": {
"type": "object",
"properties": {
"nice" : {
"type": "boolean"
}
},
"xml": {
"name": "Cat"
}
}
}
}
}
Error below is raised 18:44 error oas3-valid-media-example "example" property type must be object paths./pet.get.responses[200].content.application/xml.example
Expected behavior No Error raised ,
Also having this problem with examples and a value that's a string.
responses:
'201':
description: Booking successful
content:
application/json:
schema:
allOf:
- $ref: '#/components/schemas/Booking'
- properties:
links:
$ref: '#/components/schemas/Links-Self'
examples:
new_booking:
summary: New Booking
value: |-
{
"id": "{{ uuid() }}",
"trip_id": "{{ request.body/trip_id }}",
"passenger_name": "{{ request.body/passenger_name }}",
"has_bicycle": {{ request.body/has_bicycle }},
"has_dog": {{ request.body/has_dog }},
"links": {
"self": "https://api.example.com/bookings/1725ff48-ab45-4bb5-9d02-88745177dedb"
}
}
This is allowed by the spec, and its eneded for using Microcks mocking tool, but I get this error:
370:26 error oas3-valid-media-example "value" property type must be object