If i define a property like this:
scopes:
type: array
default: []
items:
type: string
The generated property is an ArrayList
@JsonProperty("scopes")
@Valid
private List<String> scopes = new ArrayList<>();
However, if I want a set and use
uniqueItems: true
I don't get a default value
@JsonProperty("scopes")
@Valid
private Set<String> scopes;
How can I get the following?
@JsonProperty("scopes")
@Valid
private Set<String> scopes = new LinkedHashSet();
Unfortunately, you can not currently get your desired output.
That's because it is currently not implemented in OpenAPI Generator. From OpenAPI Generator's
toArrayDefaultValue
source code (source):Your best option might be to open an issue or even better a PR for this topic in the OpenAPI Generator project. An alternative, less easy way to get your desired output might be to use OpenAPI Generator's templating feature to override the computed default values by a hard-coded string like "new HashSet<>()".