[validate-examples] Empty model fails with "Expected type ' ' but found type object"
- Dominant language
- TypeScript
- Stars
- 104
- Forks
- 62
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 5
Description
## Workaround
Untested, but I believe a workaround might be to ensure the example also sends an empty payload (or no payload). What's the point of putting an arbitrary JSON payload into an example, if the spec allows anything?
## Organic PRs
- https://github.com/Azure/azure-rest-api-specs/actions/runs/25648310372/job/75281381578?pr=43067
## Repro
```
$ npx oav generate-examples widgets.json; npx oav validate-example widgets.json
```
If you remove `description` from `PagedWidgetSuite`, somehow validate-example **doesn't** throw an error.
## Expected
No errors
## Actual
Fails to match empty response in example, with empty model in 200 response in spec
```
$ npx oav validate-example widgets.json
{
message: 'Validating "examples" and "x-ms-examples" in widgets.json:\n',
level: '\x1B[32minfo\x1B[39m'
}
Error reported:
{
code: 'INVALID_TYPE',
message: 'Expected type but found type object',
schemaUrl: 'widgets.json',
exampleUrl: 'example.json',
schemaPosition: { line: 22, column: 22 },
schemaJsonPath: undefined,
examplePosition: { line: 10, column: 16 },
exampleJsonPath: '$response.200/body',
severity: 0,
source: 'response',
operationId: 'Widgets_ListWidgets',
level: '\x1B[31merror\x1B[39m'
}
```
## Files
### widgets.json
```json
{
"swagger": "2.0",
"paths": {
"/widgets": {
"get": {
"operationId": "Widgets_ListWidgets",
"description": "List Widget resources",
"parameters": [],
"responses": {
"200": {
"description": "The request has succeeded.",
"schema": {
"$ref": "#/definitions/PagedWidgetSuite"
}
}
}
}
},
"/widgets2": {
"get": {
"operationId": "Widgets_ListWidgets2",
"description": "List Widget resources",
"parameters": [],
"responses": {
"200": {
"description": "The request has succeeded.",
"schema": {
"$ref": "#/definitions/PagedWidgetSuite2"
}
}
}
}
}
},
"definitions": {
"PagedWidgetSuite": {
"type": "object",
"description": "Paged collection of WidgetSuite items"
},
"PagedWidgetSuite2": {
"type": "object",
"description": "Paged collection of WidgetSuite items",
"properties": {
"nextLink": {
"type": "string",
"format": "uri",
"description": "The link to the next page of items"
}
},
"required": [
"nextLink"
]
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.