Skip to content

Commit 50cd25e

Browse files
committed
refactor: migrate swagger to use [email protected], fixing the oneOf/anyOf rendering issue in the docs
1 parent 1887175 commit 50cd25e

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/plugins/swagger.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,36 @@ export const DOCS_ROUTE_PREFIX = '/docs';
1111
export default fp(async (fastify) => {
1212
fastify.register(swagger, {
1313
hideUntagged: true,
14-
swagger: {
14+
openapi: {
15+
openapi: '3.1.0',
1516
info: {
1617
title: 'Bitcoin/RGB++ Assets API',
1718
version: pkg.version,
1819
},
19-
consumes: ['application/json'],
20-
produces: ['application/json'],
2120
security: [{ apiKey: [] }],
22-
securityDefinitions: {
23-
apiKey: {
24-
type: 'apiKey',
25-
name: 'Authorization',
26-
in: 'header',
27-
description: 'JWT token for authentication. Example: Bearer <token>',
21+
components: {
22+
securitySchemes: {
23+
apiKey: {
24+
type: 'apiKey',
25+
name: 'Authorization',
26+
in: 'header',
27+
description: 'JWT token for authentication. Example: Bearer <token>',
28+
},
2829
},
2930
},
3031
},
3132
transform: jsonSchemaTransform,
32-
transformObject: ({ swaggerObject }) => {
33+
transformObject: ({ openapiObject }) => {
3334
if (env.NODE_ENV === 'production') {
34-
const { paths = {} } = swaggerObject;
35-
const newPaths = Object.entries(paths).reduce((acc, [path, methods]) => {
35+
const { paths = {} } = openapiObject;
36+
openapiObject.paths = Object.entries(paths).reduce((acc, [path, methods]) => {
3637
if (SWAGGER_PROD_IGNORE_URLS.some((ignorePath) => path.startsWith(ignorePath))) {
3738
return acc;
3839
}
3940
return { ...acc, [path]: methods };
4041
}, {});
41-
swaggerObject.paths = newPaths;
4242
}
43-
return swaggerObject;
43+
return openapiObject;
4444
},
4545
});
4646
fastify.register(swaggerUI, {

0 commit comments

Comments
 (0)