Postman to openapi
Use when asked to convert a Postman collection export (collection.json) into an OpenAPI YAML spec, or to update/sync an existing openapi.yaml so it matches a newer Postman collection. Triggers on "postman to openapi", ".postman_collection.json", "update openapi.yaml from postman", "sync swagger with postman".From its SKILL.md
npx -y skills add Alonza0314/agent-skills --skill postman-to-openapiAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
6.2 KB, as published. Nobody here has run it
Postman to OpenAPI
Overview
Merges the requests recorded in a Postman Collection v2.1 export into an OpenAPI 3.x YAML file. This is a merge into existing hand-authored YAML, not a blind regenerate — an existing openapi.yaml usually has curated operationIds, shared components/schemas, and descriptions that a naive converter would clobber or duplicate. The mechanical parts (walking folders, listing requests, diffing response bodies) are scripted; deciding operationIds, schema names/reuse, and path parameters is a judgment call you make.
When to Use
- User gives you a Postman JSON path and an OpenAPI YAML path and asks to convert/update.
- Only one file is given: ask for the other (both a Postman collection AND a target OpenAPI file are required inputs — this skill updates an existing spec, it does not scaffold one from nothing beyond
openapi.yaml's minimal skeleton if the file doesn't exist yet).
Process
-
Extract mechanically. Run
scripts/extract_requests.py <postman.json>to get a flat JSON list of every leaf request: tag (top folder name), Postman item name, method, path segments, request body, and every recorded response (code + path segments + body). Postman folders map to OpenAPI tags; nested sub-folders are flattened to the top-level folder name. -
Read the existing OpenAPI file (or start from a minimal skeleton —
openapi: 3.0.3,info, emptypaths/components/schemas— if it doesn't exist). Note what's already there: existing paths, existing schema names, existingsecurity/securitySchemes. -
Detect path parameters. A request's own
path_segmentsis one example; itsresponses[].path_segmentsare more examples of the same endpoint recorded at different times. If a segment's value varies across these examples (e.g.server,1,iphoneall appear in the same slot), that segment is a path parameter — replace it with{name}(pick a name from the resource/context, e.g. singular of the tag, or read the backend's own error messages in response bodies for a hint like"category iphone not found"→ the segment is a category name). If a segment is constant across every example, it's a literal path segment. -
Decide operationId and summary. Prefer the Postman item name (
Login→login,GetAll→listCategories). Postman collections often have lazy/generic names likeNew RequestorCopy of Get— when the name isn't usable, derive one from method + resource (DELETE /api/category/{name}→deleteCategory). -
Build/reuse schemas.
- For each distinct response body shape (grouped by status code across the endpoints), check whether an existing
components/schemasentry already matches that shape — reuse it via$refrather than duplicating (e.g. a generic{"message": string}body should reuse a sharedMessageResponse-style schema if one already exists in the target file). - For genuinely new shapes, add a new schema named
<Operation><Request|Response>(e.g.CategoryCreateRequest) and infer types from the example JSON values ("id": 1→integer, strings →string). Nested arrays of objects become their own named schema (e.g.categories: Category[]) so the item shape can be reused across list/detail endpoints. - Nest under the right response code (2xx from the success example(s), plus every documented error code with its own example body).
- For each distinct response body shape (grouped by status code across the endpoints), check whether an existing
-
Infer auth requirements from Postman scripts, not just the request headers. Check the collection's collection-level
event(prerequest) and per-itemeventscripts — a script that adds anAuthorization: Bearer <token>header to every request except one (commonly the login request) means every other endpoint requires auth even though the rawrequest.headerarray is empty (Postman injects it at runtime, so the exported JSON won't show it as a static header). Add abearerAuth(or matching) entry undercomponents/securitySchemesif missing, and applysecurity: [{bearerAuth: []}]to the affected operations, leaving the login/public operations without it. -
Write the merged result with the Edit tool, preserving formatting/ordering conventions already used in the file (e.g. blank line between path items, schema property ordering). Don't reformat parts of the file you didn't need to touch.
-
Validate: parse the resulting YAML (
python3 -c "import yaml; yaml.safe_load(open('openapi.yaml'))") to confirm it's syntactically valid before considering the task done.
Quick Reference: Postman → OpenAPI mapping
| Postman | OpenAPI |
|---|---|
| Top-level folder | tags on each operation in that folder |
request.method + url.path | HTTP method + paths.<path> |
| Path segment that varies across recorded examples | {param} path parameter |
request.body.raw (mode raw, language json) | requestBody.content.application/json.schema |
response[].body per status code | responses.<code>.content.application/json.schema (+ example) |
Collection/folder/item prerequest script adding a header | security + components.securitySchemes |
Collection variable (e.g. {{BACKEND_URL}}) | servers — only if it has a concrete non-empty value; skip if blank/templated |
Common Mistakes
- Regenerating the whole file instead of merging. Always read the existing spec first; reuse its schema names and conventions.
- Missing auth. The exported JSON's
request.headeris often empty even for authenticated endpoints because Postman adds auth headers via a pre-request script at runtime, not as a static header. Always checkevent[].scriptat the collection and item level. - Treating every path segment as literal. Compare a request's segments against all of its own response examples' segments before deciding a segment is fixed.
- Duplicating a schema that already exists (e.g. adding a second
{message: string}schema instead of reusing the existingMessageResponse).