question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OAS 3: Flasgger seems not being able to resolve *components* reference when using yml file

See original GitHub issue

Using an external yml file, even if adding as suggested app['SWAGGER']['openapi'] = '3.0.2', it seems not being able to resolve the #/schemas/components reference:

My API is awesome......
---
tags:
  - My API
post:
  parameters:
    - name: user-id
      in: header
      description: Id of the user
      type: string
      required: true
  requestBody:
    required: true
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/Users'

responses:
  200:
    description: something.
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/UserData'

components:
  schemas:
    Users:
      type: object
      properties:
          property1:
              type: string 
    UserData:
      type: object
      properties:
          property2:
              type: string

.........
...............
..............

on the Swagger page i get:

Errors
Hide
Resolver error at paths./v1/notifications/compute.post.responses.200.content.application/json.schema.$ref
Could not resolve reference because of: Could not resolve pointer: /components/schemas/UserData does not exist in document

the schema referred by $ref: '#/components/schemas/Users' is not shown at all and no errors are visualized for this

I can’t type properly the tabs on here, but the indentation is ok on my side.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
lcbmcommented, Nov 6, 2020

Not working here as well ☹️

I’ll leave some information below, but LMK if there’s anything else I could provide you, or do for you, in order to further assist in the resolution of this issue 😄

Flasgger version: 0.9.5

Here are the relevant parts of code which include flasgger 👇

# __init__.py
...
def create_app():
    app = flask.Flask(__name__, instance_relative_config=False)
    mymodule.config.configure_app(app)
    flasgger.Swagger(app)
...

# config.py
...
    SWAGGER = {
        "uiversion": 3,
        "openapi": "3.0.3",
        "info": {
            "title": "My API",
            "description": "Awesome API.",
            "version": "0.1.0",
        },
        "optional_fields": ['components'],
    }
...

OpenAPI Specification yamlresponse 400 (which uses components) does NOT work, while the response 500 (which has the same specification as the 400 one and doesn’t use components) works. Also, to be clear, I tried some variations of the code below. 👇

# availability_graph.yml
...
responses:
  400:
    description: Bad Request
    content:
      application/json:
        schema:
          $ref: '#/components/schemas/Error'
  500:
    description: Internal Server Error
    content:
      application/json:
        schema:
          type: object
          properties:
            error:
              type: object
              properties:
                description:
                  schema:
                    type: string
                  description: A message which describes the error that occured
                  example: "An unexpected error occurred"
                message:
                  schema:
                    type: string
                  description: A message which describes the source of the error
                  example: "Internal server error"
                status_code:
                  schema:
                    type: integer
                  description: HTTP status code related to the error
                  example: 500
components:
  schemas:
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            description:
              schema:
                type: string
              description: A message which describes the error that occured
              example: "An unexpected error occurred"
            message:
              schema:
                type: string
              description: A message which describes the source of the error
              example: "Internal server error"
            status_code:
              schema:
                type: integer
              description: HTTP status code related to the error
              example: 500

Output 👇 image

Error 👇 image

2reactions
homekeeper89commented, Sep 29, 2020

Is this solved? I had a same problem and ‘optional_fields’ is not working.

Read more comments on GitHub >

github_iconTop Results From Across the Web

OAS 3: Flasgger seems not being able to resolve ... - GitHub
OAS 3 : Flasgger seems not being able to resolve *components* reference when using yml file #308. Open. vitodsk opened this issue on...
Read more >
OAS 3: Flasgger seems not being able to resolve *components ...
OAS 3 : Flasgger seems not being able to resolve *components* reference when using yml file.
Read more >
openAPI unable to resolve ref to external file. Component ...
My mistake was in thinking that the Map contained either a key, value pair of string, Schema Object or a Reference Object that...
Read more >
Splitting specification file - API Handyman
In part 3 - Simplifying spefication file we have learned how to simplify the specification by creating reusable elements.
Read more >
Adding Examples - Swagger
OAS 2 This page applies to OpenAPI Specification ver. 2 (fka Swagger). ... Note: Do not confuse example values with the default values....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found