Skip to content

Commit e164db5

Browse files
committed
Update operationId strategy mapping to use strings, update docs
Signed-off-by: Michael Edgar <[email protected]>
1 parent 1dc2fe6 commit e164db5

File tree

3 files changed

+44
-17
lines changed

3 files changed

+44
-17
lines changed

extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,23 @@ public interface SmallRyeOpenApiConfig {
236236
Optional<String> infoLicenseUrl();
237237

238238
/**
239-
* Set the strategy to automatically create an operation Id
240-
*/
241-
Optional<OperationIdStrategy> operationIdStrategy();
239+
* Set the strategy to automatically create an operation Id. The strategy may be
240+
* one of the predefined values or the name of a fully-qualified class that
241+
* implements the {@code io.smallrye.openapi.api.OperationIdGenerator}
242+
* interface.
243+
*
244+
* <p>
245+
* Predefined strategies:
246+
* <ul>
247+
* <li>{@code method}: generate an operationId with the resource method's
248+
* name</li>
249+
* <li>{@code class-method}: generate an operationId with the resource class's
250+
* simple name and the resource method's name</li>
251+
* <li>{@code package-class-method}: generate an operationId with the resource
252+
* class's fully-qualified name and the resource method's name</li>
253+
* </ul>
254+
*/
255+
Optional<String> operationIdStrategy();
242256

243257
/**
244258
* Set this boolean value to enable or disable the merging of the deprecated `@Schema`
@@ -258,12 +272,6 @@ public enum SecurityScheme {
258272
oauth2Implicit
259273
}
260274

261-
public enum OperationIdStrategy {
262-
METHOD,
263-
CLASS_METHOD,
264-
PACKAGE_CLASS_METHOD
265-
}
266-
267275
default Map<String, String> getValidSecuritySchemeExtensions() {
268276
return securitySchemeExtensions()
269277
.entrySet()

extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/deployment/filter/SecurityConfigFilterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public Optional<String> infoLicenseUrl() {
258258
}
259259

260260
@Override
261-
public Optional<OperationIdStrategy> operationIdStrategy() {
261+
public Optional<String> operationIdStrategy() {
262262
return Optional.empty();
263263
}
264264

extensions/smallrye-openapi/runtime/src/main/java/io/quarkus/smallrye/openapi/runtime/OpenApiConfigMapping.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import java.util.HashMap;
55
import java.util.Map;
66

7-
import org.eclipse.microprofile.config.spi.Converter;
87
import org.eclipse.microprofile.openapi.OASConfig;
98

109
import io.smallrye.config.ConfigSourceInterceptorContext;
1110
import io.smallrye.config.ConfigValue;
12-
import io.smallrye.config.Converters;
1311
import io.smallrye.config.RelocateConfigSourceInterceptor;
14-
import io.smallrye.openapi.api.OpenApiConfig.OperationIdStrategy;
12+
import io.smallrye.config.common.utils.StringUtil;
13+
import io.smallrye.openapi.api.OpenApiConfig;
1514
import io.smallrye.openapi.api.SmallRyeOASConfig;
1615

1716
/**
@@ -20,8 +19,6 @@
2019
public class OpenApiConfigMapping extends RelocateConfigSourceInterceptor {
2120
private static final long serialVersionUID = 1L;
2221
private static final Map<String, String> RELOCATIONS = relocations();
23-
private static final Converter<OperationIdStrategy> OPERATION_ID_STRATEGY_CONVERTER = Converters
24-
.getImplicitConverter(OperationIdStrategy.class);
2522

2623
public OpenApiConfigMapping() {
2724
super(RELOCATIONS);
@@ -31,15 +28,37 @@ public OpenApiConfigMapping() {
3128
public ConfigValue getValue(ConfigSourceInterceptorContext context, String name) {
3229
ConfigValue configValue = super.getValue(context, name);
3330

34-
// Special case for enum. The converter run after the interceptors, so we have to do this here.
31+
/*
32+
* Special case for operationId strategy that supports both enumerated values or a FQCN.
33+
* The converter run after the interceptors, so we have to do this here.
34+
*/
3535
if (configValue != null && name.equals(SmallRyeOASConfig.OPERATION_ID_STRAGEGY)) {
36-
String correctValue = OPERATION_ID_STRATEGY_CONVERTER.convert(configValue.getValue()).toString();
36+
String correctValue = convertOperationIdStrategy(configValue.getValue());
3737
configValue = configValue.withValue(correctValue);
3838
}
3939

4040
return configValue;
4141
}
4242

43+
private static String convertOperationIdStrategy(String value) {
44+
final String trimmedValue = value.trim();
45+
46+
if (trimmedValue.isEmpty()) {
47+
return null;
48+
}
49+
50+
switch (StringUtil.skewer(trimmedValue)) {
51+
case "method":
52+
return OpenApiConfig.OperationIdStrategy.METHOD;
53+
case "class-method":
54+
return OpenApiConfig.OperationIdStrategy.CLASS_METHOD;
55+
case "package-class-method":
56+
return OpenApiConfig.OperationIdStrategy.PACKAGE_CLASS_METHOD;
57+
default:
58+
return trimmedValue;
59+
}
60+
}
61+
4362
private static Map<String, String> relocations() {
4463
Map<String, String> relocations = new HashMap<>();
4564
mapKey(relocations, SmallRyeOASConfig.VERSION, QUARKUS_OPEN_API_VERSION);

0 commit comments

Comments
 (0)