Skip to content

Use compiler endpoint artifacts for HTTP endpoint export#2640

Open
chiranSachintha wants to merge 1 commit into
ballerina-platform:masterfrom
chiranSachintha:new-endpint-export
Open

Use compiler endpoint artifacts for HTTP endpoint export#2640
chiranSachintha wants to merge 1 commit into
ballerina-platform:masterfrom
chiranSachintha:new-endpint-export

Conversation

@chiranSachintha

@chiranSachintha chiranSachintha commented Jul 7, 2026

Copy link
Copy Markdown
Member

$title.

Examples

FIxed: wso2/product-integrator#1427

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests
  • Updated the spec
  • Checked native-image compatibility
  • Checked the impact on OpenAPI generation

Updated the HTTP compiler plugin to export endpoint artifacts through the compiler context instead of writing individual endpoint YAML files.

  • Replaced file-based endpoint YAML generation with artifact registration in EndpointYamlGenerator.
  • Adjusted ServiceArtifactsExtractor to use the new artifact flow.
  • Removed the now-unused EndpointWrapper helper.
  • Updated module dependencies to drop Jackson YAML/databind requirements and add runtime/logging modules.
  • Refactored compiler plugin tests to assert the consolidated target/artifact/endpoints.yaml output and support the new API.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Endpoint YAML generation in the compiler plugin is refactored from writing per-service endpoint YAML files to registering endpoint details as a consolidated artifact (endpoints.yaml) via a new context API. The EndpointWrapper class is removed, Jackson dependencies are dropped, and module/build configs and tests are updated accordingly.

Changes

Endpoint artifact consolidation

Layer / File(s) Summary
Artifact registration API
compiler-plugin/.../EndpointYamlGenerator.java
Replaces writeEndpointYaml() with addEndpointArtifact(), which derives endpoint details and registers them via context.addEndpointArtifact(...) instead of serializing YAML to disk; removes YAML/file-generation constants and imports.
Extractor wiring update
compiler-plugin/.../ServiceArtifactsExtractor.java
Calls addEndpointArtifact() directly per server, removing the prior try/catch IOException handling.
EndpointWrapper removal
compiler-plugin/.../EndpointWrapper.java
Removes the wrapper class entirely along with its constructor and accessor.
Dependency and module cleanup
compiler-plugin/build.gradle, compiler-plugin/src/main/java/module-info.java
Drops Jackson databind/YAML dependencies and module requires; adds java.logging and io.ballerina.runtime requires.
Test suite updates
compiler-plugin-tests/.../ServiceArtifactsExtractionTest.java
Replaces per-endpoint YAML assertions with checks against consolidated endpoints.yaml (existence, schemaPath, port, artifact counts) and updates the mocked context proxy to support addEndpointArtifact.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ServiceArtifactsExtractor
  participant EndpointYamlGenerator
  participant CompilerPluginContext

  ServiceArtifactsExtractor->>EndpointYamlGenerator: addEndpointArtifact()
  EndpointYamlGenerator->>EndpointYamlGenerator: getEndpoint()
  EndpointYamlGenerator->>EndpointYamlGenerator: getEndpointName()
  EndpointYamlGenerator->>CompilerPluginContext: addEndpointArtifact(port, basePath, type, schemaPath)
  CompilerPluginContext-->>ServiceArtifactsExtractor: consolidated endpoints.yaml entry recorded
Loading

Poem

A hop, a skip, one file to keep,
No more scattered YAMLs to sweep,
endpoints.yaml holds them tight,
Jackson's weight now out of sight,
This bunny cheers the tidy leap! 🐰📄

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description misses the required Purpose section and is mostly just a placeholder plus checklist, so it doesn't match the template. Add the Purpose section, flesh out Examples with relevant context, and ensure the checklist items are reviewed or updated to reflect the PR.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: switching HTTP endpoint export to compiler endpoint artifacts.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/ServiceArtifactsExtractionTest.java (2)

