Skip to content

chore: oas related changes#180

Merged
MihalyToth20 merged 4 commits intomainfrom
dev
Dec 1, 2025
Merged

chore: oas related changes#180
MihalyToth20 merged 4 commits intomainfrom
dev

Conversation

@MihalyToth20
Copy link
Collaborator

@MihalyToth20 MihalyToth20 commented Dec 1, 2025

  • table schemas are not included by default anymore
  • adjustments for the predefined schemas to comply better with spectral common sense rules
  • extracting tags from individual queries to the global level

Summary by CodeRabbit

Release Notes

  • New Features

    • Added --include-tables CLI flag to optionally include table schemas in OpenAPI specification generation.
  • Chores

    • Table schemas now excluded from generated OpenAPI specs by default.
    • Tags extracted from operation paths and globally aligned in specifications.
    • Enhanced validation constraints for error codes, messages, and payloads in OpenAPI error schemas.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 1, 2025

Walkthrough

This pull request introduces a feature to conditionally include table schemas in OpenAPI specification generation. A new includeTables flag is threaded through the CLI and core packages, enabling users to control table schema generation via a --include-tables command-line option. A utility function extracts tags from OpenAPI paths to the global level, and error schemas are enhanced with format and maxLength constraints.

Changes

Cohort / File(s) Summary
Changesets
\.changeset/gentle-trees-tan\.md, \.changeset/tangy-windows-taste\.md
Documents version bumps for @calycode/core and @calycode/cli packages; notes chores including tag extraction alignment, maxLength constraints on error codes, and default disabling of table schema generation in OAS spec.
CLI Flag and Entry Point
packages/cli/src/commands/generate/index\.ts, packages/cli/src/commands/generate/implementation/oas-spec\.ts
Adds --include-tables CLI flag and threads includeTables option through to updateOasWizard function signature.
Core Implementation Pipeline
packages/core/src/implementations/generate-oas\.ts, packages/core/src/features/oas/generate/methods/do-oas-update\.ts, packages/core/src/features/oas/generate/methods/update-spec-for-group\.ts, packages/core/src/index\.ts
Propagates includeTables parameter through the OAS generation call stack, from public API entry point through group-level updates and core implementation.
OAS Specification Patching
packages/core/src/features/oas/generate/methods/patch-oas-spec\.ts
Conditionally generates table schemas based on includeTables flag; extracts tags to global level; enhances error schemas with format: 'const' and maxLength constraints on code, message, and payload fields.
Utility Function
packages/core/src/features/oas/generate/methods/extract-tags-to-global-level\.ts
New exported utility function that scans OpenAPI paths to collect unique operation tags and constructs a global tags array with auto-generated descriptions.

Sequence Diagram(s)

sequenceDiagram
    participant User as User/CLI
    participant CLI as CLI Command<br/>(generate/index.ts)
    participant OasWizard as OAS Wizard<br/>(oas-spec.ts)
    participant Core as Core Implementation<br/>(generate-oas.ts)
    participant OasGen as OAS Patcher<br/>(patch-oas-spec.ts)

    User->>CLI: Execute with --include-tables flag
    CLI->>OasWizard: updateOasWizard(opts.includeTables)
    OasWizard->>Core: updateOpenapiSpecImplementation({includeTables})
    Core->>Core: updateSpecForGroup for each group<br/>(pass includeTables)
    Core->>OasGen: patchOasSpec({oas, includeTables})
    alt includeTables is true
        OasGen->>OasGen: Generate table schemas<br/>tableSchemas = {...}
    else includeTables is false
        OasGen->>OasGen: Skip table schemas<br/>tableSchemas = {}
    end
    OasGen->>OasGen: extractTagsToGlobal(paths)<br/>to populate tags array
    OasGen->>OasGen: Enhance error schemas with<br/>format and maxLength constraints
    OasGen-->>Core: Return updated OAS spec
    Core-->>OasWizard: Return generated items
    OasWizard-->>CLI: Return OAS output
    CLI-->>User: Save OAS spec to disk
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • extractTagsToGlobal logic: Verify tag collection and description generation algorithm works correctly across all operation types
  • patch-oas-spec.ts schema modifications: Review the newly added format and maxLength constraints across all error schema variants (AccessDenied, Unauthorized, InternalServerError, TooManyRequests, NotFound, BadRequest) to ensure consistency and correctness
  • Conditional table schema generation: Confirm the logic properly toggles between generating table schemas and returning empty object based on flag value
  • Parameter threading: Verify includeTables flag propagates correctly through all call sites without dropping or defaulting incorrectly

Poem

🐰 Tables now optional, tags aligned with grace,
A flag to control the schema's embrace,
Through pipelines and paths, the feature takes flight,
Error constraints tightened, everything tight,
The OpenAPI spec now bends to our will! 📋✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'chore: oas related changes' is vague and generic, using non-descriptive terminology that doesn't convey meaningful information about the specific changes in the changeset. Consider a more specific title that highlights the main change, such as 'chore: exclude table schemas from OAS spec by default' or 'chore: configure table schema generation and improve schema compliance'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

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.

Copy link
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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/core/src/features/oas/generate/methods/update-spec-for-group.ts (1)

9-27: Type definition inconsistency.

The includeTables parameter has a default value on line 15 (includeTables = false) but is typed as required (not optional) on line 23 (includeTables: boolean).

For consistency and correctness, it should be marked as optional in the type definition.

Apply this diff to fix the type definition:

 async function updateSpecForGroup({
    group,
    instanceConfig,
    workspaceConfig,
    storage,
    core,
    includeTables = false,
 }: {
    group: any;
    instanceConfig: any;
    workspaceConfig: any;
    branchConfig: any;
    storage: any;
    core: any;
-   includeTables: boolean;
+   includeTables?: boolean;
 }): Promise<{
packages/core/src/features/oas/generate/methods/do-oas-update.ts (1)

14-26: Type definition inconsistency.

Similar to update-spec-for-group.ts, the includeTables parameter has a default value on line 19 (includeTables = false) but is typed as required on line 25 (includeTables: boolean).

Apply this diff to fix the type definition:

 async function doOasUpdate({
    inputOas,
    instanceConfig,
    workspaceConfig,
    storage,
    includeTables = false,
 }: {
    inputOas: any;
    instanceConfig: any;
    workspaceConfig: any;
    storage: any;
-   includeTables: boolean;
+   includeTables?: boolean;
 }): Promise<DoOasUpdateOutput> {
packages/core/src/features/oas/generate/methods/patch-oas-spec.ts (1)

93-116: Replace non-standard format: 'const' with the const keyword.

The format: 'const' value is not a standard JSON Schema format. JSON Schema Draft 2020-12 (which OpenAPI 3.1 uses) defines standard formats only as: date-time, date, time, duration, email, idn-email, hostname, idn-hostname, ipv4, ipv6, uri, uri-reference, iri, iri-reference, uri-template, uuid, json-pointer, relative-json-pointer, and regex.

To enforce constant string values, use the const keyword instead:

"code": { "type": "string", "const": "ERROR_CODE_ACCESS_DENIED" }

This approach is standard, properly enforces exact value matching, and will be correctly recognized by OpenAPI tooling and validators.

🧹 Nitpick comments (1)
packages/core/src/index.ts (1)

144-164: Update JSDoc to document the new includeTables parameter.

The updateOpenapiSpec method now accepts an optional includeTables parameter, but the JSDoc block (lines 114-143) doesn't document it. Consider adding:

    * @param groups - Array of API group names to generate specs for, or ['all'] for all groups
+   * @param startDir - Starting directory for the operation
+   * @param includeTables - Whether to include table schemas in the generated OAS (default: false)
    * @returns Promise resolving to array of generated OAS documents with metadata
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3e2bbc and d9da43b.

📒 Files selected for processing (10)
  • .changeset/gentle-trees-tan.md (1 hunks)
  • .changeset/tangy-windows-taste.md (1 hunks)
  • packages/cli/src/commands/generate/implementation/oas-spec.ts (3 hunks)
  • packages/cli/src/commands/generate/index.ts (2 hunks)
  • packages/core/src/features/oas/generate/methods/do-oas-update.ts (1 hunks)
  • packages/core/src/features/oas/generate/methods/extract-tags-to-global-level.ts (1 hunks)
  • packages/core/src/features/oas/generate/methods/patch-oas-spec.ts (8 hunks)
  • packages/core/src/features/oas/generate/methods/update-spec-for-group.ts (2 hunks)
  • packages/core/src/implementations/generate-oas.ts (2 hunks)
  • packages/core/src/index.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
packages/*/src/**/*.ts?(x)

📄 CodeRabbit inference engine (AGENTS.md)

packages/*/src/**/*.ts?(x): Use TypeScript for all source code in the monorepo
Configure and use Eslint and Prettier for linting and formatting with default configs

Files:

  • packages/cli/src/commands/generate/index.ts
  • packages/core/src/implementations/generate-oas.ts
  • packages/core/src/features/oas/generate/methods/extract-tags-to-global-level.ts
  • packages/core/src/index.ts
  • packages/core/src/features/oas/generate/methods/patch-oas-spec.ts
  • packages/cli/src/commands/generate/implementation/oas-spec.ts
  • packages/core/src/features/oas/generate/methods/do-oas-update.ts
  • packages/core/src/features/oas/generate/methods/update-spec-for-group.ts
packages/cli/src/**/*.ts?(x)

📄 CodeRabbit inference engine (AGENTS.md)

Use Commander.js for CLI command registration and parsing

Files:

  • packages/cli/src/commands/generate/index.ts
  • packages/cli/src/commands/generate/implementation/oas-spec.ts
**/*.ts?(x)

📄 CodeRabbit inference engine (AGENTS.md)

Use js-yaml for YAML processing

Files:

  • packages/cli/src/commands/generate/index.ts
  • packages/core/src/implementations/generate-oas.ts
  • packages/core/src/features/oas/generate/methods/extract-tags-to-global-level.ts
  • packages/core/src/index.ts
  • packages/core/src/features/oas/generate/methods/patch-oas-spec.ts
  • packages/cli/src/commands/generate/implementation/oas-spec.ts
  • packages/core/src/features/oas/generate/methods/do-oas-update.ts
  • packages/core/src/features/oas/generate/methods/update-spec-for-group.ts
packages/core/src/index.ts

📄 CodeRabbit inference engine (AGENTS.md)

Core logic entry point is packages/core/src/index.ts

Files:

  • packages/core/src/index.ts
🧠 Learnings (1)
📚 Learning: 2025-11-28T05:59:33.267Z
Learnt from: CR
Repo: calycode/xano-tools PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-28T05:59:33.267Z
Learning: Organize code into logical package separation: calycode/cli, calycode/core, calycode/types, and calycode/utils

Applied to files:

  • .changeset/tangy-windows-taste.md
🧬 Code graph analysis (4)
packages/cli/src/commands/generate/index.ts (1)
packages/cli/src/utils/commands/option-sets.ts (1)
  • addPrintOutputFlag (49-51)
packages/core/src/index.ts (1)
packages/core/src/features/oas/generate/methods/generate-table-schemas.ts (1)
  • generateTableSchemas (4-52)
packages/core/src/features/oas/generate/methods/patch-oas-spec.ts (2)
packages/core/src/features/oas/generate/methods/generate-table-schemas.ts (2)
  • generateTableSchemas (54-54)
  • generateTableSchemas (4-52)
packages/core/src/features/oas/generate/methods/extract-tags-to-global-level.ts (1)
  • extractTagsToGlobal (29-29)
packages/core/src/features/oas/generate/methods/do-oas-update.ts (1)
packages/core/src/features/oas/generate/methods/patch-oas-spec.ts (1)
  • patchOasSpec (282-282)
🔍 Remote MCP DeepWiki

Relevant facts to help review PR #180 (chore: oas related changes):

  • Where to inspect (call flow): CLI generate-oas → core.updateOpenapiSpec → per-group updateSpecForGroup → doOasUpdate → patchOasSpec. Confirm includeTables threads through these call sites and public method signatures.

  • Intent & default: includeTables is optional and defaults to false — table schemas should be omitted by default (tableSchemas = {}) and only generated when --include-tables / includeTables=true is passed. Verify default behavior in CLI flag handling and core.updateOpenapiSpec implementation.

  • Tags change: new extractTagsToGlobal(paths) is added and assigned to newOas.tags before components are built — check it preserves existing tags and generated descriptions.

  • Schema tweaks: Error schemas were extended with format: 'const' and maxLength (e.g., payload maxLength: 1024) for code/message/payload variants to satisfy Spectral rules — verify these constraints don't break codegen, tests, or downstream consumers.

  • Review checklist (quick):

    • Confirm function signatures updated and exported API surfaces adjusted (packages/core/src/index.ts).
    • Verify CLI flag wiring: packages/cli/src/commands/generate/index.ts and oas-spec.ts pass opts.includeTables through.
    • Validate patchOasSpec uses includeTables to skip/generate table schemas conditionally.
    • Run/generate spec.json locally and run generate-code to ensure openapi-generator still accepts the spec.
    • Run run-test (if available) or unit tests that rely on OAS to detect regressions (responseSchema assertion default is typically off).
    • Ensure docs/changesets are present and CI release/docs workflows will behave as expected.
  • Files to focus on in this PR (practical):

    • packages/core/src/features/oas/generate/methods/patch-oas-spec.ts (includeTables logic, extractTagsToGlobal import/use).
    • packages/core/src/features/oas/generate/methods/extract-tags-to-global-level.ts.
    • packages/core/src/features/oas/generate/methods/do-oas-update.ts.
    • packages/cli/src/commands/generate/index.ts and packages/cli/src/commands/generate/implementation/oas-spec.ts (flag + propagation).
    • .changeset/* (version bump / release metadata).
  • CI/Release note: repository uses Changesets + GitHub workflows that auto-generate docs for changeset PRs and publish on merge; merging this will trigger the usual docs/release flow — expect a changeset-release PR and CI doc commits.

Tooling/docs sources consulted:,,

🔇 Additional comments (15)
.changeset/gentle-trees-tan.md (1)

1-6: LGTM! Changeset appropriately documents the new feature.

The changeset correctly bumps both packages to minor versions, which is appropriate for introducing a new optional feature (the --include-tables flag). The description clearly explains the default behavior.

packages/cli/src/commands/generate/index.ts (2)

111-114: LGTM! CLI flag correctly defined.

The --include-tables option is properly registered using Commander.js conventions, with a clear description explaining the default behavior.


116-129: LGTM! Flag propagation is correct.

The includeTables option is properly passed through to updateOasWizard via opts.includeTables, maintaining the optional nature of the parameter.

.changeset/tangy-windows-taste.md (1)

1-8: LGTM! Changeset appropriately documents compliance improvements.

The changeset correctly uses patch-level bumps for schema refinements and OWASP compliance fixes. The specific references to OWASP rules provide helpful traceability.

packages/cli/src/commands/generate/implementation/oas-spec.ts (2)

10-28: LGTM! Parameter signature and default value correctly defined.

The includeTables parameter is properly added as optional with a sensible default of false, maintaining backward compatibility. The TypeScript typing is correct.


60-67: LGTM! Flag correctly propagated to core.

The includeTables parameter is properly passed through to core.updateOpenapiSpec, threading the flag deeper into the OAS generation pipeline.

packages/core/src/features/oas/generate/methods/update-spec-for-group.ts (1)

36-42: LGTM! Flag correctly propagated to doOasUpdate.

The includeTables parameter is properly passed through to doOasUpdate, continuing the thread through the OAS generation pipeline.

packages/core/src/implementations/generate-oas.ts (2)

5-16: LGTM! Optional parameter correctly added.

The includeTables parameter is properly typed as optional in the options object, maintaining backward compatibility.


39-47: LGTM! Safe default value handling.

The use of the nullish coalescing operator (?? false) ensures that includeTables always has a boolean value when passed to updateSpecForGroup, properly handling undefined values.

packages/core/src/features/oas/generate/methods/do-oas-update.ts (1)

28-34: LGTM! Flag correctly propagated to patchOasSpec.

The includeTables parameter is properly passed through to patchOasSpec, completing the threading of the flag through the entire OAS generation pipeline.

packages/core/src/index.ts (1)

391-410: LGTM!

The includeTables parameter is correctly added with a default of false, ensuring backward compatibility and aligning with the PR objective that table schemas are not included by default. The parameter is properly threaded to the underlying doOasUpdate implementation.

packages/core/src/features/oas/generate/methods/patch-oas-spec.ts (4)

2-2: LGTM!

Import of extractTagsToGlobal aligns with the PR objective to extract tags from individual queries to the global level.


5-19: LGTM!

The includeTables parameter with default false correctly implements the PR objective. Table schemas are conditionally generated only when explicitly requested, and extractTagsToGlobal is appropriately called to populate global tags.


263-263: LGTM!

The tableSchemas spread correctly includes table schemas only when includeTables is true (otherwise it's an empty object with no effect).


282-282: LGTM!

Export statement correctly exports patchOasSpec.

Comment on lines +1 to +27
function extractTagsToGlobal(paths) {
// 1. Collect all tags used in operations
const tagSet = new Set();
for (const [path, methods] of Object.entries(paths || {})) {
for (const [method, operation] of Object.entries(methods)) {
if (operation.tags && Array.isArray(operation.tags)) {
operation.tags.forEach((tag) => tagSet.add(tag));
}
}
}

// 2. Build the global tags array if not present
let tags = Array.from(tagSet).map((tag) => ({
name: tag,
description: `Auto-generated tag for ${tag}`,
}));

// (Optional) If you want to preserve existing tags and only add missing ones:
const existingTags = (tags || []).map((t) => t.name);
const allTags = Array.from(new Set([...existingTags, ...tagSet]));
tags = allTags.map((tag) => ({
name: tag,
description: `Auto-generated tag for ${tag}`,
}));

return tags;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Redundant logic in tag preservation.

The function has confusing and redundant logic:

  1. Lines 13-16 build a tags array from tagSet
  2. Line 19 references tags (just created) as if it were pre-existing input
  3. Lines 20-24 completely rebuild the tags array, making lines 13-16 unnecessary

The comment on line 18 mentions "preserve existing tags," but the function doesn't accept any existing tags as input. Either:

  • The function should accept an existingTags parameter to truly preserve them, or
  • Lines 18-24 should be removed as they just recreate what lines 13-16 already built

Apply this diff to simplify the function:

 function extractTagsToGlobal(paths) {
    // 1. Collect all tags used in operations
    const tagSet = new Set();
    for (const [path, methods] of Object.entries(paths || {})) {
       for (const [method, operation] of Object.entries(methods)) {
          if (operation.tags && Array.isArray(operation.tags)) {
             operation.tags.forEach((tag) => tagSet.add(tag));
          }
       }
    }

-   // 2. Build the global tags array if not present
-   let tags = Array.from(tagSet).map((tag) => ({
+   // 2. Build the global tags array
+   const tags = Array.from(tagSet).map((tag) => ({
       name: tag,
       description: `Auto-generated tag for ${tag}`,
    }));

-   // (Optional) If you want to preserve existing tags and only add missing ones:
-   const existingTags = (tags || []).map((t) => t.name);
-   const allTags = Array.from(new Set([...existingTags, ...tagSet]));
-   tags = allTags.map((tag) => ({
-      name: tag,
-      description: `Auto-generated tag for ${tag}`,
-   }));
-
    return tags;
 }

If you truly need to preserve existing tags from the OpenAPI spec, modify the signature:

-function extractTagsToGlobal(paths) {
+function extractTagsToGlobal(paths, existingTags = []) {
    // 1. Collect all tags used in operations
    const tagSet = new Set();
    for (const [path, methods] of Object.entries(paths || {})) {
       for (const [method, operation] of Object.entries(methods)) {
          if (operation.tags && Array.isArray(operation.tags)) {
             operation.tags.forEach((tag) => tagSet.add(tag));
          }
       }
    }

-   // 2. Build the global tags array if not present
-   let tags = Array.from(tagSet).map((tag) => ({
-      name: tag,
-      description: `Auto-generated tag for ${tag}`,
-   }));
-
-   // (Optional) If you want to preserve existing tags and only add missing ones:
-   const existingTags = (tags || []).map((t) => t.name);
+   // 2. Preserve existing tags and add discovered ones
+   const existingTagNames = existingTags.map((t) => t.name);
-   const allTags = Array.from(new Set([...existingTags, ...tagSet]));
-   tags = allTags.map((tag) => ({
+   const allTags = Array.from(new Set([...existingTagNames, ...tagSet]));
+   const tags = allTags.map((tag) => ({
       name: tag,
       description: `Auto-generated tag for ${tag}`,
    }));

    return tags;
 }
🤖 Prompt for AI Agents
In
packages/core/src/features/oas/generate/methods/extract-tags-to-global-level.ts
lines 1-27, the function builds a tags array from operations then immediately
recomputes it as if preserving pre-existing tags though no such input exists;
remove the redundant intermediate build and the "preserve existing tags" block
(lines that compute existingTags, allTags and rebuild tags) OR change the
function signature to accept an existingTags parameter and merge
operation-derived tags with that input (deduplicate) before returning the final
tags array — implement one of these two fixes so the function is no longer doing
confusing duplicate work.

@MihalyToth20 MihalyToth20 merged commit 8d01210 into main Dec 1, 2025
2 checks passed
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