@antklim/api-to-cloud
v0.2.0
Published
This tool injects cloud specific integration points to API definition in Swagger.
Readme
API to Cloud
This tool injects cloud specific integration points to API definition in Swagger.
Installing
This is a NodeJS module available through the npm register.
Installation is done using the npm install command:
$ npm install @antklim/api-to-cloudUsage
After installation api-to-cloud CLI will be available in node_modules/.bin.
Usage: api-to-cloud [options]
Options:
-V, --version output the version number
-a, --api <path> API definition file path
-i, --integration <path> API integration file path
-o, --output <path> path to output extended API file
-c, --cloud [cloud] cloud provider [AWS], default 'AWS'
-f, --format [format] output file format [yaml|yml|json], default 'yaml'
-h, --help output usage informationRun the following command to produce swagger file with AWS specific integration points:
$ node_modules/.bin/api-to-cloud --api test-api.yaml \
--integration test-integration.yaml \
--output aws.yamlProgrammatic API
parser
The parser module provides utilities for parsing of API and integration point descriptions. Currently supported two formats: YAML and JSON. It can be accessed using:
const {parser} = require('@antklim/api-to-cloud')parser.parse(file)
fileString - path to the file to parse- Returns: Promise - resolves with the file data parsed into object
Example:
parser.parse('input.yaml')
.then(data => console.log(JSON.stringify(data, null, 2)))
.catch(err => console.error(err))parser.for(format)
formatString - file format to parse- Returns: Function - parser function or null
encoder
The encoder module provides utilities for formatting and storing of API definition. Currently supported two formats: YAML and JSON. It can be accessed using:
const {encoder} = require('@antklim/api-to-cloud')encoder.save(data, file, format)
dataObject - data to write to filefileString - path to file to writeformatString - format to save payload in- Returns: Promise - resolves when payload written into the file
Example:
encoder.save({'foo': 'bar'}, 'example.yaml', 'yaml')
.then(() => console.log('Payload written into \'example.yaml\''))
.catch(err => console.error(err))encoder.for(format)
formatString - file format to encode to- Returns: Function - encoder function or null
integrator
The integrator module provides utilities for merging pure API description in Swagger format with cloud specific integration points. It can be accessed using:
const {integrator} = require('@antklim/api-to-cloud')integrator.extend(api, integrationPaths, cloud)
apiObject - Swagger API definitionintegrationPathsObject - cloud integration points to add to APIcloudString - target cloud provider, [AWS]- Returns: Object - extended Swagger API (API + integrations)
Format of the integration points object:
path:
method:
integrationPoint: ...Example of integration object:
/pets:
get:
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
post:
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"
/pets/{petId}:
get:
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
requestTemplates:
application/json: "{\"statusCode\": 200}"
passthroughBehavior: "when_no_match"
type: "mock"integrator.cleanApi(api, removables)
apiObject - Swagger API definitionremovablesArray - the list of paths to remove from the API description- Returns: Object - API definition cleaned from removables
Built With
- js-yaml - YAML parser/encoder for JavaScript
- ava - Futuristic test runner
- ESLint - JavaScript linting utility
- testdouble - JavaScript test mocking library
Authors
License
This project is licensed under the MIT License - see the LICENSE file for details
