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

Is there a way to make the $ref even more reusable with placeholders? #1749

Closed
elfin-sbreuers opened this issue Nov 13, 2018 · 5 comments
Closed
Labels
Needs author feedback No recent activity The issue has not been updated in 7 days. re-use: traits/merges Selective or modified re-use
Milestone

Comments

@elfin-sbreuers
Copy link

My use case is the following:

I have several schema definitions. The API should return these definitions always wrapped in a certain structure. So my idea would be to have something like this:

paths:
  /path
     responses:
       '200':
          content:
            application/json:
              schema:
                $ref:
                  scaffold: '#/components/schemas/dataContainer'
                  placeholders:
                     data: '#/components/schemas/pet'
components:
  schemas:
    dataContainer:
       type: object
       properties:
         data:
           type: placeholder
           name: data

    pet:
      type: object
      properties:
         arbitrary:
            type: string

Searching for placeholder, nested $ref, DRY, and similar variations did not lead me to satisfying solution. I found the allOf keyword but this forces me to rebuild the structure that should be provided by the scaffold.

There is also something comparable for the servers key with url and variables.

Is something comparable possible to reuse schema scaffolds?

If not I would rephrase this issue as feature request.

@darrelmiller
Copy link
Member

This has been a fairly common request over the years. Sometimes it is described as an envelope or wrapper for the internal data. The issue is more of a schema related issue. If you can find a schema language that supports this concept then you may be able to use that using with the proposed alternative schema feature.

From an API design perspective, I often find that envelopes around data are just duplicating what HTTP headers can already do.

@handrews
Copy link
Member

https://github.com/json-schema-org/json-schema-spec/issues/322 is the JSON Schema issue closest to this. It has not really found a champion, and it does open up considerable amounts of complexity. But we haven't rejected it either. It definitely won't go into draft-08, which is now wrapping up, but could possibly get into a future draft if someone can advocate for it successfully.

I'm personally a bit skeptical as I've been down this road of essentially implementing function calls in what was supposed to be a declarative system before, and it was mostly a sign that the original solution was being re-purposed in a way that didn't really fit, but feel free to comment on the issue :-)

@kscheirer
Copy link

This issue has been listed as a possible use case for Overlays. I don't think it would help here though - you could have overlays replace a value in the contract, but the replacement value would be fixed/static in the overlay, it would not be able to dynamically merge to elements.

@handrews
Copy link
Member

Do $dynamicAnchor and $dynamicRef (available in OAS 3.1) help here? They allow you to reference something that is determined at runtime. Sadly they're a bit confusing- json-schema-org/json-schema-spec#1140 has a proposal for simplifying them.

@github-actions github-actions bot added the No recent activity The issue has not been updated in 7 days. label Feb 4, 2024
Copy link
Contributor

github-actions bot commented Feb 4, 2024

This issue has been labeled with No recent activity because there has been no recent activity. It will be closed if no further activity occurs within 28 days. Please re-open this issue or open a new one after this delay if you need to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs author feedback No recent activity The issue has not been updated in 7 days. re-use: traits/merges Selective or modified re-use
Projects
None yet
Development

No branches or pull requests

4 participants