-
Notifications
You must be signed in to change notification settings - Fork 59
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
Duplicate entries in required
#499
Comments
Alright, it's not about the interfaces. Here's a repro: Here's a repro: package org.example;
import java.io.IOException;
import java.util.Set;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.github.victools.jsonschema.generator.Module;
import com.github.victools.jsonschema.generator.Option;
import com.github.victools.jsonschema.generator.OptionPreset;
import com.github.victools.jsonschema.generator.SchemaGenerator;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfig;
import com.github.victools.jsonschema.generator.SchemaGeneratorConfigBuilder;
import com.github.victools.jsonschema.generator.SchemaVersion;
import com.github.victools.jsonschema.module.swagger2.Swagger2Module;
import io.swagger.v3.core.util.Json;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode;
public class SchemaTest {
public static void main(String[] args) throws IOException {
SchemaGenerator schemaGenerator = createSchemaGenerator();
ObjectNode schema = schemaGenerator.generateSchema(Bar.class);
Json.pretty().writeValue(System.out, schema);
}
private static SchemaGenerator createSchemaGenerator() {
Module swagger2Module = new Swagger2Module();
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(
SchemaVersion.DRAFT_2019_09, OptionPreset.PLAIN_JSON).with(swagger2Module).with(
Option.INLINE_ALL_SCHEMAS, Option.NONSTATIC_NONVOID_NONGETTER_METHODS,
Option.FIELDS_DERIVED_FROM_ARGUMENTFREE_METHODS);
SchemaGeneratorConfig config = configBuilder.build();
return new SchemaGenerator(config);
}
interface Foo {
@Schema(requiredMode = RequiredMode.REQUIRED)
String getFoo();
}
public class Bar {
@ArraySchema(schema = @Schema(allOf = Foo.class))
public Set<Foo> getFoos() {
return null;
}
}
} The output is: {
"$schema" : "https://json-schema.org/draft/2019-09/schema",
"type" : "object",
"properties" : {
"foos" : {
"type" : "array",
"items" : {
"type" : "object",
"properties" : {
"foo" : {
"type" : "string"
}
},
"required" : [ "foo", "foo" ]
}
}
}
} I'm using the |
Hi @jochenberger, Yeah, the Maybe something like this would fix it: main...avoid-duplicate-array-items |
lgtm. |
I'm creating a schema for my entity with the
JakartaValidationModule
andSwagger2Module
. I have an interface that has a method annotated with@Schema(requiredMode = REQUIRED)
. The interface has a sub-interface and there's a class implementing the sub-interface. Neither have additional validation or schema annotations.In the schema, the property is contained in the
required
array twice.I'm still trying to find out why, please let me know if you need additional information.
The text was updated successfully, but these errors were encountered: