-
-
Notifications
You must be signed in to change notification settings - Fork 544
Fix requestBodies that use hypenated naming #550
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
Fix requestBodies that use hypenated naming #550
Conversation
If a request body's name is hypenated it breaks when prettier formats the code as it is an invalid object. Wrapping the request body's name in quotes resolves the issue, and prettier will strip the quotes when they're not required. Example for reproducing: ``` npx openapi-typescript https://github.com/raw/ashsmith/api-specs/fix-invalid-examples/reference/channels.v3.yml --output channels.v3.ts ```
Codecov Report
@@ Coverage Diff @@
## main #550 +/- ##
==========================================
+ Coverage 85.20% 85.50% +0.29%
==========================================
Files 9 9
Lines 338 338
Branches 112 112
==========================================
+ Hits 288 289 +1
+ Misses 46 45 -1
Partials 4 4
Continue to review full report at Codecov.
|
@@ -68,7 +68,7 @@ export function transformRequestBodies(requestBodies: Record<string, RequestBody | |||
|
|||
Object.entries(requestBodies).forEach(([bodyName, requestBody]) => { | |||
if (requestBody && requestBody.description) output += ` ${comment(requestBody.description)}`; | |||
output += ` ${bodyName}: {`; | |||
output += ` "${bodyName}": {`; |
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.
👍🏻
}; | ||
};`) | ||
); | ||
}); |
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.
Awesome test, thank you!
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.
Thank you! Will release this as v3.2.2
right now.
If a request body's name is hypenated it breaks when prettier formats the code as it is an invalid object.
Wrapping the request body's name in quotes resolves the issue, and prettier will strip the quotes when they're not required.
Example for reproducing:
Current result: