swagger-fetch-client
v2.0.1
Published
Generate a typescript api client from a swagger 2.0 schema
Downloads
79
Keywords
Readme
swagger-fetch-client
Generates a typescript fetch api client from a swagger configuration endpoint (v1 or v2)
Running
Install the fetch client into your application (as a dev dependency)
npm i swagger-fetch-client -SD
In the root of your repository create a swagger-fetch-client.config.js
file, like:
module.exports = {
url: "https://api.rocketmakers.net/swagger/docs/v1",
apiOutputPath: "./source/api/apiclient.ts",
defintionOutputFile: "./source/typings/api/apiclient.d.ts"
}
The complete list of config options are:
/** The url of the swagger endpoint */
url: string,
/** The path of the generated typescript api (.ts) */
apiOutputPath: string,
/** The path of the generated typescript api definitions (.d.ts) */
defintionOutputFile: string,
/** If property required not specified, override with true */
propertiesRequiredByDefault?: boolean,
/** ensure the generated models use proper case */
properCaseProps?: boolean
/** Generate a sample fetch client (beta) */
generateFetchClient?: boolean
/** To override the generated IFetchApiResponse<T> you can import your own version */
fetchApiInterfaceImport?: string
/** encodes all URI params after the "?" with "encodeURIComponent" */
encodeUriParams?: boolean
/** By default we write 'const enums' - set this to true to create full enums */
fullEnums?: boolean
/** Allows the grouping of endpoint parameters into a single object, named using this string */
paramObjectKey?: string
Then from the command line run:
swagger-fetch-client
If you want to create an alternative config file you can:
swagger-fetch-client <config file path>