org.openapitools.codegen.CodegenProperty Java Examples

The following examples show how to use org.openapitools.codegen.CodegenProperty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Swift4ModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a java model with an reserved word string enum and a default value")
public void convertReservedWordStringDefaultValueTest() {
    final StringSchema enumSchema = new StringSchema();
    enumSchema.setEnum(Arrays.asList("1st", "2nd", "3rd"));
    enumSchema.setDefault("2nd");
    final Schema model = new Schema().type("object").addProperties("name", enumSchema);

    final DefaultCodegen codegen = new Swift4Codegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty enumVar = cm.vars.get(0);
    Assert.assertEquals(enumVar.baseName, "name");
    Assert.assertEquals(enumVar.dataType, "String");
    Assert.assertEquals(enumVar.datatypeWithEnum, "Name");
    Assert.assertEquals(enumVar.name, "name");
    Assert.assertEquals(enumVar.defaultValue, "._2nd");
    Assert.assertEquals(enumVar.baseType, "String");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example #2
Source File: JavaModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a java model with an enum")
public void converterTest() {
    final StringSchema enumSchema = new StringSchema();
    enumSchema.setEnum(Arrays.asList("VALUE1", "VALUE2", "VALUE3"));
    final Schema model = new Schema().type("object").addProperties("name", enumSchema);

    final JavaClientCodegen codegen = new JavaClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty enumVar = cm.vars.get(0);
    Assert.assertEquals(enumVar.baseName, "name");
    Assert.assertEquals(enumVar.dataType, "String");
    Assert.assertEquals(enumVar.datatypeWithEnum, "NameEnum");
    Assert.assertEquals(enumVar.name, "name");
    Assert.assertEquals(enumVar.defaultValue, null);
    Assert.assertEquals(enumVar.baseType, "String");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example #3
Source File: CSharpModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with array property to default List<T>")
public void arrayPropertyTest() {
    final Schema schema = getArrayTestSchema();

    final DefaultCodegen codegen = new CSharpClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel generated = codegen.fromModel("sample", schema);

    Assert.assertEquals(generated.name, "sample");
    Assert.assertEquals(generated.classname, "Sample");
    Assert.assertEquals(generated.description, "a sample model");
    Assert.assertEquals(generated.vars.size(), 2);

    final CodegenProperty property = generated.vars.get(1);
    Assert.assertEquals(property.baseName, "examples");
    Assert.assertEquals(property.getter, "getExamples");
    Assert.assertEquals(property.setter, "setExamples");
    Assert.assertEquals(property.dataType, "List<string>");
    Assert.assertEquals(property.name, "Examples");
    Assert.assertNull(property.defaultValue);
    Assert.assertEquals(property.baseType, "List");
    Assert.assertEquals(property.containerType, "array");
    Assert.assertFalse(property.required);
    Assert.assertTrue(property.isContainer);
}
 
Example #4
Source File: JavaCXFExtServerCodegen.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
private void appendPropertyAssignments(StringBuilder buffer, String indent, CodegenOperation op,
                                       CodegenVariable parent, String localVar, Collection<String> localVars, Map<String, CodegenModel> models) {

    CodegenModel cm = models.get(parent.dataType);
    if (cm != null) { // TODO: handle isArrayModel and isMapModel
        for (CodegenProperty cp : cm.allVars) {
            CodegenVariable var = new CodegenVariable(parent, cp, null, models);
            if (var.isContainer || !var.isPrimitiveType) {
                String containerVar = appendLocalVariable(buffer, indent, op, var, localVars, models);
                if (!loadTestDataFromFile) {
                    buffer.append(NL).append(indent).append(localVar).append('.').append(var.setter).append('(')
                            .append(containerVar);
                }
            } else {
                // No need to use a local variable for types which can be initialised with a single expression.
                if (!loadTestDataFromFile)
                    buffer.append(NL).append(indent).append(localVar).append('.').append(var.setter).append('(');
                appendValue(buffer, indent, op, var, localVar, localVars, models);
            }
            if (!loadTestDataFromFile)
                buffer.append(");");
        }
    }
}
 
Example #5
Source File: JavaCXFExtServerCodegen.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
private CodegenVariable(CodegenVariable parent, CodegenProperty prop, String testDataPath,
                        Map<String, CodegenModel> models) {

    name = prop.name;
    dataFormat = prop.dataFormat;
    dataType = prop.dataType;
    enumName = prop.enumName;
    allowableValues = prop.allowableValues;
    isContainer = prop.isContainer;
    isListContainer = prop.isListContainer;
    isMapContainer = prop.isMapContainer;
    isPrimitiveType = prop.isPrimitiveType;
    minItems = prop.minItems;
    minimum = prop.minimum;
    maximum = prop.maximum;
    exclusiveMinimum = prop.exclusiveMinimum;
    exclusiveMaximum = prop.exclusiveMaximum;
    minLength = prop.minLength;
    maxLength = prop.maxLength;
    pattern = prop.pattern;
    setter = prop.getSetter();
    varVendorExtensions = prop.vendorExtensions;
    init(parent, testDataPath, models);

    items = prop.items == null ? null : new CodegenVariable(this, prop.items, null, models);
}
 
Example #6
Source File: AbstractKotlinCodegen.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Override
public CodegenModel fromModel(String name, Schema schema) {
    CodegenModel m = super.fromModel(name, schema);
    m.optionalVars = m.optionalVars.stream().distinct().collect(Collectors.toList());
    // Update allVars/requiredVars/optionalVars with isInherited
    // Each of these lists contains elements that are similar, but they are all cloned
    // via CodegenModel.removeAllDuplicatedProperty and therefore need to be updated
    // separately.
    // First find only the parent vars via baseName matching
    Map<String, CodegenProperty> allVarsMap = m.allVars.stream()
            .collect(Collectors.toMap(CodegenProperty::getBaseName, Function.identity()));
    allVarsMap.keySet()
            .removeAll(m.vars.stream().map(CodegenProperty::getBaseName).collect(Collectors.toSet()));
    // Update the allVars
    allVarsMap.values().forEach(p -> p.isInherited = true);
    // Update any other vars (requiredVars, optionalVars)
    Stream.of(m.requiredVars, m.optionalVars)
            .flatMap(List::stream)
            .filter(p -> allVarsMap.containsKey(p.baseName))
            .forEach(p -> p.isInherited = true);
    return m;
}
 
Example #7
Source File: AbstractKotlinCodegen.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
    objs = super.postProcessModelsEnum(objs);
    List<Object> models = (List<Object>) objs.get("models");
    for (Object _mo : models) {
        Map<String, Object> mo = (Map<String, Object>) _mo;
        CodegenModel cm = (CodegenModel) mo.get("model");
        if (cm.getDiscriminator() != null) {
            cm.vendorExtensions.put("x-has-data-class-body", true);
            break;
        }

        for (CodegenProperty var : cm.vars) {
            if (var.isEnum || isSerializableModel()) {
                cm.vendorExtensions.put("x-has-data-class-body", true);
                break;
            }
        }
    }
    return postProcessModelsEnum(objs);
}
 
Example #8
Source File: Swift5ModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a java model with an integer enum and a default value")
public void convertIntegerDefaultValueTest() {
    final IntegerSchema enumSchema = new IntegerSchema();
    enumSchema.setEnum(Arrays.asList(1, 2, 3));
    enumSchema.setDefault(2);
    final Schema model = new Schema().type("object").addProperties("name", enumSchema);

    final DefaultCodegen codegen = new Swift5ClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty enumVar = cm.vars.get(0);
    Assert.assertEquals(enumVar.baseName, "name");
    Assert.assertEquals(enumVar.dataType, "Int");
    Assert.assertEquals(enumVar.datatypeWithEnum, "Name");
    Assert.assertEquals(enumVar.name, "name");
    Assert.assertEquals(enumVar.defaultValue, "._2");
    Assert.assertEquals(enumVar.baseType, "Int");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example #9
Source File: TypeScriptAngularModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with complex property")
public void complexPropertyTest() {
    final Schema schema = new Schema()
            .description("a sample model")
            .addProperties("children", new Schema().$ref("#/definitions/Children"));
    final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "children");
    Assert.assertEquals(property1.dataType, "Children");
    Assert.assertEquals(property1.name, "children");
    Assert.assertEquals(property1.defaultValue, "undefined");
    Assert.assertEquals(property1.baseType, "Children");
    Assert.assertFalse(property1.required);
}
 
Example #10
Source File: CSharpModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with complex list property")
public void complexListPropertyTest() {
    OpenAPI openAPI = TestUtils.createOpenAPI();
    final Schema schema = new Schema()
            .description("a sample model")
            .addProperties("children", new ArraySchema()
                    .items(new Schema().$ref("#/components/schemas/Children")));
    final DefaultCodegen codegen = new CSharpClientCodegen();
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "children");
    Assert.assertEquals(property1.complexType, "Children");
    Assert.assertEquals(property1.dataType, "List<Children>");
    Assert.assertEquals(property1.name, "Children");
    Assert.assertEquals(property1.baseType, "List");
    Assert.assertEquals(property1.containerType, "array");
    Assert.assertFalse(property1.required);
    Assert.assertTrue(property1.isContainer);
}
 
