Package org.mockserver.imports
Class PostmanCollectionImporter
java.lang.Object
org.mockserver.imports.PostmanCollectionImporter
Imports expectations from Postman Collection v2.x (v2.0 and v2.1) JSON files.
Walks the item[] array recursively (folders contain nested item[]).
For each request that has saved example responses (response[]), one expectation
is created per example. Requests without saved examples are skipped with a logged count.
Handles Postman url being either a plain string or an object with
raw, path[], and query[].
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionimportExpectations(String collectionJson) Parses a Postman Collection v2.x JSON string and returns one expectation per saved example response, with sensitive headers and body fields redacted (seeImportRedaction).importExpectations(String collectionJson, ImportRedaction.Options redactionOptions) Parses a Postman Collection v2.x JSON string and returns one expectation per saved example response, applying the supplied redaction options before the expectations are returned.
-
Constructor Details
-
PostmanCollectionImporter
public PostmanCollectionImporter()
-
-
Method Details
-
importExpectations
Parses a Postman Collection v2.x JSON string and returns one expectation per saved example response, with sensitive headers and body fields redacted (seeImportRedaction). Postman requests/examples often carry realAuthorization/API-key headers and secret body fields, so redaction is on by default.- Parameters:
collectionJson- the Postman collection as a JSON string- Returns:
- the generated expectations (may be empty if no examples are present)
- Throws:
IllegalArgumentException- if the JSON is null, blank, or not a valid Postman collection
-
importExpectations
public List<Expectation> importExpectations(String collectionJson, ImportRedaction.Options redactionOptions) Parses a Postman Collection v2.x JSON string and returns one expectation per saved example response, applying the supplied redaction options before the expectations are returned.- Parameters:
collectionJson- the Postman collection as a JSON stringredactionOptions- controls whether/how sensitive data is masked; passImportRedaction.Options.disabled()to keep imported values verbatim- Returns:
- the generated expectations (may be empty if no examples are present)
- Throws:
IllegalArgumentException- if the JSON is null, blank, or not a valid Postman collection
-