swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

ValueError: swagger.yaml is not a valid swagger2.0 file: expected string or buffer

Open ptman opened this issue 6 years ago • 5 comments

I'm trying to parse a swagger file:

from swagger_parser import SwaggerParser
p = SwaggerParser(swagger_path='swagger.yaml')

The same file is valid in editor.swagger.io and http://bigstickcarpet.com/swagger-parser/www/index.html

I'd like at least a line number or similar to better understand the error.

ptman avatar Nov 07 '17 09:11 ptman

I have the same issue. Even with minimal swagger, such as:

swagger: "2.0"
info:
  description: "This is a sample server Petstore server."
  version: "1.0.0"
  title: "Swagger Petstore"
schemes:
- "http"
paths:
  /pet:
    post:
      operationId: "addPet"
      parameters:
      - in: "body"
        name: "body"
        required: true
        schema:
          $ref: "#/definitions/Pet"
      responses:
        201:
          description: "Created"
        400:
          description: "Bad request"

definitions:
  Pet:
    type: "object"
    required:
    - "name"
    properties:
      id:
        type: "integer"
      name:
        type: "string"
        example: "doggie"

robertlagrant avatar Feb 21 '18 18:02 robertlagrant

Issue remains with version 1.0.1, JSON converted swagger files work fine though.

gs11 avatar Mar 14 '18 11:03 gs11

I am having the same error when parsing a yaml file.

alext234 avatar Nov 05 '19 23:11 alext234

I was able to track the problem down to python's re module and it is having problems with the yaml similar to the following

        201:
          description: "Created"
        400:
          description: "Bad request"

values 201 and 400 above are parsed as integers and therefore re complains about the type of the value being inserted. Yaml below will work perfectly with the lib

        "201":
          description: "Created"
        "400":
          description: "Bad request"

I can make a pr

alexsiaba avatar May 24 '20 13:05 alexsiaba

Good catch! Sure you can go ahead with a PR, I’ll review it

Le dim. 24 mai 2020 à 15:56, alexsiaba [email protected] a écrit :

I was able to track the problem down to python's re module and it is having problems with the yaml similar to the following

    201:
      description: "Created"
    400:
      description: "Bad request"

values 201 and 400 above are parsed as integers and therefore re complains about the type of the value being inserted. Yaml below will work perfectly with the lib

    "201":
      description: "Created"
    "400":
      description: "Bad request"

I can make a pr

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Trax-air/swagger-parser/issues/56#issuecomment-633234848, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJF2US6MACVC7KFMWTFJ6DRTERSLANCNFSM4ECSADQA .

-- F. Hautbois

flavianh avatar May 24 '20 15:05 flavianh