Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValidationError: expected string or bytes-like object #35

Closed
DeAJota opened this issue Jun 15, 2019 · 7 comments
Closed

ValidationError: expected string or bytes-like object #35

DeAJota opened this issue Jun 15, 2019 · 7 comments

Comments

@DeAJota
Copy link

DeAJota commented Jun 15, 2019

I'm creating app with Flask, Connexion and Swagger. I want split swagger yaml file in multilpe files.
I have followed this reply:
spec-first/connexion#254 (comment)

When I execute my app appears the exception. This exception is raised by the function _validate_openapi_spec_validator on class BaseParser, line 235.
validate_v2_spec(self.specification)
specification is a dict.

This is the yaml with the reference:

swagger: "2.0"

info:
  title: "Document Repository Service API"
  version: "1.0"

basePath: /v1.0

paths:
  $ref: ./resolutions.yaml

And this is the yaml referenced:

 /resolutions/{id}:
      get:
        x-swagger-router-controller: controllers.resolution_controller
        operationId: get_resolution
        parameters:
          - name: id
            in: path
            description: Resolution ID
            type: string
            required: true
          - name: format
            in: query
            type: string
            enum: [xml, json]
            required: false
            default: xml
          - name: encoding
            in: query
            type: string
            enum: [utf-8, original]
            required: false
            default: utf-8
        responses:
          200:
            description: OK
          404:
            description: A resolution with the specified ID was not found.

@jfinkhaeuser
Copy link
Collaborator

The reason is that JSON doesn't accept any keys that are not strings. Your YAML contains integer keys in the form of response codes. Make them strings by quoting them and it will be fine.

@jfinkhaeuser
Copy link
Collaborator

FWIW, this is documented in the readme - look for strict mode.

@DeAJota
Copy link
Author

DeAJota commented Jun 16, 2019

Excuse me for my mistake, I should have read more, you are absolutely right

@DeAJota DeAJota closed this as completed Jun 16, 2019
@jfinkhaeuser
Copy link
Collaborator

No, it's all good, no need for excuses! Is there something about the documentation I could improve?

@DeAJota
Copy link
Author

DeAJota commented Jun 16, 2019

I think isn't necessary. I followed the yaml code examples of Swagger/OpenApi and, how you say, they does not always match the JSON specs. Thank you so much for your attention.

@adaamz
Copy link

adaamz commented Sep 4, 2020

Would be nice to know file+line of validation error, if you have multiple files/big files it's hard to find it.

Anyway your answer helped me, thx!

@jfinkhaeuser
Copy link
Collaborator

@adaamz yes, see #74 - when I get to it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants