Skip to content

chore(api): add aip schema bundle - #3646

Merged
tothandras merged 3 commits into
mainfrom
feat/aip-openapi-tooling
Nov 28, 2025
Merged

tothandras merged 3 commits into
mainfrom
feat/aip-openapi-tooling

Conversation

@tothandras

@tothandras tothandras commented Nov 28, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features

    • Introduced v3 API surface: new generated server/models and OpenAPI bundle for the metering events endpoint.
    • Linting expanded to validate multiple OpenAPI specs.
  • Chores

    • Updated API route from /metering-events → /metering/events.
    • Build and packaging updated to publish v3 exports and add v3 build/watch/bundle steps.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Nov 28, 2025 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Replaces AIP-focused spec workflow with a v3 OpenAPI pipeline: linting now covers multiple spec files, adds a v3 bundling step, updates TypeSpec routes/auth, adjusts package.json exports/scripts to v3, and introduces oapi-codegen config plus generated Go bindings for the v3 API.

Changes

Cohort / File(s) Summary
Top-level Make & Lint
Makefile, api/spec/Makefile
lint-openapi updated to run spectral against multiple files (api/openapi.yaml, api/openapi.cloud.yaml, api/v3/openapi.yaml). api/spec/Makefile generate target adds pnpm run bundle:v3 -o ../v3/openapi.yaml.
Spec package config & scripts
api/spec/package.json
Swapped AIP scripts/exports for v3: removed compile:aip/watch:aip, added compile:v3/watch:v3/bundle:v3; exports now expose ./v3 → ./src/v3/main.tsp; added @redocly/cli devDependency.
TypeSpec changes (v3)
api/spec/src/v3/konnect.tsp, api/spec/src/v3/openmeter.tsp
Route annotation on MeteringEventsEndpoints changed from "/metering-events" → "/metering/events". Auth models for system/personal/konnect tokens refactored to use ...Http.BearerAuth.
v3 codegen files
api/v3/codegen.yaml, api/v3/api.go, api/v3/api.gen.go
Added oapi-codegen config (codegen.yaml) and go:generate hook (api.go); generated api.gen.go introduces v3 Go types, errors, parameter validation helpers, chi-based handlers/middleware wrappers, embedded OpenAPI spec and loader utilities.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review propagation of the route change across TypeSpec and generated code (/metering-events → /metering/events).
  • Validate auth model refactor to ...Http.BearerAuth preserves security metadata and docs.
  • Inspect codegen.yaml options and generated api.gen.go for nullable types and handler signatures.
  • Confirm build order in api/spec/Makefile (compile → bundle → copy) is correct for CI.

Possibly related PRs

Suggested labels

area/api

Suggested reviewers

  • turip
  • chrisgacsal

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions 'add aip schema bundle', but the actual changes replace AIP-related workflows with V3 equivalents, add v3 OpenAPI tooling, and update the metering events API route—not about adding an AIP bundle. Update the title to reflect the main changes, such as 'chore(api): migrate to v3 OpenAPI schema with TypeSpec and update metering events route' or similar.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/aip-openapi-tooling

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d1d7141 and 9ca6ee5.

📒 Files selected for processing (1)
  • api/spec/src/v3/konnect.tsp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/spec/src/v3/konnect.tsp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Quickstart
  • GitHub Check: E2E
  • GitHub Check: Lint
  • GitHub Check: Migration Checks
  • GitHub Check: Test
  • GitHub Check: Build
  • GitHub Check: Code Generators
  • GitHub Check: Repository Scan
  • GitHub Check: Analyze (go)

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.

@tothandras tothandras added the release-note/ignore Ignore this change when generating release notes label Nov 28, 2025
turip
turip previously approved these changes Nov 28, 2025
@tothandras
tothandras marked this pull request as ready for review November 28, 2025 14:01
@tothandras
tothandras requested a review from a team as a code owner November 28, 2025 14:01

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5b117b8 and d1d7141.

