-
-
Couldn't load subscription status.
- Fork 126
fix(openapi): support spec generation for JSON fields #2089
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
Conversation
📝 WalkthroughWalkthroughThe changes extend the OpenAPI schema generator to support Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant RESTfulOpenAPIGenerator
participant Schema
User->>RESTfulOpenAPIGenerator: Generate OpenAPI schema
RESTfulOpenAPIGenerator->>Schema: Retrieve DataModel, Enum, TypeDef declarations
RESTfulOpenAPIGenerator->>RESTfulOpenAPIGenerator: generateComponents for DataModel, Enum, TypeDef
RESTfulOpenAPIGenerator->>RESTfulOpenAPIGenerator: generateTypeDefComponent for each TypeDef
RESTfulOpenAPIGenerator->>RESTfulOpenAPIGenerator: generateField for each field (DataModelField or TypeDefField)
RESTfulOpenAPIGenerator->>RESTfulOpenAPIGenerator: fieldTypeToOpenAPISchema for DataModelFieldType or TypeDefFieldType
RESTfulOpenAPIGenerator-->>User: Return OpenAPI schema with TypeDef and JSON support
Assessment against linked issues
✨ 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:
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 (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/plugins/openapi/src/rest-generator.ts (1)
793-800: Return type annotation removed from generateEnumComponent.The explicit return type annotation was removed while preserving the logic. While this doesn't affect functionality, consider maintaining consistent typing across similar methods.
Consider adding the explicit return type
OAPI.SchemaObjectfor consistency with other component generation methods:-private generateEnumComponent(_enum: Enum) { +private generateEnumComponent(_enum: Enum): OAPI.SchemaObject {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
packages/plugins/openapi/tests/baseline/rest-type-coverage-3.0.0.baseline.yamlis excluded by!**/*.yamlpackages/plugins/openapi/tests/baseline/rest-type-coverage-3.1.0.baseline.yamlis excluded by!**/*.yaml
📒 Files selected for processing (2)
packages/plugins/openapi/src/rest-generator.ts(6 hunks)packages/plugins/openapi/tests/openapi-restful.test.ts(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: OSSAR-Scan
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: build-test (20.x)
- GitHub Check: build-test (20.x)
🔇 Additional comments (8)
packages/plugins/openapi/src/rest-generator.ts (6)
15-27: Imports expanded to support TypeDef declarations.The imports have been updated to include the necessary TypeDef-related types from the SDK's AST module, which is essential for properly supporting TypeDef declarations in the OpenAPI schema generation.
508-511: Appropriate JSON handling for filter parameters.Fields referencing a TypeDef or of type Json are now correctly treated as strings with JSON format when generating filter parameters. This ensures proper OpenAPI representation for JSON fields in query parameters.
557-560: TypeDef components generation added.Iterating through TypeDef declarations to generate corresponding schema components completes the support for custom type definitions in the OpenAPI specification.
802-812: New TypeDef component generator implementation.The implementation correctly generates OpenAPI schema objects for TypeDef declarations, creating properties for each field in the TypeDef using the existing field generation logic.
979-984: Field generator updated to handle TypeDef fields.The generateField method now accepts both DataModelField and TypeDefField types, enabling it to process fields from both data models and type definitions while maintaining the same logic.
986-988: Field type to OpenAPI schema conversion updated.The fieldTypeToOpenAPISchema method now handles both DataModelFieldType and TypeDefFieldType, ensuring consistent schema generation regardless of where the field is defined.
packages/plugins/openapi/tests/openapi-restful.test.ts (2)
309-311: Added TypeDef declaration for testing.A new
Metatype has been added with a string field, which provides a good test case for the TypeDef component generation implementation.
324-325: Test coverage added for JSON fields.Two new field types have been added to the test model:
- A nullable
Metatype with the@jsonattribute, testing custom JSON object serialization- A plain
Jsonfield, testing the standard JSON type handlingThese additions provide complete test coverage for the new JSON field support.
fixes #2084