Skip to content

Add smoke tests for OpenAPI examples - #49

Closed
christianhelle wants to merge 1 commit into
mainfrom
christianhelle/smoke-tests
Closed

Add smoke tests for OpenAPI examples#49
christianhelle wants to merge 1 commit into
mainfrom
christianhelle/smoke-tests

Conversation

@christianhelle

@christianhelle christianhelle commented Apr 30, 2026

Copy link
Copy Markdown
Owner

Why

The repo only smoke-tested a small canned generation path, which made it easy for spec-specific generation bugs to slip through. This adds a broader smoke test flow that exercises the real example specs under openapi/ and verifies the generated Zig actually compiles.

What changed

  • Added test/smoke-tests.ps1 to discover supported JSON OpenAPI and Swagger examples, generate code one spec at a time, and compile each generated client through a tiny Zig test harness with clear per-spec logging.
  • Updated CI to run that smoke script in the smoke-tests job, so pull requests validate the full JSON example matrix instead of only the petstore path.
  • Documented local smoke test usage in the README and ignored generated/smoke/ so local runs do not leave noisy artifacts behind.
  • Hardened code generation based on failures found by the sweep:
    • preserve enough casing in nested helper type names to avoid collisions
    • map empty property names to a valid Zig identifier
    • escape unresolved path placeholders before emitting writer.print(...) format strings

Notes for reviewers

The smoke suite intentionally covers only supported JSON OpenAPI and Swagger inputs. YAML examples and openapi/json-schema/** are excluded because YAML generation is still unsupported and the JSON Schema fixtures are not OpenAPI smoke targets.

The generator fixes are tightly coupled to the smoke work because the new sweep immediately exposed real compile failures in ingram-micro.json. Those fixes are included here so the new CI coverage is green instead of introducing a permanently failing workflow.

Validation

  • zig build test -Doptimize=ReleaseFast
  • generated and compiled all 22 supported JSON example specs through the smoke harness

Summary by CodeRabbit

Release Notes

  • New Features

    • Smoke test infrastructure for validating OpenAPI/Swagger example generation across the codebase
  • Bug Fixes

    • Enhanced URL path handling in generated code with proper format placeholder escaping
    • Improved identifier naming for empty inputs and field type generation
  • Documentation

    • Added comprehensive smoke testing guide with setup commands and optimization options

Add a smoke test script that generates and compiles every supported JSON OpenAPI example, run it from CI, and document how to use it locally.

The smoke sweep also hardens generated model and API code for name collisions, empty identifiers, and unresolved path placeholders found in real specs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 30, 2026 18:55
@coderabbitai

coderabbitai Bot commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 44c0a993-de38-4d55-90d7-b5a8b8a43440

📥 Commits

Reviewing files that changed from the base of the PR and between 0414274 and 7a39f5d.

📒 Files selected for processing (6)
  • .github/workflows/ci.yml
  • .gitignore
  • README.md
  • src/generators/unified/api_generator.zig
  • src/generators/unified/model_generator.zig
  • test/smoke-tests.ps1

📝 Walkthrough

Walkthrough

The pull request introduces a dedicated PowerShell smoke-test suite (test/smoke-tests.ps1) that replaces direct code-execution validation in CI. It discovers JSON OpenAPI specifications, generates Zig clients, compiles them against a test harness, and reports results. Supporting changes include URL path escaping in the API generator, improved identifier naming in the model generator, documentation of the test process, and .gitignore updates for generated artifacts.

Changes

Cohort / File(s) Summary
CI & Testing Infrastructure
.github/workflows/ci.yml, test/smoke-tests.ps1
Replaced inline code-generation-and-run step with dedicated smoke-test PowerShell script. New script handles Zig discovery, optimized CLI builds, JSON spec discovery (excluding json-schema fixtures), per-spec code generation, compilation via test harness, and aggregate failure reporting.
Configuration & Ignore Rules
.gitignore
Added generated/smoke/ directory to prevent tracking of smoke-test generated artifacts.
Documentation
README.md
Documented smoke-test suite execution, pipeline steps (build, per-example generation, per-client compilation), supported file types (JSON only), optimization modes, and excluded paths.
Code Generators
src/generators/unified/api_generator.zig, src/generators/unified/model_generator.zig
Added URL path brace-escaping to preserve Zig format placeholders ({s}, {d}, {any}). Updated model generator to emit stable __empty identifiers for empty inputs and improved title-part generation with configurable capitalization.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant CI as CI System
    participant Script as smoke-tests.ps1
    participant Builder as Zig Builder
    participant Generator as openapi2zig CLI
    participant Compiler as Zig Compiler
    participant Harness as Test Harness

    User->>CI: Trigger CI workflow
    CI->>Script: Execute smoke-tests.ps1
    Script->>Builder: Build openapi2zig (ReleaseFast)
    Builder-->>Script: Compiled CLI binary
    Script->>Script: Discover JSON specs in openapi/
    loop For each spec file
        Script->>Generator: Run openapi2zig generate
        Generator-->>Script: generated.zig
        Script->>Script: Write compile.zig harness
        Script->>Compiler: Execute zig test
        Compiler->>Harness: Compile & test harness
        Harness-->>Compiler: Pass/Fail result
        Compiler-->>Script: Test result
        Script->>Script: Log result or collect failure
    end
    Script->>CI: Report aggregate pass/fail
    CI-->>User: Workflow status
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested Labels

enhancement, documentation

Poem

🐰 A warren of tests now hop and bound,
Through specs where code shall be found,
Escape those braces, name them clean,
The finest smoke tests ever seen! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the primary change: adding smoke tests for OpenAPI examples. It matches the main purpose of the changeset.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch christianhelle/smoke-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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR expands repository validation by adding a smoke-test workflow that iterates over the real OpenAPI/Swagger JSON examples under openapi/, generates Zig clients for each, and verifies the generated code compiles—while also hardening the unified generators based on issues found by the broader sweep.

Changes:

  • Added a PowerShell smoke-test runner that discovers JSON example specs, generates output per spec, and compiles each via a tiny Zig test harness.
  • Updated CI to run the smoke-test script instead of only exercising the petstore generation path.
  • Hardened unified code generation to avoid compile failures from edge-case spec inputs (empty identifiers, casing collisions, and brace escaping in URI format strings).

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/smoke-tests.ps1 New smoke-test runner: discover JSON specs, generate per spec, and compile via Zig test harness with per-spec logging.
src/generators/unified/model_generator.zig Avoid invalid Zig identifiers for empty names; adjust helper type-name casing to reduce collisions.
src/generators/unified/api_generator.zig Escape {/} in paths before embedding into writer.print(...) format strings, while preserving generated format placeholders.
README.md Documents how to run the smoke tests locally.
.gitignore Ignores local smoke outputs under generated/smoke/.
.github/workflows/ci.yml Runs the smoke-test script in CI to validate the full JSON example matrix.

@christianhelle
christianhelle deleted the christianhelle/smoke-tests branch April 30, 2026 22:03
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.

2 participants