Skip to content
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

[BUG][Swift5] Generator output not compilable with uniqueItems #7281

Closed
5 of 6 tasks
pgrosslicht opened this issue Aug 24, 2020 · 1 comment · Fixed by #7300
Closed
5 of 6 tasks

[BUG][Swift5] Generator output not compilable with uniqueItems #7281

pgrosslicht opened this issue Aug 24, 2020 · 1 comment · Fixed by #7300

Comments

@pgrosslicht
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

#6773 introduced a change where Set is used instead of Arrays when the array spec has the uniqueItems flag set. Set however needs all elements to conform to Hashable, which they do not.

openapi-generator version

v5.0.0-beta a77fd44
was working in v4.3.1 003165c

OpenAPI declaration file content or url

https://gist.github.com/pgrosslicht/c519f7e011eee94ed356779a0096e256

Generation Details

swift5 generator with everything as default

Steps to reproduce
java -jar openapi-generator-cli-5.0.0-beta.jar generate -i error.yaml -g swift5
swift build

Build will fail with

OpenAPIClient/Classes/OpenAPIs/APIs/PetsAPI.swift:20:37: error: type 'Pet' does not conform to protocol 'Hashable'
    open class func createPets(pet: Set<Pet>, apiResponseQueue: DispatchQueue = OpenAPIClientAPI.apiResponseQueue, completion: @escaping ((_ data: Void?,_ error: Error?) -> Void)) {
Related issues/PRs

Introduced in #6773

Suggest a fix
  1. Make all structs conform to Hashable. This should work since Swift can automatically synthesize the Hashable protocol in most cases, but might lead to some edge cases where Swift is not capable of synthesizing them.
  2. Introduce config option for the change original change in [SWIFT5] Add the ability to turn uniqueItems array into Set in swift. #6773 and the suggested Hashable conformance.
@wing328
Copy link
Member

wing328 commented Aug 26, 2020

@pgrosslicht thanks for filing the issue. I've filed #7300 to fix it.

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

Successfully merging a pull request may close this issue.

2 participants