-
Notifications
You must be signed in to change notification settings - Fork 6k
Closed
Labels
Milestone
Description
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
- Save the above example YAML as
test.yaml. - Run swagger-codegen without a prefix:
swagger-codegen generate -i test.yaml -l php. - Open the generated file
SwaggerClient-php/lib/Model/InlineResponse200.php. - See on line 57 that
some_datefromtest.yamlis correctly mapped to\DateTime. - See on line 58 that
some_datetimefromtest.yamlis correctly mapped to\DateTime. - Run swagger-codegen with a prefix:
swagger-codegen generate -i test.yaml -l php --model-name-prefix Foo. - Open the (prefixed) generated file
SwaggerClient-php/lib/Model/FooInlineResponse200.php. - See on line 57 that
some_dateis incorrectly mapped toFooDatewhere it should be\DateTime. - See on line 58 that
some_datetimeis correctly mapped to\DateTimeeven 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.
ackintosh