Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
swagger-themes
Advanced tools
This library adds the ability to "painlessly" change your Swagger documentation theme.
npm i swagger-themes
yarn add swagger-themes
Connecting and using the library
const { SwaggerTheme, SwaggerThemeNameEnum } = require('swagger-themes');
const theme = new SwaggerTheme();
const darkStyle = theme.getBuffer(SwaggerThemeNameEnum.DARK); // Getting a Style
Standard dark theme connection with Express. The connection takes place via the swagger-ui-express library
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const { SwaggerTheme; SwaggerThemeNameEnum } = require('swagger-themes');
const swaggerDocument = require('./swagger.json');
const app = express();
const theme = new SwaggerTheme();
const options = {
explorer: true,
customCss: theme.getBuffer(SwaggerThemeNameEnum.DARK)
};
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument, options));
Connecting 2 documentation files. For example - 2 different themes are used
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const { SwaggerTheme, SwaggerThemeNameEnum } = require('swagger-themes');
const swaggerDocument = require('./swagger.json');
const app = express();
const theme = new SwaggerTheme();
const optionsV1 = {
explorer: true,
customCss: theme.getBuffer(SwaggerThemeNameEnum.DARK)
};
const optionsV2 = {
explorer: true,
customCss: theme.getBuffer(SwaggerThemeNameEnum.CLASSIC)
}
app.use('/api-docs/v1', swaggerUi.serve, swaggerUi.setup(swaggerDocument, optionsV1)); // Dark theme documentation
app.use('/api-docs/v2', swaggerUi.serve, swaggerUi.setup(swaggerDocument, optionsV2)); // Classic theme documentation
The method of getting the default config for the swagger library is ui-express
const express = require('express');
const swaggerUi = require('swagger-ui-express');
const { SwaggerTheme, SwaggerThemeNameEnum } = require('swagger-themes');
const swaggerDocument = require('./swagger.json');
const app = express();
const theme = new SwaggerTheme();
const optionsV1 = theme.getDefaultConfig(SwaggerThemeNameEnum.DARK);
const optionsV2 = theme.getDefaultConfig(SwaggerThemeNameEnum.CLASSIC);
app.use('/api-docs/v1', swaggerUi.serve, swaggerUi.setup(swaggerDocument, optionsV1)); // Dark theme documentation
app.use('/api-docs/v2', swaggerUi.serve, swaggerUi.setup(swaggerDocument, optionsV2)); // Classic theme documentation
Standard dark theme connection with Fastify. The connection takes place via the @fastify/swagger and @fastify/swagger-ui library
const fastify = require('fastify')({ logger: true })
const { SwaggerTheme, SwaggerThemeNameEnum } = require('swagger-themes');
const theme = new SwaggerTheme();
const content = theme.getBuffer(SwaggerThemeNameEnum.DARK);
fastify.register(require('@fastify/swagger'));
fastify.register(require('@fastify/swagger-ui'), {
theme: {
css: [
{ filename: 'theme.css', content: content }
],
}
})
fastify.listen({ port: 3000 }, (err) => {
if (err) throw err
})
Standard dark theme connection with NestJS. The connection takes place via the @nestjs/swagger library
// file main.ts
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { SwaggerTheme, SwaggerThemeNameEnum } from 'swagger-themes';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle('Cats example')
.setDescription('The cats API description')
.setVersion('1.0')
.addTag('cats')
.build();
const document = SwaggerModule.createDocument(app, config);
const theme = new SwaggerTheme();
const options = {
explorer: true,
customCss: theme.getBuffer(SwaggerThemeNameEnum.DARK)
};
SwaggerModule.setup('api', app, document, options);
await app.listen(3000);
}
bootstrap();
Connecting 2 documentation files. For example - 2 different themes are used
// file main.ts
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { SwaggerTheme, SwaggerThemeNameEnum } from 'swagger-themes';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle('Cats example')
.setDescription('The cats API description')
.setVersion('1.0')
.addTag('cats')
.build();
const document = SwaggerModule.createDocument(app, config);
const theme = new SwaggerTheme();
const optionsV1 = {
explorer: true,
customCss: theme.getBuffer(SwaggerThemeNameEnum.DARK)
};
const optionsV2 = {
explorer: true,
customCss: theme.getBuffer(SwaggerThemeNameEnum.CLASSIC)
};
SwaggerModule.setup('api-v1', app, document, optionsV1);
SwaggerModule.setup('api-v2', app, document, optionsV2);
await app.listen(3000);
}
bootstrap();
The method of getting the default config for the swagger library is @nestjs/swagger
// file main.ts
import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { SwaggerTheme, SwaggerThemeNameEnum } from 'swagger-themes';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = new DocumentBuilder()
.setTitle('Cats example')
.setDescription('The cats API description')
.setVersion('1.0')
.addTag('cats')
.build();
const document = SwaggerModule.createDocument(app, config);
const theme = new SwaggerTheme();
const optionsV1 = theme.getDefaultConfig(SwaggerThemeNameEnum.DARK);
const optionsV2 = theme.getDefaultConfig(SwaggerThemeNameEnum.CLASSIC);
SwaggerModule.setup('api-v1', app, document, optionsV1);
SwaggerModule.setup('api-v2', app, document, optionsV2);
await app.listen(3000);
}
bootstrap();
classic dark-monokai dark dracula feeling-blue flattop gruvbox material monokai muted newspaper nord-dark one-dark outline
FAQs
Library for measuring the topic of Swagger documentation
We found that swagger-themes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.