Skip to content

Provide better error messages for oneOf schema validation failures #60

Closed
@tedepstein

Description

@tedepstein

This Swagger Spec has a "body" parameter that is missing the required "schema" property:


---
swagger: "2.0"
info:
  description: "Tax Blaster"
  version: "1.0.0"
  title: "TaxBlaster"
host: "taxblaster.com"
basePath: "/api"
tags:
- name: "TaxFilingObject"
  description: "An individual Tax Filing record, accessed by its ID"
schemes:
- "http"
parameters:
  idParam:
    name: "id"
    in: "path"
    description: "filingID of the requested TaxFiling"
    required: true
    type: "string"
paths:
  /taxFilings/{id}:
    put:
      tags:
      - "TaxFilingObject"
      description: ""
      operationId: "getTaxFiling"
      consumes:
      - "application/json"
      produces:
      - "application/json"
      parameters:
      - name: "MyPayload"
        in: "body"
        description: "Here's something" 
        required: true
      responses:
        200:
          description: ""
          schema:
            $ref: "#/definitions/TaxFilingObject"
        404:
          description: ""
definitions:
  TaxFilingObject:
    type: "object"
    description: "An individual Tax Filing record, accessed by its ID"
    properties:
      filingID:
        type: "string"
      jurisdiction:
        type: "string"

I would hope for an error message like missing required property: 'schema'. But what it shows is a long, repetitive list of error messages on the parameter object:

Multiple markers at this line
- value body is not allowed, value should be one of "header"
- object has missing required properties "$ref"
- object has properties "description", "in", "name", "required" which are not allowed
- value body is not allowed, value should be one of "query"
- instance failed to match exactly one schema (matched 0 out of 2)
- instance failed to match exactly one schema (matched 0 out of 4)
- object has missing required properties "schema"
- value body is not allowed, value should be one of "path"
- value body is not allowed, value should be one of "formData"
- object has missing required properties "type"

If it's reasonably easy to provide the user with a simple, helpful error message in cases like this, we should. If it's going to require a lot of work, we can defer it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions