-
Notifications
You must be signed in to change notification settings - Fork 21
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
Implement API Model Auto Generation using openapi-generation
#442
Conversation
Warning Rate limit exceeded@devleejb has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 7 minutes and 5 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (5)
WalkthroughThis pull request introduces a new OpenAPI specification (version 3.0.0) for the CodePair API, detailing multiple endpoints for user authentication, workspace management, document handling, and utility functions. It includes comprehensive request and response schemas to ensure structured data representation and error handling. Additionally, new Go model structs are generated to provide type-safe representations of the API's data structures, supporting robust backend implementation. A README file and configuration for the OpenAPI generator CLI are also included to facilitate development. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthService
participant WorkspaceService
participant DocumentService
Client->>AuthService: Login with GitHub
AuthService-->>Client: Return Access & Refresh Tokens
Client->>WorkspaceService: Create Workspace
WorkspaceService-->>Client: Return Workspace Details
Client->>DocumentService: Create Document in Workspace
DocumentService-->>Client: Return Document Metadata
Possibly related PRs
Suggested labels
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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: 20
🧹 Nitpick comments (12)
backend-go/api/codepair/v1/models/model_file_upload_config.go (1)
5-6
: Enhance field documentation.While the documentation is present, consider making it more descriptive by explaining the implications of enabling/disabling file uploads.
- // Whether file upload is enabled + // Enable controls whether file uploads are allowed in the system. + // When set to true, users can upload files; when false, file upload functionality is disabled.backend-go/api/codepair/v1/models/model_check_name_conflict_request.go (1)
5-6
: Add validation rules to documentation.Consider enhancing the documentation to specify any validation rules for the name field (e.g., allowed characters, length limits).
- // Name to check for conflict + // Name to check for conflict. The name should follow the system's naming rules + // and will be checked against existing names to ensure uniqueness.backend-go/api/codepair/v1/models/model_change_nickname_request.go (1)
5-6
: Add validation rules to documentation.Consider enhancing the documentation to specify any validation rules for the nickname field (e.g., allowed characters, length limits).
- // New nickname to update + // New nickname to update. The nickname should follow the system's naming conventions + // and any length or character restrictions defined in the validation rules.backend-go/api/codepair/v1/models/model_create_workspace_request.go (2)
5-6
: Add validation rules to documentation.Consider enhancing the documentation to specify any validation rules for the workspace title (e.g., allowed characters, length limits).
- // Title for the new workspace + // Title for the new workspace. The title should follow workspace naming conventions + // and any length or character restrictions defined in the validation rules.
1-7
: Consider adding validation at the OpenAPI specification level.Since these models are auto-generated, consider defining validation rules (e.g., minLength, maxLength, pattern) in the OpenAPI specification. This would ensure consistent validation across different generated clients and servers.
backend-go/api/codepair/v1/models/model_yorkie_intelligence_config.go (1)
3-10
: Consider using stronger types for configuration values.While using
map[string]interface{}
provides flexibility, it could lead to runtime type assertion issues. Consider:
- Using a more specific type for config values if the possible types are known
- Adding validation methods for the config map
- Documenting expected config key-value pairs
Example of a more type-safe approach:
type ConfigValue struct { Type string `json:"type"` // e.g., "string", "number", "boolean" Value interface{} `json:"value"` } type YorkieIntelligenceConfig struct { Enable bool `json:"enable"` Config map[string]ConfigValue `json:"config"` }backend-go/api/codepair/v1/models/model_create_workspace_document_share_token_request.go (1)
7-14
: Add role validation and expiration constraints.The model could benefit from:
- Defining valid roles as constants/enums
- Adding validation for the expiration time
Example implementation:
const ( RoleReader = "reader" RoleWriter = "writer" // Add other valid roles... ) type CreateWorkspaceDocumentShareTokenRequest struct { Role string `json:"role" validate:"oneof=reader writer"` ExpiredAt time.Time `json:"expiredAt" validate:"gt=now"` } func (r *CreateWorkspaceDocumentShareTokenRequest) Validate() error { if !isValidRole(r.Role) { return fmt.Errorf("invalid role: %s", r.Role) } if r.ExpiredAt.Before(time.Now()) { return fmt.Errorf("expiration time must be in the future") } return nil }backend-go/api/codepair/v1/models/model_find_settings_response.go (1)
3-10
: Clean composition of configuration types!The model effectively combines the configuration types with clear documentation. Consider documenting whether these fields can be nil and how they should be handled by consumers.
Consider adding a comment about nil handling:
type FindSettingsResponse struct { // Settings related to Yorkie Intelligence // This field will never be nil in responses YorkieIntelligence YorkieIntelligenceConfig `json:"yorkieIntelligence"` // Settings related to file uploads // This field will never be nil in responses FileUpload FileUploadConfig `json:"fileUpload"` }backend-go/api/codepair/v1/models/model_export_file_request.go (1)
3-13
: Consider adding validation for ExportType field.While the struct is well-designed, consider adding validation to ensure ExportType only accepts valid values (e.g., "PDF", "HTML").
Example validation implementation:
var ValidExportTypes = map[string]bool{ "PDF": true, "HTML": true, } func (r *ExportFileRequest) Validate() error { if !ValidExportTypes[r.ExportType] { return fmt.Errorf("invalid export type: %s", r.ExportType) } return nil }backend-go/api/codepair/v1/models/model_workspace_domain.go (1)
1-1
: Consider updating the OpenAPI specification.Since these models are auto-generated, the identified issues (float32 for counts, naming conventions) should be addressed in the OpenAPI specification itself. Consider:
- Using integer types for count fields in the spec
- Following Go naming conventions (URL, ID) in the spec's schema definitions
This will ensure the generated code follows Go best practices.
api/backend-openapi-spec.json (1)
906-916
: Add maximum length validation for nickname.The
ChangeNicknameRequest
schema has a minimum length validation but lacks a maximum length constraint.Add a maximum length validation:
"ChangeNicknameRequest": { "type": "object", "properties": { "nickname": { "type": "string", "description": "New nickname to update", - "minLength": 2 + "minLength": 2, + "maxLength": 50 } }, "required": ["nickname"] },backend-go/api/codepair/v1/README.md (1)
3-3
: Use a more robust path reference.The relative path to the OpenAPI spec (
../../../../api/backend-openapi-spec.json
) is fragile and could break if the directory structure changes.Consider using a path relative to the repository root:
-The types in `./models` are all automatically generated from the [OpenAPI spec](../../../../api/backend-openapi-spec.json). +The types in `./models` are all automatically generated from the [OpenAPI spec](/api/backend-openapi-spec.json).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (38)
api/backend-openapi-spec.json
(1 hunks)backend-go/api/codepair/v1/README.md
(1 hunks)backend-go/api/codepair/v1/models/model_change_nickname_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_check_name_conflic_reponse.go
(1 hunks)backend-go/api/codepair/v1/models/model_check_name_conflict_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_check_yorkie_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_check_yorkie_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_create_invitation_token_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_create_invitation_token_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_create_upload_presigned_url_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_create_upload_presigned_url_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_create_workspace_document_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_create_workspace_document_share_token_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_create_workspace_document_share_token_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_create_workspace_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_export_file_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_export_file_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_file_upload_config.go
(1 hunks)backend-go/api/codepair/v1/models/model_find_document_from_sharing_token_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_find_settings_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_find_user_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_find_workspace_documents_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_find_workspace_users_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_find_workspaces_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_http_exception_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_join_workspace_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_login_response.go
(1 hunks)backend-go/api/codepair/v1/models/model_refresh_token_request_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_refresh_token_response_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_run_feature_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_run_follow_up_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_update_document_title_request.go
(1 hunks)backend-go/api/codepair/v1/models/model_workspace_document_domain.go
(1 hunks)backend-go/api/codepair/v1/models/model_workspace_domain.go
(1 hunks)backend-go/api/codepair/v1/models/model_workspace_user_domain.go
(1 hunks)backend-go/api/codepair/v1/models/model_yorkie_intelligence_config.go
(1 hunks)openapitools.json
(1 hunks)package.json
(2 hunks)
✅ Files skipped from review due to trivial changes (3)
- backend-go/api/codepair/v1/models/model_refresh_token_request_request.go
- backend-go/api/codepair/v1/models/model_create_invitation_token_response.go
- openapitools.json
🧰 Additional context used
🪛 golangci-lint (1.62.2)
backend-go/api/codepair/v1/models/model_http_exception_response.go
[warning] 3-3: var-naming: type HttpExceptionResponse should be HTTPExceptionResponse
(revive)
backend-go/api/codepair/v1/models/model_workspace_domain.go
[warning] 10-10: var-naming: struct field Id should be ID
(revive)
backend-go/api/codepair/v1/models/model_run_follow_up_request.go
[warning] 6-6: var-naming: struct field DocumentId should be DocumentID
(revive)
backend-go/api/codepair/v1/models/model_workspace_document_domain.go
[warning] 10-10: var-naming: struct field Id should be ID
(revive)
[warning] 13-13: var-naming: struct field YorkieDocumentId should be YorkieDocumentID
(revive)
backend-go/api/codepair/v1/models/model_create_upload_presigned_url_response.go
[warning] 3-3: var-naming: type CreateUploadPresignedUrlResponse should be CreateUploadPresignedURLResponse
(revive)
backend-go/api/codepair/v1/models/model_find_document_from_sharing_token_response.go
[warning] 13-13: var-naming: struct field YorkieDocumentId should be YorkieDocumentID
(revive)
backend-go/api/codepair/v1/models/model_create_upload_presigned_url_request.go
[warning] 3-3: var-naming: type CreateUploadPresignedUrlRequest should be CreateUploadPresignedURLRequest
(revive)
backend-go/api/codepair/v1/models/model_run_feature_request.go
[warning] 6-6: var-naming: struct field DocumentId should be DocumentID
(revive)
backend-go/api/codepair/v1/models/model_workspace_user_domain.go
[warning] 10-10: var-naming: struct field Id should be ID
(revive)
🪛 Checkov (3.2.334)
api/backend-openapi-spec.json
[HIGH] 1-1449: Ensure that the global security field has rules defined
(CKV_OPENAPI_4)
[HIGH] 1-1449: Ensure that security operations is not empty.
(CKV_OPENAPI_5)
🪛 LanguageTool
backend-go/api/codepair/v1/README.md
[duplication] ~10-~10: Possible typo: you repeated a word.
Context: .... Move to the root of the repository 2. Run pnpm install
3. Run pnpm run generate:backend
(ENGLISH_WORD_REPEAT_RULE)
🔇 Additional comments (10)
backend-go/api/codepair/v1/models/model_update_document_title_request.go (1)
3-7
: LGTM!The struct is well-defined with proper documentation and follows Go conventions for JSON tags.
backend-go/api/codepair/v1/models/model_create_workspace_document_request.go (1)
3-7
: LGTM!The struct is well-defined with proper documentation and follows Go conventions for JSON tags.
backend-go/api/codepair/v1/models/model_join_workspace_request.go (1)
1-7
: LGTM!The struct is well-defined with proper documentation and JSON tags.
backend-go/api/codepair/v1/models/model_create_workspace_document_share_token_response.go (1)
1-7
: LGTM!The struct is well-defined with proper documentation and JSON tags.
backend-go/api/codepair/v1/models/model_create_invitation_token_request.go (1)
1-11
: LGTM!The struct is well-defined with proper documentation, JSON tags, and time.Time import.
backend-go/api/codepair/v1/models/model_login_response.go (1)
3-10
: LGTM!The struct is well-documented and follows Go conventions.
backend-go/api/codepair/v1/models/model_find_workspaces_response.go (1)
3-10
: Verify the WorkspaceDomain type.The struct looks good, but let's verify the existence and implementation of the
WorkspaceDomain
type.✅ Verification successful
WorkspaceDomain type verification successful
The
WorkspaceDomain
type is properly defined with all necessary fields and follows Go conventions. The type exists in the same package and is correctly structured for use in theFindWorkspacesResponse
.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the WorkspaceDomain type exists and is properly defined # Search for WorkspaceDomain type definition rg -t go "type WorkspaceDomain struct" backend-go/Length of output: 142
Script:
#!/bin/bash # Description: Inspect the WorkspaceDomain implementation cat backend-go/api/codepair/v1/models/model_workspace_domain.goLength of output: 442
backend-go/api/codepair/v1/models/model_check_yorkie_response.go (1)
3-10
: Well-structured response model with clear documentation!The
CheckYorkieResponse
struct is well-designed with appropriate field types and clear documentation for each field. The JSON serialization tags follow standard naming conventions.backend-go/api/codepair/v1/models/model_check_yorkie_request.go (1)
3-13
: LGTM! Well-structured request model with clear documentation.The struct is well-designed with appropriate field types and helpful documentation for each field.
package.json (1)
17-18
: LGTM! OpenAPI generator integration looks good.The changes correctly set up the OpenAPI generator:
- Added script to generate Go Echo server models
- Added required openapi-generator-cli dependency
Also applies to: 28-29
backend-go/api/codepair/v1/models/model_check_name_conflic_reponse.go
Outdated
Show resolved
Hide resolved
backend-go/api/codepair/v1/models/model_refresh_token_response_request.go
Outdated
Show resolved
Hide resolved
backend-go/api/codepair/v1/models/model_create_upload_presigned_url_response.go
Show resolved
Hide resolved
backend-go/api/codepair/v1/models/model_find_document_from_sharing_token_response.go
Show resolved
Hide resolved
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.
LGTM :)
I believe this can be merged quickly, so I have left just one simple suggestion.
What this PR does / why we need it:
This pull request includes the addition of several new models to the
backend-go/api/codepair/v1
directory, as well as documentation updates. The changes introduce new request and response models for various API endpoints and provide instructions for generating these models from the OpenAPI specification.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist:
Summary by CodeRabbit
New Features
Documentation
Chores