Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #9984
Closed
Open
Issue created Jul 20, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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.

Assignee
Assign to
Time tracking