Swagger: Add a way to add custom css to the generated swagger html

Created on 16 Aug 2018  路  8Comments  路  Source: nestjs/swagger

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior


There's no option to add custom styles to the generated swagger html

Expected behavior


have an option for the DocumentBuilder to setCustomCss that recieves a path to a css file (or scss file?)

Environment


Nest version: 5.0.0


For Tooling issues:
- Node version: 7.7.3
- Platform:  Mac

Most helpful comment

The SwaggerModule accepts options argument as a 4th argument:

public static setup(
    path: string,
    app: INestApplication,
    document: SwaggerDocument,
    options?: SwaggerCustomOptions
) {...}

These options are passed down to the underlying swagger-ui-express package. Here is a SwaggerCustomOptions interface:

export interface SwaggerCustomOptions {
  explorer?: boolean;
  swaggerOptions?: any;
  customCss?: string;
  customJs?: string;
  customfavIcon?: string;
  swaggerUrl?: string;
  customSiteTitle?: string;
}

as you see, there is a customCss property available already.

All 8 comments

I don't mind adding this myself. I just need a little guidance to where the actual swagger express module is called and passed the generated options

The SwaggerModule accepts options argument as a 4th argument:

public static setup(
    path: string,
    app: INestApplication,
    document: SwaggerDocument,
    options?: SwaggerCustomOptions
) {...}

These options are passed down to the underlying swagger-ui-express package. Here is a SwaggerCustomOptions interface:

export interface SwaggerCustomOptions {
  explorer?: boolean;
  swaggerOptions?: any;
  customCss?: string;
  customJs?: string;
  customfavIcon?: string;
  swaggerUrl?: string;
  customSiteTitle?: string;
}

as you see, there is a customCss property available already.

@kamilmysliwiec great! thanks for the info! :-) didn't find that in the docs

Maybe it is a good point to add it into the documentation :) feel free to create a PR, if you want to

can we pass custom css 'file' in the customCss option

does this not work in fastify-swagger?

Not working when using fastify-swagger

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

yuval-hazaz picture yuval-hazaz  路  3Comments

kalaivanan-muthusamy picture kalaivanan-muthusamy  路  4Comments

malbertSC picture malbertSC  路  5Comments

alisherks picture alisherks  路  4Comments

vh13294 picture vh13294  路  4Comments