From 85090f506855d0a1a50f7d3337d21ec1dcbbc62c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Bresson?= Date: Thu, 17 May 2018 09:05:00 +0200 Subject: [PATCH] Revert pull request #45 (#82) Reverts: Consider minLength, maxLength and pattern in referenced schema (#45) This reverts commit 6b8079808b0d1d730324caf26489030a0cd960bd. --- .../openapitools/codegen/DefaultCodegen.java | 22 ++++++++----------- .../codegen/java/JavaModelTest.java | 8 +++---- 2 files changed, 13 insertions(+), 17 deletions(-) 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 b56b03e63f13..79cd8db2780e 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 @@ -1519,7 +1519,7 @@ public CodegenModel fromModel(String name, Schema schema, Map al addProperties(allProperties, allRequired, child, allDefinitions); } } - addVars(m, properties, required, allProperties, allRequired, allDefinitions); + addVars(m, properties, required, allProperties, allRequired); // TODO //} else if (schema instanceof RefModel) { } else { @@ -1533,7 +1533,7 @@ public CodegenModel fromModel(String name, Schema schema, Map al if (ModelUtils.isMapSchema(schema)) { addAdditionPropertiesToCodeGenModel(m, schema); } - addVars(m, schema.getProperties(), schema.getRequired(), allDefinitions); + addVars(m, schema.getProperties(), schema.getRequired()); } if (m.vars != null) { @@ -3095,12 +3095,12 @@ protected void addImport(CodegenModel m, String type) { } } - private void addVars(CodegenModel model, Map properties, List required, Map allDefinitions) { - addVars(model, properties, required, null, null, allDefinitions); + private void addVars(CodegenModel model, Map properties, List required) { + addVars(model, properties, required, null, null); } private void addVars(CodegenModel m, Map properties, List required, - Map allProperties, List allRequired, Map allDefinitions) { + Map allProperties, List allRequired) { m.hasRequired = false; if (properties != null && !properties.isEmpty()) { @@ -3109,7 +3109,7 @@ private void addVars(CodegenModel m, Map properties, List mandatory = required == null ? Collections.emptySet() : new TreeSet(required); - addVars(m, m.vars, properties, mandatory, allDefinitions); + addVars(m, m.vars, properties, mandatory); m.allMandatory = m.mandatory = mandatory; } else { m.emptyVars = true; @@ -3120,12 +3120,12 @@ private void addVars(CodegenModel m, Map properties, List allMandatory = allRequired == null ? Collections.emptySet() : new TreeSet(allRequired); - addVars(m, m.allVars, allProperties, allMandatory, allDefinitions); + addVars(m, m.allVars, allProperties, allMandatory); m.allMandatory = allMandatory; } } - private void addVars(CodegenModel m, List vars, Map properties, Set mandatory, Map allDefinitions) { + private void addVars(CodegenModel m, List vars, Map properties, Set mandatory) { // convert set to list so that we can access the next entry in the loop List> propertyList = new ArrayList>(properties.entrySet()); final int totalCount = propertyList.size(); @@ -3133,11 +3133,7 @@ private void addVars(CodegenModel m, List vars, Map entry = propertyList.get(i); final String key = entry.getKey(); - Schema prop = entry.getValue(); - if (allDefinitions != null && prop != null && StringUtils.isNotEmpty(prop.get$ref())) { - String refName = ModelUtils.getSimpleRef(prop.get$ref()); - prop = allDefinitions.get(refName); - } + final Schema prop = entry.getValue(); if (prop == null) { LOGGER.warn("null property for " + key); diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelTest.java index 482651ce6611..7668177fd1d4 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaModelTest.java @@ -937,11 +937,11 @@ public void stringPropertyReferencedInObjectTest() { Assert.assertTrue(cp.isNotContainer); Assert.assertFalse(cp.isLong); Assert.assertFalse(cp.isInteger); - Assert.assertTrue(cp.isString); + // Assert.assertTrue(cp.isString); //TODO: issue swagger-api/swagger-codegen#8001 Assert.assertEquals(cp.getter, "getSomePropertyWithMinMaxAndPattern"); - Assert.assertEquals(cp.minLength, Integer.valueOf(3)); - Assert.assertEquals(cp.maxLength, Integer.valueOf(10)); - Assert.assertEquals(cp.pattern, "^[A-Z]+$"); + // Assert.assertEquals(cp.minLength, Integer.valueOf(3)); //TODO: issue swagger-api/swagger-codegen#8001 + // Assert.assertEquals(cp.maxLength, Integer.valueOf(10)); //TODO: issue swagger-api/swagger-codegen#8001 + // Assert.assertEquals(cp.pattern, "^[A-Z]+$"); //TODO: issue swagger-api/swagger-codegen#8001 } @Test(description = "convert an array schema")