References to internal sections in swagger.json work correctly, but attempting to reference a JSON file in the same directory seems to be ignored. I have some large example data files so would like to reference them instead of including them in the swagger.json file.
How do I get swagger to dereference the $ref tags for external files in the ./static/ directory (this is the same location as the swagger.json file)? Is there a swagger log file that shows what/how it loads files?
Things that work:
- http://localhost:5002/swagger
- http://localhost:5002/static/swagger.json
- http://localhost:5002/static/components.json
So this proves the web server can find the static/components.json file.
Part of swagger.json:
"components": {
"schemas": {
"id": {
"properties": {
"id": {
"type": "number",
"format": "int64"
}
}
},
"componentsPost": {
"type": "object",
"properties": {
"id": {
"$ref": "#/components/schemas/id" <-- THIS WORKS
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"component_type_id": {
"$ref": "#/components/schemas/id" <-- THIS WORKS
},
"system_type_id": {
"$ref": "#/components/schemas/id" <-- THIS WORKS
},
"parent_id": {
"$ref": "#/components/schemas/id"
}
},
"example": {
"$ref": "components.json" <-- THIS DOES *NOT* WORK
}
},
Note: components.json is different than the #components/schema/id
reference, which is in the same file as shown above.
Beginning of components.json data file:
{
"components": [
{
"id": 99999,
"name": "root",
"description": "Root Component",
"component_type_id": 1,
"system_type_id": 1
},
{
"id": 1,
"name": "lan1",
"description": "LAN",
"component_type_id": 1,
"system_type_id": 4,
"parent_id": 99999
},
The swagger.json file gets loaded but components.json does not:
[06/Jan/2021 12:32:53] "GET /static/swagger.json HTTP/1.1" 200 -
The swagger web site shows the $ref, not the expected components.json:
Alternate code I have tried:
"example": {
"components": {
"$ref": "components.json"
}
}
"example": {
"$ref": "/static/components.json"
}
"example": {
"$ref": "./static/components.json"
}
"example": {
"$ref": "static/components.json"
}