Skip to content

[validate-examples] Empty model fails with "Expected type ' ' but found type object" #1065

@mikeharder

Description

@mikeharder

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

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

{
  "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"
      ]
    }
  }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

Status

📋 Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions