Swagger2; issue making array items nullable
See original GitHub issueHi,
I’m evaluating adoption of the Swagger2Module
(which seems pretty flexible!) and I noticed that I was unable to apply nullable = true
to the items of an array.
Configuration
Dependencies: 4.19.0
Generator:
Swagger2Module swagger2Module = new Swagger2Module();
SchemaGeneratorConfigBuilder configBuilder = new SchemaGeneratorConfigBuilder(SchemaVersion.DRAFT_2019_09,
OptionPreset.PLAIN_JSON)
.with(Option.VALUES_FROM_CONSTANT_FIELDS,
Option.MAP_VALUES_AS_ADDITIONAL_PROPERTIES,
Option.FORBIDDEN_ADDITIONAL_PROPERTIES_BY_DEFAULT,
Option.FLATTENED_OPTIONALS)
.with(swagger2Module);
POJO:
@ArraySchema(
arraySchema = @Schema(description = "Description on root field"),
schema = @Schema(
nullable = true,
description = "Description on individual items"))
private Set<String> features = Set.of();
Expectation
"features" : {
"description" : "Description on root field",
"type" : "array",
"items" : {
"type" : ["string", "null"],
"description" : "Description on individual items"
}
}
Generated
"features" : {
"description" : "Description on root field",
"type" : "array",
"items" : {
"type" : "string",
"description" : "Description on individual items"
}
}
Is it clear from my configuration why this is happening? Setting @Schema(nullable = true)
seems to work for non-lists/arrays.
Thanks.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
x-nullable for array values doesn't have any effect #774 - GitHub
Problem statement If an array/slice value is nil and the aim is to exclude it from the encoded JSON there doesn't seem to...
Read more >Swagger 2.0 default null for List in models - Stack Overflow
I am trying to build a model object, which contains a "string-list" key-value pair. Is there a way to default the list to...
Read more >Solved: Array null values - SmartBear Community
Is it possible to define an array that can not contain null? I'm compiling it to Java with Open API 3.0. f.e for...
Read more >Describing Parameters - Swagger
Path parameters containing arrays and objects can be serialized in different ways: ... OpenAPI 3.0 also supports nullable in schemas, allowing operation ......
Read more >How to manage nullable properties - Jane - Read the Docs
Most of the time, the schema you get from vendor have issues about nullability of their properties. Here Jane has an option called...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fantastic! I go on one little weekend vacation and there it is! 🎉 Thank you @CarstenWickner, I will be sure to reach out if I can identify any issues.
The change has just been released in version 4.20.0. The new behavior is only available when explicitly enabling the new
Option.NULLABLE_ARRAY_ITEMS_ALLOWED
.