Forum Discussion

Stoplight's avatar
Stoplight
Community Manager
10 months ago

Reference parameters/components from another OpenAPI json (same project)

Originally posted by user Luca P. to the Stoplight Community on 05/18/2023 at 13:18 ET.

I have multiple OpenAPI JSON files in the same project, let's call them A.json and B.json. In A there are a few parameters defined in #/components/parameters. I've just found out, while editing in "Form" mode the parameters of an API in B, that the picker allows to select A's parameters (selecting "This project" in the dropdown), with an extended reference as ./A.json#/components/parameters/my_parameter.

First question: is this an intended behavior?

Second: I tried the same trick with models and responses, but both pickers don't show any definitions from A ("This project" is selected). But, switching from "Form" to "Code" mode, and entering manually the exact $ref path (e.g. ./A.json#/components/schemas/my_model), everything seems to work without issues.

In general, are cross-file references allowed?

  • Stoplight's avatar
    Stoplight
    Community Manager

    a_welch (Staff) [05/18/2023 - 17:11 ET]

    Hey I am looking into this one fore you. I can tell you, for your second question, cross-file references are allowed but they are not a good practice. I will let you know when I have some additional info on your first question.

    • Stoplight's avatar
      Stoplight
      Community Manager

      Luca P. (OP) [05/18/2023 - 17:18 ET]

      Thank you ! I can see why it's not a good practice, but in my case A.json and B.json refer to different web-apps, with B web-app (public) acting as a transparent proxy for select APIs of A web-app (private). So being able to reference in B.json params/responses/models of A.json would really help.