Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support constructor parameters annotations for schemes #1417

Merged
Merged
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
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ micronaut-data = "4.6.2"
micronaut-test = "4.2.1"
micronaut-kotlin = "4.2.0"
micronaut-logging = "1.2.3"
micronaut-session = "4.2.0"
micronaut-docs = "2.0.0"

[libraries]
Expand All @@ -49,6 +50,7 @@ micronaut-reactor = { module = "io.micronaut.reactor:micronaut-reactor-bom", ver
micronaut-gradle-plugin = { module = "io.micronaut.gradle:micronaut-minimal-plugin", version.ref = "micronaut-gradle-plugin"}
micronaut-groovy = { module = "io.micronaut.groovy:micronaut-groovy-bom", version.ref = "micronaut-groovy" }
micronaut-validation = { module = "io.micronaut.validation:micronaut-validation-bom", version.ref = "micronaut-validation" }
micronaut-session = { module = "io.micronaut.session:micronaut-session-bom", version.ref = "micronaut-session" }
micronaut-data = { module = "io.micronaut.data:micronaut-data-bom", version.ref = "micronaut-data" }
micronaut-test = { module = "io.micronaut.test:micronaut-test-bom", version.ref = "micronaut-test" }
micronaut-kotlin = { module = "io.micronaut.kotlin:micronaut-kotlin-bom", version.ref = "micronaut-kotlin" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,14 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
param.vendorExtensions.put("hasMultipleParams", hasMultipleParams);
}
op.vendorExtensions.put("originReturnProperty", op.returnProperty);
if (op.responses != null && !op.responses.isEmpty()) {
for (var resp : op.responses) {
if (resp.isDefault) {
resp.code = "default";
}
}
}

processParametersWithAdditionalMappings(op.allParams, op.imports);
processWithResponseBodyMapping(op);
processOperationWithResponseWrappers(op);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,14 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
param.vendorExtensions.put("hasMultipleParams", hasMultipleParams);
}
op.vendorExtensions.put("originReturnProperty", op.returnProperty);
if (op.responses != null && !op.responses.isEmpty()) {
for (var resp : op.responses) {
if (resp.isDefault) {
resp.code = "default";
}
}
}

processParametersWithAdditionalMappings(op.allParams, op.imports);
processWithResponseBodyMapping(op);
processOperationWithResponseWrappers(op);
Expand Down
1 change: 1 addition & 0 deletions openapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
// this dependency needs to be updated manually. It's used by html2md
api(libs.managed.jsoup)

testImplementation(mnSession.micronaut.session)
testImplementation(mn.micronaut.management)
testImplementation(mn.micronaut.inject.kotlin.test)
testImplementation(mn.micronaut.inject.groovy.test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,26 +883,18 @@ private Parameter processMethodParameterAnnotation(VisitorContext context, io.sw
newParameter.setExplode(true);
}
} else if (parameter.isAnnotationPresent(Header.class)) {
String headerName = parameter.stringValue(Header.class, "name")
.orElse(parameter.stringValue(Header.class)
.orElseGet(() -> NameUtils.hyphenate(parameterName)));

if (isIgnoredHeader(headerName)) {
var headerName = getHeaderName(parameter, parameterName);
if (headerName == null) {
return null;
}

newParameter = new HeaderParameter();
newParameter.setName(headerName);
} else if (parameter.isAnnotationPresent(Headers.class)) {

List<AnnotationValue<Header>> headerAnnotations = parameter.getAnnotationValuesByType(Header.class);
if (CollectionUtils.isNotEmpty(headerAnnotations)) {
var headerAnn = headerAnnotations.get(0);
var headerName = headerAnn.stringValue("name")
.orElse(headerAnn.stringValue()
.orElseGet(() -> NameUtils.hyphenate(parameterName)));

if (isIgnoredHeader(headerName)) {
var headerName = getHeaderName(parameter, parameterName);
if (headerName == null) {
return null;
}
newParameter = new HeaderParameter();
Expand Down Expand Up @@ -1067,6 +1059,26 @@ private Parameter processMethodParameterAnnotation(VisitorContext context, io.sw
return newParameter;
}

private String getHeaderName(TypedElement parameter, String parameterName) {
// skip params like this: @Header Map<String, String>
if (isIgnoredParameter(parameter)) {
return null;
}
String headerName = parameter.stringValue(Header.class, "name")
.orElse(parameter.stringValue(Header.class)
.orElseGet(() -> NameUtils.hyphenate(parameterName)));

if (isIgnoredHeader(headerName)) {
return null;
}

return headerName;
}

private boolean isIgnoredHeaderParameter(TypedElement parameter) {
return parameter.getType().isAssignable(Map.class);
}

private void processBody(VisitorContext context, OpenAPI openAPI,
io.swagger.v3.oas.models.Operation swaggerOperation, JavadocDescription javadocDescription,
boolean permitsRequestBody, List<MediaType> consumesMediaTypes, TypedElement parameter,
Expand Down
Loading
Loading