Example #11
Source File: Swift5ModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a java model with an number enum and a default value")
public void convertNumberDefaultValueTest() {
    final NumberSchema enumSchema = new NumberSchema();
    enumSchema.setEnum(Arrays.asList(new BigDecimal(10), new BigDecimal(100), new BigDecimal(1000)));
    enumSchema.setDefault(new BigDecimal((100)));
    final Schema model = new Schema().type("object").addProperties("name", enumSchema);

    final DefaultCodegen codegen = new Swift5ClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty enumVar = cm.vars.get(0);
    Assert.assertEquals(enumVar.baseName, "name");
    Assert.assertEquals(enumVar.dataType, "Double");
    Assert.assertEquals(enumVar.datatypeWithEnum, "Name");
    Assert.assertEquals(enumVar.name, "name");
    Assert.assertEquals(enumVar.defaultValue, "._100");
    Assert.assertEquals(enumVar.baseType, "Double");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example #12
Source File: CsharpModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "use default suffixes for enums")
public void useDefaultEnumSuffixes() {
    final AspNetCoreServerCodegen codegen = new AspNetCoreServerCodegen();

    OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml");
    codegen.setOpenAPI(openAPI);

    final Schema petSchema = openAPI.getComponents().getSchemas().get("Pet");
    final CodegenModel cm = codegen.fromModel("Pet", petSchema);
    final CodegenProperty statusProperty = cm.vars.get(5);
    Assert.assertEquals(statusProperty.name, "Status");
    Assert.assertTrue(statusProperty.isEnum);
    Assert.assertEquals(statusProperty.datatypeWithEnum, "StatusEnum");

    Assert.assertEquals(codegen.toEnumVarName("Aaaa", ""), "AaaaEnum");
}
 
