Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,33 @@
}
}

void mapParameterSchema(Parameter param, ParameterContext context) {

Check failure on line 662 in core/src/main/java/io/smallrye/openapi/runtime/scanner/spi/AbstractParameterProcessor.java

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 39 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=smallrye_smallrye-open-api&issues=AZ7RDwlCK3HGsrH-9GmK&open=AZ7RDwlCK3HGsrH-9GmK&pullRequest=2596
if (ModelUtil.parameterHasSchema(param) || context.targetType == null) {
if (context.targetType == null) {
return;
}

if (ModelUtil.parameterHasSchema(param)) {
Schema existingSchema = param.getSchema();
if (existingSchema != null && existingSchema.getRef() == null && existingSchema.getType() == null) {
Schema typeSchema = SchemaFactory.typeToSchema(scannerContext, context.targetType, null);
if (typeSchema != null) {
if (typeSchema.getRef() != null) {
Schema resolved = ModelUtil.getComponent(scannerContext.getOpenApi(), typeSchema.getRef());
if (resolved != null) {
typeSchema = resolved;
}
}
if (typeSchema.getType() != null) {
existingSchema.setType(typeSchema.getType());
}
if (existingSchema.getEnumeration() == null && typeSchema.getEnumeration() != null) {
existingSchema.setEnumeration(typeSchema.getEnumeration());
}
if (existingSchema.getFormat() == null && typeSchema.getFormat() != null) {
existingSchema.setFormat(typeSchema.getFormat());
}
}
}
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,31 @@ void testJakartaParameterInBeanFromField() throws IOException, JSONException {
test.io.smallrye.openapi.runtime.scanner.Widget.class);
}

@Test
void testBeanParamEnumDefaultValue() throws IOException, JSONException {
class QueryOptions {
@jakarta.ws.rs.QueryParam("sortOrder")
@Parameter(description = "Sort direction", schema = @Schema(defaultValue = "ASC"))
SortOrder sortOrder;
}

@jakarta.ws.rs.Path("/beanparam-enum-default")
class ListResource {
@jakarta.ws.rs.GET
@jakarta.ws.rs.Produces(jakarta.ws.rs.core.MediaType.APPLICATION_JSON)
public String list(@jakarta.ws.rs.BeanParam QueryOptions options) {
return "ok";
}
}

test("params.beanparam-enum-default-value.json", SortOrder.class, QueryOptions.class, ListResource.class);
}

enum SortOrder {
ASC,
DESC
}

@Test
void testJavaxParameterInBeanFromSetter() throws IOException, JSONException {
test("params.parameter-in-bean-from-setter.json",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"openapi": "3.1.0",
"paths": {
"/beanparam-enum-default": {
"get": {
"parameters": [
{
"name": "sortOrder",
"in": "query",
"description": "Sort direction",
"schema": {
"default": "ASC",
"enum": [
"ASC",
"DESC"
],
"type": "string"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"SortOrder": {
"enum": [
"ASC",
"DESC"
],
"type": "string"
}
}
}
}