Skip to content

Commit

Permalink
update samples and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mosesonline committed Jun 17, 2024
1 parent ea9d8b8 commit 3b1a057
Show file tree
Hide file tree
Showing 273 changed files with 582 additions and 582 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@ public class AbstractJavaCodegenTest {
"3_0/mapSchemas", TestUtils.parseFlattenSpec("src/test/resources/3_0/mapSchemas.yaml"),
"3_0/spring/date-time-parameter-types-for-testing", TestUtils.parseFlattenSpec("src/test/resources/3_0/spring/date-time-parameter-types-for-testing.yml")
);

private AbstractJavaCodegen codegen;

/**
* In TEST-NG, test class (and its fields) is only constructed once (vs. for every test in Jupiter),
* using @BeforeMethod to have a fresh codegen mock for each test
*/
@BeforeMethod void mockAbstractCodegen() {
codegen = Mockito.mock(
AbstractJavaCodegen.class, Mockito.withSettings().defaultAnswer(Answers.CALLS_REAL_METHODS).useConstructor()
);
);
}

@Test
Expand Down Expand Up @@ -124,7 +124,7 @@ public void testPreprocessOpenApiIncludeAllMediaTypesInAcceptHeader() {
@Test
public void testPreprocessOpenAPINumVersion() {
final OpenAPI openAPIOtherNumVersion = TestUtils.parseFlattenSpec("src/test/resources/2_0/duplicateOperationIds.yaml");

codegen.preprocessOpenAPI(openAPIOtherNumVersion);

Assert.assertEquals(codegen.getArtifactVersion(), openAPIOtherNumVersion.getInfo().getVersion());
Expand Down Expand Up @@ -156,7 +156,7 @@ public void convertVarNameWithCaml() {
Assert.assertEquals(codegen.toVarName("$name"), "$Name");
Assert.assertEquals(codegen.toVarName("1AAaa"), "_1AAaa");
}

@Test
public void convertModelName() {
Assert.assertEquals(codegen.toModelName("name"), "Name");
Expand Down Expand Up @@ -399,7 +399,7 @@ public void defaultVersionTest() {
codegen.setArtifactVersion(null);
OpenAPI api = TestUtils.createOpenAPI();
api.getInfo().setVersion(null);

codegen.processOpts();
codegen.preprocessOpenAPI(api);

Expand All @@ -412,7 +412,7 @@ public void snapshotVersionTest() {
codegen.additionalProperties().put("snapshotVersion", "true");
OpenAPI api = TestUtils.createOpenAPI();
api.getInfo().setVersion(null);

codegen.processOpts();
codegen.preprocessOpenAPI(api);

Expand All @@ -425,7 +425,7 @@ public void snapshotVersionOpenAPITest() {
codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, "true");
OpenAPI api = TestUtils.createOpenAPI();
api.getInfo().setVersion("2.0");

codegen.processOpts();
codegen.preprocessOpenAPI(api);

Expand Down Expand Up @@ -484,7 +484,7 @@ public void snapshotVersionAlreadySnapshotTest() {

codegen.processOpts();
codegen.preprocessOpenAPI(TestUtils.createOpenAPI());

Assert.assertEquals(codegen.getArtifactVersion(), "4.1.2-SNAPSHOT");
}

Expand Down Expand Up @@ -537,11 +537,11 @@ public void toDefaultValueTest() {

ModelUtils.setGenerateAliasAsModel(false);
defaultValue = codegen.toDefaultValue(codegen.fromProperty("", schema), schema);
Assert.assertEquals(defaultValue, "new ArrayList<>()");
Assert.assertNull(defaultValue);

ModelUtils.setGenerateAliasAsModel(true);
defaultValue = codegen.toDefaultValue(codegen.fromProperty("", schema), schema);
Assert.assertEquals(defaultValue, "new ArrayList<>()");
Assert.assertNull(defaultValue);

// Create a map schema with additionalProperties type set to array alias
schema = new MapSchema().additionalProperties(new Schema<>().$ref("#/components/schemas/NestedArray"));
Expand Down Expand Up @@ -623,7 +623,7 @@ public void getTypeDeclarationGivenSchemaMappingTest() {
codegen.schemaMapping().put("MyStringType", "com.example.foo");
codegen.setOpenAPI(new OpenAPI().components(new Components().addSchemas("MyStringType", new StringSchema())));
Schema<?> schema = new ArraySchema().items(new Schema<>().$ref("#/components/schemas/MyStringType"));

String defaultValue = codegen.getTypeDeclaration(schema);

Assert.assertEquals(defaultValue, "List<com.example.foo>");
Expand Down Expand Up @@ -678,16 +678,16 @@ public void getTypeDeclarationTest() {
@Test
public void processOptsBooleanTrueFromString() {
codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, "true");

codegen.preprocessOpenAPI(FLATTENED_SPEC.get("3_0/petstore"));

Assert.assertTrue((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION));
}

@Test
public void processOptsBooleanTrueFromBoolean() {
codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, true);

codegen.preprocessOpenAPI(FLATTENED_SPEC.get("3_0/petstore"));

Assert.assertTrue((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION));
Expand All @@ -696,7 +696,7 @@ public void processOptsBooleanTrueFromBoolean() {
@Test
public void processOptsBooleanFalseFromString() {
codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, "false");

codegen.preprocessOpenAPI(FLATTENED_SPEC.get("3_0/petstore"));

Assert.assertFalse((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION));
Expand All @@ -705,16 +705,16 @@ public void processOptsBooleanFalseFromString() {
@Test
public void processOptsBooleanFalseFromBoolean() {
codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, false);

codegen.preprocessOpenAPI(FLATTENED_SPEC.get("3_0/petstore"));

Assert.assertFalse((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION));
}

@Test
public void processOptsBooleanFalseFromGarbage() {
codegen.additionalProperties().put(CodegenConstants.SNAPSHOT_VERSION, "blibb");

codegen.preprocessOpenAPI(FLATTENED_SPEC.get("3_0/petstore"));

Assert.assertFalse((boolean) codegen.additionalProperties().get(CodegenConstants.SNAPSHOT_VERSION));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void converterInArrayTest() {
Assert.assertEquals(enumVar.dataType, "List<String>");
Assert.assertEquals(enumVar.datatypeWithEnum, "List<NameEnum>");
Assert.assertEquals(enumVar.name, "name");
Assert.assertEquals(enumVar.defaultValue, "new ArrayList<>()");
Assert.assertEquals(enumVar.defaultValue, null);
Assert.assertEquals(enumVar.baseType, "List");
Assert.assertTrue(enumVar.isEnum);

Expand Down Expand Up @@ -108,7 +108,7 @@ public void converterInArrayInArrayTest() {
Assert.assertEquals(enumVar.dataType, "List<List<String>>");
Assert.assertEquals(enumVar.datatypeWithEnum, "List<List<NameEnum>>");
Assert.assertEquals(enumVar.name, "name");
Assert.assertEquals(enumVar.defaultValue, "new ArrayList<>()");
Assert.assertEquals(enumVar.defaultValue, null);
Assert.assertEquals(enumVar.baseType, "List");
Assert.assertTrue(enumVar.isEnum);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void listPropertyTest() {
Assert.assertEquals(property.setter, "setUrls");
Assert.assertEquals(property.dataType, "List<String>");
Assert.assertEquals(property.name, "urls");
Assert.assertEquals(property.defaultValue, "new ArrayList<>()");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "List");
Assert.assertEquals(property.containerType, "array");
Assert.assertFalse(property.required);
Expand Down Expand Up @@ -164,7 +164,7 @@ public void setPropertyTest() {
Assert.assertEquals(property.setter, "setUrls");
Assert.assertEquals(property.dataType, "Set<String>");
Assert.assertEquals(property.name, "urls");
Assert.assertEquals(property.defaultValue, "new LinkedHashSet<>()");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "Set");
Assert.assertEquals(property.containerType, "set");
Assert.assertFalse(property.required);
Expand Down Expand Up @@ -250,7 +250,7 @@ public void list2DPropertyTest() {
Assert.assertEquals(property.setter, "setList2D");
Assert.assertEquals(property.dataType, "List<List<Pet>>");
Assert.assertEquals(property.name, "list2D");
Assert.assertEquals(property.defaultValue, "new ArrayList<>()");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "List");
Assert.assertEquals(property.containerType, "array");
Assert.assertFalse(property.required);
Expand Down Expand Up @@ -335,7 +335,7 @@ public void complexListPropertyTest() {
Assert.assertEquals(property.setter, "setChildren");
Assert.assertEquals(property.dataType, "List<Children>");
Assert.assertEquals(property.name, "children");
Assert.assertEquals(property.defaultValue, "new ArrayList<>()");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "List");
Assert.assertEquals(property.containerType, "array");
Assert.assertFalse(property.required);
Expand Down Expand Up @@ -398,7 +398,7 @@ public void complexArrayPropertyTest() {
Assert.assertEquals(property.setter, "setChildren");
Assert.assertEquals(property.dataType, "List<Children>");
Assert.assertEquals(property.name, "children");
Assert.assertEquals(property.defaultValue, "new ArrayList<>()");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "List");
Assert.assertEquals(property.containerType, "array");
Assert.assertFalse(property.required);
Expand Down Expand Up @@ -431,7 +431,7 @@ public void complexSetPropertyTest() {
Assert.assertEquals(property.setter, "setChildren");
Assert.assertEquals(property.dataType, "Set<Children>");
Assert.assertEquals(property.name, "children");
Assert.assertEquals(property.defaultValue, "new LinkedHashSet<>()");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "Set");
Assert.assertEquals(property.containerType, "set");
Assert.assertFalse(property.required);
Expand Down Expand Up @@ -468,7 +468,7 @@ public void arrayModelWithItemNameTest() {
Assert.assertEquals(property.setter, "setChildren");
Assert.assertEquals(property.dataType, "List<Child>");
Assert.assertEquals(property.name, "children");
Assert.assertEquals(property.defaultValue, "new ArrayList<>()");
Assert.assertEquals(property.defaultValue, null);
Assert.assertEquals(property.baseType, "List");
Assert.assertEquals(property.containerType, "array");
Assert.assertFalse(property.required);
Expand Down Expand Up @@ -976,7 +976,7 @@ public void modelWithWrappedXmlTest() {
Assert.assertEquals(property2.setter, "setArray");
Assert.assertEquals(property2.dataType, "List<String>");
Assert.assertEquals(property2.name, "array");
Assert.assertEquals(property2.defaultValue, "new ArrayList<>()");
Assert.assertEquals(property2.defaultValue, null);
Assert.assertEquals(property2.baseType, "List");
Assert.assertTrue(property2.isContainer);
Assert.assertTrue(property2.isXmlWrapped);
Expand Down Expand Up @@ -1131,14 +1131,14 @@ public void stringPropertyTest() {
Assert.assertEquals(cp.maxLength, Integer.valueOf(10));
Assert.assertEquals(cp.pattern, "^[A-Z]+$");
}

@Test(description = "convert string property with password format")
public void stringPropertyPasswordFormatTest() {
OpenAPI openAPI = TestUtils.createOpenAPI();
final Schema property = new StringSchema().format("password");
final DefaultCodegen codegen = new JavaClientCodegen();
codegen.setOpenAPI(openAPI);

final CodegenProperty cp = codegen.fromProperty("somePropertyWithPasswordFormat", property);
Assert.assertEquals(cp.isPassword, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4762,7 +4762,7 @@ public void optionalListShouldBeEmpty() throws IOException {
.collect(Collectors.toMap(File::getName, Function.identity()));

JavaFileAssert.assertThat(files.get("PetDto.java"))
.fileContains("private List<@Valid TagDto> tags = new ArrayList<>();")
.fileContains("private List<@Valid TagDto> tags;")
.fileContains("private List<String> photoUrls = new ArrayList<>();");

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static ArrayStringEnumDefaultEnum fromValue(String value) {
private List<Integer> arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3));

public static final String JSON_PROPERTY_ARRAY_STRING = "array_string";
private List<String> arrayString = new ArrayList<>();
private List<String> arrayString;

public static final String JSON_PROPERTY_ARRAY_STRING_NULLABLE = "array_string_nullable";
private JsonNullable<List<String>> arrayStringNullable = JsonNullable.<List<String>>undefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Pet {
private List<String> photoUrls = new ArrayList<>();

public static final String JSON_PROPERTY_TAGS = "tags";
private List<Tag> tags = new ArrayList<>();
private List<Tag> tags;

/**
* pet status in the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.7.0-SNAPSHOT")
public class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter {
public static final String JSON_PROPERTY_VALUES = "values";
private List<String> values = new ArrayList<>();
private List<String> values;

public TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static ArrayStringEnumDefaultEnum fromValue(String value) {
private List<Integer> arrayIntegerDefault = new ArrayList<>(Arrays.asList(1, 3));

public static final String JSON_PROPERTY_ARRAY_STRING = "array_string";
private List<String> arrayString = new ArrayList<>();
private List<String> arrayString;

public static final String JSON_PROPERTY_ARRAY_STRING_NULLABLE = "array_string_nullable";
private JsonNullable<List<String>> arrayStringNullable = JsonNullable.<List<String>>undefined();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class Pet {
private List<String> photoUrls = new ArrayList<>();

public static final String JSON_PROPERTY_TAGS = "tags";
private List<Tag> tags = new ArrayList<>();
private List<Tag> tags;

/**
* pet status in the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.7.0-SNAPSHOT")
public class TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter {
public static final String JSON_PROPERTY_VALUES = "values";
private List<String> values = new ArrayList<>();
private List<String> values;

public TestQueryStyleFormExplodeTrueArrayStringQueryObjectParameter() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class NewPet {

public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
private List<Tag> tags = new ArrayList<>();
private List<Tag> tags;

/**
* pet status in the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public class NullableClass {

public static final String SERIALIZED_NAME_ARRAY_ITEMS_NULLABLE = "array_items_nullable";
@SerializedName(SERIALIZED_NAME_ARRAY_ITEMS_NULLABLE)
private List<Object> arrayItemsNullable = new ArrayList<>();
private List<Object> arrayItemsNullable;

public static final String SERIALIZED_NAME_OBJECT_NULLABLE_PROP = "object_nullable_prop";
@SerializedName(SERIALIZED_NAME_OBJECT_NULLABLE_PROP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class ObjectWithDeprecatedFields {
public static final String SERIALIZED_NAME_BARS = "bars";
@Deprecated
@SerializedName(SERIALIZED_NAME_BARS)
private List<String> bars = new ArrayList<>();
private List<String> bars;

public ObjectWithDeprecatedFields() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class Pet {

public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
private List<Tag> tags = new ArrayList<>();
private List<Tag> tags;

/**
* pet status in the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class PetComposition {

public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
private List<Tag> tags = new ArrayList<>();
private List<Tag> tags;

/**
* pet status in the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class PetRef {

public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
private List<Tag> tags = new ArrayList<>();
private List<Tag> tags;

/**
* pet status in the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class PetUsingAllOf {

public static final String SERIALIZED_NAME_TAGS = "tags";
@SerializedName(SERIALIZED_NAME_TAGS)
private List<Tag> tags = new ArrayList<>();
private List<Tag> tags;

/**
* pet status in the store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.7.0-SNAPSHOT")
public class ArrayOfArrayOfNumberOnly {
public static final String JSON_PROPERTY_ARRAY_ARRAY_NUMBER = "ArrayArrayNumber";
private List<List<BigDecimal>> arrayArrayNumber = new ArrayList<>();
private List<List<BigDecimal>> arrayArrayNumber;

public ArrayOfArrayOfNumberOnly() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.7.0-SNAPSHOT")
public class ArrayOfNumberOnly {
public static final String JSON_PROPERTY_ARRAY_NUMBER = "ArrayNumber";
private List<BigDecimal> arrayNumber = new ArrayList<>();
private List<BigDecimal> arrayNumber;

public ArrayOfNumberOnly() {
}
Expand Down
Loading

0 comments on commit 3b1a057

Please sign in to comment.