Skip to content

Should x-* references be parsed? #100

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

Closed
amnuts opened this issue Feb 1, 2021 · 3 comments · Fixed by #113
Closed

Should x-* references be parsed? #100

amnuts opened this issue Feb 1, 2021 · 3 comments · Fixed by #113
Labels
bug Something isn't working help wanted Extra attention is needed
Milestone

Comments

@amnuts
Copy link

amnuts commented Feb 1, 2021

I'm using x-* extensions in a number of places and wanted to split up my OAS doc over multiple files. If I have a x-subscription content inline in the main file at root level, like this:

    "x-subscriptions": [
        {
            "on": "some.event",
            "do": [
                {
                    //...
                }
            ]
        }

Then after I do $specs = Reader::readFromJsonFile(realpath($specPath)); I can access the subscriptions, eg var_dump($spec->{'x-subscriptions'}); gives me:

array(1) {
  [0]=>
  array(2) {
    ["on"]=>
    string(32) "some.event"
    ["do"]=>
    array(1) {
        ...

But if I have:

    "x-subscriptions": {
        "$ref": "./x-subscriptions/some-event.json"
    },

with the full array moved to another file, the same $spec calls returns:

array(1) {
  ["$ref"]=>
  string(46) "./x-subscriptions/some-event.json"
}

I've tried a variety of ways (using 'allOf', having the array be in the root and reference individual events, etc.) but the reference doesn't resolve.

So I guess my question is; should it?

Thanks!

@cebe
Copy link
Owner

cebe commented Feb 16, 2021

have you called resolveReferences() method on the base object after reading the file?

@cebe cebe added the needs more info More information is needed to reproduce the issue. label Feb 16, 2021
@eric-pfi
Copy link

eric-pfi commented May 9, 2021

I'm having a similar issue. If I define a path that contains an x-* attribute without using a reference then:

$spec->paths['path']->{'x-*'}

contains the value of the x-* attribute. However, if the path only contains:

$ref: 'filename.yaml'

where filename.yaml has the x-attribute defined, then:

$spec->paths['path']->{'x-*'}

throws the exception: Exception: Getting unknown property: cebe\openapi\spec\PathItem::x-*

I've worked around it for the moment in an odd way, if I define the path so that the x-* attribute is in the paths spec, followed by the $ref attribute, then I'm able to access the x-* property as expected. More specifically this works:

paths:
  'path':
    x-*: 'value'
    $ref: 'filename.yaml'


and this doesn't:

paths:
  'path':
    $ref: 'filename.yaml'  # where x-* is a root element of filename.yaml

I'm unsure if this is clear enough, and if it is the same issue. If you need a working example, I can probably put it together.

cebe added a commit that referenced this issue May 24, 2021
@cebe cebe added bug Something isn't working help wanted Extra attention is needed and removed needs more info More information is needed to reproduce the issue. labels May 24, 2021
@cebe cebe added this to the 1.5.3 milestone May 24, 2021
@cebe
Copy link
Owner

cebe commented May 24, 2021

Reproduced, added a failing test case in #111. If someone wants to dig into fixing this, I'd be happy to merge a fix. Have no time to fix it myself right now.

@cebe cebe closed this as completed in #113 May 26, 2021
@cebe cebe modified the milestones: 1.5.3, 1.6.0 Feb 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants