OpenApi Schema references non-existing JSON fields
See original GitHub issueDescription 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:
- Created a year ago
- Comments:8 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
See https://github.com/django-json-api/django-rest-framework-json-api/discussions/1082