2020@ Configuration
2121public class OpenApiConfig {
2222
23- @ Bean
24- public GroupedOpenApi tempOpenApi1 (@ Qualifier ("openApbCustomizerV1" ) OpenApiCustomiser openApiCustomiser ) {
25- String [] paths = {"/v1/**" };
26- String [] packagedToMatch = {"com.github.elibracha.samples.controllers" };
27- GroupedOpenApi openApi = GroupedOpenApi .builder ().setGroup ("v1" ).pathsToMatch (paths ).packagesToScan (packagedToMatch ).addOpenApiCustomiser (openApiCustomiser ).build ();
28- return openApi ;
29- }
23+ @ Bean
24+ public GroupedOpenApi tempOpenApi1 (@ Qualifier ("openApbCustomizerV1" ) OpenApiCustomiser openApiCustomiser ) {
25+ String [] paths = { "/v1/**" };
26+ String [] packagedToMatch = { "com.github.elibracha.samples.controllers" };
27+ GroupedOpenApi openApi = GroupedOpenApi .builder ().setGroup ("v1" ).pathsToMatch (paths )
28+ .packagesToScan (packagedToMatch ).addOpenApiCustomiser (openApiCustomiser ).build ();
29+ return openApi ;
30+ }
3031
31- @ Bean
32- public GroupedOpenApi tempOpenApi2 (@ Qualifier ("openApbCustomizerV2" ) OpenApiCustomiser openApiCustomiser ) {
33- String [] paths = {"/v2/**" };
34- String [] packagedToMatch = {"com.github.elibracha.samples.controllers" };
35- GroupedOpenApi openApi = GroupedOpenApi .builder ().setGroup ("v2" ).pathsToMatch (paths ).packagesToScan (packagedToMatch ).addOpenApiCustomiser (openApiCustomiser ).build ();
36- return openApi ;
37- }
32+ @ Bean
33+ public GroupedOpenApi tempOpenApi2 (@ Qualifier ("openApbCustomizerV2" ) OpenApiCustomiser openApiCustomiser ) {
34+ String [] paths = { "/v2/**" };
35+ String [] packagedToMatch = { "com.github.elibracha.samples.controllers" };
36+ GroupedOpenApi openApi = GroupedOpenApi .builder ().setGroup ("v2" ).pathsToMatch (paths )
37+ .packagesToScan (packagedToMatch ).addOpenApiCustomiser (openApiCustomiser ).build ();
38+ return openApi ;
39+ }
3840
39- @ Bean
40- public OpenApiCustomiser openApbCustomizerV1 () {
41- return openApi -> {
42- openApi .paths (removeSubstringVersionFromPath (openApi .getPaths ()));
43- openApi .info (new Info ().title ("OpenAPI PetStore - OpenAPI 3.0 - Version 1.0" )
44- . version ( "v1" ) .description ("PetStore Api version 1.0" ));
45- };
46- }
41+ @ Bean
42+ public OpenApiCustomiser openApbCustomizerV1 () {
43+ return openApi -> {
44+ openApi .paths (removeSubstringVersionFromPath (openApi .getPaths ()));
45+ openApi .info (new Info ().title ("OpenAPI PetStore - OpenAPI 3.0 - Version 1.0" ). version ( "v1 " )
46+ .description ("PetStore Api version 1.0" ));
47+ };
48+ }
4749
48- @ Bean
49- public OpenApiCustomiser openApbCustomizerV2 () {
50- return openApi -> {
51- openApi .paths (removeSubstringVersionFromPath (openApi .getPaths ()));
52- openApi .info (new Info ().title ("OpenAPI PetStore - OpenAPI 3.0 - Version 2.0" )
53- . version ( "v2" ) .description ("PetStore Api version 2.0" ));
54- };
55- }
50+ @ Bean
51+ public OpenApiCustomiser openApbCustomizerV2 () {
52+ return openApi -> {
53+ openApi .paths (removeSubstringVersionFromPath (openApi .getPaths ()));
54+ openApi .info (new Info ().title ("OpenAPI PetStore - OpenAPI 3.0 - Version 2.0" ). version ( "v2 " )
55+ .description ("PetStore Api version 2.0" ));
56+ };
57+ }
5658
57- public Paths removeSubstringVersionFromPath (Paths openApiPaths ) {
58- Paths paths = new Paths ();
59- for (Map .Entry <String , PathItem > entry : openApiPaths .entrySet ()) {
60- int cut = entry .getKey ().indexOf ("/" , entry .getKey ().indexOf ("/" ) + 1 );
61- paths .put (entry .getKey ().substring (cut ), entry .getValue ());
62- }
63- return paths ;
64- }
59+ public Paths removeSubstringVersionFromPath (Paths openApiPaths ) {
60+ Paths paths = new Paths ();
61+ for (Map .Entry <String , PathItem > entry : openApiPaths .entrySet ()) {
62+ int cut = entry .getKey ().indexOf ("/" , entry .getKey ().indexOf ("/" ) + 1 );
63+ paths .put (entry .getKey ().substring (cut ), entry .getValue ());
64+ }
65+ return paths ;
66+ }
6567
66- @ Bean
67- public OpenAPI customOpenAPI () {
68- return new OpenAPI ().openapi ("3.0.2" )
69- .components (new Components ().addSecuritySchemes ("api_key" ,
70- new SecurityScheme ().type (SecurityScheme .Type .APIKEY ).name ("api_key" ).in (SecurityScheme .In .HEADER ))
71- .addSecuritySchemes ("petstore_auth" , new SecurityScheme ().type (SecurityScheme .Type .OAUTH2 ).flows (new OAuthFlows ()
72- .implicit (new OAuthFlow ().authorizationUrl ("https://petstore3.swagger.io/oauth/authorize" )
73- .scopes (new Scopes ().addString ("write:pets" , "modify pets in your account" ).addString ("read:pets" , "read your pets" ))))));
74- }
68+ @ Bean
69+ public OpenAPI customOpenAPI () {
70+ return new OpenAPI ().openapi ("3.0.2" )
71+ .components (new Components ()
72+ .addSecuritySchemes ("api_key" ,
73+ new SecurityScheme ().type (SecurityScheme .Type .APIKEY ).name ("api_key" )
74+ .in (SecurityScheme .In .HEADER ))
75+ .addSecuritySchemes ("petstore_auth" ,
76+ new SecurityScheme ().type (SecurityScheme .Type .OAUTH2 )
77+ .flows (new OAuthFlows ().implicit (new OAuthFlow ()
78+ .authorizationUrl ("https://petstore3.swagger.io/oauth/authorize" )
79+ .scopes (new Scopes ()
80+ .addString ("write:pets" , "modify pets in your account" )
81+ .addString ("read:pets" , "read your pets" ))))));
82+ }
7583}
0 commit comments