532-553: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Match the assertion to endpoints.yaml. safeFileName(p).contains("_endpoint") never matches the consolidated artifact name, so this test can pass even if endpoints.yaml is generated. Assert directly on artifactDir.resolve("endpoints.yaml") instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/ServiceArtifactsExtractionTest.java`
around lines 532 - 553, The test is checking the wrong artifact name, so it may
miss a generated consolidated endpoints file. Update
testEndpointYamlSkippedWhenNoServersDefined in ServiceArtifactsExtractionTest to
assert directly on artifactDir.resolve("endpoints.yaml") instead of filtering
Files.walk with safeFileName(p).contains("_endpoint"). This keeps the check
aligned with the actual artifact produced when no servers are defined.

191-202: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Stale filename makes this test vacuous. service_endpoint.yaml is no longer emitted; the consolidated artifact is endpoints.yaml, so this assertion always passes and no longer checks the no-server case. Use endpoints.yaml here, or assert that no *_endpoint files exist.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/ServiceArtifactsExtractionTest.java`
around lines 191 - 202, The test is asserting against a stale artifact name, so
it no longer verifies anything meaningful. Update
testConfigurablePortWithRequiredValue in ServiceArtifactsExtractionTest to use
the current consolidated artifact name endpoints.yaml, or change the assertion
to verify that no *_endpoint files are generated. Keep the check centered on the
artifactDir path and the existing executeBallerinaCommand flow.
🧹 Nitpick comments (2)
compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/ServiceArtifactsExtractor.java (1)

169-185: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

diagnostics parameter is now unused in exportEndpointYaml. After replacing writeEndpointYaml() (which added an ExceptionDiagnostic on IOException) with addEndpointArtifact(), this method no longer reads or writes diagnostics. Confirm addEndpointArtifact()/context.addEndpointArtifact() cannot fail in a way that previously surfaced as a diagnostic; if so, drop the now-dead parameter, otherwise reinstate error handling so registration failures aren't silently swallowed.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/ServiceArtifactsExtractor.java`
around lines 169 - 185, The diagnostics parameter in exportEndpointYaml is now
unused after switching from writeEndpointYaml to addEndpointArtifact, so either
remove that dead parameter from exportEndpointYaml and its callers if
addEndpointArtifact/context.addEndpointArtifact cannot fail, or restore error
handling if artifact registration can still throw so failures continue to
surface as diagnostics. Check the control flow around exportEndpointYaml,
EndpointYamlGenerator.addEndpointArtifact, and any context.addEndpointArtifact
usage to keep the method signature and behavior consistent.
compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointYamlGenerator.java (1)

49-51: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Misplaced Javadoc. This block reads "Adds endpoint details of HTTP service to the build context," which describes addEndpointArtifact(), but it sits directly above the constructor. Move it onto addEndpointArtifact() (or replace it with a constructor-appropriate description).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointYamlGenerator.java`
around lines 49 - 51, The Javadoc for EndpointYamlGenerator is attached to the
wrong member: it describes addEndpointArtifact() but currently sits above the
constructor. Move that comment to addEndpointArtifact() (or rewrite it to
describe the constructor) so the documentation matches the symbol it annotates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointYamlGenerator.java`:
- Around line 102-103: The endpoint name extraction in getEndpointName() is
removing every occurrence of OPENAPI_SUFFIX instead of only the trailing one,
which can corrupt names containing that substring earlier in the schema name.
Update getEndpointName() in EndpointYamlGenerator to trim only the suffix at the
end of schemaFileName after splitting off the extension, and keep the rest of
the name unchanged.

---

Outside diff comments:
In
`@compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/ServiceArtifactsExtractionTest.java`:
- Around line 532-553: The test is checking the wrong artifact name, so it may
miss a generated consolidated endpoints file. Update
testEndpointYamlSkippedWhenNoServersDefined in ServiceArtifactsExtractionTest to
assert directly on artifactDir.resolve("endpoints.yaml") instead of filtering
Files.walk with safeFileName(p).contains("_endpoint"). This keeps the check
aligned with the actual artifact produced when no servers are defined.
- Around line 191-202: The test is asserting against a stale artifact name, so
it no longer verifies anything meaningful. Update
testConfigurablePortWithRequiredValue in ServiceArtifactsExtractionTest to use
the current consolidated artifact name endpoints.yaml, or change the assertion
to verify that no *_endpoint files are generated. Keep the check centered on the
artifactDir path and the existing executeBallerinaCommand flow.

---

Nitpick comments:
In
`@compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointYamlGenerator.java`:
- Around line 49-51: The Javadoc for EndpointYamlGenerator is attached to the
wrong member: it describes addEndpointArtifact() but currently sits above the
constructor. Move that comment to addEndpointArtifact() (or rewrite it to
describe the constructor) so the documentation matches the symbol it annotates.

In
`@compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/ServiceArtifactsExtractor.java`:
- Around line 169-185: The diagnostics parameter in exportEndpointYaml is now
unused after switching from writeEndpointYaml to addEndpointArtifact, so either
remove that dead parameter from exportEndpointYaml and its callers if
addEndpointArtifact/context.addEndpointArtifact cannot fail, or restore error
handling if artifact registration can still throw so failures continue to
surface as diagnostics. Check the control flow around exportEndpointYaml,
EndpointYamlGenerator.addEndpointArtifact, and any context.addEndpointArtifact
usage to keep the method signature and behavior consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 56007526-60c4-41c3-912b-d8556c1036bf

📥 Commits

Reviewing files that changed from the base of the PR and between 8d364d4 and 2f7e552.

📒 Files selected for processing (6)
  • compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/ServiceArtifactsExtractionTest.java
  • compiler-plugin/build.gradle
  • compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointWrapper.java
  • compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointYamlGenerator.java
  • compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/ServiceArtifactsExtractor.java
  • compiler-plugin/src/main/java/module-info.java
💤 Files with no reviewable changes (3)
  • compiler-plugin/build.gradle
  • compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointWrapper.java
  • compiler-plugin/src/main/java/module-info.java

Comment on lines +102 to +103
private String getEndpointName() {
return schemaFileName.split("\\.")[0].replace(OPENAPI_SUFFIX, "");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

file='compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointYamlGenerator.java'

echo '--- outline ---'
ast-grep outline "$file" --view expanded || true

echo
echo '--- relevant lines ---'
cat -n "$file" | sed -n '1,220p'

echo
echo '--- OPENAPI_SUFFIX references ---'
rg -n "OPENAPI_SUFFIX|getEndpointName|schemaFileName" compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator -S

Repository: ballerina-platform/module-ballerina-http

Length of output: 8067


🏁 Script executed:

#!/bin/bash
set -euo pipefail

file='compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/FileNameGeneratorUtil.java'

echo '--- outline ---'
ast-grep outline "$file" --view expanded || true

echo
echo '--- relevant lines ---'
cat -n "$file" | sed -n '1,220p'

echo
echo '--- related constants/usages ---'
rg -n "OPENAPI_SUFFIX|YAML_EXTENSION|getFileName|FileNameGeneratorUtil" compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator -S

Repository: ballerina-platform/module-ballerina-http

Length of output: 10413


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- getNormalizedFileName definition ---'
rg -n "String getNormalizedFileName|getNormalizedFileName\\(" -S compiler-plugin/src/main/java

echo
echo '--- endpoint artifact consumers ---'
rg -n "EndpointArtifact\\(|getEndpointName\\(|addEndpointArtifact\\(" -S compiler-plugin/src/main/java

Repository: ballerina-platform/module-ballerina-http

Length of output: 1370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- OpenAPISpecGenerator relevant section ---'
file='compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/OpenAPISpecGenerator.java'
ast-grep outline "$file" --view expanded || true
echo
cat -n "$file" | sed -n '130,210p'

echo
echo '--- search for replace(OPENAPI_SUFFIX, "") and suffix stripping patterns ---'
rg -n 'replace\(OPENAPI_SUFFIX, ""\)|endsWith\(OPENAPI_SUFFIX\)|substring\(0, .*OPENAPI_SUFFIX\.length\(\)\)' compiler-plugin/src/main/java -S

Repository: ballerina-platform/module-ballerina-http

Length of output: 6412


Strip only the trailing _openapi suffix

getEndpointName() uses replace(OPENAPI_SUFFIX, ""), so any _openapi earlier in the schema name is removed too. A service/path name containing that substring will produce the wrong endpoint name; trim only the trailing suffix instead.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@compiler-plugin/src/main/java/io/ballerina/stdlib/http/compiler/endpointyaml/generator/EndpointYamlGenerator.java`
around lines 102 - 103, The endpoint name extraction in getEndpointName() is
removing every occurrence of OPENAPI_SUFFIX instead of only the trailing one,
which can corrupt names containing that substring earlier in the schema name.
Update getEndpointName() in EndpointYamlGenerator to trim only the suffix at the
end of schemaFileName after splitting off the extension, and keep the rest of
the name unchanged.

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.

Consolidate Service Endpoint Definitions into a Single endpoints.yaml File

1 participant