Skip to content

[PHP] Bug with 'format: date' when using --model-name-prefix #6474

Closed
@SunMar

Description

@SunMar
Description

When an object property in the Swagger definition is defined as a date and swagger-codegen is called with --model-name-prefix it incorrectly maps the object to <Prefix>Date instead of a \DateTime object.

Swagger-codegen version

I am using swagger-codegen-cli-2.2.3.

Swagger declaration file content
---
swagger: '2.0'

info:
  title: 'Test Codegen Date'
  version: '1.0'
  
paths:
  '/foo':
    get:
      responses:
        200:
          description: 'Success'
          schema:
            type: object
            properties:
              some_date:
                type: string
                format: 'date'
              some_datetime:
                type: string
                format: 'date-time'
Command line used for generation

java -jar swagger-codegen-cli-2.2.3.jar generate -i test.yaml -l php --model-name-prefix Foo

Steps to reproduce
  1. Save the above example YAML as test.yaml.
  2. Run swagger-codegen without a prefix: swagger-codegen generate -i test.yaml -l php.
  3. Open the generated file SwaggerClient-php/lib/Model/InlineResponse200.php.
  4. See on line 57 that some_date from test.yaml is correctly mapped to \DateTime.
  5. See on line 58 that some_datetime from test.yaml is correctly mapped to \DateTime.
  6. Run swagger-codegen with a prefix: swagger-codegen generate -i test.yaml -l php --model-name-prefix Foo.
  7. Open the (prefixed) generated file SwaggerClient-php/lib/Model/FooInlineResponse200.php.
  8. See on line 57 that some_date is incorrectly mapped to FooDate where it should be \DateTime.
  9. See on line 58 that some_datetime is correctly mapped to \DateTime even when using a prefix.
Related issues/PRs

Issue #4430 looks similar but it is regarding Java generated code, I haven't been able to find a similar issue for PHP.

Suggest a fix/enhancement

Unfortunately I was not able to find where in the code this is managed, but since it works correctly for format: 'date-time' it could be that it's an easy fix once the difference in handling prefixes between format: 'date-time' and format: 'date' is identified.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions