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

Fix for clojure API filenames #2271

Merged

Conversation

timbogit
Copy link
Contributor

When the API name is more than one word (e.g., UsersAPI in a users-service), then the API namespace name will become users-service.api.users-api.

Prior to this fix, the API filename would include a dash, as it is solvely based on the API name (i.e., it currently is users_service/api/users-api.clj), which breaks clojure's conventions and leads to compilation errors.

With this fix, the API filename will be correctly converted to have underscores in place of dashes (i.e., the API file will be generated as users_service/api/users_api.clj).

…lojure filenames have to replace dashes with underscores)
@xhh
Copy link
Contributor

xhh commented Feb 29, 2016

Thanks for the PR.
I tried and it works for users api and UsersApi by generating the API file named users_api.clj.
However, for users-api or users_api, usersapi.clj is generated. It would be better to generate users_api.clj as well.

@timbogit do you mind including the improvements in this PR?

@timbogit
Copy link
Contributor Author

Thanks for the comment / suggestion, @xxh!
I was mainly taking the approach to simply fix the "un-requirable" filename for a given API name by 'underscoring' it. I am not familiar enough with the code to actually know where the tag name that is fed into the apiFilename originates, and how it can be made to match the classname that is used in the api.mustache template, which seems to be needed to implement the suggestion you made above.
I mainly took the 'inspiration' for my fix from the other language codegen classes (like here).

If you prefer, I can simply use a standard replaceAll() call, like so:

@Override
 public String toApiFilename(String name) {
     return toApiName(name).replaceAll("-", "_");
 }

Thoughts / pointers welcome!

@wing328
Copy link
Contributor

wing328 commented Mar 1, 2016

As discussed with @xhh we'll merge this fix and he might add more enhancement and test cases with another PR later.

Thanks @timbogit for the contribution.

wing328 added a commit that referenced this pull request Mar 1, 2016
@wing328 wing328 merged commit 9aa59b9 into swagger-api:master Mar 1, 2016
@xhh
Copy link
Contributor

xhh commented Mar 1, 2016

See #2286 for my PR on further improvements on api names for Clojure client.

@timbogit
Copy link
Contributor Author

timbogit commented Mar 4, 2016

Thanks for the merge, and 👏 for the PR that generalizes this for more use cases, and adds test coverage!

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