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

How to document type properties used for polymorphism? #171

Open
JoergSiebahn opened this issue Aug 4, 2022 · 0 comments
Open

How to document type properties used for polymorphism? #171

JoergSiebahn opened this issue Aug 4, 2022 · 0 comments

Comments

@JoergSiebahn
Copy link

Hi,

when I have a polymorphic class and add @JsonSchemaDescription at the visible type property, the description is ignored and not put in the Schema.

While generating the schema, I see this log (thanks for that, guess it saved some hours of research):

WARN com.kjetland.jackson.jsonSchema.JsonSchemaGenerator - Ignoring property 'type' in [simple type, class java.lang.String] since it has already been added, probably as type-property using polymorphism

Here is a simple example to reproduce:

@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    property = "type",
    include = JsonTypeInfo.As.EXISTING_PROPERTY,
    visible = true)
@JsonSubTypes({
  @JsonSubTypes.Type(value = SomeSuperclass.SomeSubType.class, name = "some"),
  @JsonSubTypes.Type(value = SomeSuperclass.SomeOtherSubType.class, name = "other")
})
public class SomeSuperclass {

  @JsonSchemaDescription("Defines the type.")
  private String type;

  public String getType() {
    return type;
  }

  public void setType(String type) {
    this.type = type;
  }

  public static class SomeSubType extends SomeSuperclass {}

  public static class SomeOtherSubType extends SomeSuperclass {}
}

I get JSON Schema for the two subtypes like this:

    SomeOtherSubType:
      type: "object"
      additionalProperties: true
      properties:
        type:
          type: "string"
          enum:
          - "other"
          default: "other"
      title: "other"
      required:
      - "type"
    SomeSubType:
      type: "object"
      additionalProperties: true
      properties:
        type:
          type: "string"
          enum:
          - "some"
          default: "some"
      title: "some"
      required:
      - "type"

So my description is missing. I als tried to merge the description in the property spec with different variants of @JsonSchemaInject and @JsonSchemaString at the property, the super class and the sub classes. None of my variants did the trick.

Is there any workaround to add a description to a type property that is used with @JsonTypeInfo?

Thanks in advance for any ideas that help.

My desired output would be like this:

    SomeOtherSubType:
      type: "object"
      additionalProperties: true
      properties:
        type:
          description: "Defines the type."
          type: "string"
          enum:
          - "other"
          default: "other"
      title: "other"
      required:
      - "type"
    SomeSubType:
      type: "object"
      additionalProperties: true
      properties:
        type:
          description: "Defines the type."
          type: "string"
          enum:
          - "some"
          default: "some"
      title: "some"
      required:
      - "type"
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

1 participant