swagger-api / swagger-api/swagger-codegen-generators
[PHP] Date isn't correctly formatted
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
Description
Date is not correctly formatted from a DateTime Object in a generated PHP-Client
Expected was 'Y-m-d' instead 'Y-m-d\TH:i:sP' was generated
Swagger-codegen version
- 3.0.24
- git commit 912afd4052f5bb37064ba9e604e2ab1027eb83cf (swagger-codegen)
Swagger declaration file content or url
https://gist.github.com/a4blue/db06f076317ac6150a65b682e971039b
Command line used for generation
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i ../test.yml -l php -o ../test_api
Steps to reproduce
<?php
include_once "vendor/autoload.php";
$model = new \Swagger\Client\Model\Model();
$model->setSampleDate(new DateTime());
var_dump((string)$model);
Related issues/PRs
https://github.com/swagger-api/swagger-codegen/issues/6533
https://github.com/swagger-api/swagger-codegen/issues/6474
https://github.com/swagger-api/swagger-codegen/issues/5607
Suggest a fix/enhancement
In lib/ObjectSerializer.php:
Line 74
- $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $swaggerType, $formats[$property]);
+ $values[$data::attributeMap()[$property]] = self::sanitizeForSerialization($value, $formats[$property], $swaggerType);
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 at lib/ObjectSerializer.php line 74 and reproduce the generated PHP client with the provided Swagger declaration and DateTime example. Check the serialization call's handling of the date format, then verify that casting the model produces the expected 'Y-m-d' value instead of 'Y-m-d\TH:i:sP'.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100