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

[Question] Group API Endpoints by tags #23

Closed
dangthaison91 opened this issue May 26, 2017 · 9 comments
Closed

[Question] Group API Endpoints by tags #23

dangthaison91 opened this issue May 26, 2017 · 9 comments

Comments

@dangthaison91
Copy link
Contributor

Hi, first of all, thanks for your great work.

I'm working on creating RxSwift + Moya Swift template for Swagger. It worked perfectly after some modifications in Swift3 Codegen. I can finally make a PR but it is painful with inconsistent Java coding conventions, complex codebase.

Luckily, I found your awesome library while finalizing my code before making a PR (after nearly 2 months pending). I can easily understand your codes and implementing task #8. I will submit a PR after I finished.

But I have a question: It is possible to groups API Endpoints by their tags then put them in one file for example: Fake.swift, Pet.swift, Store.swift, User.swift? I see your suggestion in #5 but couldn't find a solution for my case.

@dangthaison91
Copy link
Contributor Author

Update: I changed template.yml to this:

- path: request.swift
  context: tags
  destination: "Sources/Requests/{{ name|upperCamelCase }}.swift"

then update request.swift template:

public enum {{ operation.operationId|upperCamelCase }} {

    public static let service = APIService<Response>(id: "{{ operationId }}", tag: "{{ tag }}", method: "{{ method|uppercase }}", path: "{{ path }}" ... {% endif %})

To:

{% for operation in operations %}

    public enum {{ operation.operationId|upperCamelCase }} {

         public static let service = APIService<Response>(id: "{{ operation.operationId }}", tag: "{{ operation.tag }}", method: "{{ operation.method|uppercase }}", path: "{{ operation.path }}" .. .{% endif %})

{% endfor %}

Can we do it without adding operation. prefix?

@yonaskolb
Copy link
Owner

Hi @dangthaison91
I'm glad you're getting some good use out of it.

If you'd like to define an operation without always typing operation. you can make it an include:

{% for operation in operations %}
  {% include "Includes/operation.yml" using operation %}
{% endfor %}

And then move the relevant operation code to Includes/operation.yml" within the template. This is enabled by some changes to include` I made to my fork of Stencil stencilproject/Stencil#114

@yonaskolb
Copy link
Owner

It would be great if you could submit your custom template in a PR when you're done! It can be added to Templates/Swift-Moya

@yonaskolb
Copy link
Owner

Yeah, I have similar feelings to you about the Swagger Codegen Java project. I've also made quite a few PR's and also got sick of their java interface, so that was the main reason I actually created this

@dangthaison91
Copy link
Contributor Author

Thank you so much @yonaskolb. I'd be happy to submit my PR when I've done.

@yonaskolb
Copy link
Owner

Hi @dangthaison91, how's your Moya template going? Anything you'd feel comfortable submitting?

@dangthaison91
Copy link
Contributor Author

dangthaison91 commented Jul 11, 2017

Hi @yonaskolb , I already created my own Moya template but having some problems while generating Models to use with Realm. I used in some company's project but sometimes I have to manual edit/fix errors.

I pushed it to my folk repo, you can get it here: https://github.com/dangthaison91/SwagGen/tree/master/Templates/Swift-Moya

I have created an example but need to remove private stuffs before making it public.

@yonaskolb
Copy link
Owner

@dangthaison91 Just you you know I've released 0.6.0. Check the release notes https://github.com/yonaskolb/SwagGen/releases/tag/0.6.0
You might want to merge that into your branch and see if it still works or if it fixes anything for you.
One thing that has changed that I know will affect you is within a template tags has been renamed to operationsByTag. tags is now just a list of tag names

@dangthaison91
Copy link
Contributor Author

@yonaskolb Oh, thanks for your reminder. I will check this weekend.

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

No branches or pull requests

2 participants