Skip to content

format:int64 parameter throws data mismatch error #407

Description

While parsing this document:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
  termsOfService: http://swagger.io/terms/
  contact:
    name: Swagger API Team
    email: apiteam@swagger.io
    url: http://swagger.io
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
servers:
  - url: http://petstore.swagger.io/api
paths:
  /users:
    post:
      summary: Adds a new user
      requestBody:
        content:
          application/xml:
            schema:      # Request body contents
              $ref: '#/components/schemas/User'
            example:   # Sample object
                id: 10
                name: Jessica Smith
      responses:
        '200':
          description: OK
components:
  schemas:
    User:    # Schema name
      type: object
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string

I am getting this error in diagnostics:

Data and type mismatch found. [#/paths/~1users/post/requestBody/content/application~1xml/example/id

If I remove format:int64 in the id definition, the error goes away. I don't understand what's wrong here, how should int64 format look like? 10 is not a valid value in long format??

Version 1.1.1 didn't throw this error, I started getting it after updating to 1.1.3
sample.txt

Activity

  1. darrelmiller commented on Aug 23, 2019

    @darrelmiller
    Member

    This definitely seems like a bug to me. I actually don't think we should be returning errors at all for examples that don't match the schema. They should only be warnings. However, what you are showing is worse because you actually have a valid number.

  2. david-jessee commented on Apr 5, 2020

    @david-jessee

    So apparently its parsing the integers at strings since it sees them as an "any type"
    This can be fixed in the current version by nesting the example inside of a value attribute (see below. the attach function wasn't working).
    However, if you do this then the swagger ui's don't work that well. When you past the below yml into https://editor.swagger.io/ it sees "value" as part of the output.

    openapi: "3.0.0"
    info:
      version: 1.0.0
      title: Swagger Petstore
      description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
      termsOfService: http://swagger.io/terms/
      contact:
        name: Swagger API Team
        email: apiteam@swagger.io
        url: http://swagger.io
      license:
        name: Apache 2.0
        url: https://www.apache.org/licenses/LICENSE-2.0.html
    servers:
      - url: http://petstore.swagger.io/api
    paths:
      /users:
        post:
          summary: Adds a new user
          requestBody:
            content:
              application/xml:
                schema:      # Request body contents
                  $ref: '#/components/schemas/User'
                example:   # Sample object
                    value:
                      id: 10
                      name: Jessica Smith
          responses:
            '200':
              description: OK
    components:
      schemas:
        User:    # Schema name
          type: object
          properties:
            id:
              type: integer
              format: int64
            name:
              type: string
    
  3. added this to the Backlog milestone on Apr 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:bugA broken experience

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions