swagger-api / swagger-api/swagger-codegen
[JAVA] Enhance JSON.mustache to be able to handle LocalDateTime fomatted date-time
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
So far, when trying to replace a OffsetDateTime object with a LocalDateTime (to be able to read from a server which is not following the standard...), i was able to do so by mapping the fields, alas, the generated code seems not to be able to run, as it had no idea how to deserialize a LocalDateTime. Now i am not sure if i just did the mapping wrong... But anyhow, i patched the JSON.mustache file, and since it seems to work nicely.
Swagger-codegen version
I used 2.4.6
Swagger declaration file content or url
https://unitest01.public360online.com/Biz/v2/api/swagger/SI.Data.RPC/SI.Data.RPC/CaseService
Command line used for generation
java -jar ../swagger-codegen-cli-2.4.6.jar generate -i "https://unitest01.public360online.com/Biz/v2/api/swagger/SI.Data.RPC/SI.Data.RPC/CaseService" -l java -c case.json -o public360-case-service
with the case.json lookig lik that:
{
"groupId": "no.unit.p360.rpc",
"artifactId": "public360-case-service",
"artifactVersion": "1.0.0",
"library": "okhttp-gson",
"modelPackage": "no.unit.p360.cases.model",
"invokerPackage" : "no.unit.p360.cases",
"apiPackage": "no.unit.p360.cases.api",
"generateSupportingFiles" : true,
"codegenVersion": "V2",
"useOas2": true,
"dateLibrary": "java8",
"java8": true,
"importMappings": {
"GetCasesArgsParameter" : "no.unit.mule.p360.cases.model.GetCasesArgsParameter",
"java.time.OffsetDateTime" : "java.time.LocalDateTime"
},
"typeMappings" : {
"OffsetDateTime" : "java.time.LocalDateTime"
}
}
Steps to reproduce
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/7589 is somehow related, but this one tries not to introduce a new mapping
Suggest a fix/enhancement
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 JSON.mustache template and reproduce the issue using the documented swagger-codegen 2.4.6 command and case.json mappings. Compare generated LocalDateTime handling with the attached JSON.zip patch; done means generated Java can deserialize LocalDateTime when OffsetDateTime is mapped as shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100