Skip to content

Commit d40ace4

Browse files
committed
add property springdoc.show-spring-cloud-functions
1 parent b1367f8 commit d40ace4

File tree

6 files changed

+195
-0
lines changed

6 files changed

+195
-0
lines changed

springdoc-openapi-common/src/main/java/org/springdoc/core/Constants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ public final class Constants {
140140
*/
141141
public static final String SPRINGDOC_SHOW_ACTUATOR = "springdoc.show-actuator";
142142

143+
/**
144+
* The constant SPRINGDOC_SHOW_SPRING_CLOUD_FUNCTIONS.
145+
*/
146+
public static final String SPRINGDOC_SHOW_SPRING_CLOUD_FUNCTIONS = "springdoc.show-spring-cloud-functions";
147+
143148
/**
144149
* The constant SPRINGDOC_ACTUATOR_TAG.
145150
*/

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfigProperties.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,34 @@ public class SpringDocConfigProperties {
167167
*/
168168
private boolean disableI18n;
169169

170+
/**
171+
* The Show spring cloud functions.
172+
*/
173+
private boolean showSpringCloudFunctions;
174+
170175
/**
171176
* The model Converters
172177
*/
173178
private ModelConverters modelConverters = new ModelConverters();
174179

180+
/**
181+
* Is show spring cloud functions boolean.
182+
*
183+
* @return the boolean
184+
*/
185+
public boolean isShowSpringCloudFunctions() {
186+
return showSpringCloudFunctions;
187+
}
188+
189+
/**
190+
* Sets show spring cloud functions.
191+
*
192+
* @param showSpringCloudFunctions the show spring cloud functions
193+
*/
194+
public void setShowSpringCloudFunctions(boolean showSpringCloudFunctions) {
195+
this.showSpringCloudFunctions = showSpringCloudFunctions;
196+
}
197+
175198
/**
176199
* Gets model converters.
177200
*

springdoc-openapi-common/src/main/java/org/springdoc/core/SpringDocConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
import static org.springdoc.core.Constants.SPRINGDOC_POLYMORPHIC_CONVERTER_ENABLED;
9696
import static org.springdoc.core.Constants.SPRINGDOC_SCHEMA_RESOLVE_PROPERTIES;
9797
import static org.springdoc.core.Constants.SPRINGDOC_SHOW_ACTUATOR;
98+
import static org.springdoc.core.Constants.SPRINGDOC_SHOW_SPRING_CLOUD_FUNCTIONS;
9899
import static org.springdoc.core.SpringDocUtils.getConfig;
99100

100101
/**
@@ -494,6 +495,7 @@ PageableOpenAPIConverter pageableOpenAPIConverter() {
494495
* The type Spring doc function catalog configuration.
495496
*/
496497
@ConditionalOnClass(FunctionEndpointInitializer.class)
498+
@ConditionalOnProperty(name=SPRINGDOC_SHOW_SPRING_CLOUD_FUNCTIONS, matchIfMissing = true)
497499
static class SpringDocFunctionCatalogConfiguration {
498500

499501
/**
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app175;
20+
21+
public class PersonDTO {
22+
private String email;
23+
24+
private String firstName;
25+
26+
private String lastName;
27+
28+
public PersonDTO() {
29+
}
30+
31+
public PersonDTO(final String email, final String firstName, final String lastName) {
32+
this.email = email;
33+
this.firstName = firstName;
34+
this.lastName = lastName;
35+
}
36+
37+
public String getEmail() {
38+
return email;
39+
}
40+
41+
public void setEmail(final String email) {
42+
this.email = email;
43+
}
44+
45+
public String getFirstName() {
46+
return firstName;
47+
}
48+
49+
public void setFirstName(final String firstName) {
50+
this.firstName = firstName;
51+
}
52+
53+
public String getLastName() {
54+
return lastName;
55+
}
56+
57+
public void setLastName(final String lastName) {
58+
this.lastName = lastName;
59+
}
60+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
*
3+
* * Copyright 2019-2020 the original author or authors.
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * https://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package test.org.springdoc.api.app175;
20+
21+
import java.util.function.Consumer;
22+
import java.util.function.Function;
23+
import java.util.function.Supplier;
24+
25+
import io.swagger.v3.oas.annotations.Operation;
26+
import io.swagger.v3.oas.annotations.media.ArraySchema;
27+
import io.swagger.v3.oas.annotations.media.Content;
28+
import io.swagger.v3.oas.annotations.media.Schema;
29+
import io.swagger.v3.oas.annotations.responses.ApiResponse;
30+
import org.springdoc.core.annotations.RouterOperation;
31+
import org.springdoc.core.annotations.RouterOperations;
32+
import reactor.core.publisher.Flux;
33+
import test.org.springdoc.api.AbstractSpringDocTest;
34+
35+
import org.springframework.boot.autoconfigure.SpringBootApplication;
36+
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
37+
import org.springframework.cloud.function.web.mvc.ReactorAutoConfiguration;
38+
import org.springframework.cloud.function.web.source.FunctionExporterAutoConfiguration;
39+
import org.springframework.context.annotation.Bean;
40+
import org.springframework.context.annotation.Import;
41+
import org.springframework.test.context.TestPropertySource;
42+
import org.springframework.web.bind.annotation.RequestMethod;
43+
44+
@Import({ ReactorAutoConfiguration.class, FunctionExporterAutoConfiguration.class, ContextFunctionCatalogAutoConfiguration.class })
45+
@TestPropertySource(properties="springdoc.show-spring-cloud-functions=false")
46+
public class SpringDocApp175Test extends AbstractSpringDocTest {
47+
48+
@SpringBootApplication
49+
static class SpringDocTestApp {
50+
@Bean
51+
public Function<String, String> reverseString() {
52+
return value -> new StringBuilder(value).reverse().toString();
53+
}
54+
55+
@Bean
56+
public Function<String, String> uppercase() {
57+
return value -> value.toUpperCase();
58+
}
59+
60+
@Bean
61+
@RouterOperations({
62+
@RouterOperation(method = RequestMethod.GET, operation = @Operation(description = "Say hello GET", operationId = "lowercaseGET", tags = "positions",
63+
responses = @ApiResponse(responseCode = "200", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class)))))),
64+
@RouterOperation(method = RequestMethod.POST, operation = @Operation(description = "Say hello POST", operationId = "lowercasePOST", tags = "positions",
65+
responses = @ApiResponse(responseCode = "200", description = "new desc", content = @Content(array = @ArraySchema(schema = @Schema(implementation = String.class))))))
66+
})
67+
public Function<Flux<String>, Flux<String>> lowercase() {
68+
return flux -> flux.map(value -> value.toLowerCase());
69+
}
70+
71+
@Bean(name = "titi")
72+
@RouterOperation(operation = @Operation(description = "Say hello By Id", operationId = "hellome", tags = "persons",
73+
responses = @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = PersonDTO.class)))))
74+
public Supplier<PersonDTO> helloSupplier() {
75+
return () -> new PersonDTO();
76+
}
77+
78+
@Bean
79+
public Consumer<PersonDTO> helloConsumer() {
80+
return personDTO -> personDTO.getFirstName();
81+
}
82+
83+
@Bean
84+
public Supplier<Flux<String>> words() {
85+
return () -> Flux.fromArray(new String[] { "foo", "bar" });
86+
}
87+
88+
}
89+
90+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "OpenAPI definition",
5+
"version": "v0"
6+
},
7+
"servers": [
8+
{
9+
"url": "http://localhost",
10+
"description": "Generated server url"
11+
}
12+
],
13+
"paths": {},
14+
"components": {}
15+
}

0 commit comments

Comments
 (0)