Hey @haiderali
I’m using the same request from the Collection that you were originally using.
The URL is only getting the Collection using the Postman API, the actual code that changes the Collection into a Swagger 2.0 schema is in the Post-response script.
This is making an external async request out to a hosted service and then using the visualizer to present the new schema data.
const res = pm.response.json();
const collection = JSON.stringify(res.collection);
const makeVisualizerTemplate = (swagger, errors, warnings) => `Swagger:<br> <textarea style="width: 100vw; height: 100vh; font-family: monospace;">${JSON.stringify(swagger)}</textarea><br>
Errors:<br><textarea style="width: 100vw; height: 100vh; font-family: monospace;">${JSON.stringify(errors)}</textarea><br>
Warnings:<br><textarea style="width: 100vw; height: 100vh; font-family: monospace;">${JSON.stringify(warnings)}</textarea>`;
pm.sendRequest({
url: `https://demo.postmansolutions.com/postman2swagger`,
method: 'POST',
header: 'Content-Type:application/json',
body: {
mode: 'raw',
raw: collection
}
}, (err, res) => {
const payload = JSON.parse(res.text());
const visualizerTemplate = makeVisualizerTemplate(payload.swagger, payload.errors, payload.warnings);
pm.visualizer.set(visualizerTemplate);
});
My dummy Collection produced a response like this:
{
"swagger": "2.0",
"info": {
"contact": {},
"title": "GetUserIdentifier",
"version": "1.0.0"
},
"host": "postman-echo.com",
"basePath": "/",
"schemes": [
"https"
],
"paths": {
"/get": {
"get": {
"produces": [
"application/json"
],
"parameters": [],
"responses": {
"200": {
"description": "Timeout_1",
"headers": {
"Connection": {
"type": "string"
},
"Content-Length": {
"type": "string"
},
"Date": {
"type": "string"
},
"ETag": {
"type": "string"
},
"Server": {
"type": "string"
},
"set-cookie": {
"type": "string"
}
},
"schema": {
"properties": {
"args": {
"properties": {},
"type": "object"
},
"headers": {
"properties": {
"host": {
"example": "postman-echo.com",
"type": "string"
},
"accept": {
"example": "*/*",
"type": "string"
},
"accept-encoding": {
"example": "gzip, deflate, br",
"type": "string"
},
"connection": {
"example": "close",
"type": "string"
},
"cookie": {
"example": "sails.sid=s%3AQVT6X6_JJwYj-d54FBXuhrdkMvKtVVQv.odvdrp5reLK%2FUldh8PwlJsQUxZ5OnAjmwRtaTr5%2B8XU",
"type": "string"
},
"user-agent": {
"example": "PostmanRuntime/7.43.3",
"type": "string"
},
"x-amzn-trace-id": {
"example": "Root=1-67f527e5-1673e408126622ef545b6c98",
"type": "string"
},
"x-forwarded-port": {
"example": "443",
"type": "string"
},
"x-forwarded-proto": {
"example": "https",
"type": "string"
},
"x-request-start": {
"example": "t1744119781.863",
"type": "string"
}
},
"type": "object"
},
"url": {
"example": "https://postman-echo.com/get",
"type": "string"
}
},
"type": "object"
}
}
},
"tags": [
"Timeout Path"
],
"description": "Timeout_1",
"operationId": "timeout1",
"summary": "Timeout_1"
}
},
"/post": {
"post": {
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"properties": {
"test": {
"example": 1234,
"type": "number"
}
},
"type": "object"
}
}
],
"responses": {
"200": {
"description": "Happy_1",
"headers": {
"Connection": {
"type": "string"
},
"Content-Length": {
"type": "string"
},
"Date": {
"type": "string"
},
"ETag": {
"type": "string"
},
"Server": {
"type": "string"
}
},
"schema": {
"properties": {
"args": {
"properties": {},
"type": "object"
},
"data": {
"properties": {
"test": {
"example": 1234,
"type": "number"
}
},
"type": "object"
},
"files": {
"properties": {},
"type": "object"
},
"form": {
"properties": {},
"type": "object"
},
"headers": {
"properties": {
"host": {
"example": "postman-echo.com",
"type": "string"
},
"accept": {
"example": "*/*",
"type": "string"
},
"accept-encoding": {
"example": "gzip, deflate, br",
"type": "string"
},
"cache-control": {
"example": "no-cache",
"type": "string"
},
"connection": {
"example": "close",
"type": "string"
},
"content-length": {
"example": "20",
"type": "string"
},
"content-type": {
"example": "application/json",
"type": "string"
},
"cookie": {
"example": "sails.sid=s%3AqvAFENI_HPeQa6VisYqvDmbPQb3JoQlE.9CAlnfEe9moPNYOJyplfcVNeaFqlMccG9eItOVFVdE0",
"type": "string"
},
"postman-token": {
"example": "1ba12b52-aa93-4537-8a94-5e5f213d31b1",
"type": "string"
},
"user-agent": {
"example": "PostmanRuntime/7.43.3",
"type": "string"
},
"x-amzn-trace-id": {
"example": "Root=1-67f62fa9-7420aeb307cd4c5b5d7a51c4",
"type": "string"
},
"x-forwarded-port": {
"example": "443",
"type": "string"
},
"x-forwarded-proto": {
"example": "https",
"type": "string"
},
"x-request-start": {
"example": "t1744187305.652",
"type": "string"
}
},
"type": "object"
},
"json": {
"properties": {
"test": {
"example": 1234,
"type": "number"
}
},
"type": "object"
},
"url": {
"example": "https://postman-echo.com/post",
"type": "string"
}
},
"type": "object"
}
}
},
"tags": [
"Happy Path"
],
"description": "Happy_1",
"operationId": "happy1",
"summary": "Happy_1"
}
}
},
"tags": [
{
"name": "Happy Path"
},
{
"name": "Unhappy Path"
},
{
"name": "Timeout Path"
}
]
}