Skip to content

chore(api): update API skills and enforce doc formatting#4330

Merged
tothandras merged 2 commits into
mainfrom
chore/api-format
May 11, 2026
Merged

chore(api): update API skills and enforce doc formatting#4330
tothandras merged 2 commits into
mainfrom
chore/api-format

Conversation

@tothandras
Copy link
Copy Markdown
Contributor

@tothandras tothandras commented May 9, 2026

Summary by CodeRabbit

Release Notes

  • Documentation

    • Added comprehensive guides for API error handling, including inline error formats and OpenMeter-specific error response types
    • Enhanced documentation clarity and consistency across API specifications
    • Improved formatting and structure of API documentation throughout the specification
  • Improvements

    • Feature update requests now support explicitly setting unit costs to null to clear existing values

Review Change Stack

@tothandras tothandras added the release-note/ignore Ignore this change when generating release notes label May 9, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: fd730067-9d2b-4d2a-908d-0d14ddf0248d

📥 Commits

Reviewing files that changed from the base of the PR and between 9aa48ec and ff7d811.

⛔ Files ignored due to path filters (2)
  • api/spec/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (8)
  • api/spec/packages/aip/package.json
  • api/spec/packages/aip/src/currencies/cost-bases/cost-basis.tsp
  • api/spec/packages/aip/src/features/feature.tsp
  • api/spec/packages/aip/src/llmcost/prices.tsp
  • api/spec/packages/aip/src/productcatalog/addon.tsp
  • api/spec/packages/aip/src/productcatalog/plan.tsp
  • api/spec/packages/aip/src/productcatalog/unitconfig.tsp
  • api/v3/api.gen.go
✅ Files skipped from review due to trivial changes (4)
  • api/spec/packages/aip/src/currencies/cost-bases/cost-basis.tsp
  • api/spec/packages/aip/src/productcatalog/plan.tsp
  • api/spec/packages/aip/src/llmcost/prices.tsp
  • api/spec/packages/aip/src/productcatalog/unitconfig.tsp
🚧 Files skipped from review as they are similar to previous changes (2)
  • api/spec/packages/aip/src/features/feature.tsp
  • api/spec/packages/aip/src/productcatalog/addon.tsp

📝 Walkthrough

Walkthrough

This PR introduces a TypeScript linter system to format TypeSpec documentation comments as Markdown and reorganizes error handling documentation, then applies that formatting across 50+ API specification files. It also lets features explicitly clear unit cost by accepting null values.

Changes

Documentation Formatting Tooling Infrastructure

Layer / File(s) Summary
Utility Functions
api/spec/packages/aip/lib/rules/utils.js
Exports detectNewline, getIndentBefore, extractMarkdownFromDocComment, and wrapMarkdownAsDocComment to handle doc comment parsing and reformatting.
TypeSpec Linter Rule
api/spec/packages/aip/lib/rules/docs.js
Implements docFormatRule that collects doc nodes via semantic traversal, formats Markdown with Prettier, and reports diagnostics with code fixes for unformatted docs.
Linter Registration
api/spec/packages/aip/lib/index.js
Registers the new docFormatRule alongside existing rules in the linter configuration.
Auto-Fix Script
api/spec/packages/aip/scripts/apply-doc-fixes.mjs
CLI script that compiles TypeSpec with the linter, filters for doc-format diagnostics, and applies code fixes to reformat docs in-place.
Build Integration
api/spec/package.json, api/spec/packages/aip/package.json
Updates npm format scripts to run doc-fixes before Prettier; adds Prettier 3.8.3 to devDependencies.

Error Handling Documentation System

Layer / File(s) Summary
Documentation References
.agents/skills/api/SKILL.md, .agents/skills/api/rules/aip-193-errors.md
Updates skill docs to clarify Konnect TypeSpec maintenance and point to separate error guides; removes inlined Common.* type tables.
Inline Error Pattern
.agents/skills/api/rules/inline-errors.md
Defines inline (partial/non-fatal) error format as Shared.BaseError<T> for 2xx response bodies with composition, naming, and visibility conventions.
OpenMeter Error Types
.agents/skills/api/rules/openmeter-error-types.md
Specifies how to wire AIP-193 errors via Common.* types, mandates Common.ErrorResponses on every operation, and lists OpenMeter-specific status codes (404, 409, 410, 413, 422).

API Specification Documentation Formatting

Consistent comment reformatting applied across all domains (50+ files):

