How to generate openapi spec for multiple class inheritance?

Viewed 702

I would like to generate the openapi spec yaml openapi.yaml, for my classes, but I am not sure how do I model the Java classes hierarchy (using swagger annotations):

  @Schema(discriminatorProperty = "name",
          discriminatorMapping = {
               @DiscriminatorMapping(value = "B", schema = B.class),
          }
          subTypes = {B.class})
  public abstract class A {
      public String name; // the discriminator
      private String aa;
      private String ab;
  }


  @Schema(discriminatorProperty = "name2",
          discriminatorMapping = {
               @DiscriminatorMapping(value = "C", schema = C.class),
          },
          subTypes = {C.class})
 public abstract class B extends A {
      public String name2; // second discriminator for the subclasses of this one
      private String ba;
      private String bb;
 }

 @Schema()
 public abstract class C extends B {
      private String ca;
      private String cc;
 }

Is this the correct way, should every parent class have a public field which is the discriminator?

how does the class B sets the discriminator value for name? Should it be set explicitly?

0 Answers
Related