WIP: new javascript flowtyped generator #175
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in swagger-api/swagger-codegen#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 Fetch Generator, so differs from the other Javascript Generators in code and architecture.
Simply adding flow annotations didn't work with the current js es6 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
npm install
NODE_ENV=production npm run build
git add .
git commit -m 'update sdk version'
git tag v
git push && git push --tags
in your react app do:
npm install #v
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.
see swagger-api/swagger-codegen#8101 for reference and discussion.