Javascript Flow typed
As discussed in #5733 there is no generator which outputs Javascript which is properly flow typed and easy to use with React.
Here is it now.
Is is based on the Typescript Generator, so differs from the other Javascript Generators.
Please have a look @CodeNinjai @frol @cliffano
This is such an awesome accomplishment! I can't wait to try it with a react app with flow.
Base on the code change, could you confirm that it is this a different flavour of JavaScript client than the original ES 6 JavaScript client with useES6 : true configuration flag? i.e. the code gen command would be
java -jar swagger-codegen-cli-2.3.1.jar generate -i swagger.json -l javascript-flowtyped -o ./js-flow-sdk
I have no experience with Flow, so I won't be able to review.
@joyfulelement this client is different from the es6 client. simply adding flow annotations didn't work with the current code.
The code is written in ES6 with flow syntax. In order to use it as a library in your react app, it comes with a npm build script to transpile it into node.js and browser compatible es5 syntax with additional .js.flow for flow to use the types properly.
steps to use this client as a npm library:
- create yourself a new folder and repo for the client sdk
- generate client with
java -jar swagger-codegen-cli-2.3.1.jar generate -i swagger.json -l javascript-flowtyped -o <path-to-sdk-repo> -
npm install -
NODE_ENV=production npm run build -
git add . -
git commit -m 'update sdk version' -
git tag v<SEMVER> -
git push && git push --tags - in your react app do:
-
npm install <SDK-REPO-URL>#v<SEMVER> -
import { * as api } from 'client-sdk-package'
if you want to generate the api directly inside your client-app you can do so. just import the files from the generated src then. these are pure es6 with flow types and need to be transpiled like you would do with the other code.
Hi @wing328, this PR introduces a new javascript language dialect, please advise how to proceed with reviewing this changes.
@jaypea I'm using your branch for my react-native project and it works great! :+1:
Two small things I had to tweak using a custom template that you might want to take into consideration:
-
Change the way basePath is accessed. I need to be able to change the basePath during runtime without re-instantiating the api class. Currently the basePath variable is set as a constant and protected by the scoping.
-
Change some of the typing surrounding portableFetch so that it would type properly when using react native's built in fetch (My flow comes with the
RequestOptionstype built in, so I had to use that). I'm not sure if these changes are specific to my react native setup.
@wouterhund thanks for the feedback.
to change the basePath during runtime, I feed it into the Configuration Object:
const myConfig = new apiclient.Configuration({
apiKey: token,
basePath: (process.env.REACT_APP_API_BASEPATH: any),
});
const myApi = apiclient.MyApi(myConfig);
I've no experience with react native, though.
whether/when this change going to be merged and released? this is very desired feature - imo
When will this PR be merged? I would really like to try it out to generated a flow client to use it in Frontend.
@ivanantipin @MichaelSu1983 please see the linked PR from May 29 in another repository to try it ;)
any update?
Hi , When i run the script java -jar swagger-codegen-cli-2.3.1.jar generate -i swagger.json -l javascript-flowtyped -o sdk-repo
I am seeing the following error:
Caused by: java.lang.ClassNotFoundException: javascript-flowtyped at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Unknown Source) at io.swagger.codegen.CodegenConfigLoader.forName(CodegenConfigLoader.java:29) ... 3 more
somebody help?