From 594b390e1149c3d4a9a0fc3b1d41975c48dc1f7c Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Tue, 19 Sep 2017 19:07:37 +0900 Subject: [PATCH] [PHP] Fix #6474: Bug with 'format: date' when using --model-name-prefix (#6510) * Add test case which repeats the issue #6474 * Add "date" to type mapping * Update samples ./bin/php-petstore.sh ./bin/security/php-petstore.sh --- .../codegen/languages/PhpClientCodegen.java | 1 + .../java/io/swagger/codegen/php/PhpModelTest.java | 14 ++++++++++++++ .../php/SwaggerClient-php/docs/Model/FormatTest.md | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java index 8c889b19a06..98420bb37e1 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PhpClientCodegen.java @@ -117,6 +117,7 @@ public PhpClientCodegen() { typeMapping.put("string", "string"); typeMapping.put("byte", "int"); typeMapping.put("boolean", "bool"); + typeMapping.put("date", "\\DateTime"); typeMapping.put("Date", "\\DateTime"); typeMapping.put("DateTime", "\\DateTime"); typeMapping.put("file", "\\SplFileObject"); diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/php/PhpModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/php/PhpModelTest.java index d7726b0945b..77d036272fa 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/php/PhpModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/php/PhpModelTest.java @@ -1,12 +1,14 @@ package io.swagger.codegen.php; import io.swagger.codegen.CodegenModel; +import io.swagger.codegen.CodegenOperation; import io.swagger.codegen.CodegenProperty; import io.swagger.codegen.DefaultCodegen; import io.swagger.codegen.languages.PhpClientCodegen; import io.swagger.models.ArrayModel; import io.swagger.models.Model; import io.swagger.models.ModelImpl; +import io.swagger.models.Operation; import io.swagger.models.properties.Property; import io.swagger.models.properties.ArrayProperty; import io.swagger.models.properties.DateTimeProperty; @@ -344,5 +346,17 @@ public void testReservedWord() throws Exception { Assert.assertEquals(codegen.toEnumVarName("hello", null), "HELLO"); } + @Test(description = "returns DateTime when using `--model-name-prefix`") + public void dateTest() { + final Swagger model = new SwaggerParser().read("src/test/resources/2_0/datePropertyTest.json"); + final DefaultCodegen codegen = new PhpClientCodegen(); + codegen.setModelNamePrefix("foo"); + + final String path = "/tests/dateResponse"; + final Operation p = model.getPaths().get(path).getPost(); + final CodegenOperation op = codegen.fromOperation(path, "post", p, model.getDefinitions()); + Assert.assertEquals(op.returnType, "\\DateTime"); + Assert.assertEquals(op.bodyParam.dataType, "\\DateTime"); + } } diff --git a/samples/client/petstore/php/SwaggerClient-php/docs/Model/FormatTest.md b/samples/client/petstore/php/SwaggerClient-php/docs/Model/FormatTest.md index c31305010fc..57cb0b1c332 100644 --- a/samples/client/petstore/php/SwaggerClient-php/docs/Model/FormatTest.md +++ b/samples/client/petstore/php/SwaggerClient-php/docs/Model/FormatTest.md @@ -12,7 +12,7 @@ Name | Type | Description | Notes **string** | **string** | | [optional] **byte** | **string** | | **binary** | **string** | | [optional] -**date** | [**\DateTime**](Date.md) | | +**date** | [**\DateTime**](\DateTime.md) | | **date_time** | [**\DateTime**](\DateTime.md) | | [optional] **uuid** | **string** | | [optional] **password** | **string** | |