Hi I am trying to autogenerate a class using swagger plugin. One property of this class has to be array, but when I write type: “array” always create a List.
This is part of my “yml” file:
JavaScript
x
probabilities:
type: "array"
items:
type: "number"
format: "double"
minimum: 0
maximum: 1
description:
"Vector with probabilities"
example: [ 0.5, 0.3, 0.1 ]
And this is the property that create:
JavaScript
@JsonProperty("probabilities")
@SerializedName("probabilities")
private List<Double> probabilities = new ArrayList<Double>();
Advertisement
Answer
In Java, an array has a fixed length. This is different from OpenAPI and JavaScript specifications, where an array can have variable length at runtime. The variable-length equivalent in Java is the List
.
The implementation of swagger-codegen for Java converts an array
into a java.util.List