Skip to content

Fix OpenAPI spec generation compiler plugin tests#2612

Open
Viranya2006 wants to merge 1 commit into
ballerina-platform:masterfrom
Viranya2006:fix/openapi-spec-generation-tests
Open

Fix OpenAPI spec generation compiler plugin tests#2612
Viranya2006 wants to merge 1 commit into
ballerina-platform:masterfrom
Viranya2006:fix/openapi-spec-generation-tests

Conversation

@Viranya2006

Copy link
Copy Markdown

Summary

Fixes flaky and failing \OpenAPISpecGenerationTest\ cases seen in CI (stdlib level builds).

Changes

  • Test cleanup: @AfterMethod(alwaysRun = true)\ removes \ arget/\ (and generated \Dependencies.toml) for all OpenAPI sample packages after every test, so a failed \�erifySpecContent\ no longer leaves \ arget/openapi\ and breaks \ estSpecGenerationWithoutFlag.
  • sample_package_42: Align with current \http:Caller\ / @http:CallerInfo\ rules (valid \callerInf\ resource, remove invalid \callerErr*\ resources and the conflicting local \Caller\ record type).
  • complex_openapi.yaml: Regenerated golden to match OpenAPI output from Ballerina 2201.13.0 with current HTTP module behavior.

Notes

  • Invalid \CallerInfo\ combinations remain covered in other compiler-plugin test packages (e.g. sample_package_43, sample_package_6).

Made with Cursor

- Add AfterMethod cleanup so failed verifySpecContent does not leave stale
  target/openapi and break testSpecGenerationWithoutFlag.
- Update sample_package_42: valid @http:CallerInfo http:Caller signature and
  remove invalid callerErr resources that no longer compile.
- Refresh complex_openapi.yaml golden to match generated OpenAPI.

Made-with: Cursor
@Viranya2006 Viranya2006 requested a review from daneshk as a code owner April 1, 2026 16:39
Copilot AI review requested due to automatic review settings April 1, 2026 16:39
@sonarqubecloud

sonarqubecloud Bot commented Apr 1, 2026

Copy link
Copy Markdown

Copilot AI 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.

Pull request overview

Updates the HTTP compiler-plugin OpenAPI spec generation tests and their associated golden resources to eliminate CI flakiness caused by leftover build artifacts and to align sample sources/spec output with current http:Caller / @http:CallerInfo behavior.

Changes:

  • Added per-test cleanup to remove target/ (and generated Dependencies.toml) for OpenAPI sample packages after each test.
  • Updated sample_package_42 to use a valid @http:CallerInfo http:Caller resource and removed invalid CallerInfo cases from that sample.
  • Regenerated complex_openapi.yaml to match current OpenAPI output for the updated sample.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
compiler-plugin-tests/src/test/java/io/ballerina/stdlib/http/compiler/OpenAPISpecGenerationTest.java Adds @AfterMethod cleanup and fixes an assertion message to reduce test flakiness from stale build artifacts.
compiler-plugin-tests/src/test/resources/ballerina_sources/sample_package_42/service.bal Aligns the sample service’s CallerInfo usage with current HTTP module rules used by the OpenAPI generator.
compiler-plugin-tests/src/test/resources/yaml_files/complex_openapi.yaml Updates the golden OpenAPI YAML to reflect the new sample behavior and current generated output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +46 to +51
@AfterMethod(alwaysRun = true)
public void cleanOpenApiSampleTargets() throws IOException {
for (String pkg : OPENAPI_SAMPLE_PACKAGES) {
deleteDirectories(RESOURCE_DIRECTORY.resolve(pkg));
}
}

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

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

The cleanup is only done in @AfterMethod. If a developer runs a single test method (or the suite is re-run in a workspace that already has stale target/openapi from a previous run), tests that assert the spec is not generated (e.g., testSpecGenerationWithoutFlag, testSpecGenerationWithCompilationErrors) can still fail because the old OpenAPI artifacts exist before the test executes. Consider also cleaning the relevant package(s) in a @BeforeMethod(alwaysRun = true) (or cleaning at the start of each test) so each test is hermetic regardless of prior filesystem state.

Copilot uses AI. Check for mistakes.
@TharmiganK

Copy link
Copy Markdown
Contributor

Hi @Viranya2006!
Please resolve the conflicts and address the copilot's comment

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.

3 participants