Skip to content

Producing allOf with $ref and additional properties using @Schema annotations? #3290

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

Closed
DSW-PS opened this issue Sep 12, 2019 · 4 comments
Closed

Comments

@DSW-PS
Copy link

DSW-PS commented Sep 12, 2019

I'm trying to figure out if it is possible to produce something like

w307BetrBeg:
  title: 'Betrag'
  description: 'BETRAG BEGUENSTIGTER'
  allOf:
    - $ref: '#/components/schemas/Betrag'

using the @Schema annotation.

I thought that the following use should produce what I want:

@Schema(name = "w307BetrBeg", description = "BETRAG BEGUENSTIGTER ", 
allOf = { com.diesoftware.services.utils.Betrag.class }, required = true)
public void setW307BetrBeg(final Betrag w307BetrBeg) {
  this.w307BetrBeg = w307BetrBeg;
}

But instead I end up with:

w307BetrBeg:
  $ref: '#/components/schemas/Betrag'

According to this commont on the related issue on the OpenAPI-Spec itself, it is valid in the API and it seems like the suggested way to do if you are writing the API by hand.

Is this a parser/annotation issue or am I using the annotation wrong?

@Kadams64
Copy link

I have exactly the same question. I'm using Swagger 2.0.9, and use of the allOf property of @Schema as described by the original poster doesn't seem to produce the expected OpenAPI.json output

  • I had originally raised a related issue regarding Swagger UI not rendering descriptions for nested entities, and was given the guidance to use the 'allOf' construct...=> Nested schemas do not show description in swagger-ui swagger-ui#5139
  • I waited until we had completed an upgrade to Swagger 2.0.9 and the OpenApi V3 specification on the assumption that this would (should) work

Thoughts or help appreciated.

@jochenberger
Copy link

See #3035

@kochn
Copy link

kochn commented May 5, 2023

Hi, I have the same issue. Here my concrete example:

@Data
public class Measurement {

    @Schema(description = "Description Value A")
    private TimedValue valueA;

    @Schema(description = "Description Value B")
    private TimedValue valueB;

}

@Data
public class TimedValue {
    private BigDecimal value;
    private Instant measuredValue;
}

The workaround above describes, to use allOf to solve this conflict. Nevertheless this is not applicable in Java:

          allOf:
            - "$ref": "#/components/schemas/TimedValue"
            - description: "Description Value B"

The reason is, that @Schema needs Java implementation classes for the allOf array. Am I the only one, who needs to describe attributes with same base object but different descriptions?

@frantuma
Copy link
Member

frantuma commented Oct 8, 2024

this has been addressed implementing new config property and annotation as detailed in wiki

@frantuma frantuma closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants