-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix #852 - Process Qute templates in a strict manner * Fix discriminator annotations on pojo.qute * Improve testing on discriminator annotations * Incorporate @hbelmiro review --------- Signed-off-by: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com> Co-authored-by: Ricardo Zanini <1538000+ricardozanini@users.noreply.github.com>
- Loading branch information
1 parent
75f328d
commit b4d52c0
Showing
50 changed files
with
6,460 additions
and
160 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...ent/src/main/java/io/quarkiverse/openapi/generator/deployment/template/ExprEvaluator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.quarkiverse.openapi.generator.deployment.template; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.ExecutionException; | ||
|
||
import io.quarkus.qute.EvalContext; | ||
import io.quarkus.qute.Expression; | ||
|
||
final class ExprEvaluator { | ||
|
||
private ExprEvaluator() { | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T> T evaluate(EvalContext context, Expression expression) throws ExecutionException, InterruptedException { | ||
return (T) context.evaluate(expression).toCompletableFuture().get(); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static <T> T[] evaluate(EvalContext context, List<Expression> expressions, Class<T> type) | ||
throws ExecutionException, InterruptedException { | ||
T[] results = (T[]) java.lang.reflect.Array.newInstance(type, expressions.size()); | ||
|
||
for (int i = 0; i < expressions.size(); i++) { | ||
Expression expression = expressions.get(i); | ||
T result = type.cast(context.evaluate(expression).toCompletableFuture().get()); | ||
results[i] = result; | ||
} | ||
|
||
return results; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../main/java/io/quarkiverse/openapi/generator/deployment/template/StrNamespaceResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package io.quarkiverse.openapi.generator.deployment.template; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionStage; | ||
|
||
import io.quarkus.qute.EvalContext; | ||
import io.quarkus.qute.NamespaceResolver; | ||
|
||
/** | ||
* Namespace resolver to mimic the function of io.quarkus.qute.runtime.extensions.StringTemplateExtensions. | ||
* This extension is built-in with Qute when used in a context with Quarkus DI. | ||
* Since these extensions are built in build time by Qute we can't use them because our process also runs in build time without | ||
* a CDI context. | ||
* So any namespace resolver auto-generated by Quarkus won't be added to our engine. | ||
* | ||
* @see <a href="https://quarkus.io/guides/qute-reference#template_extension_methods">Template Extension Methods</a> | ||
*/ | ||
public class StrNamespaceResolver implements NamespaceResolver { | ||
|
||
static final StrNamespaceResolver INSTANCE = new StrNamespaceResolver(); | ||
|
||
private StrNamespaceResolver() { | ||
} | ||
|
||
@Override | ||
public String getNamespace() { | ||
return "str"; | ||
} | ||
|
||
/** | ||
* @see io.quarkus.qute.runtime.extensions.StringTemplateExtensions#fmt(String, String, Object...) | ||
*/ | ||
public String fmt(String format, Object... args) { | ||
return String.format(format, args); | ||
} | ||
|
||
@Override | ||
public CompletionStage<Object> resolve(EvalContext context) { | ||
switch (context.getName()) { | ||
case "fmt": | ||
if (context.getParams().size() < 2) { | ||
throw new IllegalArgumentException( | ||
"Missing required parameter for 'fmt'. Make sure that the function has at least two parameters"); | ||
} | ||
try { | ||
return CompletableFuture.completedFuture( | ||
fmt(ExprEvaluator.evaluate(context, context.getParams().get(0)), | ||
ExprEvaluator.evaluate(context, context.getParams().subList(1, context.getParams().size()), | ||
Object.class))); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
default: | ||
throw new IllegalArgumentException("There's no method named '" + context.getName() + "'"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.