Skip to content

[typescript-fetch] handle uniqueItems correctly in model and api#8695

Merged
wing328 merged 2 commits into
OpenAPITools:masterfrom
t-h-e:fix_typescript-fetch_uniqueitems
Feb 14, 2021
Merged

[typescript-fetch] handle uniqueItems correctly in model and api#8695
wing328 merged 2 commits into
OpenAPITools:masterfrom
t-h-e:fix_typescript-fetch_uniqueitems

Conversation

@t-h-e

@t-h-e t-h-e commented Feb 13, 2021

Copy link
Copy Markdown
Contributor

uniqueItems produces Set instead of Array as type, but the corresponding code did not treat Set correctly

use Array.from and new Set to convert from Set to Array and vice versa, if uniqueItems is true.

related to #8258, but only fixes typescript-fetch

@auto-labeler

auto-labeler Bot commented Feb 13, 2021

Copy link
Copy Markdown

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

uniqueItems produces Set instead of Array as type, but the corresponding code did not treat Set correctly

use `Array.from` and `new Set` to convert from Set to Array and vice versa, if uniqueItems is true.

related to OpenAPITools#8258, but only fixes typescript-fetch
@t-h-e t-h-e force-pushed the fix_typescript-fetch_uniqueitems branch from b202b3c to 531a852 Compare February 13, 2021 10:35
@macjohnny

Copy link
Copy Markdown
Member

@t-h-e thanks for your contribution. please follow the steps described in https://github.com/OpenAPITools/openapi-generator/blob/master/.github/PULL_REQUEST_TEMPLATE.md

@macjohnny macjohnny left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

the code looks good, but I think this might be a breaking change if currently someone uses a type-mapping. I am not sure how we should proceed. @wing328 any thoughts?

@t-h-e

t-h-e commented Feb 13, 2021

Copy link
Copy Markdown
Contributor Author

@macjohnny Thanks for the hint. I updated the samples.

As @macjohnny mentioned correctly, this change will break setups, where type-mapping has been used.

I think I found another issue, unless I'm mistaken. Pet.ts in samples/client/petstore/typescript-fetch/builds/default-3.0/models may not work correctly in line 94 and 112, as photoUrls of type Set is treated as primitive. This worked when photoUrls was of type Array, but not with Set.

@wing328

wing328 commented Feb 14, 2021

Copy link
Copy Markdown
Member

For other generators, we do not consider it as a breaking change as we're making a correction to the output. Let's see if any TS users have a different opinion on this.

@wing328 wing328 added this to the 5.1.0 milestone Feb 14, 2021
@wing328 wing328 merged commit 99b36b9 into OpenAPITools:master Feb 14, 2021
@macjohnny

Copy link
Copy Markdown
Member

@wing328

wing328 commented Mar 22, 2021

Copy link
Copy Markdown
Member

@t-h-e thanks for the PR, which has been included in the v5.1.0 release: https://twitter.com/oas_generator/status/1373636654024380423

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants