17
17
import io .swagger .v3 .oas .models .responses .ApiResponse ;
18
18
import io .swagger .v3 .oas .models .responses .ApiResponses ;
19
19
import org .apache .commons .lang3 .ArrayUtils ;
20
+ import org .apache .commons .lang3 .StringUtils ;
20
21
import org .springdoc .core .GenericResponseService ;
21
22
import org .springdoc .core .SpringDocAnnotationsUtils ;
22
23
import org .springdoc .core .SpringDocConfigProperties ;
23
24
import org .springdoc .core .annotations .RouterOperations ;
24
25
import org .springdoc .core .fn .RouterOperation ;
25
26
import org .springdoc .core .providers .CloudFunctionProvider ;
26
27
28
+ import org .springframework .beans .factory .annotation .Value ;
27
29
import org .springframework .cloud .function .context .FunctionCatalog ;
28
30
import org .springframework .cloud .function .context .catalog .SimpleFunctionRegistry .FunctionInvocationWrapper ;
29
31
import org .springframework .cloud .function .context .config .RoutingFunction ;
@@ -83,6 +85,11 @@ public class SpringCloudFunctionProvider implements CloudFunctionProvider {
83
85
*/
84
86
private static final String [] defaultMediaTypes = new String [] { MediaType .APPLICATION_JSON_VALUE , MediaType .TEXT_PLAIN_VALUE };
85
87
88
+ /**
89
+ * The spring cloud function prefix.
90
+ */
91
+ @ Value ("${spring.cloud.function.web.path:}" )
92
+ private String prefix = "" ;
86
93
87
94
/**
88
95
* Instantiates a new Spring cloud function provider.
@@ -95,7 +102,7 @@ public SpringCloudFunctionProvider(Optional<FunctionCatalog> functionCatalogOpti
95
102
this .functionCatalogOptional = functionCatalogOptional ;
96
103
this .genericResponseService = genericResponseService ;
97
104
this .springDocConfigProperties = springDocConfigProperties ;
98
- this .applicationContext = applicationContext ;
105
+ this .applicationContext = applicationContext ;
99
106
}
100
107
101
108
@ Override
@@ -113,10 +120,19 @@ public List<RouterOperation> getRouterOperations(OpenAPI openAPI) {
113
120
buildRequest (openAPI , name , function , requestMethod , routerOperation );
114
121
ApiResponses apiResponses = buildResponses (openAPI , function , defaultMediaTypes );
115
122
routerOperation .getOperationModel ().responses (apiResponses );
116
- if (GET .equals (requestMethod ))
117
- routerOperation .setPath (AntPathMatcher .DEFAULT_PATH_SEPARATOR + name + AntPathMatcher .DEFAULT_PATH_SEPARATOR + "{" + name + "}" );
118
- else
119
- routerOperation .setPath (AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
123
+ if (StringUtils .isEmpty (prefix )) {
124
+ if (GET .equals (requestMethod ))
125
+ routerOperation .setPath (AntPathMatcher .DEFAULT_PATH_SEPARATOR + name + AntPathMatcher .DEFAULT_PATH_SEPARATOR + "{" + name + "}" );
126
+ else
127
+ routerOperation .setPath (AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
128
+ }
129
+ else {
130
+ if (GET .equals (requestMethod ))
131
+ routerOperation .setPath (prefix + AntPathMatcher .DEFAULT_PATH_SEPARATOR + name + AntPathMatcher .DEFAULT_PATH_SEPARATOR + "{" + name + "}" );
132
+ else
133
+ routerOperation .setPath (prefix + AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
134
+ }
135
+
120
136
RouterOperation userRouterOperation = this .getRouterFunctionPaths (name , requestMethod );
121
137
if (userRouterOperation != null )
122
138
mergeRouterOperation (routerOperation , userRouterOperation );
@@ -131,7 +147,10 @@ else if (function.isConsumer()) {
131
147
apiResponse .setContent (new Content ());
132
148
apiResponses .put (String .valueOf (HttpStatus .ACCEPTED .value ()), apiResponse .description (HttpStatus .ACCEPTED .getReasonPhrase ()));
133
149
routerOperation .getOperationModel ().responses (apiResponses );
134
- routerOperation .setPath (AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
150
+ if (StringUtils .isEmpty (prefix ))
151
+ routerOperation .setPath (AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
152
+ else
153
+ routerOperation .setPath (prefix + AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
135
154
RouterOperation userRouterOperation = this .getRouterFunctionPaths (name , requestMethod );
136
155
if (userRouterOperation != null )
137
156
mergeRouterOperation (routerOperation , userRouterOperation );
@@ -142,7 +161,10 @@ else if (function.isSupplier()) {
142
161
RouterOperation routerOperation = buildRouterOperation (name , " supplier" , requestMethod , routerOperationList );
143
162
ApiResponses apiResponses = buildResponses (openAPI , function , new String [] { springDocConfigProperties .getDefaultProducesMediaType () });
144
163
routerOperation .getOperationModel ().responses (apiResponses );
145
- routerOperation .setPath (AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
164
+ if (StringUtils .isEmpty (prefix ))
165
+ routerOperation .setPath (AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
166
+ else
167
+ routerOperation .setPath (prefix + AntPathMatcher .DEFAULT_PATH_SEPARATOR + name );
146
168
RouterOperation userRouterOperation = this .getRouterFunctionPaths (name , requestMethod );
147
169
if (userRouterOperation != null )
148
170
mergeRouterOperation (routerOperation , userRouterOperation );
0 commit comments