I have the following api documentation:
swagger: "3.0"
info:
version: 0.0.1
title: Test API
paths:
/users:
get:
summary: Get all registered users
produces:
- application/json
responses:
200:
description: Users successfully returned
403:
description: User not authorised to call this API
schema:
$ref: 'components.yaml#/components/schemas/AuthError'
Where the AuthError schema is defined in a separate yaml file called components.yaml:
components:
schemas:
AuthError:
type: object
properties:
error:
type: sting
description: Error message
And the Swagger configurations:
const swaggerDefinition = {
info: {
title: 'FlexiWAN REST API documentation',
version: '1.0.0',
description: 'This is the REST API for FlexiWAN management',
},
components: {},
host: 'local.flexiwan.com:3443',
basePath: '/api',
securityDefinitions: {
JWT: {
type: 'apiKey',
in: 'header',
name: 'Authorization',
description: "",
}
}
};
const options = {
swaggerDefinition,
apis: ['./swagger/**/*.yaml'],
};
const swaggerSpec = swaggerJSDoc(options);
app.use('/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
But when I try to access Swagger UI I get the following error:
Resolver error at paths./users.get.responses.403.schema.$ref Could not resolve reference: Tried to resolve a relative URL, without having a basePath. path: 'components.yaml' basePath: 'undefined'
What am I missing here?
$ref: './components.yaml##/components/schemas/AuthError'
? Do you use Swagger UI or Swagger Editor? – Helenswagger: "3.0"
withswagger: "2.0"
– Helen