Skip to content

$ref to other OAS file does not quite work as expected #552

@cw112233

Description

@cw112233

Hi there!

I want to post a problem I've met when I use Portman to generate the multi-file OAS.
They are all defined under the same path, i.e.
├── A.yaml
├── B.yaml
├── C.yaml

Firstly, I have rootOAS A.yaml:

openapi: 3.1.0
...
paths:
  /a/b/{id}:
    summary: An Endpoint
    post:
      parameters:
        - in: path
          name: id
          schema:
            type: string
          required: true
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "./B.yaml#/components/schemas/action"

As you can see, the rootOAS refers to B schema

B.yaml

components:
  schemas:
    action:
      anyOf:
        - $ref: "C.yaml#/components/schemas/Cart"

Which internally refers to C Schmea
C.yaml

components:
  schemas:
    Cart:
      type: object
            allOf:     
              - properties:
                  id:
                    type: string

Then when I tried to generate collection with portman command feeding the rootOAS

portman -l ./A.yaml --cliOptionsFile ./portman/configs/portman-cli.json -o ./definitions/postman.json

I got error:

Portman config file not provided.
ResolverError: Error opening file "/Users/my.name/documents/tmp/converted/schemas/B.yaml" 
ENOENT: no such file or directory, open '/Users/my.name/documents/tmp/converted/schemas/B.yaml'

I saw someone posted a similar question, and the answer said Portman will de-reference before doing the converting, but here the problem is obvisouly the rootOAS A.yaml got convert Before dereferencing other OAS.

One workaround I've made it work is change the reference path from A to B:

$ref: "../../B.yaml#/components/schemas/action"

It works but not really seems to be correct to me.

Any help will be appreciated, thanks!

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions