[cozystack-api] Refactor OpenAPI Schema - #1173
Conversation
|
Caution Review failedThe pull request is closed. """ WalkthroughThe changes modularize OpenAPI schema post-processing by introducing dedicated builder functions for both OpenAPI v2 and v3. Inline schema manipulation logic is removed from the server startup, replaced by dynamic versioning based on resource configuration and external post-processing functions. The Changes
Sequence Diagram(s)sequenceDiagram
participant Server
participant Config
participant PostProcessorV2
participant PostProcessorV3
participant OpenAPI
Server->>Config: Load resource configuration
Config-->>Server: Return kind-to-schema map
Server->>PostProcessorV2: Pass kind-to-schema map
Server->>PostProcessorV3: Pass kind-to-schema map
Server->>OpenAPI: Set version (with hash), assign post-processors
OpenAPI-->>Server: Serve processed schemas
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
ddb64f5 to
21fbcd0
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
pkg/cmd/server/openapi.go (2)
103-106: Document the fallback behavior for spec container.When
findSpecContainerreturns nil, the code falls back to patching the root schema. This behavior should be documented.container := findSpecContainer(s) -if container == nil { // fallback: use the root +if container == nil { + // fallback: use the root schema when spec property container is not found + // this handles cases where the schema structure differs from expected container = s }
52-67: Consider adding OpenAPI schema validation.While the function validates JSON syntax, it doesn't validate that the provided schema is a valid OpenAPI schema. Invalid schemas could cause issues for API consumers.
Would you like me to help implement OpenAPI schema validation to ensure the user-provided schemas are semantically correct?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
pkg/cmd/server/openapi.go(1 hunks)pkg/cmd/server/start.go(2 hunks)pkg/config/config.go(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
pkg/cmd/server/start.go (4)
pkg/config/config.go (1)
ResourceConfig(27-29)pkg/apis/apps/v1alpha1/types.go (1)
Application(56-64)pkg/generated/applyconfiguration/apps/v1alpha1/application.go (1)
Application(39-46)pkg/generated/openapi/zz_generated.openapi.go (1)
GetOpenAPIDefinitions(31-117)
⏰ 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). (1)
- GitHub Check: Build
🔇 Additional comments (5)
pkg/config/config.go (1)
38-44: LGTM! Field addition follows existing patterns.The new
OpenAPISchemafield is appropriately placed and follows the same naming conventions as other fields in the struct.pkg/cmd/server/start.go (2)
190-194: Efficient schema extraction approach.Creating a map for fast lookups is a good optimization for the post-processing functions.
196-206: Clean modularization of OpenAPI post-processing.The refactoring successfully separates concerns by delegating schema customization to dedicated post-processing functions.
pkg/cmd/server/openapi.go (2)
32-49: Well-implemented recursive schema traversal.The function correctly handles all schema composition patterns (AllOf, OneOf, AnyOf) to find the spec property container.
124-175: Comprehensive OpenAPI v2 post-processing implementation.The function correctly handles both individual resource schemas and their corresponding List schemas, properly updating the items reference.
df21caa to
b42ad59
Compare
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
f63c0a0 to
91583a4
Compare
Depends on #1173 Signed-off-by: Andrei Kvapil <kvapss@gmail.com> <!-- Thank you for making a contribution! Here are some tips for you: - Start the PR title with the [label] of Cozystack component: - For system components: [platform], [system], [linstor], [cilium], [kube-ovn], [dashboard], [cluster-api], etc. - For managed apps: [apps], [tenant], [kubernetes], [postgres], [virtual-machine] etc. - For development and maintenance: [tests], [ci], [docs], [maintenance]. - If it's a work in progress, consider creating this PR as a draft. - Don't hesistate to ask for opinion and review in the community chats, even if it's still a draft. - Add the label `backport` if it's a bugfix that needs to be backported to a previous version. --> ## What this PR does ### Release note <!-- Write a release note: - Explain what has changed internally and for users. - Start with the same [label] as in the PR title - Follow the guidelines at https://github.com/kubernetes/community/blob/master/contributors/guide/release-notes.md. --> ```release-note [cozystack-api] Specify OpenAPI schema for apps ```
Signed-off-by: Andrei Kvapil kvapss@gmail.com
What this PR does
Release note
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Refactor