Layer / File(s) Summary
Common Types
api/spec/packages/aip/src/common/*, api/spec/packages/aip/src/shared/*
Reformats filters, properties, labels, addresses, and scalars (DateTime, Currency, Country, Tax ID, Duration).
Metering
api/spec/packages/aip/src/events/*, api/spec/packages/aip/src/meters/*
Reformats meter definitions, event structures, granularity/filtering, and query request/response shapes.
Billing & Tax
api/spec/packages/aip/src/billing/*
Reformats billing profiles, tax config, payment settings, collection methods, and workflow alignment.
Features & Pricing
api/spec/packages/aip/src/features/*, api/spec/packages/aip/src/productcatalog/*
Reformats feature definitions, unit cost models, cost queries, and product catalog structures. Updates FeatureUpdateRequest.unit_cost to allow null for clearing existing values.
Customers & Credits
api/spec/packages/aip/src/customers/*
Reformats customer models, charges, credits, ledger entries, and billing operations.
Other Domains
api/spec/packages/aip/src/subscriptions/*, api/spec/packages/aip/src/invoices/*, api/spec/packages/aip/src/currencies/*, api/spec/packages/aip/src/entitlements/*, api/spec/packages/aip/src/llmcost/*, api/spec/packages/aip/src/apps/*, api/spec/packages/aip/src/konnect.tsp
Reformats documentation across remaining API domains including subscriptions, invoices, currencies, entitlements, LLM pricing, and integrations.
OpenAPI Test Spec
api/v3/test/openapi.test.yaml
Updates schema descriptions to use YAML block scalars with proper line wrapping.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • solkimicreb
  • chrisgacsal
  • gergely-kurucz-konghq
🚥 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 accurately describes the primary change: updating API documentation and adding doc formatting enforcement through linter rules and automated fixes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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 chore/api-format

@tothandras tothandras force-pushed the feat/governance-v3 branch 3 times, most recently from b2c8e96 to 4019f74 Compare May 11, 2026 14:32
@tothandras tothandras force-pushed the chore/api-format branch 2 times, most recently from 9ae5f9a to 8175eba Compare May 11, 2026 16:23
@tothandras tothandras changed the base branch from feat/governance-v3 to main May 11, 2026 16:27
@tothandras tothandras marked this pull request as ready for review May 11, 2026 16:27
@tothandras tothandras requested a review from a team as a code owner May 11, 2026 16:27
@tothandras tothandras enabled auto-merge (squash) May 11, 2026 16:28
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🧹 Nitpick comments (2)
api/spec/packages/aip/src/features/feature.tsp (1)

59-64: ⚡ Quick win

Clarify what null means for unit_cost updates

Since Line 64 now allows null, it’d help to state that null clears existing unit_cost, while omission leaves it unchanged.

Suggested patch
   /**
    * Optional per-unit cost configuration. Use "manual" for a fixed per-unit cost, or
    * "llm" to look up cost from the LLM cost database based on meter group-by
-   * properties.
+   * properties. Set to `null` to remove existing unit cost; omit to keep unchanged.
    */
🤖 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 `@api/spec/packages/aip/src/features/feature.tsp` around lines 59 - 64, Update
the documentation for the unit_cost field on the Feature type to clarify update
semantics: in the comment/JSDoc above the unit_cost?: FeatureUnitCost | null
declaration, state that setting unit_cost to null will clear any existing
unit_cost on the resource, while omitting unit_cost from an update request will
leave the existing value unchanged; reference the field name unit_cost and the
type FeatureUnitCost so readers know this applies to that property.
api/spec/packages/aip/package.json (1)

19-21: 💤 Low value

Prettier in dependencies rather than devDependencies.

Typically, Prettier would live in devDependencies since it's a development tool. However, if the format script needs to be runnable in contexts where devDependencies aren't installed, this placement might be intentional. Worth double-checking if this was deliberate or if it should be moved to devDependencies.

🤖 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 `@api/spec/packages/aip/package.json` around lines 19 - 21, The package.json
currently lists "prettier" under "dependencies" which is meant for runtime
packages; move "prettier" to "devDependencies" unless the "format" or other npm
scripts must run in environments without devDependencies installed. Edit
package.json to remove "prettier" from "dependencies" and add it under
"devDependencies" (keeping the same version string "3.8.3"), and verify any
scripts like "format" still work as intended after the change.
🤖 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 `@api/spec/packages/aip/lib/rules/utils.js`:
- Around line 110-123: The opening doc-comment delimiter is not indented in
wrapMarkdownAsDocComment, causing the comment block to shift left; update the
function so the opening '/**' is prefixed with the indent variable in both the
non-empty branch (change '/**' to `${indent}/**` in the out array) and the
empty-case return (make the returned opening line include indent as well),
leaving the existing `${indent} *` and `${indent} */` lines unchanged so the
entire block preserves the requested indentation.

In `@api/spec/packages/aip/src/currencies/cost-bases/cost-basis.tsp`:
- Around line 27-29: Update the documentation string for the cost basis field
effective_from in cost-basis.tsp: change the phrase "will set to `now`" to "will
be set to `now`" so the sentence reads that if not provided it will be effective
immediately and will be set to `now` by the system; locate the effective_from
doc comment within the CostBasis (or related) type and apply this wording fix.

In `@api/spec/packages/aip/src/features/feature.tsp`:
- Around line 35-36: The doc comment for the feature's meter contains a
duplicated word ("and and"); locate the meter description in feature.tsp (the
comment above the meter property or within the Feature type definition) and
remove the duplicate so the sentence reads correctly (e.g., "The meter that the
feature is associated with and based on which usage is calculated. If not
specified, the feature is static.").

In `@api/spec/packages/aip/src/llmcost/prices.tsp`:
- Around line 98-103: The field effective_to is declared optional but the
comment claims "null = current", so update the type to reflect that null is a
valid value: change effective_to?: Shared.DateTime to explicitly allow null
(e.g., effective_to?: Shared.DateTime | null) and keep or adjust the JSDoc to
state "null = current" so the API type and comment are consistent; update any
related usages/validators of effective_to to accept null if needed.

In `@api/spec/packages/aip/src/productcatalog/addon.tsp`:
- Around line 8-10: Update the doc comment that currently references
effectiveFrom/effectiveTo to use the actual declared field names effective_from
and effective_to so the documentation matches the model; locate the comment near
the add-on status description (around the add-on model/docblock in addon.tsp)
and replace the camelCase references with the snake_case field names
(effective_from, effective_to) to keep generated docs consistent with the
implementation.
- Around line 92-96: The status documentation for add-ons is missing the case
where effectiveTo is unset; update the rules around effectiveFrom/effectiveTo
(referencing effectiveFrom, effectiveTo and the status values draft, active,
archived) so active is defined as: effectiveFrom is set and effectiveFrom <= now
and (effectiveTo is unset OR now < effectiveTo); keep draft = no effectiveFrom
and archived = effectiveTo <= now and ensure the wording clearly states that an
absent effectiveTo means the add-on is effective indefinitely.

In `@api/spec/packages/aip/src/productcatalog/plan.tsp`:
- Around line 88-94: Update the doc comment for plan status to use the exact
schema field names and enum values: replace camelCase with snake_case (use
effective_from and effective_to) and remove the non-enum term "inactive";
enumerate only the actual statuses (draft, active, archived, scheduled) and
their precise conditions (draft = no effective_from; active = effective_from <=
now < effective_to; archived = effective_to <= now; scheduled = now <
effective_from < effective_to), updating the comment near the Plan status/enum
definition (e.g., where the plan status is documented) accordingly.

In `@api/spec/packages/aip/src/productcatalog/unitconfig.tsp`:
- Around line 75-76: The documentation line containing both formulas should be
split into two sentences/lines to improve readability: change the run-on comment
"For divide: converted = raw / conversionFactor For multiply: converted = raw ×
conversionFactor" in unitconfig.tsp to two separate lines such as one line for
the divide formula and a second line for the multiply formula (the doc block
that explains conversion semantics near the unit conversion description in
unitconfig.tsp).

---

Nitpick comments:
In `@api/spec/packages/aip/package.json`:
- Around line 19-21: The package.json currently lists "prettier" under
"dependencies" which is meant for runtime packages; move "prettier" to
"devDependencies" unless the "format" or other npm scripts must run in
environments without devDependencies installed. Edit package.json to remove
"prettier" from "dependencies" and add it under "devDependencies" (keeping the
same version string "3.8.3"), and verify any scripts like "format" still work as
intended after the change.

In `@api/spec/packages/aip/src/features/feature.tsp`:
- Around line 59-64: Update the documentation for the unit_cost field on the
Feature type to clarify update semantics: in the comment/JSDoc above the
unit_cost?: FeatureUnitCost | null declaration, state that setting unit_cost to
null will clear any existing unit_cost on the resource, while omitting unit_cost
from an update request will leave the existing value unchanged; reference the
field name unit_cost and the type FeatureUnitCost so readers know this applies
to that property.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 02d5755f-c6d6-4b65-b0d5-eed39183e47e

📥 Commits

Reviewing files that changed from the base of the PR and between f3ae09c and 9aa48ec.

⛔ Files ignored due to path filters (2)
  • api/spec/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • api/v3/openapi.yaml is excluded by !**/openapi.yaml
📒 Files selected for processing (64)
  • .agents/skills/api/SKILL.md
  • .agents/skills/api/rules/aip-193-errors.md
  • .agents/skills/api/rules/inline-errors.md
  • .agents/skills/api/rules/openmeter-error-types.md
  • api/spec/package.json
  • api/spec/packages/aip/lib/index.js
  • api/spec/packages/aip/lib/rules/docs.js
  • api/spec/packages/aip/lib/rules/utils.js
  • api/spec/packages/aip/package.json
  • api/spec/packages/aip/scripts/apply-doc-fixes.mjs
  • api/spec/packages/aip/src/apps/catalog.tsp
  • api/spec/packages/aip/src/apps/external_invoicing.tsp
  • api/spec/packages/aip/src/apps/stripe.tsp
  • api/spec/packages/aip/src/billing/operations.tsp
  • api/spec/packages/aip/src/billing/profile.tsp
  • api/spec/packages/aip/src/billing/tax.tsp
  • api/spec/packages/aip/src/common/parameters.tsp
  • api/spec/packages/aip/src/common/properties.tsp
  • api/spec/packages/aip/src/currencies/cost-bases/cost-basis.tsp
  • api/spec/packages/aip/src/currencies/cost-bases/operations.tsp
  • api/spec/packages/aip/src/currencies/currency.tsp
  • api/spec/packages/aip/src/currencies/operations.tsp
  • api/spec/packages/aip/src/customers/charges/charges.tsp
  • api/spec/packages/aip/src/customers/charges/operations.tsp
  • api/spec/packages/aip/src/customers/credits/adjustment.tsp
  • api/spec/packages/aip/src/customers/credits/balance.tsp
  • api/spec/packages/aip/src/customers/credits/grant.tsp
  • api/spec/packages/aip/src/customers/credits/ledger.tsp
  • api/spec/packages/aip/src/customers/credits/operations.tsp
  • api/spec/packages/aip/src/customers/customer.tsp
  • api/spec/packages/aip/src/customers/operations.tsp
  • api/spec/packages/aip/src/entitlements/access.tsp
  • api/spec/packages/aip/src/events/event.tsp
  • api/spec/packages/aip/src/events/operations.tsp
  • api/spec/packages/aip/src/features/cost.tsp
  • api/spec/packages/aip/src/features/feature.tsp
  • api/spec/packages/aip/src/features/operations.tsp
  • api/spec/packages/aip/src/features/unitcost.tsp
  • api/spec/packages/aip/src/governance/governance.tsp
  • api/spec/packages/aip/src/invoices/invoice.tsp
  • api/spec/packages/aip/src/invoices/party.tsp
  • api/spec/packages/aip/src/konnect.tsp
  • api/spec/packages/aip/src/llmcost/operations.tsp
  • api/spec/packages/aip/src/llmcost/prices.tsp
  • api/spec/packages/aip/src/meters/meter.tsp
  • api/spec/packages/aip/src/meters/operations.tsp
  • api/spec/packages/aip/src/meters/query.tsp
  • api/spec/packages/aip/src/openmeter.tsp
  • api/spec/packages/aip/src/productcatalog/addon.tsp
  • api/spec/packages/aip/src/productcatalog/operations.tsp
  • api/spec/packages/aip/src/productcatalog/plan.tsp
  • api/spec/packages/aip/src/productcatalog/planaddon.tsp
  • api/spec/packages/aip/src/productcatalog/price.tsp
  • api/spec/packages/aip/src/productcatalog/ratecard.tsp
  • api/spec/packages/aip/src/productcatalog/unitconfig.tsp
  • api/spec/packages/aip/src/shared/address.tsp
  • api/spec/packages/aip/src/shared/enums.tsp
  • api/spec/packages/aip/src/shared/filters.tsp
  • api/spec/packages/aip/src/shared/properties.tsp
  • api/spec/packages/aip/src/subscriptions/operations.tsp
  • api/spec/packages/aip/src/subscriptions/reference.tsp
  • api/spec/packages/aip/src/subscriptions/subscription.tsp
  • api/v3/api.gen.go
  • api/v3/test/openapi.test.yaml

Comment thread api/spec/packages/aip/lib/rules/utils.js
Comment thread api/spec/packages/aip/src/currencies/cost-bases/cost-basis.tsp
Comment thread api/spec/packages/aip/src/features/feature.tsp Outdated
Comment thread api/spec/packages/aip/src/llmcost/prices.tsp
Comment thread api/spec/packages/aip/src/productcatalog/addon.tsp Outdated
Comment thread api/spec/packages/aip/src/productcatalog/addon.tsp Outdated
Comment thread api/spec/packages/aip/src/productcatalog/plan.tsp
Comment thread api/spec/packages/aip/src/productcatalog/unitconfig.tsp Outdated
@tothandras tothandras merged commit 4fed364 into main May 11, 2026
26 of 28 checks passed
@tothandras tothandras deleted the chore/api-format branch May 11, 2026 17:44
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.

2 participants