Skip to content

feat: option to include models tagged with @openapi.ignore in the spec file #2221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2025

Conversation

lenageorgescu-dsl
Copy link
Contributor

@lenageorgescu-dsl lenageorgescu-dsl commented Aug 12, 2025

Add option "includeOpenApiIgnored" to the OpenAPI-Plugin. If set to true, models tagged with @openapi.ignore are also included in the generated spec.

Our use case is to produce separate API specifications for internal and external audiences. By providing a flag in the OpenAPI plugin, we could easily generate two different spec files - one for internal use and one for customers.

Copy link
Contributor

coderabbitai bot commented Aug 12, 2025

📝 Walkthrough

Walkthrough

The includedModels getter in packages/plugins/openapi/src/generator-base.ts now respects a new option includeOpenApiIgnored (default false). When true it returns all data models; when false it filters out models annotated with @@openapi.ignore. No public/exported signatures changed. (≤50 words)

Changes

Cohort / File(s) Change summary
OpenAPI generator filtering
packages/plugins/openapi/src/generator-base.ts
includedModels now respects a new includeOpenApiIgnored option (default false). If true, returns all models; if false, filters out models annotated with @@openapi.ignore. No exported/public signatures changed.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant GeneratorBase
  participant ModelSet

  Caller->>GeneratorBase: get includedModels(options)
  alt includeOpenApiIgnored == true
    GeneratorBase->>ModelSet: return all models
  else includeOpenApiIgnored == false
    GeneratorBase->>ModelSet: filter out @@openapi.ignore
  end
  GeneratorBase-->>Caller: models list
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d32424a and 0d8c504.

📒 Files selected for processing (1)
  • packages/plugins/openapi/src/generator-base.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/plugins/openapi/src/generator-base.ts
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

🧹 Nitpick comments (3)
packages/plugins/openapi/src/generator-base.ts (3)

18-25: Nit: compute models once and simplify the conditional

Minor readability/refactor: avoid calling getDataModels in both branches and unify the return.

Apply this diff:

-        const includeApiIgnored = this.getOption<boolean>('includeApiIgnored', false);
-        if (includeApiIgnored) {
-            return getDataModels(this.model);
-        } else {
-            return getDataModels(this.model).filter(
-                (d) => !hasAttribute(d, '@@openapi.ignore')
-            );
-        }
+        const includeApiIgnored = this.getOption<boolean>('includeApiIgnored', false);
+        const models = getDataModels(this.model);
+        return includeApiIgnored ? models : models.filter((d) => !hasAttribute(d, '@@openapi.ignore'));

18-25: Consider aligning option naming with existing conventions

If other options use “openapi” consistently, consider renaming to includeOpenapiIgnored for clarity and discoverability. Since this is a new option, this can be done before release to avoid future breaking changes.


18-25: Add tests to cover inclusion/exclusion behavior

Recommend adding tests that assert:

  • Default behavior (no option or false) filters out models with '@@openapi.ignore'.
  • When includeApiIgnored: true, ignored models are included.

I can help draft integration tests for the OpenAPI plugin that validate the generated schema components.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 17ad113 and d32424a.

📒 Files selected for processing (1)
  • packages/plugins/openapi/src/generator-base.ts (1 hunks)

@lenageorgescu-dsl lenageorgescu-dsl changed the title feat: option to include @openapi.ignored models in the spec file feat: option to include @openapi.ignore models in the spec file Aug 12, 2025
@lenageorgescu-dsl lenageorgescu-dsl changed the title feat: option to include @openapi.ignore models in the spec file feat: option to include models tagged with @openapi.ignore in the spec file Aug 12, 2025
Copy link
Member

@ymc9 ymc9 left a comment

Choose a reason for hiding this comment

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

Hi @lenageorgescu-dsl , thanks for working on it. The change looks good to me. Do you want to add documentation for it as well? It's in a separate repo:

https://github.com/zenstackhq/zenstack-docs/blob/main/docs/reference/plugins/openapi.mdx

@lenageorgescu-dsl
Copy link
Contributor Author

lenageorgescu-dsl commented Aug 16, 2025

Thanks @ymc9 , I've updated the docs accordingly:
zenstackhq/zenstack-docs#486

@ymc9
Copy link
Member

ymc9 commented Aug 17, 2025

Thanks @ymc9 , I've updated the docs accordingly: zenstackhq/zenstack-docs#486

Thank you! I'm merging this PR and will include it in the upcoming 2.18.1 release. The doc PR will be merged when the release is out.

@ymc9 ymc9 merged commit 18dd6f0 into zenstackhq:dev Aug 17, 2025
12 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.

2 participants