-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Properties with "$ref" and "description" cause warnings in editor #1184
Comments
Unfortunately, you just can't add anything to $refs. The JSON Reference spec is very clear, saying that anything added to it will be ignored. We're working on a major update which will affect both the UI and the editor. In the UI - you will no longer see the descriptions. In the editor, warnings will appear only in the gutter, but will not appear under Errors section in the editor. |
Please confirm this (rephrased): are you saying that my YAML above is, by design, illegal, and that those description fields should be moved to definitions that their $refs point to, and that swagger-ui should be adjusted to look for those values there instead of where I defined it? What about those 2 example JSON snippets that I copied over from http://json-schema.org/example1.html (bottom of that page)? They are clearly showing examples of |
In JSON Schema, |
@hlubovac - When it comes to technical subtleties, it's not illegal. You can write whatever you want alongside a $ref - they will just be ignored (so not the behavior you'd expect). The example in JSON Schema's website is just misleading. It's not an error, but processors will ignore it. The text can still be read by any person actually reading the schema itself. |
I see. Thank you. I noticed that @fehguy is involved in swagger-ui project. You two indirectly stated that swagger-ui is the one that incorrectly processes that |
@hlubovac - I've mentioned in the first comment that this is going to change in swagger-ui. |
that darn @fehguy |
@webron - sorry, I misinterpreted that somehow. Thank you very much. |
I'm new to Swagger and have run into this issue as well. After the update, will the UI display descriptions from referenced definitions? Or will it simply become impossible to display a description for any property that is defined by $ref? |
If you define it in the object you reference, it will be displayed. If at the same level of the $ref, it will be ignored. |
Just to mention that new editor defines "Sibling values are not allowed alongside a $ref." as a Semantic Error as the previous one defined it as a Warning. Is there a reason for that ? I can't figure out why put a comment for a $ref induces a semantic error ? |
@Cooker-Monster it's a bug. it should be a warning. |
Ok, fine. |
@Cooker-Monster would you mind filing a ticket on that? |
Hi, I came across the same issue more than once and, IMHO, this is a quite relevant limitation in current implementation (I'm not an expert... so I dont know whether it depends on some constraints in the OpenAPI specs or in the Swagger-ui/editor...). In my experience the scenario @hlubovac depicted in his original post is quite common... I'd like/need often to obtain something similar to what in picture below: As you can see, in this case I need to provide a "general description" for the array of strings listing the set of possible values a property can take, and a "context-spceific" description for the attribute of the specific class of object (a "device", in the example) referring to the array. The purposes of the two descriptions are very different:
If I've well understood, this is something we cannot achieve now and is not in any future plan. Bye. |
@naldino74 - again, this is a limitation of the spec, not the tool. We can't make this work in the editor without making changes in the spec. There are related tickets on it on the spec's repo. If you'd like to see it changed, you should voice your opinion there. |
Issue in OpenAPI spec repo OAI/OpenAPI-Specification#1514 |
@webron The spec guys don't want to collaborate. Can we ignore the spec in this particular case and allow descriptions alongside $refs? |
@otto-gebb I'm actually one of those 'spec guys', but regardless, no - we can't ignore the spec in this particular case. |
YAML anchors can be used to achieve this (Swagger 2). Example: definitions:
country: &country
type: string
enum: [UK, DE, PL, UNKNOWN]
default: UNKNOWN
parameters:
country:
name: country
in: query
description: Country
<<: *country More info in the Swagger documentation for enums |
@rafenden In OpenAPI 3.0 your example can be written without YAML anchors: components:
schemas:
country:
type: string
enum: [UK, DE, PL, UNKNOWN]
default: UNKNOWN
parameters:
country:
name: country
in: query
description: Country
schema:
$ref: '#/components/schemas/country' There's also the some_property:
description: My custom description
allOf:
- $ref: '#/components/schemas/Something' |
Is @hkosova's allOf workaround above safe to use? Or will it just depend on the particular tool used to process the spec? ...Badly needing to solve the use case of having $ref "siblings"... |
@mindstretch23 AFAIK, this should work in any tool that is properly(!) implementing the OpenAPI Specification. |
For me the error occurred when using incorrectly the required attribute. Note that required is an object-level attribute, not a property attribute: type: object
properties:
id:
type: integer
required: true **# Wrong!**
required: **# Correct**
- id |
Hi @hkosova, sorry for digging up an old thread, but for the first suggestion you made in this comment, is it possible to define |
…rsion only - swagger-cli was validating the schemas, bundling and validating the bundle without any warning - SwaggerUI was showing the API as invalid with these messages: "attribute components.schemas.tileSetMetadata.items is missing" - A $ref fully replaces sibling properties and should always be used alone: "Any members other than "$ref" in a JSON Reference object SHALL be ignored." https://datatracker.ietf.org/doc/html/draft-pbryan-zyp-json-ref-03#section-3 - See also: https://stackoverflow.com/questions/33565090/json-schema-property-description-and-ref-usage OAI/OpenAPI-Specification#556 OAI/OpenAPI-Specification#1514 swagger-api/swagger-editor#1184 - NOTE: We may need to update the 2DTMS schemas as well with this in mind
- A $ref fully replaces sibling properties and should always be used alone: "Any members other than "$ref" in a JSON Reference object SHALL be ignored." https://datatracker.ietf.org/doc/html/draft-pbryan-zyp-json-ref-03#section-3 - See also: https://stackoverflow.com/questions/33565090/json-schema-property-description-and-ref-usage OAI/OpenAPI-Specification#556 OAI/OpenAPI-Specification#1514 swagger-api/swagger-editor#1184 - NOTE: We may need to update the 2DTMS schemas as well with these changes
- A $ref fully replaces sibling properties and should always be used alone: "Any members other than "$ref" in a JSON Reference object SHALL be ignored." https://datatracker.ietf.org/doc/html/draft-pbryan-zyp-json-ref-03#section-3 - See also: https://stackoverflow.com/questions/33565090/json-schema-property-description-and-ref-usage OAI/OpenAPI-Specification#556 OAI/OpenAPI-Specification#1514 swagger-api/swagger-editor#1184 - NOTE: We may need to update the 2DTMS schemas as well with these changes
I'm having a hard time finding information about this in specs, so I can't guess whether the problem that I'm about to describe is by design or a if it's a bug.
When, within
definitions
, an entry exists with a property referencing another definition via$ref
and also having adescription
value, then swagger-editor shows a warning.If it's only one, it wouldn't bother me as much, but my swagger-json is large, and I have dozens (and growing) of these. I'm trying to stay adamant with keeping the
description
field where it is (as opposed to moving it to the actual referenced definition, which is what fixes the problem), because otherwise swagger-ui doesn't display it at all.For example, the editor does not like
description
values in this YAMLdefinition
snippet):... while swagger-ui displays those

description
values regardless (which I like):When I move those
description
fields to definition of objects that$ref
values point to, then swagger-editor shows the content as valid (so, no warning), but swagger-ui does not display those description values at all (not at the property level, not at the type level).I did find some traces showing that my
description
values are where they are supposed to be - see this:Source: http://json-schema.org/example1.html
It seems logical to me that both locations should allow
description
field: it may be desired that the definition ($ref
) is described in some generic way, while its usage (properties
) is described in addition to that. E.g. I could say that my$ref
"agent" is "a record that represents an employee", while mydata
property can be described as "collection of agents". In other words, I think that both editor and swagger-ui should add the missing functionality in their code base, cause there's an obvious mismatch. I guess, ifdescription
can't be in both places, then if the two projects are at least in agreement about where it goes, it would help.Thanks.
The text was updated successfully, but these errors were encountered: