Skip to content

fix(api): skip OpenAPI post-processor for non-apps group versions#2212

Merged
kvaps merged 3 commits intocozystack:mainfrom
kvaps:fix/openapi-postprocess-skip-non-apps-gv
Mar 13, 2026
Merged

fix(api): skip OpenAPI post-processor for non-apps group versions#2212
kvaps merged 3 commits intocozystack:mainfrom
kvaps:fix/openapi-postprocess-skip-non-apps-gv

Conversation

@kvaps
Copy link
Member

@kvaps kvaps commented Mar 12, 2026

What this PR does

The OpenAPI PostProcessSpec callback is invoked for every registered
group-version (apps, core, version, etc.), but the Application schema
cloning logic only applies to apps.cozystack.io. When called for other
GVs the base Application schemas are absent, producing a spurious error
on every API server start:

ERROR klog Failed to build OpenAPI v3 for group version, "base Application* schemas not found"

This PR changes the post-processor (both v2 and v3) to return early
when the base schemas are not found, instead of returning an error.

Release note

[platform] Fix spurious "base Application* schemas not found" error logged on cozystack-api startup

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for missing OpenAPI schema components. The system now gracefully continues processing instead of halting when certain base schemas are unavailable.

The OpenAPI PostProcessSpec callback is invoked for every group-version
(apps, core, version, etc.), but the Application schema cloning logic
only applies to apps.cozystack.io. When called for other GVs the base
Application schemas are absent, causing a spurious error log on every
API server start.

Return early instead of erroring when the base schemas are not found.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andrei Kvapil <[email protected]>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

The OpenAPI post-processors for v3 and v2 schemas in the server command now return early without patching when essential base schemas are absent, instead of raising an error. This simplifies the error handling logic while maintaining the unchanged patching flow for other scenarios.

Changes

Cohort / File(s) Summary
OpenAPI Post-Processor Error Handling
pkg/cmd/server/openapi.go
Simplified guard logic in OpenAPI post-processors (v3 and v2) to return nil early when base schemas (Application, ApplicationList, ApplicationStatus) are missing, replacing previous error-returning behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 When schemas are sparse, we don't fret or despair,
We gracefully skip with a hop and a care,
No errors returned where there's nothing to mend,
Just nil and move on—a much cleaner end! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 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 main change: simplifying the OpenAPI post-processor to skip processing when base Application schemas are absent for non-apps group versions, which aligns with the file-level changes in pkg/cmd/server/openapi.go.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a recurring spurious error log during the cozystack-api startup by refining the OpenAPI schema post-processing. The change ensures that the OpenAPI post-processor, which is designed for apps.cozystack.io schemas, no longer produces an error when invoked for other group-versions that do not contain the expected base Application schemas. This leads to a cleaner and more stable API server initialization process.

Highlights

  • OpenAPI Post-processor Logic: Modified both OpenAPI v2 and v3 post-processors to gracefully handle cases where base Application schemas are not found. Instead of returning an error, the post-processors now return early with a nil error, indicating that no patching is needed for non-apps group versions.
  • Error Suppression: Removed the condition && len(kindSchemas) > 0 from the error check, ensuring that the early return without error occurs consistently when base schemas are absent, regardless of whether other kind schemas are present.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • pkg/cmd/server/openapi.go
    • Updated OpenAPI v3 post-processor (buildPostProcessV3) to return nil instead of an error when base Application schemas are not found, preventing spurious error logs.
    • Updated OpenAPI v2 post-processor (buildPostProcessV2) to return nil instead of an error under the same conditions as v3, ensuring consistent behavior.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a spurious error message logged during API server startup. The error occurs because the OpenAPI post-processor, which is designed for the apps.cozystack.io group version, was also being executed for other group versions where the necessary base schemas are not present. The fix is to make the post-processor return early without an error if the base schemas are not found. The change is correct in fixing the log spam. However, I've added a couple of comments pointing out that this approach could potentially mask a real problem if the base schemas were missing for the apps group version itself, leading to a silent failure. This is a trade-off between log noise and error reporting robustness.

stat, ok3 := doc.Components.Schemas[baseStatusRef]
if !(ok1 && ok2 && ok3) && len(kindSchemas) > 0 {
return doc, fmt.Errorf("base Application* schemas not found")
if !(ok1 && ok2 && ok3) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This change effectively silences the error when base schemas are not found, which fixes the issue for non-apps group versions. However, this introduces a potential for silent failures. If the base schemas are missing for the apps group version due to an underlying issue (e.g., a code generation problem), this will no longer be reported as an error. The server would start, but the OpenAPI specification for all dynamic application kinds would be incorrect. This could make issues harder to debug in the future.

stat, ok3 := defs[baseStatusRef]
if !(ok1 && ok2 && ok3) && len(kindSchemas) > 0 {
return sw, fmt.Errorf("base Application* schemas not found")
if !(ok1 && ok2 && ok3) {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the V3 post-processor, this change introduces a risk of silent failure. If the base schemas are missing for the apps group version, the issue will no longer be surfaced as an error, potentially leading to an incomplete OpenAPI V2 specification and making debugging more difficult.

When dependencies are not ready the reconciler returned without
requeueing, relying solely on watch events to re-trigger. If a watch
event was missed (controller restart, race condition, dependency already
ready before watch setup), the package would stay stuck in
DependenciesNotReady forever.

Add RequeueAfter: 30s so dependencies are periodically rechecked.

Co-Authored-By: Claude <[email protected]>
Signed-off-by: Andrei Kvapil <[email protected]>
@kvaps kvaps changed the title fix(api): skip OpenAPI post-processor for non-apps group versions fix(api,operator): fix OpenAPI post-processor and package dependency requeue Mar 12, 2026
@kvaps kvaps changed the title fix(api,operator): fix OpenAPI post-processor and package dependency requeue fix(api): skip OpenAPI post-processor for non-apps group versions Mar 12, 2026
@kvaps kvaps marked this pull request as ready for review March 13, 2026 00:00
@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. bug Something isn't working labels Mar 13, 2026
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.

🧹 Nitpick comments (1)
pkg/cmd/server/openapi.go (1)

227-229: Differentiate “non-apps GV” from “partially broken base schemas.”

Good direction to no-op for non-apps group-versions, but the current guard also silently skips when only some base Application schemas are present. That can hide malformed apps OpenAPI state. Consider: all missing ⇒ no-op; partial missing ⇒ return error.

Suggested guard split (v3 + v2)
-		if !(ok1 && ok2 && ok3) {
-			return doc, nil // not the apps GV — nothing to patch
-		}
+		if !ok1 && !ok2 && !ok3 {
+			return doc, nil // not the apps GV — nothing to patch
+		}
+		if !(ok1 && ok2 && ok3) {
+			return nil, fmt.Errorf("incomplete base Application schemas: Application=%t, ApplicationList=%t, ApplicationStatus=%t", ok1, ok2, ok3)
+		}
-		if !(ok1 && ok2 && ok3) {
-			return sw, nil // not the apps GV — nothing to patch
-		}
+		if !ok1 && !ok2 && !ok3 {
+			return sw, nil // not the apps GV — nothing to patch
+		}
+		if !(ok1 && ok2 && ok3) {
+			return nil, fmt.Errorf("incomplete base Application schemas: Application=%t, ApplicationList=%t, ApplicationStatus=%t", ok1, ok2, ok3)
+		}

Also applies to: 342-344

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/cmd/server/openapi.go` around lines 227 - 229, The current guard (using
ok1, ok2, ok3) treats any missing base Application schema the same as the apps
group-version being absent; change it so that if all three (ok1, ok2, ok3) are
false you still return doc, nil (no-op), but if at least one is true and not all
are true then return a descriptive error about partially missing base schemas to
surface malformed OpenAPI state; update the same logic at the other occurrence
(the block around the 342-344 equivalent) and ensure the error message names the
missing pieces so callers can diagnose which of ok1/ok2/ok3 (the base
Application schemas) are absent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@pkg/cmd/server/openapi.go`:
- Around line 227-229: The current guard (using ok1, ok2, ok3) treats any
missing base Application schema the same as the apps group-version being absent;
change it so that if all three (ok1, ok2, ok3) are false you still return doc,
nil (no-op), but if at least one is true and not all are true then return a
descriptive error about partially missing base schemas to surface malformed
OpenAPI state; update the same logic at the other occurrence (the block around
the 342-344 equivalent) and ensure the error message names the missing pieces so
callers can diagnose which of ok1/ok2/ok3 (the base Application schemas) are
absent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d5c958b4-56dd-40f1-ac5c-54833789cbad

📥 Commits

Reviewing files that changed from the base of the PR and between 941fb02 and 2b60c01.

📒 Files selected for processing (1)
  • pkg/cmd/server/openapi.go

@kvaps kvaps added backport Should change be backported on previus release backport-previous labels Mar 13, 2026
@kvaps kvaps merged commit ffd6e62 into cozystack:main Mar 13, 2026
18 of 19 checks passed
@github-actions
Copy link

Successfully created backport PR for release-1.0:

@github-actions
Copy link

Successfully created backport PR for release-1.1:

kvaps added a commit that referenced this pull request Mar 13, 2026
…apps group versions (#2216)

# Description
Backport of #2212 to `release-1.0`.
kvaps added a commit that referenced this pull request Mar 13, 2026
…apps group versions (#2217)

# Description
Backport of #2212 to `release-1.1`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport Should change be backported on previus release backport-previous bug Something isn't working size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant