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

OAS: External references in path items are broken #3030

Open
ben-lc opened this issue Jan 24, 2025 · 5 comments
Open

OAS: External references in path items are broken #3030

ben-lc opened this issue Jan 24, 2025 · 5 comments

Comments

@ben-lc
Copy link

ben-lc commented Jan 24, 2025

Expected Behavior

An external reference can be used on a path item with $ref key as specified in openapi 2+ specs :
Allows for a referenced definition of this path item. The referenced structure MUST be in the form of a Path Item Object. In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined. See the rules for resolving Relative References.
Adding an external reference should throw no error if it references a valid path item and should be handled by apicurio dereferencer.

Actual Behavior

In source mode an issue is thrown Path Item Reference must refer to a valid Path Item Definition . When preview or export with dereferencement is done an error is thrown.

Steps to Reproduce the Problem

  1. open an openapi spec
  2. in source mode add for example
paths:
    /stuffs:
        $ref: >-
            https://raw.githubusercontent.com/Apicurio/apicurio-data-models/refs/heads/1.x/src/test/resources/fixtures/dereference/oai3/domino-issue-1366.expected.json#/paths/~1addresslookup

  1. save the doc
  2. try to preview the spec

Specifications

  • apicurio studio: 0.2.62.Final
  • apicurio data models: 1.1.30

Cause

The referenced path item node can't be fetched because / must be unescaped from ~1 to get correct path item key . (see Apicurio/apicurio-data-models#858).

The second error during dereference is because the Dereferencer class in apicurio-data-models doesn't implement path item case. It tries to add the referenced node into components and then change originel external ref to an internal one. But path items can't be defined in components. The referenced node is supposed to be "merged" according the spec.

Proposed fix

I can write a PR to fix the second issue. I propose to do a simple non recursive merge of the external path item properties into the internal one and ignore external path item properties if they are already defined in internal path item (since spec says In case a Path Item Object field appears both in the defined object and the referenced object, the behavior is undefined).

@ben-lc
Copy link
Author

ben-lc commented Jan 27, 2025

I created #3031 to fix a bug in uri creation when a path item references a path containing templates.

I created Apicurio/apicurio-data-models#859 in apicurio-data-models to update the Dereferencer in order to deal with path item ref as explained in the proposed fix.

Wdyt @EricWittmann

@EricWittmann
Copy link
Member

I agree with your approach here. The local properties should take precedent over the remote properties, for sure. +1

Also this was a big miss in our dereferencing support in data-models, so thanks for catching this and contributing a fix. I'll need to forward-port your data-models work to v2, unless you feel motivated to do that yourself. :)

EricWittmann pushed a commit to Apicurio/apicurio-data-models that referenced this issue Jan 28, 2025
* fix: unescape json references special chars

Characters '/' and '~' are escaped with respectively '~1' and '~0' cf: https://swagger.io/docs/specification/v3_0/using-ref/ and must be unescaped accordingly.

* fix: handle dereference of path items

see Apicurio/apicurio-studio#3030

---------

Co-authored-by: Benjamin Ledentec <[email protected]>
@EricWittmann
Copy link
Member

Oh I see now that we haven't migrated the dereferencing functionality from v1 to v2 yet, so no need to forward-port the PathItem work you've done.

@EricWittmann
Copy link
Member

I'm releasing data-models 1.1.31 now.

@ben-lc
Copy link
Author

ben-lc commented Jan 29, 2025

Great thanks.

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

2 participants