Skip to content

Option.ALLOF_CLEANUP_AT_THE_END doesn't reduce allOf when the class has @JsonSubTypes #542

@tearfur

Description

@tearfur

I think I found a case where Option.ALLOF_CLEANUP_AT_THE_END doesn't reduce an allOf when it should.

This is reproducible on 995a71e.

I expected a schema like this:

{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "type" : "object",
  "properties" : {
    "tag" : {
      "type" : "string",
      "const" : "tag1"
    }
  },
  "required" : [ "tag" ]
}

But I got this instead:

{
  "$schema" : "https://json-schema.org/draft/2020-12/schema",
  "allOf" : [ {
    "type" : "object",
    "properties" : {
      "tag" : {
        "type" : "string"
      }
    }
  }, {
    "type" : "object",
    "properties" : {
      "tag" : {
        "const" : "tag1"
      }
    },
    "required" : [ "tag" ]
  } ]
}

Code:

SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2020_12, OptionPreset.PLAIN_JSON)
        .with(new JacksonModule());
SchemaGeneratorConfig config = configBuilder.build();
System.out.println(new SchemaGenerator(config).generateSchema(Tagged.class).toPrettyString());
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "tag", visible = true)
@JsonSubTypes({
        @JsonSubTypes.Type(value = Tagged1.class, name = "tag1")
})
static abstract class Tagged {
    private final String tag;

    Tagged(String tag) {
        this.tag = tag;
    }

    public String getTag() {
        return this.tag;
    }
}

static class Tagged1 extends Tagged {
    public Tagged1() {
        super("tag1");
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions