Add automatic URI detection for OpenAPI document configuration#1319
Add automatic URI detection for OpenAPI document configuration#1319fjtirado merged 1 commit intoserverlessworkflow:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Improves the fluent OpenAPI task builder to accept a document(String) that can represent either a literal OpenAPI document URI or a runtime (JQ) expression, aiming to prevent JsonQueryException when users pass URL strings (Issue #1303).
Changes:
- Added
EndpointUtil.isJqExpr()to identify JQ-style${...}expressions. - Updated
CallOpenAPITaskFluent.document(String)to route${...}to runtimeExpression and everything else todocument(URI). - Added an experimental integration test using
MockWebServer, plus a new OpenAPI impl dependency for the experimental test module.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/EndpointUtil.java | Adds a helper for detecting ${...} expressions. |
| fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/CallOpenAPITaskFluent.java | Changes document(String) to auto-detect literal vs expression. |
| experimental/test/src/test/java/io/serverlessworkflow/fluent/test/FuncOpenAPITest.java | Adds a MockWebServer-based OpenAPI execution test. |
| experimental/test/pom.xml | Adds the OpenAPI implementation dependency for tests. |
| .gitignore | Ignores .bob/notes/ and normalizes .vscode/ entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| FuncWorkflowBuilder.workflow("openapi-call-workflow") | ||
| .tasks( | ||
| openapi() | ||
| .document(URI.create(mockWebServer.url("/v2/swagger.json").toString())) | ||
| .operation("findPetsByStatus") | ||
| .parameters(Map.of("status", "available"))) |
There was a problem hiding this comment.
This test is named as if it validates the new auto-detection in document(String), but it calls document(URI) (line 94) and therefore never exercises the updated logic that distinguishes literal URIs from JQ expressions. To prevent regressions of #1303, update/add assertions to cover openapi().document(mockWebServer.url(...).toString()) (string overload) and (ideally) a ${...} / raw-JQ case to ensure it still gets treated as a runtime expression.
There was a problem hiding this comment.
This one should be deleted
|
@mcruzdev see mcruzdev#5 |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Test | ||
| void test_openapi_document_with_non_jq_uri_string() { | ||
| String mockedSwaggerDoc = | ||
| """ | ||
| { | ||
| "swagger": "2.0", | ||
| "info": { "version": "1.0.0", "title": "Mock Petstore" }, | ||
| "host": "localhost:%d", | ||
| "basePath": "/v2", | ||
| "schemes": [ "http" ], | ||
| "paths": { | ||
| "/pet/findByStatus": { | ||
| "get": { | ||
| "operationId": "findPetsByStatus", | ||
| "parameters": [ | ||
| { | ||
| "name": "status", | ||
| "in": "query", | ||
| "required": true, | ||
| "type": "string" | ||
| } | ||
| ], | ||
| "responses": { "200": { "description": "OK" } } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| """ | ||
| .formatted(mockWebServer.getPort()); | ||
|
|
||
| mockWebServer.enqueue( | ||
| new MockResponse(200, Headers.of("Content-Type", "application/json"), mockedSwaggerDoc)); | ||
| mockWebServer.enqueue( | ||
| new MockResponse( | ||
| 200, | ||
| Headers.of("Content-Type", "application/json"), | ||
| """ | ||
| { "description": "OK" } | ||
| """)); | ||
| var w = | ||
| FuncWorkflowBuilder.workflow("openapi-call-workflow") | ||
| .tasks( | ||
| openapi() | ||
| .document(URI.create(mockWebServer.url("/v2/swagger.json").toString())) | ||
| .operation("findPetsByStatus") | ||
| .parameters(Map.of("status", "available"))) | ||
| .build(); |
There was a problem hiding this comment.
This test is named as if it validates the new document(String) auto-detection behavior, but it currently calls the document(URI) overload. That means it won’t catch regressions of the original issue (passing a URL as a string being treated as a JQ expression). Consider switching to document(mockWebServer.url("/v2/swagger.json").toString()) and/or adding an explicit test that document(String) with an http(s)://... value loads successfully (and optionally a separate test for a real JQ expression string).
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public static Endpoint fromString(String uri) { | ||
| return fromString(uri, null); | ||
| } | ||
|
|
||
| public static Endpoint fromString(String uri, ReferenceableAuthenticationPolicy auth) { | ||
| Objects.requireNonNull(uri, "Endpoint URI cannot be null"); | ||
| String trimmed = uri.trim(); | ||
| Endpoint endpoint = new Endpoint(); | ||
| if (isUrlLike(trimmed)) { | ||
| UriTemplate template = new UriTemplate(); | ||
| if (trimmed.indexOf('{') >= 0 || trimmed.indexOf('}') >= 0) { | ||
| template.setLiteralUriTemplate(trimmed); | ||
| } else { | ||
| template.setLiteralUri(URI.create(trimmed)); | ||
| } | ||
| endpoint.setUriTemplate(template); | ||
| return endpoint; | ||
| } | ||
|
|
There was a problem hiding this comment.
The PR description says a new EndpointUtil.isJqExpr() helper was added to detect JQ expressions (strings starting with "${"), but there is no such method in this change set (and no references found in the repo). Either add the helper (and use it where intended) or update the PR description to match the implemented URL-vs-expression detection logic.
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 9 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /** | ||
| * Sets the OpenAPI document location. This method automatically detects whether the provided | ||
| * string is a literal URI or a JQ runtime expression. | ||
| * | ||
| * @param uri the OpenAPI document location as either a literal URI string or a JQ expression | ||
| * @return this builder instance for method chaining | ||
| * @see #document(URI) for setting a literal URI directly | ||
| * @see #document(String, AuthenticationConfigurer) for setting a document with authentication | ||
| */ |
There was a problem hiding this comment.
The Javadoc says this method detects "literal URI vs JQ runtime expression", but the implementation delegates to EndpointUtil.fromString(...) which classifies inputs as literal only when they look like scheme://... (and treats everything else as an expression). Consider tightening the wording to match the actual behavior (e.g., require a URI scheme) or adjusting the detection logic so it aligns with the documented JQ vs literal distinction.
Changes
The document() method now intelligently handles both:
This improves the developer experience by eliminating the need to choose between document(String) and document(URI) methods based on the input type.
Closes #1303