swagger-api / swagger-api/swagger-codegen
Problems with parsing datetime on serverside with generated serverside and clientside Java code
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I have a swagger definition like below and generated serverside code and generated client side code with the swagger editor, run the server code and try to call the get-method, it always results in a failure that the called method could not be found.
When you debug on serverside you can see, that the problem is the parsing of the datetime parameter, a format exception is thrown while new java.util.Date( String ).
Swagger-codegen version
Swagger Editor Version 2.10.3
Swagger declaration file content or url
/services:
get:
parameters:
- name: begin
in: query
required: true
type: string
format: date-time
responses:
200:
schema:
type: object
properties:
response_code:
$ref: '#/definitions/Responsecode'
services:
type: array
items:
$ref: '#/definitions/Service'
Command line used for generation
- Swagger editor (Generate Server -> JAX-RS)
- Swagger editor (Generate Client -> Java)
Steps to reproduce
- Swagger editor (Generate Server -> JAX-RS)
- Swagger editor (Generate Client -> Java)
Related issues
There is also a problem with the date format (property with type string and format date). When you send such data as an answer from the server to the client, you get en error from the yoda framework, that the given "string" is not parseable for DateLocal. When you replace the DateLocal via java.util.Date in the clientside API everything works fine.
Suggest a Fix
To solve the problem I tried to change the generated clientside code. In the API-class I used java.util.Date instead of DateTime (yoda-framework). But it does not work, too.
Afterwards I tried to change the generated serverside code. In the API-class I changed the parametertype of the parameter begin from java.util.Date to DateTime (yoda-Framework). But after that I get a new error during starting the server: Missing dependency for method public javax.ws.rs.core.Response gen.java.io.swagger.api.ServicesApi.servicesGet(java.lang.String,org.joda.time.DateTime) throws gen.java.io.swagger.api.NotFoundException at parameter at index 1.
Because of the related issue I think it is a problem in the serverside generated code.
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 Swagger Editor JAX-RS server and Java client generation steps described in the issue, using the supplied YAML definition with the date-time query parameter. Reproduce the server-side parsing failure and the client-side date and DateTime errors, then trace the generated API parameter types and JAX-RS handling. Done means date-time and date values work between the generated server and client without manual type changes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, yaml
- Domain
- api, backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100