swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.79k stars 6.02k forks source link

Customization Requests #2505

Open cdennison opened 8 years ago

cdennison commented 8 years ago

I recently created an SDK for a REST API (https://thingspace.verizon.com) and needed to do the following. Not sure how these fit with the overall goals of swagger-codegen, but I wanted to share my experience.

  1. For some requests with few fields I wanted to map the fields to parameters so the user doesn't have to create a request POJO (see example below).
  2. I needed to wrap the entire SDK anyways to try and hide minor changes from the user. One of the disadvantages of using Java for my SDK is that any change in the REST API request schema is a breaking change whereas for other types of clients (e.g. JavaScript) it would not be.
  3. I wanted to combine all of my APIs into a single class (instead of the 6 that were auto-generated by end point) to make it easier to call.
  4. I wanted to add a custom Auth token to the header of every request, but because I called apiClient.invokeAPI in 6 different places (see above) I had to add that token to each class and set it 6 times.

    public CallbackAction registerCallback(String aname, String name, String password, String url, String username) throws ApiException { RegisterCallback request = new RegisterCallback(); request.setName(name); request.setPassword(password); request.setUrl(url); request.setUsername(username); return aCallbacksApi.registerCallbackUsingPOST(aname, request); }

cdaringe commented 8 years ago

my guess is that you'll have to hack up the templates and do some post-processing. i know that's not entirely helpful, but based on the functionality that this tool provides, it may be your only route!

cdennison commented 8 years ago

That's fine - I was just asked to submit my comments on SO http://stackoverflow.com/questions/35851014/swagger-converting-underscore-to-camelcase/35875446?noredirect=1#comment60497557_35875446.

wing328 commented 8 years ago

@cdennison thanks for sharing your use case with us.

  1. For the endpoint that currently takes a model (JSON), is there a equivalent/similar endpoint that takes POJO fields as HTTP form parameters instead?
  2. Can you tell us more about the minor changes from the users?
  3. Currently, do you have 6 Swagger/OpenAPI spec to generate 6 different SDKs?
  4. Does your Swagger/OpenAPI spec use security definition object to define authentication setting for endpoint? If the security definition is defined properly, there's no need to repeatedly apply the same authentcation setting in the API client.