Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cw112233 opened this issue Jan 24, 2024 · 4 comments
Open

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

cw112233 opened this issue Jan 24, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@cw112233
Copy link

cw112233 commented Jan 24, 2024

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!

@cw112233 cw112233 changed the title $ref does not quite work as expected $ref to other OAS file does not quite work as expected Jan 24, 2024
@thim81
Copy link
Collaborator

thim81 commented Feb 2, 2024

hi @cw112233

We will have to replicate the 3 references to see where de-reference goes wrong. It is a bit strange that Portman is looking for the referenced file in the "tmp" folder.

@andreicherechesbyx
Copy link

@thim81 I'm having the same problem, any clues on what might be causing this?

@thim81
Copy link
Collaborator

thim81 commented Mar 3, 2024

@andreicherechesbyx We briefly looked into to it, but we have not yet found any indication of the strange behaviour.

We have the info to be able to replicate it, we just need to find time to further dive in.

@thim81
Copy link
Collaborator

thim81 commented Sep 27, 2024

hi @andreicherechesbyx & @cw112233

We just release v1.30.3, which has improvements for handling $ref in multiple files.
Can you give the latest version a spin and see if it overcomes the reported issues?

@thim81 thim81 added the question Further information is requested label Sep 27, 2024
@thim81 thim81 self-assigned this Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants