openapi-to-postman icon indicating copy to clipboard operation
openapi-to-postman copied to clipboard

Package doens't resolve $ref for relative paths

Open henriqueleite42 opened this issue 2 years ago • 2 comments

I have the following section in my openapi.yaml:

paths:
  /auth/google:
    $ref: "./paths/auth/google.yaml"

./paths/auth/google.yaml file content:

post:
  tags:
    - Auth
  summary: Sign In/Up with Google
  description: |
    Sign Ins or Sign Ups a user using a google account
  operationId: auth-google
  requestBody:
    content:
      application/json:
        schema:
          $ref: "../../components/schemas/auth-with-3rd-party.yaml"
    required: true
  responses:
    $ref: "../../components/responses/auth.yaml"

But the json output is (just a section of it, not the entire file):

{
    "item": [
        {
            "name": "auth",
            "description": "",
            "item": []
        },
    ]
}

So the CLI isn't being able to import the content of ./paths/auth/google.yaml, and it should be.

Extra information:

  • My openapi.yaml is inside an openapi folder (so the complete path is ./openapi/openapi.yaml)
  • I'm running the command openapi2postmanv2 -s openapi/openapi.yaml -o postman.json -p through a package.json script

henriqueleite42 avatar Nov 30 '23 00:11 henriqueleite42

I have the same issue. For now, I am working around it by using redocly which is able to 'bundle' (i.e. flatten everything) into one file. So I flatten it using redocly-cli, which reads in and resolves all the $refs to other files, then I use openapi2postmanv2.

Something like this in my package.json. Hope it's useful :) { "scripts": { "flatten": "redocly bundle my-openapi-spec.yaml -o flattened-spec.yml", "generate-postman": "npm run flatten && openapi2postmanv2 -s flattened-spec.yml -o collection.json -p -O folderStrategy=Tags" }, "devDependencies": { "openapi-to-postmanv2": "4.15.0", "@redocly/cli": "^1.11.0" }

dom-bjss avatar Apr 08 '24 14:04 dom-bjss

Thanks @dom-bjss, I'm actually doing the same thing for now hahaha

But would be very helpful if they fixed this issue, so we don't have to bundle to generate the collection.

henriqueleite42 avatar Apr 10 '24 00:04 henriqueleite42