openapi3 icon indicating copy to clipboard operation
openapi3 copied to clipboard

Unable to parse non-str example values

Open fralik opened this issue 4 years ago • 0 comments

Parameter examples are not necessary strings. However, the code in paths.py assumes that they are. Consider this file for validation:

openapi: 3.0.1
info:
  title: Example type bug
  version: v1.0
servers:
  - url: https://api.example.com/v1.0/
    description: Core

paths:
  /users/{id}:
    get:
      summary: Get user
      parameters:
        - name: id
          in: path
          required: true
          description: ID of a user
          schema:
            minimum: 0
            type: integer
          example: 50
      responses:
        '200':
          description: Retrieved user
          content:
            application/json:
              schema:
                type: array
                items:
                  type: string

Code

from openapi3 import OpenAPI
import yaml

with open('openapi.yaml') as f:
    spec = yaml.safe_load(f.read())

api = OpenAPI(spec)

produces the error message: openapi3.errors.SpecError: Expected paths./users/{id}.get.parameters.0.example to be one of [<class 'str'>], got <class 'int'>

fralik avatar Nov 29 '21 12:11 fralik