springfox icon indicating copy to clipboard operation
springfox copied to clipboard

[Question] How can you modify page title or header title of the swagger-ui page

Open TehBakker opened this issue 7 years ago • 37 comments

Please take the time to search the repository, if your question has already been asked or answered.

  • What version of the library are you using? 2.6.1

What kind of issue is this?

  • [ X] Question.

I can't find how to replace the title of the HTML page (which is "Swagger UI") nor the title in the header which is "Swagger".

I'm definiting my swagger properties through the ApiInfo bean

` Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage(MyApiImpl.class.getPackage().getName())) .paths(PathSelectors.any()) .build() // To Hide some path from SwaggerUi, add the ApiIgnore annotation. .ignoredParameterTypes(ApiIgnore.class) .apiInfo(getApiInfo()); }

private ApiInfo getApiInfo() {
    return new ApiInfo(
            applicationName,
            applicationDescription,
            applicationVersion,
            null,
            new Contact(company, infoUrl, contactMail), null, null);
}`

Title is displayed under the header fine but I want to remove the "swagger", the one in the logo__title span in the header and can't find how to do it.

Thanks for your help

TehBakker avatar Mar 16 '18 11:03 TehBakker

Seems like a nice feature to add. Currently its not customizable.

dilipkrish avatar Mar 17 '18 04:03 dilipkrish

Ah ok, thanks for the quick reply.

TehBakker avatar Mar 17 '18 10:03 TehBakker

+1 For this feature. What are the hacky ways we can achieve this?

timothy-mugayi avatar Nov 04 '18 12:11 timothy-mugayi

Currently none, but hacky way I would love is to push a PR for it ;)

dilipkrish avatar Nov 07 '18 02:11 dilipkrish

+1 for this feature.

stacey-sloth avatar Jul 19 '19 14:07 stacey-sloth

Is this feature added ?

talk2debendra avatar Oct 16 '19 18:10 talk2debendra

+1 for this feature.

schrufygroovy avatar Oct 22 '19 09:10 schrufygroovy

+1

markus-hsk avatar Nov 04 '19 14:11 markus-hsk

I built a small js-Code to achieve this:

function updateTitle()
{
    var elements = document.getElementsByClassName('title');
    if(elements.length > 0)
    {
        var content = elements[0].textContent;
        document.title = content;
    }
    else
    {
        setTimeout(updateTitle, 1000);
    }
}
updateTitle();

You just have to add this line in the swagger ui index.html file:

<script src="pathToJs.js"></script>

I know, its not a perfect solution and not really good programming, but it works for me and the users of my api so i'm fine with it.

markus-hsk avatar Nov 05 '19 10:11 markus-hsk

I'd like this feature aswell. ApiInfoBuilder().title("MY REST API").description("MY REST API") Using this changes title of the page, but I'd also like it to change title of the tab inside web browser I can implement this feature in my spare time if you give me some directions

grmkris avatar Jan 08 '20 09:01 grmkris

I will just add one more argument to this thread: In a world of microservices i have 3 or 4 Swagger UI opened in my browser. And all of them are titled the same.

cookieMr avatar Jan 09 '20 10:01 cookieMr

Yes that's the main reason why I'd like to change page title dynamically

grmkris avatar Jan 09 '20 10:01 grmkris

Actually, if you're using express, you can change the title by going to nodes-modules/swagger-ui-express/index.js , and modifying this section : customSiteTitle = customSiteTitle || 'Swagger UI'

Mehdi-111 avatar Jan 16 '20 23:01 Mehdi-111

customeSiteTitle

@Mehdi-111 Thank you for the tip but it is customSiteTitle not customeSiteTitle.

MoSofi avatar Mar 04 '20 16:03 MoSofi

We had a Flask application where we ran into this same exact problem. The workaround is to copy the template here, into a top-level directory called templates/, and then change the <title> HTML to what you wish. You also need to update the Flask core configuration to specify that templates directory, something like this:

app = Flask(__name__, \
            template_folder='./templates', \
            static_folder='./static',
            static_url_path='/flask-apispec/static'
)

Hope this helps anyone using Flask-APISpec!

dkheyman avatar Apr 18 '20 02:04 dkheyman

Was the solution to this ever solved? I'm attempting to add a custom logo to Swagger UI but no luck as of yet!

JHurst97 avatar Jun 04 '21 13:06 JHurst97

+1 for this feature.

cperazal avatar Jul 07 '21 05:07 cperazal

+1 for this feature.

mattivilola avatar Jan 26 '22 14:01 mattivilola

+1 for this feature.

Froostx avatar May 31 '22 03:05 Froostx

You can add a function to swaggerOptions that modifies the DOM after the swagger UI loads.

https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/#:~:text=oncomplete

fwdsimonp avatar Sep 02 '22 15:09 fwdsimonp

for now try this extension in the browser https://chrome.google.com/webstore/detail/change-page-title/ebbfpplpmnoblfmdkbicmakmbbjijdpg

till we find swagger solution

MahmoudElgml avatar Sep 23 '22 12:09 MahmoudElgml

+2 for this feature

starlingvibes avatar Feb 27 '23 13:02 starlingvibes

I have been using the swagger-ui docker container in order to update the UI elements using changes to the index.html (CSS and custom client-side scripts) and the swagger-initlializer.js in order to get a custom plugin added into the UI for a menu to choose from the various service JSON files served from a shared NFS drive mounted into the container.

The custom files are added to the docker container (using the swaggerapi/swagger-ui as the base container). Then the reference to the CSS file(s) are added to the index.html file in order to ensure that they are loaded with the page.

There is some $0.02 worth of insight that I had found to solve this particular issue. I would have opted for the Express route since it already supports the implementations that I really needed but the container is far easier to manage for the purpose we have for it.

sspieker-cc avatar May 09 '23 21:05 sspieker-cc

+1 for this feature.

brunorabaca avatar May 16 '23 18:05 brunorabaca

+1 for this feature

lehuygiang28 avatar Jun 16 '23 17:06 lehuygiang28

+1 for this feature

LeonardoPahim avatar Jun 16 '23 17:06 LeonardoPahim

+1 for this feature

MichaelStevenson2207 avatar Aug 07 '23 15:08 MichaelStevenson2207

Setting value to DocumentTitle property changes the web page title.

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1");
    c.RoutePrefix = "Swagger";
    c.DocumentTitle = "My API Help";
});

sudhakarg1net avatar Aug 23 '23 13:08 sudhakarg1net

Any idea how to do this with springdoc-openapi-starter-webmvc-ui 2.2.0's OpenAPIDefinition v3?

Currently using (this does NOT update DocumentTitle): @OpenAPIDefinition(info = @Info(title = "...", version = "1.0", description = "...")})

Thanks in advance

ajaygautam avatar Sep 06 '23 11:09 ajaygautam

+1

alan-czajkowski avatar Feb 02 '24 04:02 alan-czajkowski

+1

alanenggb avatar Feb 21 '24 20:02 alanenggb