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

Add support for $ref in API definitions #39

Open
line-o opened this issue Oct 28, 2021 · 6 comments
Open

Add support for $ref in API definitions #39

line-o opened this issue Oct 28, 2021 · 6 comments
Assignees
Labels
enhancement New feature or request OAS-spec This has to do with the OAS specification compliance

Comments

@line-o
Copy link
Member

line-o commented Oct 28, 2021

Given an API definition that includes the following user schema in components

"components": {
  "schemas": {
    "user": {
      "properties": {
        "id": { "type": "integer" },
        "name": { "type": "string" }
      }
    }
  }
}

The above user schema must be referencable by "$ref": "#/components/schemas/user" like in the response definition below:

"responses": {
  "200": {
    "description": "The response",
    "schema": {
      "$ref": "#/components/schemas/user" 
    }
  }
}

Components spec: https://oai.github.io/Documentation/specification-components.html

At least, following objects must be supported, as they tend to greatly reduce the size of the definition JSON

  • schemas
  • responses
  • requestBodies
  • examples

Due to their nature of being used very frequently, these should also be included:

  • parameters
  • headers
  • pathItems

The full list of objects that can be referenced can be found here https://spec.openapis.org/oas/v3.1.0#components-object

Do we want to allow refs from other or even external documents?

@line-o line-o added the enhancement New feature or request label Oct 28, 2021
@line-o line-o self-assigned this Aug 19, 2022
@line-o line-o added the OAS-spec This has to do with the OAS specification compliance label Aug 25, 2022
@cwittern
Copy link

cwittern commented Dec 1, 2022

Any progress on this issue?

@line-o
Copy link
Member Author

line-o commented Dec 1, 2022

@cwittern this is the number one item on our backlog (see https://github.com/orgs/eeditiones/projects/2).
When time allows this is the first thing to work on.

@line-o
Copy link
Member Author

line-o commented Dec 1, 2022

There is however a possibility to preprocess an API definition with refs see https://faq.teipublisher.com/api/designingopenapi/

@line-o
Copy link
Member Author

line-o commented Dec 1, 2022

The steps in short are

  • npm install -g swagger-cli
  • swagger-cli bundle --dereference -o api-with-inlined-references.json api-with-references.json

@cwittern
Copy link

cwittern commented Dec 1, 2022

Thanks, yes, that's an easy way out.

@line-o
Copy link
Member Author

line-o commented Feb 6, 2024

There is a new module out that can not only validate your API definition but also resolve references.
It's called oad

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request OAS-spec This has to do with the OAS specification compliance
Projects
None yet
Development

No branches or pull requests

2 participants