Java Code Examples for io.swagger.v3.oas.models.media.StringSchema#setDefault()

The following examples show how to use io.swagger.v3.oas.models.media.StringSchema#setDefault() . 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 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 2
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 3
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 4
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 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 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, "._2nd");
    Assert.assertEquals(enumVar.baseType, "String");
    Assert.assertTrue(enumVar.isEnum);
}
 
Example 5
Source File: PythonClientCodegenTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Test(description = "test single quotes escape")
public void testSingleQuotes() {
    final PythonClientCodegen codegen = new PythonClientCodegen();
    StringSchema schema = new StringSchema();
    schema.setDefault("Text containing 'single' quote");
    String defaultValue = codegen.toDefaultValue(schema);
    Assert.assertEquals("'Text containing \'single\' quote'", defaultValue);
}