This application creates a Postman collection for the Kontent.ai APIs. It takes the OpenAPI specifications generated by the Kontent.ai Learn API reference generator, converts them to Postman collections, tweaks the converted collections, and then merges them into a single collection.
- Fetches OpenAPI v3 specifications for the Kontent.ai APIs from the specified URLs.
- The URLs are specified using an environment variable.
- The names of the JSON files are hardcoded.
- Converts the downloaded OpenAPI specifications to Postman collections using the openapi-to-postman library.
- For each converted Postman collection, the app makes the following changes:
- Uses a Postman variable named
environment_id
for the:environment_id
path variable in every request that requires environment ID in its path. - Uses static base URLs for all requests instead of the
{{baseUrl}}
Postman variable. - Removes extraneous Postman collection variables such as
{{baseUrl}}
.
- Uses a Postman variable named
- Merges the processed Postman collections into a single collection.
- NodeJs v18 or higher
- IDE such as Visual Studio Code
To run the app locally, provide environment variables in the .env.local
config file.
kontent-ai-learn-oas-postman-converter/.env.local.template
Lines 1 to 7 in 8e4dac8
By default, the variables are read from environment variables and can be set up in app hosting platforms. The OpenAPI files to use are specified in the ApiReferenceFileNames
variable.
- Open the
src\workerScript.ts
. - Create a
.env.local
file based on the.env.local.template
and configure all required settings (e.g., AccessToken, Github user details) - In your terminal, run
npm install
. - In your terminal, run
npm run build
. - In your terminal, run
npm run start
. - Make a request to http://localhost:3000/collection.json.
To import the generated collection to your locally running Postman:
- In Postman, choose your workspace.
- Click Import.
- In the input field, provide a URL to the collection.json file that the app returns.
- If running locally, the URL is
http://localhost:3000/collection.json
. - If deployed publicly, the URL is
https://<domain>/collection.json
.
- If running locally, the URL is
- Press Enter.
If you need to adjust the logic behind processing the OpenAPI files and converting them to Postman collections, check the functions in collectionProcessing.ts
.
In the convertSpecToPostmanCollection
function, modify the parameters used for the conversion with openapi-to-postman.
kontent-ai-learn-oas-postman-converter/src/collectionProcessing.ts
Lines 340 to 370 in 8e4dac8
In the processCollection
function, specify how the Postman collection JSON should be modified.
kontent-ai-learn-oas-postman-converter/src/collectionProcessing.ts
Lines 293 to 338 in 8e4dac8
In themergeCollections
function, specify how the processed Postman collections should be merged. For example, this is where we're adding the manually created Postman collection for GraphQL API (see GRAPHQL_API_COLLECTION
) because GraphQL cannot be described using OpenAPI.
kontent-ai-learn-oas-postman-converter/src/collectionProcessing.ts
Lines 372 to 385 in 8e4dac8
The order of the API references in the Postman collection: Delivery GraphQL API is followed by the API references ordered as specified in the ApiReferenceFileNames
env variable.
Feel free to open a new issue where you describe your proposed changes or even create a new pull request from your branch with proposed changes.
All source code is published under the MIT licence.