inversify-express-postman
Package is not finished yet and breaking changes are likely until v1.0.0
is released.
Export inversify-express-utils metadata to a Postman Collection and sync with the Postman API
Contents | Examples |
---|---|
Getting Started | Container to JSON |
Decorators | Decorator Example |
Syncing with Postman API | PostmanApi Example |
Adding Test Scripts | Test Script Example |
Getting Started
Once a container has been setup, use one of the top level functions to convert the metadata from the container's express endpoints to a Postman Collection or a JSON of the Collection.
In this example, a container is passed in and a JSON string is returned and logged to the console.
Container to JSON
;; ; container.bindTYPES.SomeAPIModelService .toSomeAPIModelService.inSingletonScope; ;// Start the server before passing the container to inversify-express-postman// Prints to console the JSON with 2 space indentationIEPostman.ContainerToCollectionJSONcontainer, false, 2 .thenconsole.log .catchconsole.error;
All of the endpoints are split up by their controllers as folders and the endpoints as children of the controllers.
To add more information about an endpoint, utilize the @Decorators included with inversify-express-utils. (Some Decorator metadata isn't handled yet)
Decorators
The PostmanData decorator allows the entry of some more Postman Collection supported items. There are a variety of decorators that can be used jointly. A few decorators can be applied to the class controllers. Console warnings should appear if a decorator is not supported. Typescript typings should give an error for any Decorators that won't work on a class.
The example below shows some valid usage of the included decorators.
Decorator Example
; // Names the Folder // Read in a markdown file and set it as the description
Syncing with Postman API
The PostmanApi service provides methods for handling requests to the Postman API to create / update items (e.g. Collections and Environments). In order to create an instance of the PostmanApi class, a Postman API Key must be passed into the constructor. Visit Postman's API documentation to get a better understanding of what is happening when using the PostmanApi class.
If you need an API key, generate the key in your Postman Integrations Dashboard
PostmanApi Example
The example below shows how to sync collections and create them using the git branch it was executed from. A similar method can be used for environment variables.
...IEPostman.ContainerToCollectioncontainer, .then.catchconsole.error;
Adding Test Scripts
Test scripts are supported and can be associated with an endpoint by using the PostmanTestFunction decorators.
In this example, an endpoint has a prerequest and a test function.
Prequest and Test Example
;
When using a class static
method for a test function, the name of the function should start with either PREREQUEST
or TEST
or function
. See the functionStripper util to see how the stripper is working.
Support UTF-8 Encoded Test Scripts
This is still an in progress feature.
The PostmanTestFunction decorators support the use of absolute paths to files. This can be a remote resource and will be acquired using the request-promise package. Local resources are read using fs.