Skip to content

Commit

Permalink
[PHP] Fix swagger-api#6474: Bug with 'format: date' when using --mode…
Browse files Browse the repository at this point in the history
…l-name-prefix (swagger-api#6510)

* Add test case which repeats the issue swagger-api#6474

* Add "date" to type mapping

* Update samples

./bin/php-petstore.sh
./bin/security/php-petstore.sh
  • Loading branch information
ackintosh authored and wing328 committed Sep 19, 2017
1 parent e27d457 commit 594b390
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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** | |
Expand Down

0 comments on commit 594b390

Please sign in to comment.