Example #13
Source File: TypeScriptFetchModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with complex property")
public void complexPropertyTest() {
    final Schema model = new Schema()
            .description("a sample model")
            .addProperties("children", new Schema().$ref("#/definitions/Children"));
    final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "children");
    Assert.assertEquals(property1.dataType, "Children");
    Assert.assertEquals(property1.name, "children");
    Assert.assertEquals(property1.defaultValue, "undefined");
    Assert.assertEquals(property1.baseType, "Children");
    Assert.assertFalse(property1.required);
}
 
Example #14
Source File: KotlinClientCodegenModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with a map property")
public void mapPropertyTest() {
    final Schema schema = getMapSchema();
    final DefaultCodegen codegen = new KotlinClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "mapping");
    Assert.assertEquals(property1.dataType, "kotlin.collections.Map<kotlin.String, kotlin.String>");
    Assert.assertEquals(property1.name, "mapping");
    Assert.assertEquals(property1.baseType, "kotlin.collections.Map");
    Assert.assertEquals(property1.containerType, "map");
    Assert.assertFalse(property1.required);
    Assert.assertTrue(property1.isContainer);
    Assert.assertTrue(property1.isPrimitiveType);
}
 
Example #15
Source File: Swift4ModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a java model with an string enum and a default value")
public void convertStringDefaultValueTest() {
    final StringSchema enumSchema = new StringSchema();
    enumSchema.setEnum(Arrays.asList("VALUE1", "VALUE2", "VALUE3"));
    enumSchema.setDefault("VALUE2");
    final Schema model = new Schema().type("object").addProperties("name", enumSchema);

    final DefaultCodegen codegen = new Swift4Codegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty enumVar = cm.vars.get(0);
    Assert.assertEquals(enumVar.baseName, "name");
    Assert.assertEquals(enumVar.dataType, "String");
    Assert.assertEquals(enumVar.datatypeWithEnum, "Name");
    Assert.assertEquals(enumVar.name, "name");
    Assert.assertEquals(enumVar.defaultValue, ".value2");
    Assert.assertEquals(enumVar.baseType, "String");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example #16
Source File: CsharpModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "use custom suffixes for enums")
public void useCustomEnumSuffixes() {
    final AspNetCoreServerCodegen codegen = new AspNetCoreServerCodegen();
    codegen.setEnumNameSuffix("EnumName");
    codegen.setEnumValueSuffix("EnumValue");

    OpenAPI openAPI = TestUtils.parseFlattenSpec("src/test/resources/3_0/petstore.yaml");
    codegen.setOpenAPI(openAPI);

    final Schema petSchema = openAPI.getComponents().getSchemas().get("Pet");
    final CodegenModel cm = codegen.fromModel("Pet", petSchema);
    final CodegenProperty statusProperty = cm.vars.get(5);
    Assert.assertEquals(statusProperty.name, "Status");
    Assert.assertTrue(statusProperty.isEnum);
    Assert.assertEquals(statusProperty.datatypeWithEnum, "StatusEnumName");

    Assert.assertEquals(codegen.toEnumVarName("Aaaa", ""), "AaaaEnumValue");
}
 
