diff --git a/bin/windows/android-petstore-httpclient.bat b/bin/windows/android-petstore-httpclient.bat index aa94d719fc..181ec906a4 100755 --- a/bin/windows/android-petstore-httpclient.bat +++ b/bin/windows/android-petstore-httpclient.bat @@ -5,6 +5,6 @@ If Not Exist %executable% ( ) REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties -set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g android -o samples\client\petstore\android\httpclient-Dlibrary=httpclient +set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g android -o samples\client\petstore\android\httpclient -Dlibrary=httpclient java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index 507a4d1d59..811b49c02a 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -1475,7 +1475,7 @@ public class DefaultCodegen implements CodegenConfig { * @param schema * @return type */ - private static String getPrimitiveType(Schema schema) { + private String getPrimitiveType(Schema schema) { if (schema == null) { throw new RuntimeException("schema cannot be null in getPrimitiveType"); } else if (ModelUtils.isStringSchema(schema) && "number".equals(schema.getFormat())) { @@ -1519,6 +1519,13 @@ public class DefaultCodegen implements CodegenConfig { } else if (ModelUtils.isURISchema(schema)) { return "URI"; } else if (ModelUtils.isStringSchema(schema)) { + if(typeMapping.containsKey(schema.getFormat())) { + // If the format matches a typeMapping (supplied with the --typeMappings flag) + // then treat the format as a primitive type. + // This allows the typeMapping flag to add a new custom type which can then + // be used in the format field. + return schema.getFormat(); + } return "string"; } else if (ModelUtils.isFreeFormObject(schema)) { return "object"; @@ -3668,7 +3675,7 @@ public class DefaultCodegen implements CodegenConfig { * @param schemas The complete set of model definitions (schemas). * @return A mapping from model name to type alias */ - static Map getAllAliases(Map schemas) { + Map getAllAliases(Map schemas) { if (schemas == null || schemas.isEmpty()) { return new HashMap<>(); } diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index b8b3a71790..8c2e2aabc6 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -189,6 +189,7 @@ public class DefaultCodegenTest { @Test public void testArraySchemaIsNotIncluedInAliases() throws Exception { + final DefaultCodegen codegen = new DefaultCodegen(); Map schemas = new HashMap() { { put("ArraySchemaTest", new ArraySchema()); @@ -196,7 +197,7 @@ public class DefaultCodegenTest { }; - Map aliases = DefaultCodegen.getAllAliases(schemas); + Map aliases = codegen.getAllAliases(schemas); Assert.assertEquals(aliases.size(), 0); }