File tree Expand file tree Collapse file tree 5 files changed +73
-0
lines changed
java/org/opendevstack/provision/config
test/java/org/opendevstack/provision/config Expand file tree Collapse file tree 5 files changed +73
-0
lines changed Original file line number Diff line number Diff line change 44
55### Added
66
7+ - Add swagger-ui support ([ #679 ] ( https://github.com/opendevstack/ods-provisioning-app/pull/679 ) )
78- Handle logout in SPA ([ #675 ] ( https://github.com/opendevstack/ods-provisioning-app/issues/675 ) )
89- Handle form based auth in SPA ([ #637 ] ( https://github.com/opendevstack/ods-provisioning-app/issues/637 ) )
910- Add default permissions to project groups on project creation ([ #636 ] ( https://github.com/opendevstack/ods-provisioning-app/pull/636 ) )
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ configurations {
6060}
6161
6262dependencies {
63+ implementation(' io.springfox:springfox-boot-starter:3.0.0' )
6364 implementation(' org.springframework.boot:spring-boot-starter-actuator' )
6465 implementation(' org.springframework.boot:spring-boot-starter-mail' )
6566 implementation(' org.springframework.boot:spring-boot-starter-security' )
Original file line number Diff line number Diff line change 1+ package org .opendevstack .provision .config ;
2+
3+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
4+ import org .springframework .context .annotation .Bean ;
5+ import org .springframework .context .annotation .Configuration ;
6+ import springfox .documentation .builders .PathSelectors ;
7+ import springfox .documentation .builders .RequestHandlerSelectors ;
8+ import springfox .documentation .oas .annotations .EnableOpenApi ;
9+ import springfox .documentation .spi .DocumentationType ;
10+ import springfox .documentation .spring .web .plugins .Docket ;
11+
12+ @ Configuration
13+ @ EnableOpenApi
14+ @ ConditionalOnProperty (name = "springfox.documentation.enabled" , havingValue = "true" )
15+ public class SwaggerConfig {
16+
17+ @ Bean
18+ public Docket api () {
19+ return new Docket (DocumentationType .OAS_30 )
20+ .select ()
21+ .apis (RequestHandlerSelectors .any ())
22+ .paths (PathSelectors .any ())
23+ .build ();
24+ }
25+ }
Original file line number Diff line number Diff line change @@ -146,3 +146,5 @@ jenkinspipeline.adminjobs.delete-projects.repo=ods-core
146146
147147jenkinspipeline.adminjobs.delete-components.desc =Delete openshift components
148148jenkinspipeline.adminjobs.delete-components.repo =ods-core
149+
150+ springfox.documentation.enabled =false
Original file line number Diff line number Diff line change 1+ package org .opendevstack .provision .config ;
2+
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+
5+ import org .junit .jupiter .api .Assertions ;
6+ import org .junit .jupiter .api .Test ;
7+ import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
8+ import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
9+ import springfox .documentation .spring .web .plugins .Docket ;
10+
11+ class SwaggerConfigTest {
12+
13+ private final ApplicationContextRunner contextRunner = new ApplicationContextRunner ();
14+
15+ @ Test
16+ public void whenDefaultApplicationContext_thenSwaggerUINotAvailable () {
17+ this .contextRunner
18+ .withUserConfiguration (SwaggerConfig .class )
19+ .run (
20+ context -> {
21+ try {
22+ // this raise an exception if the bean does not exists!
23+ Docket docket = context .getBean (Docket .class );
24+ Assertions .fail ();
25+ } catch (NoSuchBeanDefinitionException ex ) {
26+ // This is expected
27+ }
28+ });
29+ }
30+
31+ @ Test
32+ public void whenDocumentationPropertyIsTrue_thenSwaggerUIIsAvailable () {
33+
34+ this .contextRunner
35+ .withPropertyValues ("springfox.documentation.enabled=true" )
36+ .withUserConfiguration (SwaggerConfig .class )
37+ .run (
38+ context -> {
39+ // this raise an exception if the bean does not exists!
40+ Docket docket = context .getBean (Docket .class );
41+ assertThat (docket ).isNotNull (); // This is redundant
42+ });
43+ }
44+ }
You can’t perform that action at this time.
0 commit comments