Skip to content

fix: Serialize falsey values #906

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

Merged
merged 2 commits into from
May 22, 2022

Conversation

duncanbeevers
Copy link
Contributor

Closes #890

I went through and looked for all the spots where an empty string made sense and would be translated across to the TS files.
This includes example, description, title, format, and default.

I tried to fix this up for both v2 and v3 schemas.

@@ -6,7 +6,7 @@ export function transformRequestBodies(requestBodies: Record<string, RequestBody
let output = "";

for (const [name, requestBody] of Object.entries(requestBodies)) {
if (requestBody && requestBody.description) output += ` ${comment(requestBody.description)}`;
if (requestBody && requestBody.description !== undefined) output += ` ${comment(requestBody.description)}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great fix, thank you!

@drwpow
Copy link
Contributor

drwpow commented May 2, 2022

I’m in favor of this approach, but there are some test failures now where empty JSDoc comments are being inserted into the schema. I’d like to avoid this if possible.

But when that’s fixed, happy to approve & merge!

@duncanbeevers
Copy link
Contributor Author

Are you referring to the empty JSDoc comments like this?

/** */

They definitely seem kind of weird, but I was going with the perspective "The developer put an empty string in here, for some reason…, so respect that."

https://youtu.be/OIVIDmuJZLI?t=40
u-g-F5F5P30

One would really have to go out of their way in order to introduce these empty comments.

Are you saying you'd like me to ignore descriptions and such that would generate such comments, or that you'd like me to fix the tests to match the PR behavior?

@duncanbeevers
Copy link
Contributor Author

I see that in the spec, for many fields like response-code definitions, that the description field is mandatory and can't be simply elided.

I agree that these comments are unsightly in this case when there's no mechanism available to avoid them, and I'll see about cleaning up those instances.

When a prettier config file is specified but can't be found a default prettier config is silently used as a fallback.
This change causes an error to be raised when the specified prettier config doesn't exist.

Closes openapi-ts#908
@duncanbeevers
Copy link
Contributor Author

I've re-worked this PR to only serialize falsey example and default values, and not all these other fields.
The PR depends-on, and builds-on #909, although I was unable to change the base branch of the PR.

Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@drwpow drwpow merged commit a634b33 into openapi-ts:main May 22, 2022
@drwpow
Copy link
Contributor

drwpow commented May 22, 2022

@all-contributors please add @duncanbeevers for code, bug, test

@allcontributors
Copy link
Contributor

@drwpow

I've put up a pull request to add @duncanbeevers! 🎉

duncanbeevers added a commit to duncanbeevers/openapi-typescript that referenced this pull request May 22, 2022
* fix: Error on missing prettier config

When a prettier config file is specified but can't be found a default prettier config is silently used as a fallback.
This change causes an error to be raised when the specified prettier config doesn't exist.

Closes openapi-ts#908

* fix: Serialize falsey defaults and examples

Closes openapi-ts#890
@duncanbeevers duncanbeevers deleted the fix-falsey-example branch May 22, 2022 03:03
drwpow pushed a commit that referenced this pull request May 24, 2022
* docs: add duncanbeevers as a contributor for code, bug, test (#913)

* docs: update README.md [skip ci]

* docs: update .all-contributorsrc [skip ci]

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* fix: Serialize falsey values (#906)

* fix: Error on missing prettier config

When a prettier config file is specified but can't be found a default prettier config is silently used as a fallback.
This change causes an error to be raised when the specified prettier config doesn't exist.

Closes #908

* fix: Serialize falsey defaults and examples

Closes #890

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Falsy example value do not generate comments in output
2 participants