-
Notifications
You must be signed in to change notification settings - Fork 10
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
refactors #146
base: main
Are you sure you want to change the base?
refactors #146
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThis pull request encompasses multiple changes across various components and files in the project. The modifications primarily focus on renaming functions related to example retrieval (e.g., Changes
Possibly related PRs
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 (
|
commit: |
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: 9
🔭 Outside diff range comments (1)
src/composables/useSidebar.ts (1)
Line range hint
214-214
: Consider implementing the TODO itemThe TODO comment indicates a planned
itemsByOperations
function. This could be addressed as part of the current refactoring effort.Would you like me to help implement the
itemsByOperations
function or create a GitHub issue to track this enhancement?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (25)
docs/sandbox/index.md
(1 hunks)src/components/Parameter/OAParameterExamples.vue
(2 hunks)src/components/Playground/OAPlaygroundParameterInput.vue
(2 hunks)src/components/Playground/OAPlaygroundParameters.vue
(2 hunks)src/composables/usePaths.ts
(1 hunks)src/composables/useSidebar.ts
(1 hunks)src/lib/codeSamples/buildRequest.ts
(2 hunks)src/lib/codeSamples/generateCodeSampleCurl.ts
(1 hunks)src/lib/codeSamples/generateCodeSamplePhp.ts
(2 hunks)src/lib/codeSamples/request.ts
(1 hunks)src/lib/createOpenApiInstance.ts
(1 hunks)src/lib/fetchToCurl.ts
(0 hunks)src/lib/getPropertyExample.ts
(1 hunks)src/lib/getPropertyExamples.ts
(1 hunks)src/lib/getSchemaUi.ts
(4 hunks)src/lib/getSchemaUiJson.ts
(5 hunks)src/lib/prepareOpenAPI/generateMissingSummary.ts
(1 hunks)src/lib/prepareOpenAPI/generateMissingTags.ts
(1 hunks)test/lib/fetchToCurl.test.ts
(0 hunks)test/lib/generateCodeSamples.test.ts
(1 hunks)test/lib/getPropertyExample.test.ts
(1 hunks)test/lib/getPropertyExamples.test.ts
(1 hunks)test/lib/prepareOpenAPI/generateMissingOperationIds.test.ts
(1 hunks)test/lib/prepareOpenAPI/generateMissingSummary.test.ts
(1 hunks)test/lib/prepareOpenAPI/generateMissingTags.test.ts
(1 hunks)
💤 Files with no reviewable changes (2)
- test/lib/fetchToCurl.test.ts
- src/lib/fetchToCurl.ts
🔇 Additional comments (43)
src/lib/createOpenApiInstance.ts (1)
3-3
: Verify consistent file organization across the codebase
The import path change suggests a structural reorganization. Let's verify this is consistently applied across the codebase.
✅ Verification successful
Import paths are consistently using the new directory structure
All imports of prepareOpenAPI
across the codebase are using the new path structure prepareOpenAPI/prepareOpenAPI
, and the file exists at the expected location. The structural reorganization has been applied consistently.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any remaining old-style imports of prepareOpenAPI
# and verify the new directory structure exists
# Check for any remaining old imports
rg "from ['\"].*prepareOpenAPI['\"]" --type ts
# Verify the new directory structure
fd prepareOpenAPI.ts
Length of output: 412
src/composables/usePaths.ts (1)
3-3
: LGTM! Import path update is consistent
The import path modification maintains consistency with the new file organization structure.
src/composables/useSidebar.ts (1)
5-5
: LGTM! Import path update is consistent
The import path modification maintains consistency with the new file organization structure.
src/lib/prepareOpenAPI/generateMissingTags.ts (2)
Line range hint 4-31
: Implementation looks good!
The function implementation follows best practices:
- Proper type safety with OpenAPI types
- Handles undefined/null cases gracefully
- Maintains immutability by creating new tags
- Clear and maintainable logic for tag generation
2-2
: Verify the import path change across the codebase
The import path has been updated to accommodate directory structure changes. Let's verify this change is consistent with other imports.
✅ Verification successful
Import path change is correct and consistent
The import path change from '../composables/useTheme' to '../../composables/useTheme' is verified to be correct based on the following evidence:
- The
useTheme.ts
file exists atsrc/composables/useTheme.ts
- The importing file is at
src/lib/prepareOpenAPI/generateMissingTags.ts
- Other files in the codebase correctly import from the same location:
src/index.ts
uses./composables/useTheme
src/lib/operationData.ts
uses../composables/useTheme
test/composables/useTheme.test.ts
uses../../src/composables/useTheme
The relative path adjustment is consistent with the directory structure and follows the same pattern as other imports in the codebase.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the consistency of useTheme imports across the codebase
# Check all imports of useTheme to ensure consistency
echo "Checking useTheme import patterns:"
rg "from ['\"].*composables/useTheme['\"]" --type ts
# Check if the new import path exists
echo -e "\nVerifying the existence of the useTheme file:"
fd useTheme.ts composables/
Length of output: 888
Script:
#!/bin/bash
# Let's verify the existence of useTheme.ts with a repository-wide search
echo "Searching for useTheme.ts file:"
fd useTheme.ts
# Let's also check the directory structure around the file in question
echo -e "\nChecking directory structure:"
ls -R src/lib/prepareOpenAPI/
ls -R src/composables/
Length of output: 471
src/lib/codeSamples/generateCodeSampleCurl.ts (3)
6-6
: Provide a Clear Fallback for Unknown HTTP Methods
Currently, an unknown or unrecognized HTTP method would yield an empty string for the method flag. While this is acceptable, consider logging a warning or throwing an error if the method is not recognized to avoid silently ignoring a potential misuse.
Do you want me to generate a script to search for and review all method calls in the codebase that might pass an unknown HTTP method to generateCodeSampleCurl
?
16-18
: Automatic Compression Handling
The approach for enabling --compressed
when accept-encoding
is present is clever. Just be mindful that certain cURL versions may behave differently with this flag, especially regarding supported encodings. Testing in multiple environments is advised.
20-20
: Trim the Final Output for Better CLI Usability
Trimming whitespace at the end of the command string is a helpful final step to avoid unexpected blank lines when copying or executing the command. Good practice.
src/lib/getPropertyExamples.ts (1)
1-1
: Rename Reflects Function Purpose Clearly
Changing from getExamples
to getPropertyExamples
better conveys that this function deals with property-related examples. The logic is straightforward and consistent with the naming convention across related files.
src/lib/prepareOpenAPI/generateMissingSummary.ts (1)
2-2
: Maintain Updated Import Paths to Avoid Breakages
Your import path alteration to ../../types
is valid, but be attentive that any external references or project documentation referencing the older path might need updates. Also check if your tooling (e.g., TypeScript path aliases) can simplify these relative paths.
src/lib/getPropertyExample.ts (1)
1-1
: Align Single vs. Multiple Examples with Return Value Consistency
Renaming getExample
to getPropertyExample
improves clarity. The function returns either a single value or null
. Meanwhile, getPropertyExamples
can return arrays. Ensure callers expect this difference and handle single vs. multiple examples appropriately.
test/lib/getPropertyExamples.test.ts (6)
2-2
: Import aligns with function rename.
No issues found with this import statement change.
7-7
: Test usage of getPropertyExamples
.
This looks correct and aligns with the expected return for the example
property.
12-12
: Test usage with examples
array.
This is accurate, verifying array-based examples properly.
17-17
: Test usage with missing example
and examples
.
Returning null in this scenario is consistent with the intended functionality.
22-22
: Test usage with an empty string for example
.
Ensuring the function returns an array containing an empty string is a valid edge-case check.
27-27
: Test usage with an empty examples
array.
Correctly returning an empty array fulfills expectations for this scenario.
src/components/Parameter/OAParameterExamples.vue (2)
3-3
: Import name updates.
Renaming to getPropertyExamples
accurately reflects the function’s purpose.
14-14
: Direct usage of getPropertyExamples
.
Retrieving examples from props.property
is consistent with the refactor.
src/lib/codeSamples/generateCodeSamplePhp.ts (4)
10-10
: Conditional headers handling.
Checking for headers
before accessing keys prevents runtime errors.
18-18
: Conditional query handling.
Same defensive check ensures the function won't break if query
is undefined.
31-31
: Nullish coalescing in URL construction.
Object.keys(query ?? {})
is a robust approach for handling optional queries.
35-35
: Consistent header check.
Maintaining the same pattern ensures consistent safety checks throughout.
test/lib/prepareOpenAPI/generateMissingTags.test.ts (1)
1-75
: Comprehensive new test suite.
This file thoroughly tests various scenarios for generateMissingTags
, covering default-tag insertion, existing tags preservation, and empty paths. The coverage appears complete and in line with the function’s purpose. If further extensibility is desired (e.g., custom default tags), you could consider parameterizing the tag name.
src/components/Playground/OAPlaygroundParameterInput.vue (3)
5-5
: Consistent rename to getPropertyExample
The import now correctly points to getPropertyExample
, aligning with the rest of the refactor.
42-42
: Logical fallback assignment for modelValue
Using getPropertyExample(props.parameter) ?? props.parameter.schema.enum[0]
is a proper fallback mechanism to ensure a valid model value.
46-46
: Immediate assignment for parameterExample
Storing the example value in parameterExample
ensures easy reuse in the template. No issues noted.
test/lib/getPropertyExample.test.ts (2)
2-2
: Updated import path
Renaming from getExample
to getPropertyExample
maintains consistency.
4-52
: Thorough test coverage
Each scenario explicitly checks a different data field (example
, examples
, schema.example
, etc.), ensuring comprehensive coverage for edge cases.
src/lib/codeSamples/buildRequest.ts (2)
3-3
: Import refactor
Switching from getExample
to getPropertyExample
is consistent with the updated naming across the codebase.
86-86
: Proper example variable assignment
Using getPropertyExample(parameter)
within setExamplesAsVariables
ensures that missing variables are auto-populated with relevant examples.
src/lib/getSchemaUiJson.ts (5)
2-2
: Consistent import rename
The import of getPropertyExample
reflects the refactor effort. No issues detected.
61-61
: Example usage in array properties
Correctly retrieves an example for array items when useExample
is true, improving consistency across property types.
80-80
: Literal property example retrieval
Ensures literal properties use getPropertyExample
when useExample
is set, maintaining the expected logic.
93-93
: Constant property example retrieval
For constants, using getPropertyExample
is straightforward; no functional issues.
144-144
: One-of property example resolution
Fallbacks to getPropertyExample
if no sub-properties exist, aligning with the updated naming.
src/lib/getSchemaUi.ts (2)
3-3
: Ensure consistent usage of renamed function.
This import change aligns with the updated function name but verify all references to avoid potential merge conflicts.
128-128
: Graceful fallback for constant property.
This logic correctly defaults to schema.const
when examples are unavailable. Looks good.
src/components/Playground/OAPlaygroundParameters.vue (2)
11-11
: Consistent function naming.
Using getPropertyExample
keeps the code aligned with the updated naming convention.
78-78
: Properly initializing parameter variables.
Looks good. The new function name maintains clarity and consistent usage of examples.
docs/sandbox/index.md (1)
2-2
: Updated title and layout.
No issues found. This aligns the sandbox page with a simpler naming convention and a custom layout.
test/lib/prepareOpenAPI/generateMissingSummary.test.ts (1)
2-2
: LGTM! Import path updated correctly.
The import path change aligns with the refactoring to organize OpenAPI-related functionality under the prepareOpenAPI
directory.
Let's verify the new file structure:
✅ Verification successful
Import path correctly reflects the actual file location
The verification confirms that the source file generateMissingSummary.ts
exists at the expected path src/lib/prepareOpenAPI/generateMissingSummary.ts
, which matches the import path in the test file. The refactoring to organize OpenAPI-related functionality under the prepareOpenAPI
directory has been properly implemented.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Verify the source file exists at the new location
fd -t f "generateMissingSummary.ts" src/
Length of output: 89
test/lib/prepareOpenAPI/generateMissingOperationIds.test.ts (1)
2-2
: LGTM! Import path updated consistently.
The import path change follows the same pattern as other files, maintaining consistency in the refactoring effort.
Let's verify the consistency of the refactoring:
✅ Verification successful
Import path update verified as consistent
Based on the verification results:
- The file
generateMissingOperationIds.ts
is correctly located insrc/lib/prepareOpenAPI/
- The corresponding test file is properly placed in
test/lib/prepareOpenAPI/
- No old import paths were found in the test files
- All references to
generateMissingOperationIds
in the test file use the new import path
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if all related files have been moved to prepareOpenAPI
echo "Verifying file structure..."
fd -t f "generate.*\.ts" src/
# Verify no old imports remain
echo "Checking for any remaining old import paths..."
rg -t ts "from '\.\.\/\.\.\/(src/)?lib/generate" test/
Length of output: 802
Script:
#!/bin/bash
# Let's fix the regex and check for old import paths
echo "Checking for any remaining old import paths..."
rg -t ts "from '\\.\\.\\/\\.\\.\\/(?:src\\/)?lib\\/generate" test/
# Let's also check specifically for imports of generateMissingOperationIds
echo "Checking imports of generateMissingOperationIds..."
rg -t ts "generateMissingOperationIds" test/
Length of output: 1284
Script:
#!/bin/bash
# Let's try a simpler approach to find any old imports
echo "Checking for imports from old path..."
rg -t ts "from.*lib/generate" test/
# Let's also check the file structure to ensure the move is complete
echo "Checking file structure in test directory..."
fd -t f "generate.*\.ts" test/
Length of output: 517
if (request.body) { | ||
output += ` \\\n${generateBody(JSON.stringify(request.body, null, 2))}` | ||
} |
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.
🧹 Nitpick (assertive)
Consider Centralizing JSON Stringification
The code currently stringifies the body (JSON.stringify(request.body, null, 2)
) before passing it to generateBody
, which also checks if body
is an object. This double check can be confusing. Centralizing or deferring the JSON stringification to one place (e.g., strictly within generateBody
) may improve maintainability.
body: request.body ? JSON.stringify(request.body, null, 2) : undefined, | ||
query: request.query, | ||
}) | ||
const headersArgument = generateHeadersArgument(request.headers) |
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.
🧹 Nitpick (assertive)
Use Nullish Coalescing for Enhanced Robustness
While request.headers
is typically defined (defaulted to {}
in OARequest
), consider using a nullish coalescing operator or a similar safeguard to ensure the argument is never undefined. This will make the code more defensive in scenarios where the request object might be malformed.
- const headersArgument = generateHeadersArgument(request.headers)
+ const headersArgument = generateHeadersArgument(request.headers ?? {})
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const headersArgument = generateHeadersArgument(request.headers) | |
const headersArgument = generateHeadersArgument(request.headers ?? {}) |
public headers?: Record<string, string>, | ||
public body?: any, | ||
public query?: Record<string, string>, |
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.
🧹 Nitpick (assertive)
Make Constructor Parameters Consistent with Defaults
You changed headers
, body
, and query
to optional, which is good for flexibility. However, you might consider consistent usage of defaults (e.g., public headers: Record<string, string> = {}, public body: any = null, public query: Record<string, string> = {}
) for more direct clarity. The current approach is valid, but combining default parameters with your fallback logic can be more explicit.
if (!headers) { | ||
this.headers = {} | ||
} |
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.
🧹 Nitpick (assertive)
Leverage Optional Chaining More Widely
You're already using a conditional check to see if headers
is not provided. Since you're defaulting to {}
, consider optional chaining or a nullish coalescing operator for even more robust handling. For example:
if (!this.headers) {
this.headers = {}
}
could be replaced by direct assignment in the constructor:
public headers: Record<string, string> = {}
This is more concise and ensures headers
is always an object.
if (!query) { | ||
this.query = {} | ||
} |
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.
🧹 Nitpick (assertive)
Ensure Query Object is Always Populated
Similar to the headers
fallback, using a parameter default (e.g., public query: Record<string, string> = {}
) can streamline this check. The current approach works, but explicit parameter defaults may reduce code repetition.
if (getPropertyExamples(schema.items)) { | ||
property.subexamples = getPropertyExamples(schema.items) |
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.
🧹 Nitpick (assertive)
Consider reusing the example result for subexamples.
Reduce duplication by storing getPropertyExamples(schema.items)
in a variable.
if (getPropertyExamples(schema.items)) {
- property.subexamples = getPropertyExamples(schema.items)
+ const itemExamples = getPropertyExamples(schema.items)
+ property.subexamples = itemExamples
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (getPropertyExamples(schema.items)) { | |
property.subexamples = getPropertyExamples(schema.items) | |
if (getPropertyExamples(schema.items)) { | |
const itemExamples = getPropertyExamples(schema.items) | |
property.subexamples = itemExamples |
@@ -56,7 +56,7 @@ | |||
...(property.description && { description: property.description }), | |||
...(property.default !== undefined && { defaultValue: property.default }), | |||
...(property.externalDocs && { docs: property.externalDocs }), | |||
...(getExamples(property) && { examples: getExamples(property) }), | |||
...(getPropertyExamples(property) && { examples: getPropertyExamples(property) }), |
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.
🧹 Nitpick (assertive)
Avoid repeated function calls in object spread.
Calling getPropertyExamples(property)
twice can be optimized. Store the result in a variable and reuse it to improve readability.
const propertyExamples = getPropertyExamples(property)
const baseProperty: OAProperty = {
name,
types: nodeTypes,
required,
- ...(getPropertyExamples(property) && { examples: getPropertyExamples(property) }),
+ ...(propertyExamples && { examples: propertyExamples }),
...(property.nullable && { nullable: property.nullable }),
}
Committable suggestion skipped: line range outside the PR's diff.
it('handles query parameters and headers correctly', () => { | ||
const url = 'https://api.example.com/path/testOperation' | ||
const method = 'GET' | ||
const headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer token' } | ||
const queryParams: Record<string, string> = { search: 'query', page: '2' } | ||
const result = generateCodeSampleCurl({ url, method, headers, query: queryParams }) | ||
expect(result).toBe(`curl -X GET \\ | ||
'https://api.example.com/path/testOperation?search=query&page=2' \\ | ||
-H "Content-Type: application/json" \\ | ||
-H "Authorization: Bearer token"`) | ||
}) |
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.
🧹 Nitpick (assertive)
Comprehensive coverage of query parameters and headers.
This test thoroughly checks the generation of CURL commands with multiple query parameters and headers. Consider adding edge cases for numeric or boolean query parameters in future updates.
Description
Some refactors.
Related issues/external references
Types of changes