⛔ Files ignored due to path filters (4)
  • api/spec/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
  • go.mod is excluded by !**/*.mod
  • go.sum is excluded by !**/*.sum, !**/*.sum
📒 Files selected for processing (8)
  • Makefile (1 hunks)
  • api/spec/Makefile (1 hunks)
  • api/spec/package.json (2 hunks)
  • api/spec/src/v3/konnect.tsp (2 hunks)
  • api/spec/src/v3/openmeter.tsp (1 hunks)
  • api/v3/api.gen.go (1 hunks)
  • api/v3/api.go (1 hunks)
  • api/v3/codegen.yaml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.tsp

⚙️ CodeRabbit configuration file

**/*.tsp: Review the TypeSpec code for conformity with TypeSpec best practices. When recommending changes also consider the fact that multiple codegeneration toolchains depend on the TypeSpec code, each of which have their idiosyncrasies and bugs.

The declared API should be accurate, in parity with the actual implementation, and easy to understand for the user.

Files:

  • api/spec/src/v3/openmeter.tsp
  • api/spec/src/v3/konnect.tsp
**/*.go

⚙️ CodeRabbit configuration file

**/*.go: In general when reviewing the Golang code make readability and maintainability a priority, even potentially suggest restructuring the code to improve them.

Performance should be a priority in critical code paths. Anything related to event ingestion, message processing, database operations (regardless of database) should be vetted for potential performance bottlenecks.

Files:

  • api/v3/api.go
  • api/v3/api.gen.go
🧠 Learnings (6)
📓 Common learnings
Learnt from: CR
Repo: openmeterio/openmeter PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T15:10:24.409Z
Learning: Generate API clients and OpenAPI spec via `make gen-api` from TypeSpec definitions
📚 Learning: 2025-11-25T15:10:24.409Z
Learnt from: CR
Repo: openmeterio/openmeter PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T15:10:24.409Z
Learning: Use Makefile commands for common development tasks like running tests, generating code, and linting

Applied to files:

  • Makefile
  • api/spec/Makefile
📚 Learning: 2025-11-25T15:10:24.409Z
Learnt from: CR
Repo: openmeterio/openmeter PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T15:10:24.409Z
Learning: Generate API clients and OpenAPI spec via `make gen-api` from TypeSpec definitions

Applied to files:

  • api/spec/Makefile
📚 Learning: 2025-11-25T15:10:24.409Z
Learnt from: CR
Repo: openmeterio/openmeter PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T15:10:24.409Z
Learning: Never manually edit generated directories including `api/client` (generated from TypeSpec), `api/openapi.yaml`, `**/ent/db` (generated from ent schema), `**/wire_gen.go` (generated from wire.go), and `tools/migrate/migrations` (generated migrations)

Applied to files:

  • api/v3/api.go
  • api/v3/codegen.yaml
  • api/v3/api.gen.go
📚 Learning: 2025-11-25T15:10:24.409Z
Learnt from: CR
Repo: openmeterio/openmeter PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T15:10:24.409Z
Learning: Generate Go code via `make generate` to produce database access code from ent schema and dependency injection wire code

Applied to files:

  • api/v3/codegen.yaml
📚 Learning: 2025-03-07T12:17:43.129Z
Learnt from: GAlexIHU
Repo: openmeterio/openmeter PR: 2383
File: openmeter/entitlement/metered/lateevents_test.go:37-45
Timestamp: 2025-03-07T12:17:43.129Z
Learning: In the OpenMeter codebase, test files like `openmeter/entitlement/metered/lateevents_test.go` may use variables like `meterSlug` and `namespace` without explicit declarations visible in the same file. This appears to be an accepted pattern in their test structure.

Applied to files:

  • api/v3/api.gen.go
🪛 GitHub Actions: CI
api/spec/src/v3/konnect.tsp

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues in this file.

🔇 Additional comments (6)
Makefile (1)

171-175: Nice: v3 OpenAPI added to lint coverage

Including api/v3/openapi.yaml in spectral lint keeps the new bundled spec under the same quality gate as the existing ones. No issues from my side.

api/spec/package.json (1)

5-17: V3 compile/bundle wiring looks consistent; just sanity‑check the bundle path

The updated compile pipeline (openapi → v3 → client), new compile:v3, bundle:v3, and the ./v3 export all line up with the new v3 workflow and the api/spec Makefile. The pnpm run bundle:v3 -o ../v3/openapi.yaml call should correctly pass the extra -o to the openapi CLI.