Example #17
Source File: Swift4ModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a java model with an integer enum and a default value")
public void convertIntegerDefaultValueTest() {
    final IntegerSchema enumSchema = new IntegerSchema();
    enumSchema.setEnum(Arrays.asList(1, 2, 3));
    enumSchema.setDefault(2);
    final Schema model = new Schema().type("object").addProperties("name", enumSchema);

    final DefaultCodegen codegen = new Swift4Codegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty enumVar = cm.vars.get(0);
    Assert.assertEquals(enumVar.baseName, "name");
    Assert.assertEquals(enumVar.dataType, "Int");
    Assert.assertEquals(enumVar.datatypeWithEnum, "Name");
    Assert.assertEquals(enumVar.name, "name");
    Assert.assertEquals(enumVar.defaultValue, "._2");
    Assert.assertEquals(enumVar.baseType, "Int");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example #18
Source File: Swift4ModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a java model with an number enum and a default value")
public void convertNumberDefaultValueTest() {
    final NumberSchema enumSchema = new NumberSchema();
    enumSchema.setEnum(Arrays.asList(new BigDecimal(10), new BigDecimal(100), new BigDecimal(1000)));
    enumSchema.setDefault(new BigDecimal((100)));
    final Schema model = new Schema().type("object").addProperties("name", enumSchema);

    final DefaultCodegen codegen = new Swift4Codegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty enumVar = cm.vars.get(0);
    Assert.assertEquals(enumVar.baseName, "name");
    Assert.assertEquals(enumVar.dataType, "Double");
    Assert.assertEquals(enumVar.datatypeWithEnum, "Name");
    Assert.assertEquals(enumVar.name, "name");
    Assert.assertEquals(enumVar.defaultValue, "._100");
    Assert.assertEquals(enumVar.baseType, "Double");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example #19
Source File: Swift5ModelEnumTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a java model with an string enum and a default value")
public void convertStringDefaultValueTest() {
    final StringSchema enumSchema = new StringSchema();
    enumSchema.setEnum(Arrays.asList("VALUE1", "VALUE2", "VALUE3"));
    enumSchema.setDefault("VALUE2");
    final Schema model = new Schema().type("object").addProperties("name", enumSchema);

    final DefaultCodegen codegen = new Swift5ClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty enumVar = cm.vars.get(0);
    Assert.assertEquals(enumVar.baseName, "name");
    Assert.assertEquals(enumVar.dataType, "String");
    Assert.assertEquals(enumVar.datatypeWithEnum, "Name");
    Assert.assertEquals(enumVar.name, "name");
    Assert.assertEquals(enumVar.defaultValue, ".value2");
    Assert.assertEquals(enumVar.baseType, "String");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example #20
Source File: KotlinClientCodegenModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with array property to default kotlin.Array")
public void arrayPropertyTest() {
    final Schema model = getArrayTestSchema();

    final DefaultCodegen codegen = new KotlinClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel generated = codegen.fromModel("sample", model);

    Assert.assertEquals(generated.name, "sample");
    Assert.assertEquals(generated.classname, "Sample");
    Assert.assertEquals(generated.description, "a sample model");
    Assert.assertEquals(generated.vars.size(), 2);

    final CodegenProperty property = generated.vars.get(1);
    Assert.assertEquals(property.baseName, "examples");
    Assert.assertEquals(property.getter, "getExamples");
    Assert.assertEquals(property.setter, "setExamples");
    Assert.assertEquals(property.dataType, "kotlin.Array<kotlin.String>");
    Assert.assertEquals(property.name, "examples");
    Assert.assertEquals(property.defaultValue, null);
    Assert.assertEquals(property.baseType, "kotlin.Array");
    Assert.assertEquals(property.containerType, "array");
    Assert.assertFalse(property.required);
    Assert.assertTrue(property.isContainer);
}
 
Example #21
Source File: KotlinClientCodegenModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a simple model: date java8-localdatetime")
public void selectDateLibraryAsJava8LocalDateTime() {
    final Schema schema = getSimpleSchema();
    final KotlinClientCodegen codegen = new KotlinClientCodegen();
    String value = KotlinClientCodegen.DateLibrary.JAVA8_LOCALDATETIME.value;
    Assert.assertEquals(value, "java8-localdatetime");
    codegen.setDateLibrary(KotlinClientCodegen.DateLibrary.JAVA8_LOCALDATETIME.value);
    codegen.processOpts();

    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    final CodegenProperty property3 = cm.vars.get(2);
    Assert.assertEquals(property3.baseName, "createdAt");
    Assert.assertEquals(property3.dataType, "java.time.LocalDateTime");
    Assert.assertEquals(property3.name, "createdAt");
    Assert.assertEquals(property3.defaultValue, null);
    Assert.assertEquals(property3.baseType, "java.time.LocalDateTime");
    Assert.assertFalse(property3.hasMore);
    Assert.assertFalse(property3.required);
    Assert.assertFalse(property3.isContainer);
}
 
Example #22
Source File: KotlinClientCodegenModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a simple model: date java8")
public void selectDateLibraryAsJava8() {
    final Schema schema = getSimpleSchema();
    final KotlinClientCodegen codegen = new KotlinClientCodegen();
    codegen.setDateLibrary(KotlinClientCodegen.DateLibrary.JAVA8.value);
    codegen.processOpts();

    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    final CodegenProperty property3 = cm.vars.get(2);
    Assert.assertEquals(property3.baseName, "createdAt");
    Assert.assertEquals(property3.dataType, "java.time.OffsetDateTime");
    Assert.assertEquals(property3.name, "createdAt");
    Assert.assertEquals(property3.defaultValue, null);
    Assert.assertEquals(property3.baseType, "java.time.OffsetDateTime");
    Assert.assertFalse(property3.hasMore);
    Assert.assertFalse(property3.required);
    Assert.assertFalse(property3.isContainer);
}
 
Example #23
Source File: TypeScriptAngularModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with a name starting with decimal")
public void beginDecimalNameTest() {
    final Schema schema = new Schema()
            .description("a model with a name starting with decimal")
            .addProperties("1list", new StringSchema())
            .addRequiredItem("1list");
    final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property = cm.vars.get(0);
    Assert.assertEquals(property.baseName, "1list");
    Assert.assertEquals(property.dataType, "string");
    Assert.assertEquals(property.name, "_1list");
    Assert.assertEquals(property.defaultValue, "undefined");
    Assert.assertEquals(property.baseType, "string");
    Assert.assertFalse(property.hasMore);
    Assert.assertTrue(property.required);
    Assert.assertFalse(property.isContainer);
}
 
Example #24
Source File: DartDioModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with complex property")
public void complexPropertyTest() {
    final Schema model = new Schema()
            .description("a sample model")
            .addProperties("children", new Schema().$ref("#/definitions/Children"));
    final DefaultCodegen codegen = new DartDioClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "children");
    Assert.assertEquals(property1.dataType, "Children");
    Assert.assertEquals(property1.name, "children");
    Assert.assertEquals(property1.baseType, "Children");
    Assert.assertFalse(property1.required);
    Assert.assertFalse(property1.isContainer);
}
 
Example #25
Source File: DartDioModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with complex list property")
public void complexListProperty() {
    final Schema model = new Schema()
            .description("a sample model")
            .addProperties("children", new ArraySchema()
                    .items(new Schema().$ref("#/definitions/Children")));
    final DefaultCodegen codegen = new DartDioClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "children");
    Assert.assertEquals(property1.dataType, "BuiltList<Children>");
    Assert.assertEquals(property1.name, "children");
    Assert.assertEquals(property1.baseType, "BuiltList");
    Assert.assertEquals(property1.containerType, "array");
    Assert.assertFalse(property1.required);
    Assert.assertTrue(property1.isContainer);
}
 
Example #26
Source File: KotlinClientCodegenModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a simple model: date string")
public void selectDateLibraryAsString() {
    final Schema schema = getSimpleSchema();
    final KotlinClientCodegen codegen = new KotlinClientCodegen();
    codegen.setDateLibrary(KotlinClientCodegen.DateLibrary.STRING.value);
    codegen.processOpts();

    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    final CodegenProperty property3 = cm.vars.get(2);
    Assert.assertEquals(property3.baseName, "createdAt");
    Assert.assertEquals(property3.dataType, "kotlin.String");
    Assert.assertEquals(property3.name, "createdAt");
    Assert.assertEquals(property3.defaultValue, null);
    Assert.assertEquals(property3.baseType, "kotlin.String");
    Assert.assertFalse(property3.hasMore);
    Assert.assertFalse(property3.required);
    Assert.assertFalse(property3.isContainer);
}
 
Example #27
Source File: KotlinClientCodegenModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a simple model: threetenbp-localdatetime")
public void selectDateLibraryAsThreetenbpLocalDateTime() {
    final Schema schema = getSimpleSchema();
    final KotlinClientCodegen codegen = new KotlinClientCodegen();
    String value = KotlinClientCodegen.DateLibrary.THREETENBP_LOCALDATETIME.value;
    Assert.assertEquals(value, "threetenbp-localdatetime");
    codegen.setDateLibrary(KotlinClientCodegen.DateLibrary.THREETENBP_LOCALDATETIME.value);
    codegen.processOpts();

    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    final CodegenProperty property3 = cm.vars.get(2);
    Assert.assertEquals(property3.baseName, "createdAt");
    Assert.assertEquals(property3.dataType, "org.threeten.bp.LocalDateTime");
    Assert.assertEquals(property3.name, "createdAt");
    Assert.assertEquals(property3.defaultValue, null);
    Assert.assertEquals(property3.baseType, "org.threeten.bp.LocalDateTime");
    Assert.assertFalse(property3.hasMore);
    Assert.assertFalse(property3.required);
    Assert.assertFalse(property3.isContainer);
}
 
Example #28
Source File: TypeScriptAngularJsModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with complex property")
public void complexPropertyTest() {
    final Schema schema = new Schema()
            .description("a sample model")
            .addProperties("children", new Schema().$ref("#/definitions/Children"));
    final DefaultCodegen codegen = new TypeScriptAngularJsClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", schema);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", schema);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "children");
    Assert.assertEquals(property1.dataType, "models.Children");
    Assert.assertEquals(property1.name, "children");
    Assert.assertEquals(property1.defaultValue, "undefined");
    Assert.assertEquals(property1.baseType, "models.Children");
    Assert.assertFalse(property1.required);
}
 
