-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Typescript-Fetch] Support additionalproperties, Enum, Auth and more. #6130
Conversation
c0a4108
to
b631a17
Compare
@isman-usoh thanks for so many enhancements 👍 cc @Vrolijkx @taxpon @sebastianhaas @kenisteward @TiFu Copying @mgechev as well since he's also working on some enhancements for TS Fetch generator. |
79c15b3
to
73b36e0
Compare
- Upgrade to TypeScript 2 - Use type definition from npm instead of typings, typings is deprecation - Use Enum instead of String Literal Types - Use typescript es6 lib for target es5 - Support additionalproperties - Support JSDoc - Add snapshot and npmRepository option - Update typescript-fetch run script for linux - Create typescript-fetch run script for windows
- Fix circle run script - Fix duplicate query parameter
…ger-codegen into typescript-fetch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job, that's a big improvement! I added a few comments, mostly style related, and a few with open questions.
// tslint:disable | ||
{{>licenseInfo}} | ||
|
||
import * as url from "url"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More consistent indentation, currently it's mixture between tabs and spaces.
{{>licenseInfo}} | ||
|
||
import * as url from "url"; | ||
import * as isomorphicFetch from "isomorphic-fetch"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
{{>licenseInfo}} | ||
|
||
import * as url from "url"; | ||
import * as isomorphicFetch from "isomorphic-fetch"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to introduce isomorphic-fetch
as a dependency? Why not inject the fetch implementation from the outside instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isomorphic-fetch
support run node.js and browser
If browser does not support Fetch API isomorphic-fetch
use from fetch polyfill
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, sure, that's why it's called isomorphic. My point is, does it worth coupling to a specific dependency? Why not inject it from the outside, based on the declared interface?
* @class BaseAPI | ||
*/ | ||
export class BaseAPI { | ||
public config: Configuration = new Configuration(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can delay the instantiation of the Configuration
object for after we've verified that the config
parameter has not been passed.
@@ -8,5 +11,6 @@ export class Configuration { | |||
}; | |||
username: string; | |||
password: string; | |||
accessToken: string; | |||
accessToken: string | ((name: string) => string); | |||
basePath: string; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- accessToken var >> return current token
- accessToken function >> use for multiple Oauth, parameter auth name
- basePath >> for override base path
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this all looks cool. The point of my comment is that there's missing newline https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline.
|
||
CAVEAT: Due to [privilege implications](https://docs.npmjs.com/misc/scripts#user), `npm` would skip all scripts if the user is `root`. You would need to manually run it with `npm run prepublish` or run `npm install --unsafe-perm`. | ||
### publishing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should start with uppercase being a title.
|
||
You can also use `npm link` to link the module. However, this would not modify `package.json` of the installing project, as such you would need to relink every time you deploy that project. | ||
### consuming |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should start with uppercase being a title.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
export class Configuration { | ||
apiKey: { | ||
api_key: string; | ||
}; | ||
username: string; | ||
password: string; | ||
accessToken: string; | ||
accessToken: string | ((name: string) => string); | ||
basePath: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline.
*/ | ||
|
||
export * from "./api"; | ||
export * from "./configuration"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline.
"typings/browser", | ||
"typings/main", | ||
"typings/main.d.ts" | ||
"node_modules" | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Newline.
2fcf2b2
to
633e420
Compare
If this looks good, I'll merge it tomorrow. cc @Vrolijkx @taxpon @sebastianhaas @kenisteward @TiFu @mgechev |
@isman-usoh I got the following errors when trying to update the TS Fetch Petstore samples:
Should it be "TypeScript-Fetch/index.mustache" instead? |
@wing328 I rename template folder to lowercase, to be consistent other typescript project |
@isman-usoh yes, I noticed that. Did you get any error when running the shell script or Windows batch file for TS Fetch Petstore clients? |
@wing328 No, I use windows os and run bin\windows\typescript-fetch-petstore.bat success, no error |
Why did you change from string literal types to enums? #6233 does the opposite (for the typescript-angular binding). |
Travis CI tests failed with errors. Here are some for reference:
Ref: https://travis-ci.org/swagger-api/swagger-codegen/builds/261078041 Please take a look when you've time. |
bin/typescript-fetch-petstore-all.sh
Outdated
@@ -1,5 +0,0 @@ | |||
#!/bin/sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to keep the {lang}-petstore-all.sh convention so as to make it consistent with other languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
Are there any plans on supporting automatic redirects for OAuth2 with implicit flow using the mandatory |
Implicit flow involves navigating to the identity server, which destroys all javascript objects, so I don't see how that Observable could ever complete? Could you elaborate on how you think this could work? |
In general things we implement here should be angular specific only. We can
make it easily extensible but we shouldn't have dependencies on things like
auth libraries however having easy config setup making it extensible to one
should be fine
…On Wed, Aug 9, 2017, 9:08 AM Adrian Moos ***@***.***> wrote:
Implicit flow involves navigating to the identity server, which destroys
all javascript objects, so I don't see how that Observable could ever
complete? Could you elaborate on how you think this could work?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6130 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AMPLtSNLlVWU3Y9eyptofq43vnGFYyHXks5sWa9UgaJpZM4Oe6q_>
.
|
@bedag-moo I'm not an expert on the auth flow, but with activated CORS on the auth-server it should be possible to directly send the request to the (in the swagger.json) configured authorizationUrl f.e. to refresh the accessToken using the refreshToken. In order to implement such a lazy-refresh, the result of the accessToken function needs to be async. |
alexrashed: I think this is called the code flow (the implicit flow does not provide refresh tokens AFAIK). I agree this could be useful for code flow (or implicit flow in a nested iframe, come to think of it). |
Tests passed via https://travis-ci.org/swagger-api/swagger-codegen/builds/263778502 |
PR checklist
./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
and./bin/security/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
.3.0.0
branch for breaking (non-backward compatible) changes.Description of the PR
Support additionalproperties and more.