Might be worth a quick local run of:

  • pnpm compile
  • pnpm run bundle:v3 -o ../v3/openapi.yaml

to confirm the entrypoint path and output match what api/v3/api.go expects.

Also applies to: 23-25, 27-38

api/spec/Makefile (1)

3-10: Good call adding v3 bundling to the spec generate flow

The extra pnpm run bundle:v3 -o ../v3/openapi.yaml step neatly connects the TypeSpec compile to the v3 OpenAPI bundle that api/v3 consumes, without changing the existing cloud / classic outputs.

Looks solid to me.

api/spec/src/v3/openmeter.tsp (1)

24-35: Route change to /metering/events looks consistent with v3 server

Switching the MeteringEventsEndpoints route to /metering/events matches the v3 server wiring (chi route uses /metering/events) and keeps it aligned across TypeSpec and generated Go.

Just make sure any existing v3 consumers (if any) are aware of the path tweak, since it’s not backward compatible with /metering-events.

api/v3/codegen.yaml (1)

1-16: Codegen config lines up with the generated v3 server

The config (chi server + models + embedded spec, package: v3, output: ./api.gen.go, nullable types, etc.) matches what’s in api.gen.go and should be a solid baseline for the v3 surface.

After any future spec changes, just remember to re-run the generator via the go:generate hook / your usual pipeline so api.gen.go stays in sync.

api/v3/api.gen.go (1)

1-726: Treat this as generated code; looks aligned with the v3 /metering/events spec

This file is clearly generator output (header + structure) and wires up the /metering/events endpoint plus the embedded spec and helpers. It lines up with the v3 routes you defined in TypeSpec.

All good from my side—just keep changes flowing through the spec + codegen pipeline rather than editing this file directly.

Comment thread api/spec/src/v3/konnect.tsp Resolved
Comment thread api/v3/api.go
Comment on lines +1 to +2
//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=codegen.yaml ./openapi.yaml
package v3

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.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

# Check the current state of api/v3/api.go
head -n 5 api/v3/api.go

Repository: openmeterio/openmeter

Length of output: 191


🏁 Script executed:

# Search for other go:generate directives in the codebase for comparison
rg -n "//go:generate" --type=go

Repository: openmeterio/openmeter

Length of output: 1540


🌐 Web query:

oapi-codegen go:generate invocation example documentation

💡 Result:

Short example and notes

  1. Add a tools file so the generator is tracked by go modules (tools import):
    //go:build tools
    // +build tools
    package tools

import _ "github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen"

(Use this so go mod tidy keeps the generator dependency.) [1]

  1. Example go:generate invocation (run from the package where you want generated code):
    //go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ../../api.yaml

If you install the binary instead, the shorter form works:
//go:generate oapi-codegen --config=config.yaml ../../api.yaml

The generator accepts a YAML (or JSON) config (package, generate targets, output, import-mapping, etc.). See the repo README and examples for config schema and flags. [1][2]

Sources:
[1] oapi-codegen examples (tools.go + go:generate usage).
[2] oapi-codegen README / usage and configuration details.


Fix go:generate invocation – use go run instead of go tool

The current directive is:

//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=codegen.yaml ./openapi.yaml

go tool does not accept import paths; it only works with built-in tools (like cover, vet) or pre-installed binaries. This directive will fail when running go generate. The official oapi-codegen documentation recommends using go run instead:

-//go:generate go tool github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=codegen.yaml ./openapi.yaml
+//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=codegen.yaml ./openapi.yaml

The same issue exists in api/api.go line 1 and should be fixed there as well.

🤖 Prompt for AI Agents
In api/v3/api.go lines 1-2 (and also update api/api.go line 1), the go:generate
directive incorrectly uses "go tool" with an import path which fails; replace
the directive to use "go run" to run the oapi-codegen command with the same
flags (e.g., use "go run
github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=codegen.yaml
./openapi.yaml") so go generate will run the tool correctly; make the identical
change in api/api.go.

chrisgacsal
chrisgacsal previously approved these changes Nov 28, 2025
@tothandras
tothandras dismissed stale reviews from chrisgacsal and turip via 9ca6ee5 November 28, 2025 16:47
@tothandras
tothandras enabled auto-merge (squash) November 28, 2025 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/ignore Ignore this change when generating release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants