Skip to content

feat(poc,openapi-compiler): Add basic openapi compiler#34

Merged
thumbrise merged 1 commit into
mainfrom
openapi-compiler
May 19, 2026
Merged

feat(poc,openapi-compiler): Add basic openapi compiler#34
thumbrise merged 1 commit into
mainfrom
openapi-compiler

Conversation

@thumbrise

@thumbrise thumbrise commented May 19, 2026

Copy link
Copy Markdown
Owner

No description provided.

@thumbrise thumbrise self-assigned this May 19, 2026
@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@thumbrise has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 9 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fc8b7a35-ff75-4686-867a-427ad23a306b

📥 Commits

Reviewing files that changed from the base of the PR and between 83484fd and c538f72.

⛔ Files ignored due to path filters (1)
  • poc/openapi/go.sum is excluded by !**/*.sum
📒 Files selected for processing (15)
  • .run/Emit instruction to cache.run.xml
  • .run/poc_openapi run.run.xml
  • poc/openapi/.gitignore
  • poc/openapi/.golangci.yaml
  • poc/openapi/Taskfile.yaml
  • poc/openapi/cmd/cmd.go
  • poc/openapi/go.mod
  • poc/openapi/internal/compile/compiler.go
  • poc/openapi/main.go
  • poc/openapi/pkg/oputil/decoder.go
  • poc/openapi/pkg/oputil/pull.go
  • poc/openapi/pkg/stdin/read.go
  • poc/openapi/runtime/build/.gitignore
  • poc/openapi/runtime/cache/.gitignore
  • poc/openapi/runtime/output/.gitignore
📝 Walkthrough

Walkthrough

This PR introduces a new Go application in poc/openapi that reads OpenAPI instruction schemas from stdin or files and compiles them into OpenAPI 3.0.3 YAML specifications. The application provides a CLI command with configurable input/output paths, decodes instructions in YAML or JSON formats, converts operation metadata into OpenAPI spec endpoints with error responses, and writes the resulting spec to disk.

Changes

OpenAPI instruction compiler and CLI

Layer / File(s) Summary
Instruction input and decoding utilities
poc/openapi/pkg/stdin/read.go, poc/openapi/pkg/oputil/pull.go, poc/openapi/pkg/oputil/decoder.go
Stdin reading rejects TTY/terminal input and reports stat failures; dual-format instruction decoder tries YAML first then JSON, aggregating errors; term lookup utility searches operations by ID.
CLI command and flag handling
poc/openapi/cmd/cmd.go, poc/openapi/go.mod
Root op-to-curl CLI command accepts instruction via --input-stdin flag or --input file path, validates at least one source is provided, logs resolved paths, and delegates to compiler; module declares direct dependencies on yaml/JSON parsing, OpenAPI generation, schema, and CLI frameworks.
Instruction to OpenAPI 3.0.3 compiler
poc/openapi/internal/compile/compiler.go
Compiler decodes input bytes, maps each operation's HTTP path and error terms into OpenAPI endpoint definitions with status code responses, marshals to YAML, prints to stdout, and writes to output file with 0600 permissions; skips operations missing HTTP path or status terms with logging.
Application bootstrap and configuration
poc/openapi/main.go, .run/poc_openapi run.run.xml, poc/openapi/.gitignore, poc/openapi/.golangci.yaml, poc/openapi/Taskfile.yaml, poc/openapi/output/.gitignore
Main function initializes structured text logger and runs CLI with background context; GoLand run configuration targets the poc/openapi module with example flags; linter configuration enables 40+ checkers with selective exclusions and formatter rules; Taskfile wires lint, build, run, and emit tasks; gitignore patterns exclude build artifacts, cache, and generated outputs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A compiler hops in, YAML in hand,
Transforms instruction to spec so grand,
OpenAPI blooms from each operation,
Stdin or file—no hesitation!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding a basic OpenAPI compiler for the proof-of-concept. The title directly reflects the primary objective of introducing the poc/openapi compiler functionality across multiple new files.
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 openapi-compiler

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 and usage tips.

@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: 7

🤖 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 @.run/poc_openapi run.run.xml:
- Line 19: The run configuration's filePath attribute currently points at the
old curl entrypoint ("poc/curl/main.go") and must be updated to the OpenAPI
app's entrypoint; locate the XML run config element with the filePath attribute
and replace its value ("$PROJECT_DIR$/poc/curl/main.go") with the correct
OpenAPI entrypoint path (e.g. the OpenAPI app main.go) so the run configuration
launches the new app.

In `@poc/openapi/cmd/cmd.go`:
- Around line 32-46: The CLI metadata (Name, Usage, UsageText, Description)
currently brands the tool as "op-to-curl" and mentions "curl client" which is
misleading because the command actually compiles OpenAPI specs; update these
fields (Name, Usage, UsageText and the multi-line Description string) to reflect
OpenAPI output: rename the command to something like "op-to-openapi" or
"op-to-oas", change all occurrences of "curl client" to "OpenAPI spec" (or
"OpenAPI/ OAS output"), and adjust example/help text so examples and flags
describe generating an OpenAPI spec file rather than a curl client. Ensure the
UsageText and Description still convey input options (--input, --input-stdin,
--output) and the expected OP traits.
- Around line 72-99: Detect and reject when both instructionStdin and
instruction are set instead of silently preferring stdin: inside the Action
function before reading stdin or the file (the block that branches on
instructionStdin / instruction / else), add a guard like if instructionStdin &&
instruction != "" { return fmt.Errorf("%w: --input and --input-stdin cannot be
used together", ErrConflictingInputFlags) } (create a new sentinel error
ErrConflictingInputFlags if one does not exist) so the CLI returns a clear error
when both flags are provided.

In `@poc/openapi/internal/compile/compiler.go`:
- Around line 73-90: The ResponseOrRef entries created in the loop lack the
required description field and produce invalid OpenAPI output; update the code
that builds the responses map (the loop iterating opOperation.Error that uses
oputil.PullTermByID(ophttp.StatusID, term.Trait) and assigns
responses[fmt.Sprintf("%s", httpStatusTerm.Value)] = openapi3.ResponseOrRef{})
to populate each ResponseOrRef with at least a description (for example using
the status code and/or httpStatusTerm.Value or a default text) before passing
the map to oa3Operation.Responses.WithMapOfResponseOrRefValues.

In `@poc/openapi/pkg/oputil/decoder.go`:
- Around line 27-39: The YAML fallback path may leave partial data in the target
variable 'ins' which then contaminates the subsequent JSON decode; before
calling json.Unmarshal you must reset 'ins' to its zero value (reinitialize the
struct or slice/map as appropriate) so the JSON decode does not reuse stale
fields. Locate the yaml.Unmarshal/json.Unmarshal calls and insert a
reinitialization of 'ins' (e.g., ins = <zero value of ins's type>) between the
two unmarshal attempts, preserving the existing error accumulation into 'errs'.

In `@poc/openapi/Taskfile.yaml`:
- Line 24: Replace the plain curl invocation "curl
http://localhost:8080/op/instruction > cache/instruction.yaml" with a hardened
invocation that fails fast and doesn't write non-2xx responses: use curl --fail
--show-error --max-time 10 --retry 2 -o cache/instruction.yaml (or write to a
temp file and move into place on success) so transient hangs/timeouts and
non-200 responses cause a non-zero exit and prevent corrupt
cache/instruction.yaml.
- Line 12: Taskfile.yaml currently runs the build command "cmd: go build -o
./build/op-to-curl" which fails if the ./build directory doesn't exist; update
the Taskfile.yaml task that contains this cmd to ensure the output directory is
created first (e.g., run a mkdir -p ./build or equivalent step before invoking
go build) so the directory exists when "go build -o ./build/op-to-curl" runs.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 542a105d-313f-433a-9fb9-5e705971197f

📥 Commits

Reviewing files that changed from the base of the PR and between 0213452 and 83484fd.

⛔ Files ignored due to path filters (1)
  • poc/openapi/go.sum is excluded by !**/*.sum