Example #29
Source File: GoModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with complex property")
public void complexPropertyTest() {
    final Schema model = new Schema()
            .description("a sample model")
            .addProperties("children", new Schema().$ref("#/definitions/Children"));
    final DefaultCodegen codegen = new GoClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "children");
    Assert.assertEquals(property1.dataType, "Children");
    Assert.assertEquals(property1.name, "Children");
    Assert.assertEquals(property1.baseType, "Children");
    Assert.assertFalse(property1.required);
}
 
Example #30
Source File: GoModelTest.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
@Test(description = "convert a model with complex list property")
public void complexListProperty() {
    final Schema model = new Schema()
            .description("a sample model")
            .addProperties("children", new ArraySchema()
                    .items(new Schema().$ref("#/definitions/Children")));
    final DefaultCodegen codegen = new GoClientCodegen();
    OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("sample", model);
    codegen.setOpenAPI(openAPI);
    final CodegenModel cm = codegen.fromModel("sample", model);

    Assert.assertEquals(cm.name, "sample");
    Assert.assertEquals(cm.classname, "Sample");
    Assert.assertEquals(cm.description, "a sample model");
    Assert.assertEquals(cm.vars.size(), 1);

    final CodegenProperty property1 = cm.vars.get(0);
    Assert.assertEquals(property1.baseName, "children");
    Assert.assertEquals(property1.dataType, "[]Children");
    Assert.assertEquals(property1.name, "Children");
    Assert.assertEquals(property1.baseType, "array");
    Assert.assertEquals(property1.containerType, "array");
    Assert.assertFalse(property1.required);
    Assert.assertTrue(property1.isContainer);
}