Generate a Javascript API client from a swagger document, using swagger client generator.
This project just makes it easier to define and generate API clients.
All commands must be run from the root path of your project
npm install pb-api-client-gen --save-dev
- Create an
apiClients.yml
file using the example below - Edit your project's
package.json
file and add a property namedbuild-api
with the valuebuild-api
to thescripts
object. Use the example below for reference.
apiClients.yml
should be in the root path of your project. This file defines the clients that will be generated.
- name: SpeciesRequest
swaggerDefinitionUrl: http://localhost/api/docs/v3/species.swagger.yaml
outputDirectory: resources/js/angular/apiRequest/
The following properties are required for each client that will be generated:
name
- The name of the class that will be generatedswaggerDefinitionUrl
- URL of the target swagger definitionoutputDirectory
- Destination path of generated clients
- Edit the
package.json
file of your project. Use the example below for reference. - Run
npm run build-app
to generate the client code.
Example:
"scripts": {
"build-api": "build-api"
}
This project is mostly a wrapper for https://github.com/wcandillon/swagger-js-codegen
Creating an npm command - http://blog.npmjs.org/post/118810260230/building-a-simple-command-line-tool-with-npm