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

Need a way to express contextual examples with $refs #71

Open
cmars opened this issue Nov 18, 2021 · 2 comments
Open

Need a way to express contextual examples with $refs #71

cmars opened this issue Nov 18, 2021 · 2 comments

Comments

@cmars
Copy link
Contributor

cmars commented Nov 18, 2021

OpenAPI has a fundamental limitation with examples and $refs. You can put examples in referenced types, but if that type is something really generic like a JSON API link or our stripped-down relationship type, the example isn't going to be very relevant to the resource that you're reading about.

OpenAPI 3.1.0 took a step in the right direction, allowing summary: and description: to be used with $ref:.

Proposal: x-snyk-ref-example

Until OpenAPI catches up, proposing an extension x-snyk-ref-example that provides this capability. An extension is used so that it is clear and explicit that this is not yet standard OpenAPI behavior. It also gives us a clear way to ignore or adapt OpenAPI lint rules that might otherwise fail on it.

Example:

type: object
properties:
  links:
    $ref: "#/components/schemas/Links"
    x-snyk-ref-example:
      self:
        href: /what/an/actual/path/to/one/of/these/looks/like
@cmars
Copy link
Contributor Author

cmars commented Dec 6, 2021

A better alternative to consider is requiring sub-typed links to be used in resources, which would then have actually-relevant examples. Then we don't need a custom extension.

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

No branches or pull requests

1 participant