amazon-archives / aws-serverless-auth-reference-app

Serverless reference app and backend API, showcasing authentication and authorization patterns using Amazon Cognito, Amazon API Gateway, AWS Lambda, and AWS IAM.
Other
754 stars 193 forks source link

regenerating sdk causes issues #38

Closed rakeshtembhurne closed 6 years ago

rakeshtembhurne commented 6 years ago

I am working on customised version of this app, but the same thing is observed with latest version of current app. The problem is when I try to generate sdk with gulp generate_sdk, the code generated is very different than committed code.

For example diff for a line in file app/src/services/spacefinder-sdk/api/DefaultApi.ts:

-    constructor(protected http: Http, @Optional() basePath: string) {
+    constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {

These 'extra' changes causes further problems - like it should be basePath?: string and not basepath: string, and so on.

My question is - how can we generate a consistent API with command gulp generate_sdk with no unnecessary additions?

justonian commented 6 years ago

As an FYI, this gulp task and feature isn't officially documented in the repo since it was for the developers of the project only. If you'd like to get it to work, first install Swagger-Codegen locally as described at https://github.com/swagger-api/swagger-codegen. I believe you already have this working. Next, you should be able to run "gulp generate_sdk" when in the API directory and successfully generate a new SDK folder and sub-files from the Swagger definition YAML file.

As you mentioned, between Angular 4 changes and Swagger Codegen changes, the signatures for some of the initialization options have changed, with an optional configuration. I just pushed a commit to update the project to use the latest generated SDK and pass in a null for the configuration options, which are optional.

Additionally, Angular 4 made some changes to their HTTP service to have an enum instead of a string for the HTTP methods, so I've updated the spacefinder-api-service.ts file accordingly, to properly handle this.

All should be working fine now with the latest Swagger Codegen, Ionic, and Angular 4 so let me know if you run into other issues.

Justin

rakeshtembhurne commented 6 years ago

Thank you @justonian for detailed explanation. While studying this project, I went to the code and found this really nice feature gulp generate_sdk - to build api just from swagger definition file.

I later found that the problem was with version of swagger-codegen. I installed it with Homebrew package manager and the version installed was v2.2.3. After spending few hours on it, I found that actual version should have been v2.2.1. So I downloaded old jar file and made following changes to the api/util/swagger.js file.

-    let cmd = spawn('swagger-codegen', ['generate', '-i', swaggerDir + '/SpacefinderAPI-exported.yml', '-l', 'typescript-angular2', '-o', apiSdkDir]);
+    let cmd = spawn('java', ['-jar', '/path/to/my/swagger-codegen-cli-2.2.1.jar', 'generate', '-i', swaggerDir + '/SpacefinderAPI-exported.yml', '-l', 'typescript-angular2', '-o', apiSdkDir]);

These changes worked for me.

justonian commented 6 years ago

Try again now with the latest version. I did have to make a few updates the other day to support it given their new initialization signature, but those are now made and pushed to this repo.

If you download the latest code from this repo and try it with the latest swagger codegen version, it should work fine now.