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.

OpenApi Schema references non-existing JSON fields

See original GitHub issue

Description of the Bug Report

When generating an OpenApi schema using python manage.py generateschema --file schema.yml, the schema is generated without errors, but references non-existent fields via $ref, making it unuseable.

E.g.:

paths:
  /login:
    post:
      operationId: create/login
      description: ''
      parameters: []
      tags:
      - login
      requestBody:
        content:
          application/vnd.api+json:
            schema:
              required:
              - data
              properties:
                data:
                  type: object
                  required:
                  - type
                  additionalProperties: false
                  properties:
                    type:
                      $ref: '#/components/schemas/type' # <--- This does not exist
                    id:
                      $ref: '#/components/schemas/id' # <--- This does not exist
                    links:
                      type: object
                      properties:
                        self:
                          $ref: '#/components/schemas/link' # <--- This does not exist
                    attributes:
                      type: object
                      properties: {}

For reference, this is what #/components looks like in the generated file:

components:
  schemas:
    Login:
      type: object
      required:
      - type
      - id
      additionalProperties: false
      properties:
        type:
          $ref: '#/components/schemas/type' # <--- This does not exist
        id:
          $ref: '#/components/schemas/id' # <--- This does not exist
        links:
          type: object
          properties:
            self:
              $ref: '#/components/schemas/link' # <--- This does not exist
        attributes:
          type: object
          properties:
            expiry:
              type: string
              readOnly: true
            token:
              type: string
              readOnly: true
    SuccessMessage:
      type: object
      required:
      - type
      - id
      additionalProperties: false
      properties:
        type:
          $ref: '#/components/schemas/type' # <--- This does not exist
        id:
          $ref: '#/components/schemas/id' # <--- This does not exist
        links:
          type: object
          properties:
            self:
              $ref: '#/components/schemas/link' # <--- This does not exist
        attributes:
          type: object
          properties:
            success:
              type: boolean
              readOnly: true

Checklist

  • Certain that this is a bug (if unsure or you have a question use discussions instead)
  • Code snippet or unit test added to reproduce bug

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
sliverccommented, Aug 18, 2022

@n2ygk Do I understand you correctly, once the generateschema command is run as above, OpenAPI works as expected? If so, I guess we should clarify the docs to make this clearer. As it is written now, it seems that a custom generator class is needed, which is not really the case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Defining constant value in response · Issue #1313 - GitHub
I believe OpenAPI 3.0 references draft-wright-json-schema-validation-00. We are about to release another draft (draft-07, exact IETF naming ...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
The schema exposes two types of fields: Fixed fields, which have a declared name, and Patterned fields, which declare a regex pattern for...
Read more >
What does 'required' in OpenAPI really mean - Stack Overflow
This boils down to the question whether "required = true" means "non-null value" or "property must be present". The JSON schema validator at ......
Read more >
What is the info property in OpenAPI? - API Handyman
The info property of an OpenAPI document contains metadata that provides an overview of an API, but what does it represent exactly?
Read more >
Content Management API Docs | Contentstack
You can download the OpenAPI JSON file of the Content Management API and open it on ... return the Global field's schema along...
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