I would like to define an object with BigDecimal as String in swagger.json
Right now I can do
"MyObject": {
"type": "object",
"properties": {
"amountOfMoney": {
"type": "string",
"pattern": "d+([.]d+)?"
},
"name": {
"type": "string"
}
},
"title": "MyObject"
}
Another way, I can Define amountOfMoney as a number.
"MyObject": {
"type": "object",
"properties": {
"amountOfMoney": {
"type": "number"
"minimum": 0.0,
"maximum": 100.0,
"exclusiveMinimum": false,
"exclusiveMaximum": false
},
"name": {
"type": "string"
}
},
"title": "MyObject"
}
Java class defention
public class MyObject {
private BigDecimal amountOfMoney;
private String name;
//Getters, setters.
}
How do I enforce minimum and maximum validation, like in the second example?
Update
We use springfox 2.8.0.
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>2.8.0</version>
</dependency>
We have configuration (as a Spring bean), where I could add a substitute.
Docket(DocumentationType.SWAGGER_2)
.select()
.paths(PathSelectors.any())
.build()
.pathMapping("/")
// see https://stackoverflow.com/a/40737219
.directModelSubstitute(MyObject .class, String.class)
I can even use substitute BigDecimal
by String
! I would like to have format for that string to ensure I will get numbers between min and max.
It is not recommended to create BigDecimal from numbers. Another link
https://swagger.io/docs/specification/data-models/data-types/
Swagger documentation for Spring Pageable interface
For example, there is string format for dates. How do I make one for numbers?