swagger-api / swagger-api/swagger-codegen
Getting Swagger to use LocalDate object instead of String
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Hello!
I have an application configured with Jersey 2.29, Java 8 and Swagger 1.5.22
When I open Swagger page with the interface for the rest service, this is what I see (dates in String format):
{ "alPeriod": {
"startDate": "2019-08-08",
"endDate": "2019-08-08"}
}
When in fact I am expecting this (a LocalDate with year, month and day):
{ "alPeriod":{
"startDate":{"year":2018,"month":1,"day":1},
"endDate":{"year":2018,"month":1,"day":20}}
}
I read issue #2377 and others similar to it, I tried to set @ApiModelProperty, .... but nothing works. Actually I am amazed to see that some people are trying to do the contrary! They have already dates as LocalDate working perfectly and they are trying to put it as String, as I have now.
The configuration of the application is done via BeanConfig, like this:
public class SampleApplication extends Application {
public SampleApplication() {
BeanConfig beanConfig = new BeanConfig();
beanConfig.setResourcePackage("com.x.y.z");
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[]{"http"});
beanConfig.setHost("localhost:8080");
beanConfig.setBasePath("/api");
beanConfig.setScan(true);
beanConfig.setPrettyPrint(true);
}
@Override
public Set<Class<?>> getClasses() {
...
}
}
What am I missing to get Java 8 LocalDate object format?
Thanks!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the BeanConfig setup and the attempted @ApiModelProperty changes described in the issue, then compare the generated Swagger page with the Java 8 LocalDate model. Check issue #2377 for related behavior; the work is complete when the generated schema represents the dates in the requested object form.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100