Postman to Swagger not working for my collection

Hello Team,
I have been trying to use the Generic Collection used to convert postman collection to swagger 2.0
However the output seems to give me partial results

The following is mycollection

However the generated swagger is:

{
    "swagger": "2.0",
    "info": {
        "contact": {},
        "title": "GetUserIdentifier",
        "version": "1.0.0"
    },
    "host": "localhost",
    "basePath": "/",
    "schemes": [
        "http"
    ],
    "paths": {},
    "tags": [
        {
            "description": "Scenario Happy_1:\nIdentifier returned directly from IS\n\nScenario Happy_2:\nIdentifier missing in IS, retrieving data from GW and creating user in IS",
            "name": "HappyPath"
        },
        {
            "name": "UnhappyPath"
        },
        {
            "name": "TimoutPath"
        }
    ]
}

which is not the correct output.

Any pointers is appreciated
Thanks
Haider

1 Like

Hey @haiderali :waving_hand:

Welcome to the Postman Community! :postman:

Could you share which part of the platform you’re using the Generate Collection option, please?

Which version of Postman are you using there?

apologies for the late reply
The following is my postman version


and I am using the collection online to generate the swagger using collection id
Generate a Swagger Schema | Postman to Swagger (OAS 2) | Postman API Network

the following is the curl used overall

curl --location ‘https://api.getpostman.com/collections/1151586-9620d842-c048-4982-a896-7626648ebd44
–header ‘X-API-Key: PMAK-6632140f86af8b0001446530-xxxxxx’

Let me know if anything else is required
Thanks

Have you tried this endpoint on the Postman API to transform the Collection?

Hello Danny,
This is a step better by converting the different input as examples
However the data associated with parameters(query params are different in each request) is not found in swagger as part of examples and that data is lost
Also I was looking for a case to have it compatible to swagger 2.0 if its possible
Thanks again for the help
Regards
Haider

Can you confirm that you have a full request in there and not just a container with a only the request name?

I can’t see that from the original image.

1 Like

Hello Danny,
Yes we have the request in the folders that are present


However its not seen in swagger definition

And are they fully structured requests with URLs, Headers, Request Bodies, etc.

None of the requests in that image has examples, are you expecting to see those with the conversion?

I create a dummy Collection to mock out some of that data you have and run that through the same endpoint/script - I’m seeing the swagger data in the visualisation.

1 Like

This looks great Danny,
Maybe I might be missing something.
would it be ok for you to share both your collection and swagger output
and in the screenshot you are using the following url correct

https://api.getpostman.com/collections/:collectionId
and not the transformation api … correct
Thanks again for the prompt response and helpful suggestions
Regards
Haider

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"
        }
    ]
}
1 Like

Thanks @danny-dainton
can you help me with the initial collection you used as well to get the swagger