New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using https #118
Comments
Hi, We are not able to repoduce your issue. |
|
For a quick workaround (if resources and docs are accessed from the same base URL) disable private void calculateServerUrl() {
generalInfoBuilder.setServerBaseUrl("/");
} It's more likely than not that the application serving the docs is used through some (TLS terminating, path rewriting etc) reverse proxy or other complex setup, so would be maybe useful support configuring the base URL freely (i.e could be both relative or absolute) from properties? Related specification describing the server URL configuration options: |
hi @kvedel, thanks for hints.
i am not sure where to implement that.
okay. i have to configure nevertheless i tried
and i works. but
is there any possibility to configure |
Hi, You can also use: The OpenAPI definition Bean, and inject the value of your serversUrl from your configuration files. @Bean
public OpenAPI customOpenAPI() {
return new OpenAPI().addServersItem(new Server().url("https://myserver.com"))
.components(new Components().addSecuritySchemes("basicScheme",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")))
.info(new Info().title("SpringShop API").version("V0")
.license(new License().name("Apache 2.0").url("http://springdoc.org")));
} |
Thanks! Works like a charm! |
We had the same issue and we didn't want to have environment specific URLs in our config. Therefore we tried to configuring the context path as serverUrl and it works like a charm (even the generated curl statement is correct): @Bean
public OpenAPI springShopOpenAPI(
@Value("${info.app.version}") String appVersion,
@Value("${server.servlet.context-path}") String contextPath
) {
return new OpenAPI()
.addServersItem(new Server().url(contextPath))
.info(new Info()
.title("Lala")
.description("Lala")
.version(appVersion))
.components(new Components()
.addSecuritySchemes("basicScheme",
new SecurityScheme().type(SecurityScheme.Type.HTTP).scheme("basic")));
} |
I fixed this with this: @Configuration
public class OpenAPIConfiguration {
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.addServersItem(new Server().url("/"));
}
} |
Hi, sorry for bumping. Anyone know how to remove only the server description "Generated server url"? I see that I can set a new server url, but I do not want to manually add the server url, because for deployment the baseurl will change. |
You just use the standard swagger annotation @OpenAPIDefinition (ideally, in a spring Bean): https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#OpenAPIDefinition @OpenAPIDefinition(info = @Info(title = "API Examples", version = "1.0"),
servers = @Server(url = "http://toto.com", description = "your descrption"),
tags = @Tag(name = "Operations"))
@Component
public class MyConfig {
} |
@bnasslahsen Thanks. I am familiar with the code config you placed and also via Spring Bean method. This way unfortunately I also need to define the URL address and I would like to only edit the description URL, ideally remove it and not mess with the URL which is automatically generated by springdoc. |
For changing only the description you have @Bean
public OpenApiCustomiser serverOpenApiCustomiser1() {
return openAPI -> openAPI.getServers().forEach(server -> server.setDescription("my new description"));
} |
@bnasslahsen The code does not change the description of current base Url. |
It replaces the "Generated server url" description. |
@bnasslahsen This is the code I am using and it doesn't change the default description to "my new description". @SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public OpenApiCustomiser serverOpenApiCustomiser1() {
return openAPI -> openAPI.getServers().forEach(server -> server.setDescription("my new description"));
}
} |
Here is a full working code. @SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public OpenApiCustomiser serverOpenApiCustomiser1() {
return openAPI -> openAPI.getServers().forEach(server -> server.setDescription("my new description"));
}
@RestController
public class HelloController {
@GetMapping("/hello")
String hello( ) {
return "Hello";
}
}
} And this is the generated spec: openapi: 3.0.1
info:
title: OpenAPI definition
version: v0
servers:
- url: 'http://localhost:8080'
description: my new description
paths:
/hello:
get:
tags:
- hello-controller
operationId: hello
responses:
'200':
description: OK
content:
'*/*':
schema:
type: string
components: {}
Can you test and confirm that you are getting the same result. If the following code doesn't work on your local environment, then you will have to add the link to a minimal reproducible sample. |
Given that the current url for swagger-ui uses https.
Then the generated server url still uses http.
So executing an api-call fails.
The Request URL uses http.
TypeError: Failed to fetch
Any idea how to get it work?
The text was updated successfully, but these errors were encountered: