-
Notifications
You must be signed in to change notification settings - Fork 9k
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
$ref for array example? #1967
Comments
Is it valid to use a As for the reference sort-of working but showing up as an object, that seems like a tooling issue, not a spec issue, so you should open that on the Swagger Editor repo. This repo is only for issues with the specification. |
Re:
Good question. I had—fuzzy thinking, I'll admit—assumed so. Especially because, except for arrays, it works in Swagger Editor. Rereading the spec (prompted by your comment; thank you), I suspect the answer is "no". The Swagger documentation topic "Adding Examples" (by SmartBear; not the OpenAPI spec) states that:
That documentation is consistent with the behavior of Swagger Editor 3.6.31 (the latest), which reports an error when I attempt to specify
Yet the OpenAPI 3.0.2 spec shows a property with properties:
name:
type: string
examples:
name:
$ref: http://example.org/petapi-examples/openapi.json#/components/examples/name-example As you say:
I'm going to think some more about this, but right now, I suspect what I'll need to do is ask the Swagger Editor (and UI?) developers to support I'd welcome your further thoughts on this. But I understand if you consider this to be a tooling issue, and not appropriate for further comment here. |
@GrahamHannington sorry for the lack of response, I've been focused on getting JSON Schema 2019-09 out the door. This is definitely something you should work out with the Swagger tooling folks. My focus is primarily JSON Schema (and |
@webron @MikeRalphson should this be closed as a tooling issue? |
To clarify - the OpenAPI only supports references in |
Is there any way to improve / extend the specification related to that? It would be nice to support references in
See also discussion in Swagger bugtracker. |
This is a pretty big rough edge if you can neither reference an array item, nor reference a non-array item as part of an array. |
I'm trying to use
$ref
to single-source example values for different response properties that have similar values.For example, from my OpenAPI 3.0.2 definition:
and the corresponding component:
This works. Swagger Editor shows the example response as:
All good. Although, it took me several attempts to figure out the correct combination of nested YAML object names and
$ref
path; some "examples of example components" in the OpenAPI spec would help here.But I can't get something similar to work for arrays.
The following definition:
with this component:
causes Swagger Editor to display the following example response:
which is not what I want; not an array.
To get the desired example response for an array, it seems I can't use
$ref
; I have to code the example inline in the definition:Am I missing something? Am I doing something wrong? Is there an elegant way to use
$ref
to supply an example value for an array?Finally, in case you're wondering, this:
gives this example response:
(yes, the literal "
$ref
" and its path)The text was updated successfully, but these errors were encountered: