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

Unable to reference other local json file #175

Open
mattias-persson opened this issue Dec 29, 2022 · 2 comments
Open

Unable to reference other local json file #175

mattias-persson opened this issue Dec 29, 2022 · 2 comments

Comments

@mattias-persson
Copy link

Hi!

I'm trying to build an OAPI definition where I split shared data into separate files. I'm only using json format as of now. One example would be doing something like this:

{
  "openapi": "3.0.0",
  "info": {
    "title": "My API",
    "version": "1, 2"
  },
  "paths": {
    "/v1/users/profile": {
      "get": {
        "operationId": "V1GetUserProfile",
        "summary": "Returns the user profile",
        "responses": {
          "401": {
            "$ref": "./401.json"
          }
        }
      }
    }
  }
}

and the 401 file would contain the actual details:

"description": "401 response",
"content": {
  "application/json": {
    "schema": {
      "properties": {
        "message": {
          "type": "string"
        }
      },
      "required": [
        "message"
      ]
    },
    "example": {
      "message": "Unauthenticated."
    }
  }
}

When attempting to do this, it seems this package formats the URI to become file://401.json. This causes the parser to fail. The stack trace looks like this:

cebe\openapi\exceptions\UnresolvableReferenceException : Failed to resolve Reference './401.json' to cebe\openapi\spec\Response Object: file_get_contents(file:///401.json): Failed to open stream: No such file or directory
 vendor/cebe/php-openapi/src/spec/Reference.php:220
 vendor/cebe/php-openapi/src/spec/Responses.php:244
 vendor/cebe/php-openapi/src/SpecBaseObject.php:410
 vendor/cebe/php-openapi/src/SpecBaseObject.php:410
 vendor/cebe/php-openapi/src/spec/PathItem.php:200

I'm on a Mac. Any ideas?

@tomasbreffitt
Copy link

Having the same issue here

@Aribros
Copy link

Aribros commented Sep 15, 2023

Did you try

 "401": {
    "$ref": "401.json"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants