forked from loafle/openapi-generator-original
Added exemplary usage of API to README.md
This commit is contained in:
parent
cd5da90f7f
commit
81ede197e1
@ -16,7 +16,7 @@ First build the package then run ```npm publish```
|
||||
|
||||
### Consuming
|
||||
|
||||
navigate to the folder of your consuming project and run one of the following commands.
|
||||
Navigate to the folder of your consuming project and run one of the following commands.
|
||||
|
||||
_published:_
|
||||
|
||||
@ -28,3 +28,45 @@ _unPublished (not recommended):_
|
||||
|
||||
```
|
||||
npm install PATH_TO_GENERATED_PACKAGE --save
|
||||
|
||||
### Usage
|
||||
|
||||
Below code snippet shows exemplary usage of the configuration and the API based
|
||||
on the typical `PetStore` example used for OpenAPI.
|
||||
|
||||
```
|
||||
import * as your_api from 'your_api_package'
|
||||
|
||||
// Covers all auth methods included in your OpenAPI yaml definition
|
||||
const authConfig: your_api.AuthMethodsConfiguration = {
|
||||
"api_key": "YOUR_API_KEY"
|
||||
}
|
||||
|
||||
// Implements a simple middleware to modify requests before (`pre`) they are sent
|
||||
// and after (`post`) they have been received
|
||||
class Test implements your_api.Middleware {
|
||||
pre(context: your_api.RequestContext): Promise<your_api.RequestContext> {
|
||||
// Modify context here and return
|
||||
return Promise.resolve(context);
|
||||
}
|
||||
|
||||
post(context: your_api.ResponseContext): Promise<your_api.ResponseContext> {
|
||||
return Promise.resolve(context);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Create configuration parameter object
|
||||
const configurationParameters = {
|
||||
httpApi: new your_api.JQueryHttpLibrary(), // Can also be ignored - default is usually fine
|
||||
baseServer: your_api.servers[0], // First server is default
|
||||
authMethods: authConfig, // No auth is default
|
||||
promiseMiddleware: [new Test()],
|
||||
}
|
||||
|
||||
// Convert to actual configuration
|
||||
const config = your_api.createConfiguration(configurationParameters);
|
||||
|
||||
// Use configuration with your_api
|
||||
const api = new your_api.PetApi(config);
|
||||
```
|
@ -25,7 +25,7 @@ export interface Configuration {
|
||||
export interface ConfigurationParameters {
|
||||
/**
|
||||
* Default server to use - a list of available servers (according to the
|
||||
* spec) is included in the `servers` const in `./servers`. You can also
|
||||
* OpenAPI yaml definition) is included in the `servers` const in `./servers`. You can also
|
||||
* create your own server with the `ServerConfiguration` class from the same
|
||||
* file.
|
||||
*/
|
||||
@ -53,7 +53,7 @@ export interface ConfigurationParameters {
|
||||
promiseMiddleware?: PromiseMiddleware[];
|
||||
/**
|
||||
* Configuration for the available authentication methods (e.g., api keys)
|
||||
* according to the spec. For the definition, please refer to
|
||||
* according to the OpenAPI yaml definition. For the definition, please refer to
|
||||
* `./auth/auth`
|
||||
*/
|
||||
authMethods?: AuthMethodsConfiguration
|
||||
|
@ -15,7 +15,7 @@ export class ServerConfiguration<T extends { [key: string]: string }> implements
|
||||
|
||||
/**
|
||||
* Sets the value of the variables of this server. Variables are included in
|
||||
* the `url` of this ServerConfiguration in the form `{key}`
|
||||
* the `url` of this ServerConfiguration in the form `{variableName}`
|
||||
*
|
||||
* @param variableConfiguration a partial variable configuration for the
|
||||
* variables contained in the url
|
||||
|
Loading…
x
Reference in New Issue
Block a user