Using swagger-core/swagger-annotations in version 1.5.16
Have problem to control the default property in swagger file for my data model. Have a POJO that defines the input JSON object for HTTP POST:
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(description = "Parameters to use when creating my object")
public class MyPrototype {
@JsonProperty(value = "name")
@ApiModelProperty(value = "Name of this entity", required = true, example = "MyAccountGroup1")
protected String name;
@JsonProperty(value = "flag")
@ApiModelProperty(value = "This flag is used for...")
protected Boolean statusReportRequestSuppressed;
}
My problem is that the generated swagger file will contain a default property for parameter "flag" and set this to 'false' but there seems to be no way to include a default property for parameter "name".
Is there any support given the swagger-core/annotations version to either
I would like to achieve that swagger file get default values on all or nothing.
Any tips welcome
My outcome swagger looks like this:
"MyPrototype" : {
"type" : "object",
"required" : [ "name" ],
"properties" : {
"name" : {
"type" : "string",
"example" : "MyAccountGroup1",
"description" : "Name of this entity"
},
"flag" : {
"type" : "boolean",
"description" : "This flag is used for...",
"default" : false
}
},
"description" : "Parameters to use when creating my object"
}
swagger-core 1.5 does not support default values for model properties - but it should be supported in 2.x using the @Schema
annotation:
import io.swagger.v3.oas.annotations.media;
@Schema(value = "Some optional property", defaultValue = "foo")
protected String optionalProperty;
More info:
Note that swagger-core 2.x produces OpenAPI 3.0 definitions, not OpenAPI 2.0 as in your current example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With