Skip to content

Commit

Permalink
[GLT-4300] fixed Swagger determining base URL; added manual override
Browse files Browse the repository at this point in the history
  • Loading branch information
djcooke committed Nov 13, 2024
1 parent 4b05a10 commit 336c15c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
21 changes: 12 additions & 9 deletions pinery-ws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@ JAVA_OPTS="-Duser.timezone=GMT -Djava.awt.headless=true -Xmx6144m -XX:MaxPermSiz

### Deploying

1. copy the example `.properties` file and external `context.xml` from the Pinery implementation
1. Copy the example `.properties` file and external `context.xml` from the Pinery implementation
you're using to `$CATALINA_HOME/conf/Catalina/localhost/`, where `$CATALINA_HOME` is your Tomcat
base directory
2. rename `context.xml` to match the context root of your deployment. E.g. if you're deploying to
base directory.
2. Rename `context.xml` to match the context root of your deployment. E.g. if you're deploying to
`/pinery`, call the context file `pinery.xml`. If you're deploying to the root address, call the
file `ROOT.xml`
3. Configure options specific to the source LIMS in the properties file
file `ROOT.xml`.
3. Configure options specific to the source LIMS in the properties file.
- If you are deploying Pinery behind a reverse-proxy and find that the Swagger docs are not
working properly, it may be necessary to configure the base URL for Swagger. You can do this by
adding a `swagger.baseUrl` property to your properties file.
4. Copy the built `.war` file from the Pinery implemention to `$CATALINA_HOME/webapps/`, naming it
to match your `context.xml` above. If Tomcat is configured to autodeploy, the webapp will be
(re)deployed automatically; otherwise, deploy the webapp manually
- **WARNING**: In some cases with autodeploy enabled, Tomcat may delete the context XML during redeployment.
You can prevent this by stopping tomcat before copying the WAR into the webapps directory, or by making the
file immutable via `chattr +i <filename>`
(re)deployed automatically; otherwise, deploy the webapp manually.
- **WARNING**: In some cases with autodeploy enabled, Tomcat may delete the context XML during
redeployment. You can prevent this by stopping tomcat before copying the WAR into the webapps
directory, or by making the file immutable via `chattr +i <filename>`.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ca.on.oicr.pinery.ws.component;

import java.util.Collections;

import org.springdoc.core.configuration.SpringDocConfiguration;
import org.springdoc.core.configuration.SpringDocSpecPropertiesConfiguration;
import org.springdoc.core.configuration.SpringDocUIConfiguration;
Expand All @@ -13,10 +15,13 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.filter.ForwardedHeaderFilter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.servers.Server;
import jakarta.servlet.ServletContext;

@Configuration
@EnableWebMvc
Expand Down Expand Up @@ -48,9 +53,13 @@ public GroupedOpenApi api() {
}

@Bean
public OpenAPI openApi() {
public OpenAPI openApi(ServletContext servletContext, @Value("${swagger.baseUrl:#{null}}") String baseUrl) {
Server server = new Server()
.url(baseUrl != null ? baseUrl : servletContext.getContextPath())
.description("Default server URL");
return new OpenAPI()
.info(new Info().title(projectName).version(projectVersion));
.info(new Info().title(projectName).version(projectVersion))
.servers(Collections.singletonList(server));
}

}

0 comments on commit 336c15c

Please sign in to comment.