Skip to content

Add automatic URI detection for OpenAPI document configuration#1319

Merged
fjtirado merged 1 commit intoserverlessworkflow:mainfrom
mcruzdev:issue-1303
Apr 16, 2026
Merged

Add automatic URI detection for OpenAPI document configuration#1319
fjtirado merged 1 commit intoserverlessworkflow:mainfrom
mcruzdev:issue-1303

Conversation

@mcruzdev
Copy link
Copy Markdown
Collaborator

Changes

  • Enhanced CallOpenAPITaskFluent.document(String) to automatically detect whether the input is a literal URI or a JQ runtime expression
  • Added EndpointUtil.isJqExpr() helper method to identify JQ expressions (strings starting with "${" )
  • Added comprehensive test coverage with FuncOpenAPITest using MockWebServer
  • Added serverlessworkflow-impl-openapi dependency to experimental/test module
  • Updated .gitignore to exclude Bob-Shell notes directory

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

@mcruzdev mcruzdev requested a review from fjtirado as a code owner April 15, 2026 15:00
Copilot AI review requested due to automatic review settings April 15, 2026 15:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to document(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.

Comment thread experimental/test/pom.xml
Comment thread fluent/spec/src/main/java/io/serverlessworkflow/fluent/spec/spi/EndpointUtil.java Outdated
Comment on lines +91 to +96
FuncWorkflowBuilder.workflow("openapi-call-workflow")
.tasks(
openapi()
.document(URI.create(mockWebServer.url("/v2/swagger.json").toString()))
.operation("findPetsByStatus")
.parameters(Map.of("status", "available")))
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread .gitignore
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should be deleted

@fjtirado fjtirado marked this pull request as draft April 16, 2026 10:23
@fjtirado
Copy link
Copy Markdown
Collaborator

@mcruzdev see mcruzdev#5

@fjtirado fjtirado marked this pull request as ready for review April 16, 2026 16:34
Copilot AI review requested due to automatic review settings April 16, 2026 16:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +51 to +97
@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();
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@fjtirado fjtirado self-requested a review April 16, 2026 18:13
Copilot AI review requested due to automatic review settings April 16, 2026 18:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +30 to 38
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;
}

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Signed-off-by: Matheus Cruz <matheuscruz.dev@gmail.com>
Copilot AI review requested due to automatic review settings April 16, 2026 21:22
@fjtirado fjtirado merged commit 4062fc4 into serverlessworkflow:main Apr 16, 2026
5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +44 to +52
/**
* 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
*/
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsonQueryException when using FuncDSL.openapi

3 participants