📒 Files selected for processing (12)
  • .run/poc_openapi run.run.xml
  • poc/openapi/.gitignore
  • poc/openapi/.golangci.yaml
  • poc/openapi/Taskfile.yaml
  • poc/openapi/cmd/cmd.go
  • poc/openapi/go.mod
  • poc/openapi/internal/compile/compiler.go
  • poc/openapi/main.go
  • poc/openapi/output/.gitignore
  • poc/openapi/pkg/oputil/decoder.go
  • poc/openapi/pkg/oputil/pull.go
  • poc/openapi/pkg/stdin/read.go

Comment thread .run/poc_openapi run.run.xml Outdated
Comment thread poc/openapi/cmd/cmd.go Outdated
Comment thread poc/openapi/cmd/cmd.go
Comment thread poc/openapi/internal/compile/compiler.go
Comment thread poc/openapi/pkg/oputil/decoder.go
Comment thread poc/openapi/Taskfile.yaml Outdated
Comment thread poc/openapi/Taskfile.yaml Outdated
@thumbrise thumbrise force-pushed the openapi-compiler branch 6 times, most recently from 53fdf02 to 7d38f43 Compare May 19, 2026 10:30
@thumbrise thumbrise merged commit 4175055 into main May 19, 2026
5 checks passed
@thumbrise thumbrise deleted the openapi-compiler branch May 19, 2026 10:43
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.

1 participant