Skip to content

[Jex-Generator] Update role generation #529

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

Merged
merged 4 commits into from
Dec 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.util.Base64;

/** Adds Basic Authorization header to requests. */
public class BasicAuthIntercept implements RequestIntercept {
public final class BasicAuthIntercept implements RequestIntercept {

private final String headerValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;
Expand All @@ -21,9 +20,6 @@

final class DHttpClientContext implements HttpClient, SpiHttpClient {

/**
* HTTP Authorization header.
*/
static final String AUTHORIZATION = "Authorization";
private static final String BEARER = "Bearer ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ public void buildApiDocumentation() {

public List<String> roles() {
final var roles = new ArrayList<>(methodRoles);
roles.addAll(bean.roles());
if (roles.isEmpty()) {
roles.addAll(bean.roles());
}
return roles;
}

Expand Down Expand Up @@ -521,7 +523,7 @@ private List<PathSegments.Segment> namedSegments() {

private boolean allArgParamNames() {
for (int i = 0; i < params.size(); i++) {
if (!params.get(i).name().equals("arg" + i)) {
if (!("arg" + i).equals(params.get(i).name())) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,32 @@ void writeRouting() {
final String fullPath = segments.fullPath();

if (method.isErrorMethod()) {
writer.append(" routing.error(%s.class, this::_%s)", method.exceptionShortName(), method.simpleName());
writer.append(" routing.error(%s.class, this::_%s", method.exceptionShortName(), method.simpleName());
} else if (isFilter) {
writer.append(" routing.filter(this::_%s)", method.simpleName());
writer.append(" routing.filter(this::_%s", method.simpleName());
} else {
writer.append(" routing.%s(\"%s\", ", webMethod.name().toLowerCase(), fullPath);
var hxRequest = method.hxRequest();
if (hxRequest != null) {
writeHxHandler(hxRequest);
} else {
writer.append("this::_%s)", method.simpleName());
writer.append("this::_%s", method.simpleName());
}
}
writeRoles();
writer.append(";").eol();
writer.append(");").eol();
}

private void writeRoles() {
List<String> roles = method.roles();
if (!roles.isEmpty()) {
writer.append(".withRoles(");
if (!roles.isEmpty() && !isFilter) {
writer.append(", ");
for (int i = 0; i < roles.size(); i++) {
if (i > 0) {
writer.append(", ");
}
writer.append(Util.shortName(roles.get(i), true));
}
writer.append(")");
}
}

Expand All @@ -92,7 +91,7 @@ private void writeHxHandler(HxRequestPrism hxRequest) {
} else if (hasValue(hxRequest.value())) {
writer.append(".triggerName(\"%s\")", hxRequest.value());
}
writer.append(".build())");
writer.append(".build()");
}

private static boolean hasValue(String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.avaje.http.generator.core.ControllerReader;
import io.avaje.http.generator.core.ParamType;
import io.avaje.http.generator.core.PlatformAdapter;
import io.avaje.http.generator.core.ProcessingContext;
import io.avaje.http.generator.core.UType;

class JexAdapter implements PlatformAdapter {
Expand All @@ -32,13 +33,14 @@ public boolean isBodyMethodParam() {
public String bodyAsClass(UType type) {

if ("java.io.InputStream".equals(type.full())) {
return "ctx.bodyInputStream()";
return "ctx.bodyAsInputStream()";
} else if ("java.lang.String".equals(type.full())) {
return "ctx.body()";
} else if ("byte[]".equals(type.full())) {
return "ctx.bodyAsBytes()";
} else if (ProcessingContext.useJsonb()) {
return type.shortName() + "JsonType.fromJson(ctx.bodyAsInputStream())";
}

return "ctx.bodyAsClass(" + type.mainType() + ".class)";
}

Expand Down
2 changes: 1 addition & 1 deletion tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<junit.version>5.11.3</junit.version>
<assertj.version>3.26.3</assertj.version>
<jackson.version>2.18.2</jackson.version>
<jex.version>3.0-RC8</jex.version>
<jex.version>3.0-RC10</jex.version>
<avaje-inject.version>11.0</avaje-inject.version>
<nima.version>4.1.4</nima.version>
<javalin.version>6.3.0</javalin.version>
Expand Down
Loading