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

[Javascript] ES6 with Angular #5485

Open miguelvaladez opened 7 years ago

miguelvaladez commented 7 years ago

I did not see an open issue or request for this and have since forked this project to begin working on it. I have implemented a Javascript-ES6-Angular client generator that turns the API data into a basic Angular $resource and imports them into a base module.js file. Would anyone else be interested in this functionality or in helping contribute to what I've done so far?

wing328 commented 7 years ago

@miguelvaladez thanks for enhancing the generator. Is your work related to the discussion in https://github.com/swagger-api/swagger-codegen/issues/4044 ?

miguelvaladez commented 7 years ago

Not really no - mine is much more slimmed down but also reliant on the client code being used in an Angular environment.

The API would return a resource class like this:

` export default class AuthApi { / @ngInject / constructor($resource) { this.basePath = 'http://myapp.dev/api/auth';

     return $resource(null, {}, {
       'login': this.login(),
     });
   }

   /**
    * logs a user in
    */
   login () {
     return {
       method: 'POST',
       url: this.basePath + '/login'
     }
   }
 }

`

wing328 commented 7 years ago

Is it correct to say that your version is tailored made to JS ES6 and Angular 1.x?

Any chance this can be added back to the JS generator via CLI option (e.g. supportAngular) (or {{#supportAngular}} in the mustache template)? We would like to avoid generators with very similar functionality if possible because it becomes not easy to maintain generators with similar functionality.

Can you please also file a PR so that we can review the exact enhancement?