[BUG] [PHP] [Symfony] JMS-Serializer Annotation should respect `date` format
Created by: BigBadBassMan
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Defining any object with a string property and date
format, the php-symfony generator creates a wrong JMS\Serializer Annotation due to https://github.com/OpenAPITools/openapi-generator/blob/e20ccd49ed4f03051ec071dd2dfa09de13caf632/modules/openapi-generator/src/main/resources/php-symfony/model_variables.mustache#L44-L51 providing no constraint, which then defaults to a full-blown ISO:8601 date-time string.
openapi-generator version
5.1.1 & 5.2.0
OpenAPI declaration file content or url
#...
type: object
properties:
birthday:
type: string
format: date
#....
Generation Details
via Docker run command, with:
openapitools/openapi-generator-cli:latest generate \
--additional-properties disallowAdditionalPropertiesIfNotPresent="false" \
--additional-properties modelPackage="DTO" \
--additional-properties legacyDiscriminatorBehavior="false" \
--additional-properties prependFormOrBodyParameters="true" \
--additional-properties variableNamingConvention="camelCase" \
--additional-properties phpLegacySupport="false" \
--generator-name php-symfony \
--input-spec /local/openapi/spec.yaml
--output /local/<targetpath>
Steps to reproduce
- any apispec with a date-property defined like above snippet
- generated model classes (using parameters above) will result in a DocBlock snippet like this:
/* ....
* @Assert\Date()
* @Type("DateTime")
*/
protected $birthday
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/5080
Suggest a fix
Update linked template above to this:
{{#isDate}}
* @Assert\Date()
* @Type("DateTime<'Y-m-d'>")
{{/isDate}}
{{#isDateTime}}
* @Assert\DateTime()
* @Type("DateTime")
{{/isDateTime}}
This instructs the JMS\Serializer not to look for a complete datetime string, but instead on fields marked as date
only expect a "YYYY-mm-dd" type string as per RFC3339.