1717import io .swagger .v3 .oas .models .responses .ApiResponse ;
1818import io .swagger .v3 .oas .models .responses .ApiResponses ;
1919import org .apache .commons .lang3 .ArrayUtils ;
20+ import org .apache .commons .lang3 .StringUtils ;
2021import org .springdoc .core .GenericResponseService ;
2122import org .springdoc .core .SpringDocAnnotationsUtils ;
2223import org .springdoc .core .SpringDocConfigProperties ;
2324import org .springdoc .core .annotations .RouterOperations ;
2425import org .springdoc .core .fn .RouterOperation ;
2526import org .springdoc .core .providers .CloudFunctionProvider ;
2627
28+ import org .springframework .beans .factory .annotation .Value ;
2729import org .springframework .cloud .function .context .FunctionCatalog ;
2830import org .springframework .cloud .function .context .catalog .SimpleFunctionRegistry .FunctionInvocationWrapper ;
2931import org .springframework .cloud .function .context .config .RoutingFunction ;
@@ -83,6 +85,11 @@ public class SpringCloudFunctionProvider implements CloudFunctionProvider {
8385 */
8486 private static final String [] defaultMediaTypes = new String [] { MediaType .APPLICATION_JSON_VALUE , MediaType .TEXT_PLAIN_VALUE };
8587
88+ /**
89+ * The spring cloud function prefix.
90+ */
91+ @ Value ("${spring.cloud.function.web.path:}" )
92+ private String prefix = "" ;
8693
8794 /**
8895 * Instantiates a new Spring cloud function provider.
@@ -95,7 +102,7 @@ public SpringCloudFunctionProvider(Optional<FunctionCatalog> functionCatalogOpti
95102 this .functionCatalogOptional = functionCatalogOptional ;
96103 this .genericResponseService = genericResponseService ;
97104 this .springDocConfigProperties = springDocConfigProperties ;
98- this .applicationContext = applicationContext ;
105+ this .applicationContext = applicationContext ;
99106 }
100107
101108 @ Override
@@ -113,10 +120,19 @@ public List<RouterOperation> getRouterOperations(OpenAPI openAPI) {
113120 buildRequest (openAPI , name , function , requestMethod , routerOperation );
114121 ApiResponses apiResponses = buildResponses (openAPI , function , defaultMediaTypes );
115122 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+
120136 RouterOperation userRouterOperation = this .getRouterFunctionPaths (name , requestMethod );
121137 if (userRouterOperation != null )
122138 mergeRouterOperation (routerOperation , userRouterOperation );
@@ -131,7 +147,10 @@ else if (function.isConsumer()) {
131147 apiResponse .setContent (new Content ());
132148 apiResponses .put (String .valueOf (HttpStatus .ACCEPTED .value ()), apiResponse .description (HttpStatus .ACCEPTED .getReasonPhrase ()));
133149 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 );
135154 RouterOperation userRouterOperation = this .getRouterFunctionPaths (name , requestMethod );
136155 if (userRouterOperation != null )
137156 mergeRouterOperation (routerOperation , userRouterOperation );
@@ -142,7 +161,10 @@ else if (function.isSupplier()) {
142161 RouterOperation routerOperation = buildRouterOperation (name , " supplier" , requestMethod , routerOperationList );
143162 ApiResponses apiResponses = buildResponses (openAPI , function , new String [] { springDocConfigProperties .getDefaultProducesMediaType () });
144163 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 );
146168 RouterOperation userRouterOperation = this .getRouterFunctionPaths (name , requestMethod );
147169 if (userRouterOperation != null )
148170 mergeRouterOperation (routerOperation , userRouterOperation );
0 commit comments