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

[Swift4] Class name conflicts not handled #7148

Open
dylan-colaco opened this issue Dec 11, 2017 · 6 comments
Open

[Swift4] Class name conflicts not handled #7148

dylan-colaco opened this issue Dec 11, 2017 · 6 comments

Comments

@dylan-colaco
Copy link

Description

I have one of my swagger models named 'Locale' which has custom properties. I cannot change this definition as it was used in our backend and android code for years. In the generated swift4 client file, CodableHelper there is a DateFormatter object created, and locale is set on it. The problem is that swift is using my custom Locale class instead of the one from Foundation here.

Swagger-codegen version

swagger-codegen-cli-2.3.0-20171207.164637-326.jar

Swagger declaration file content or url
Command line used for generation

java -jar swagger-codegen-cli-2.3.0-20171207.164637-326.jar generate -l swift4 -i file.yaml -o client

Steps to reproduce

Use a model like Locale which is named same as a Foundation class that is used

Related issues/PRs
Suggest a fix/enhancement

If a class name is the same as Foundation, use the Foundation namespace prefix while using it: e.g.
formatter.locale = Foundation.Locale(identifier: "en_US_POSIX")
instead of
formatter.locale = Locale(identifier: "en_US_POSIX")

@wing328
Copy link
Contributor

wing328 commented Dec 13, 2017

What about automatically renaming Locale to ModelLocale as part of the code generation process?

@dylan-colaco
Copy link
Author

The problem with that is fields are usually named after classes and Json deserialization would stop working if the java(backend) and swift models have different names

@wing328
Copy link
Contributor

wing328 commented Dec 13, 2017

Without breaking serialization/deserialization, the field can be named differently independent of how the model is named.

I know other generators (e.g. Ruby, PHP, Java) can handle this but not sure about Swift4.

Disclaimer: no expert in Swift

@dylan-colaco
Copy link
Author

I'm not sure either. If this approach works, that should be fine too

@wing328 wing328 modified the milestones: v2.3.0, v2.4.0 Dec 18, 2017
@wing328
Copy link
Contributor

wing328 commented Dec 18, 2017

I'll file a PR after 2.3.0 release, which is scheduled this week.

@thomasMinshull
Copy link

Has there been any progress with this issue? I seem to be having the same issue with a model named "Notification" in my swagger doc.

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

No branches or pull requests

3 participants