forked from loafle/openapi-generator-original
add ts tests (#337)
This commit is contained in:
parent
86f9686f29
commit
50163b4939
@ -0,0 +1,57 @@
|
|||||||
|
package org.openapitools.codegen;
|
||||||
|
|
||||||
|
import static org.openapitools.codegen.testutils.AssertFile.assertPathEqualsRecursively;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.parser.OpenAPIParser;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
import org.testng.reporters.Files;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.testutils.IntegrationTestPathsConfig;
|
||||||
|
|
||||||
|
public abstract class AbstractIntegrationTest {
|
||||||
|
|
||||||
|
protected abstract IntegrationTestPathsConfig getIntegrationTestPathsConfig();
|
||||||
|
|
||||||
|
protected abstract CodegenConfig getCodegenConfig();
|
||||||
|
|
||||||
|
protected abstract Map<String, String> configProperties();
|
||||||
|
|
||||||
|
protected Boolean generateMetadata = true;
|
||||||
|
|
||||||
|
protected Map<String, String> systemPropertyOverrides = new HashMap<>();
|
||||||
|
|
||||||
|
// @wing328: ignore for the time being until we fix the error with the integration test
|
||||||
|
@Test(enabled = false)
|
||||||
|
public void generatesCorrectDirectoryStructure() throws IOException {
|
||||||
|
DefaultGenerator codeGen = new DefaultGenerator();
|
||||||
|
codeGen.setGenerateMetadata(generateMetadata);
|
||||||
|
for (Map.Entry<String, String> propertyOverride : systemPropertyOverrides.entrySet()) {
|
||||||
|
codeGen.setGeneratorPropertyDefault(propertyOverride.getKey(), propertyOverride.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
IntegrationTestPathsConfig integrationTestPathsConfig = getIntegrationTestPathsConfig();
|
||||||
|
|
||||||
|
String specContent = Files.readFile(integrationTestPathsConfig.getSpecPath().toFile());
|
||||||
|
OpenAPI openAPI = new OpenAPIParser().readContents(specContent, null, null).getOpenAPI();
|
||||||
|
|
||||||
|
|
||||||
|
CodegenConfig codegenConfig = getCodegenConfig();
|
||||||
|
codegenConfig.setOutputDir(integrationTestPathsConfig.getOutputPath().toString());
|
||||||
|
codegenConfig.setIgnoreFilePathOverride(integrationTestPathsConfig.getIgnoreFilePath().toFile().toString());
|
||||||
|
ClientOpts clientOpts = new ClientOpts();
|
||||||
|
clientOpts.setProperties(configProperties());
|
||||||
|
ClientOptInput opts = new ClientOptInput()
|
||||||
|
.config(codegenConfig)
|
||||||
|
.opts(clientOpts)
|
||||||
|
.openAPI(openAPI);
|
||||||
|
|
||||||
|
codeGen.opts(opts).generate();
|
||||||
|
|
||||||
|
assertPathEqualsRecursively(integrationTestPathsConfig.getExpectedPath(), integrationTestPathsConfig.getOutputPath());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package org.openapitools.codegen.options;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
|
||||||
|
|
||||||
|
public class TypeScriptAngularClientOptionsProvider implements OptionsProvider {
|
||||||
|
public static final String SUPPORTS_ES6_VALUE = "false";
|
||||||
|
public static final String SORT_PARAMS_VALUE = "false";
|
||||||
|
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||||
|
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
|
||||||
|
private static final String NMP_NAME = "npmName";
|
||||||
|
private static final String NMP_VERSION = "1.1.2";
|
||||||
|
private static final String NPM_REPOSITORY = "https://registry.npmjs.org";
|
||||||
|
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||||
|
public static final String NG_VERSION = "2";
|
||||||
|
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLanguage() {
|
||||||
|
return "typescript-angular";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> createOptions() {
|
||||||
|
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||||
|
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
|
||||||
|
.put(CodegenConstants.SUPPORTS_ES6, SUPPORTS_ES6_VALUE)
|
||||||
|
.put(TypeScriptAngularClientCodegen.NPM_NAME, NMP_NAME)
|
||||||
|
.put(TypeScriptAngularClientCodegen.NPM_VERSION, NMP_VERSION)
|
||||||
|
.put(TypeScriptAngularClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
|
||||||
|
.put(TypeScriptAngularClientCodegen.WITH_INTERFACES, Boolean.FALSE.toString())
|
||||||
|
.put(TypeScriptAngularClientCodegen.TAGGED_UNIONS, Boolean.FALSE.toString())
|
||||||
|
.put(TypeScriptAngularClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
|
||||||
|
.put(TypeScriptAngularClientCodegen.NG_VERSION, NG_VERSION)
|
||||||
|
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
|
||||||
|
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package org.openapitools.codegen.options;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TypeScriptAngularJsClientOptionsProvider implements OptionsProvider {
|
||||||
|
public static final String SUPPORTS_ES6_VALUE = "false";
|
||||||
|
public static final String SORT_PARAMS_VALUE = "false";
|
||||||
|
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||||
|
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
|
||||||
|
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||||
|
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLanguage() {
|
||||||
|
return "typescript-angularjs";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> createOptions() {
|
||||||
|
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||||
|
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.SUPPORTS_ES6, SUPPORTS_ES6_VALUE)
|
||||||
|
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
|
||||||
|
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
|
||||||
|
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package org.openapitools.codegen.options;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAureliaClientCodegen;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TypeScriptAureliaClientOptionsProvider implements OptionsProvider {
|
||||||
|
public static final String SORT_PARAMS_VALUE = "false";
|
||||||
|
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||||
|
public static final Boolean SUPPORTS_ES6_VALUE = false;
|
||||||
|
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
|
||||||
|
private static final String NMP_NAME = "npmName";
|
||||||
|
private static final String NMP_VERSION = "1.0.0";
|
||||||
|
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||||
|
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLanguage() {
|
||||||
|
return "typescript-aurelia";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> createOptions() {
|
||||||
|
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||||
|
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
|
||||||
|
.put(CodegenConstants.SUPPORTS_ES6, String.valueOf(SUPPORTS_ES6_VALUE))
|
||||||
|
.put(TypeScriptAureliaClientCodegen.NPM_NAME, NMP_NAME)
|
||||||
|
.put(TypeScriptAureliaClientCodegen.NPM_VERSION, NMP_VERSION)
|
||||||
|
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
|
||||||
|
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package org.openapitools.codegen.options;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptFetchClientCodegen;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class TypeScriptFetchClientOptionsProvider implements OptionsProvider {
|
||||||
|
public static final String SORT_PARAMS_VALUE = "false";
|
||||||
|
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||||
|
public static final Boolean SUPPORTS_ES6_VALUE = false;
|
||||||
|
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
|
||||||
|
private static final String NMP_NAME = "npmName";
|
||||||
|
private static final String NMP_VERSION = "1.0.0";
|
||||||
|
private static final String NPM_REPOSITORY = "https://registry.npmjs.org";
|
||||||
|
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||||
|
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLanguage() {
|
||||||
|
return "typescript-fetch";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> createOptions() {
|
||||||
|
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||||
|
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
|
||||||
|
.put(CodegenConstants.SUPPORTS_ES6, String.valueOf(SUPPORTS_ES6_VALUE))
|
||||||
|
.put(TypeScriptFetchClientCodegen.NPM_NAME, NMP_NAME)
|
||||||
|
.put(TypeScriptFetchClientCodegen.NPM_VERSION, NMP_VERSION)
|
||||||
|
.put(TypeScriptFetchClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
|
||||||
|
.put(TypeScriptFetchClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
|
||||||
|
.put(TypeScriptFetchClientCodegen.WITH_INTERFACES, Boolean.FALSE.toString())
|
||||||
|
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
|
||||||
|
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package org.openapitools.codegen.options;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
|
||||||
|
|
||||||
|
|
||||||
|
public class TypeScriptNodeClientOptionsProvider implements OptionsProvider {
|
||||||
|
public static final String SUPPORTS_ES6_VALUE = "false";
|
||||||
|
public static final String SORT_PARAMS_VALUE = "false";
|
||||||
|
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
|
||||||
|
public static final String MODEL_PROPERTY_NAMING_VALUE = "camelCase";
|
||||||
|
public static final String NMP_NAME = "npmName";
|
||||||
|
public static final String NMP_VERSION = "1.1.2";
|
||||||
|
public static final String NPM_REPOSITORY = "https://registry.npmjs.org";
|
||||||
|
public static final String ALLOW_UNICODE_IDENTIFIERS_VALUE = "false";
|
||||||
|
public static final String PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = "true";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getLanguage() {
|
||||||
|
return "typescript-node";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> createOptions() {
|
||||||
|
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
|
||||||
|
return builder.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.SUPPORTS_ES6, SUPPORTS_ES6_VALUE)
|
||||||
|
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
|
||||||
|
.put(CodegenConstants.MODEL_PROPERTY_NAMING, MODEL_PROPERTY_NAMING_VALUE)
|
||||||
|
.put(TypeScriptAngularClientCodegen.NPM_NAME, NMP_NAME)
|
||||||
|
.put(TypeScriptAngularClientCodegen.NPM_VERSION, NMP_VERSION)
|
||||||
|
.put(TypeScriptAngularClientCodegen.SNAPSHOT, Boolean.FALSE.toString())
|
||||||
|
.put(TypeScriptAngularClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY)
|
||||||
|
.put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE)
|
||||||
|
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isServer() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,13 @@
|
|||||||
package org.openapitools.codegen.swift4;
|
package org.openapitools.codegen.swift4;
|
||||||
|
|
||||||
|
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||||
import org.openapitools.codegen.CodegenConstants;
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
import org.openapitools.codegen.CodegenOperation;
|
import org.openapitools.codegen.CodegenOperation;
|
||||||
import org.openapitools.codegen.DefaultCodegen;
|
import org.openapitools.codegen.DefaultCodegen;
|
||||||
import org.openapitools.codegen.languages.Swift4Codegen;
|
import org.openapitools.codegen.languages.Swift4Codegen;
|
||||||
import io.swagger.v3.oas.models.OpenAPI;
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
import io.swagger.v3.oas.models.Operation;
|
import io.swagger.v3.oas.models.Operation;
|
||||||
import io.swagger.v3.parser.OpenAPIV3Parser;
|
import io.swagger.parser.OpenAPIParser;
|
||||||
import org.testng.Assert;
|
import org.testng.Assert;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ public class Swift4CodegenTest {
|
|||||||
public void binaryDataTest() {
|
public void binaryDataTest() {
|
||||||
// TODO update json file
|
// TODO update json file
|
||||||
|
|
||||||
final OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/2_0/binaryDataTest.json");
|
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/2_0/binaryDataTest.json", null, new ParseOptions()).getOpenAPI();
|
||||||
final DefaultCodegen codegen = new Swift4Codegen();
|
final DefaultCodegen codegen = new Swift4Codegen();
|
||||||
final String path = "/tests/binaryResponse";
|
final String path = "/tests/binaryResponse";
|
||||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||||
@ -90,7 +91,7 @@ public class Swift4CodegenTest {
|
|||||||
|
|
||||||
@Test(description = "returns Date when response format is date", enabled = false)
|
@Test(description = "returns Date when response format is date", enabled = false)
|
||||||
public void dateTest() {
|
public void dateTest() {
|
||||||
final OpenAPI openAPI = new OpenAPIV3Parser().read("src/test/resources/2_0/datePropertyTest.json");
|
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/2_0/datePropertyTest.json", null, new ParseOptions()).getOpenAPI();
|
||||||
final DefaultCodegen codegen = new Swift4Codegen();
|
final DefaultCodegen codegen = new Swift4Codegen();
|
||||||
final String path = "/tests/dateResponse";
|
final String path = "/tests/dateResponse";
|
||||||
final Operation p = openAPI.getPaths().get(path).getPost();
|
final Operation p = openAPI.getPaths().get(path).getPost();
|
||||||
|
@ -0,0 +1,143 @@
|
|||||||
|
package org.openapitools.codegen.testutils;
|
||||||
|
|
||||||
|
import org.testng.Assert;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
|
import java.nio.file.FileVisitor;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import difflib.Delta;
|
||||||
|
import difflib.DiffUtils;
|
||||||
|
import difflib.Patch;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.fail;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assertion for recursively testing directories.
|
||||||
|
*
|
||||||
|
* @author andreas
|
||||||
|
*/
|
||||||
|
public class AssertFile {
|
||||||
|
|
||||||
|
private AssertFile() {
|
||||||
|
throw new RuntimeException("This class should not be instantiated");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that two directories are recursively equal. If they are not, an {@link AssertionError} is thrown with the
|
||||||
|
* given message.<br/>
|
||||||
|
* There will be a textual comparison of all files under expected with all files under actual. File attributes will
|
||||||
|
* not be considered.<br/>
|
||||||
|
* Missing or additional files are considered an error.<br/>
|
||||||
|
*
|
||||||
|
* @param expected Path expected directory
|
||||||
|
* @param actual Path actual directory
|
||||||
|
*/
|
||||||
|
public static void assertPathEqualsRecursively(final Path expected, final Path actual) {
|
||||||
|
Assert.assertNotNull(expected);
|
||||||
|
Assert.assertNotNull(actual);
|
||||||
|
final Path absoluteExpected = expected.toAbsolutePath();
|
||||||
|
final Path absoluteActual = actual.toAbsolutePath();
|
||||||
|
try {
|
||||||
|
Files.walkFileTree(expected, new FileVisitor<Path>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult preVisitDirectory(Path expectedDir, BasicFileAttributes attrs) throws IOException {
|
||||||
|
Path relativeExpectedDir = absoluteExpected.relativize(expectedDir.toAbsolutePath());
|
||||||
|
Path actualDir = absoluteActual.resolve(relativeExpectedDir);
|
||||||
|
|
||||||
|
if (!Files.exists(actualDir)) {
|
||||||
|
fail(String.format("Directory '%s' is missing.", actualDir));
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] expected = expectedDir.toFile().list();
|
||||||
|
String[] actual = actualDir.toFile().list();
|
||||||
|
|
||||||
|
if (expected != null) {
|
||||||
|
Arrays.sort(expected);
|
||||||
|
}
|
||||||
|
if (actual != null) {
|
||||||
|
Arrays.sort(actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(expected,
|
||||||
|
actual,
|
||||||
|
String.format("Directory content of '%s' and '%s' differ.", expectedDir, actualDir));
|
||||||
|
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path expectedFile, BasicFileAttributes attrs) throws IOException {
|
||||||
|
Path relativeExpectedFile = absoluteExpected.relativize(expectedFile.toAbsolutePath());
|
||||||
|
Path actualFile = absoluteActual.resolve(relativeExpectedFile);
|
||||||
|
|
||||||
|
if (!Files.exists(actualFile)) {
|
||||||
|
fail(String.format("File '%s' is missing.", actualFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFilesAreEqual(expectedFile, actualFile);
|
||||||
|
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
|
||||||
|
fail(exc.getMessage());
|
||||||
|
return FileVisitResult.TERMINATE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
} catch (IOException e) {
|
||||||
|
fail(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void assertFilesAreEqual(final Path expected, final Path actual) {
|
||||||
|
|
||||||
|
if (!Files.isRegularFile(expected)) {
|
||||||
|
fail("expected: '%s' is not a readable file");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Files.isRegularFile(actual)) {
|
||||||
|
fail("actual: '%s' is not a readable file");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
List<String> expectedLines = Files.readAllLines(expected, Charset.defaultCharset());
|
||||||
|
List<String> actualLines = Files.readAllLines(actual, Charset.defaultCharset());
|
||||||
|
Patch diff = DiffUtils.diff(expectedLines, actualLines);
|
||||||
|
List<Delta> deltas = diff.getDeltas();
|
||||||
|
if (!deltas.isEmpty()) {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
stringBuilder.append("files diff:\n");
|
||||||
|
stringBuilder.append("\tfile: '").append(expected.toAbsolutePath().toString()).append("' \n");
|
||||||
|
stringBuilder.append("\tfile: '").append(actual.toAbsolutePath().toString()).append("' \n");
|
||||||
|
stringBuilder.append("\tdiffs:\n");
|
||||||
|
|
||||||
|
for (Delta delta : deltas) {
|
||||||
|
stringBuilder.append(delta.toString()).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
fail(stringBuilder.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
fail(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,39 @@
|
|||||||
|
package org.openapitools.codegen.testutils;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
public class IntegrationTestPathsConfig {
|
||||||
|
private static final Path INTEGRATION_TEST_PATH = Paths.get("target/test-classes/integrationtests").toAbsolutePath();
|
||||||
|
private final Path outputPath;
|
||||||
|
private final Path specPath;
|
||||||
|
private final Path expectedPath;
|
||||||
|
private final Path ignoreFilePath;
|
||||||
|
|
||||||
|
public IntegrationTestPathsConfig(String location) {
|
||||||
|
this(location + "-spec.json", location + "-result", location + "-expected", location + ".ignore");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegrationTestPathsConfig(String specLocation, String outputLocation, String expectedLocation, String ignoreFileLocation) {
|
||||||
|
outputPath = INTEGRATION_TEST_PATH.resolve(outputLocation);
|
||||||
|
expectedPath = INTEGRATION_TEST_PATH.resolve(expectedLocation);
|
||||||
|
specPath = INTEGRATION_TEST_PATH.resolve(specLocation);
|
||||||
|
ignoreFilePath = INTEGRATION_TEST_PATH.resolve(ignoreFileLocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path getOutputPath() {
|
||||||
|
return outputPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path getSpecPath() {
|
||||||
|
return specPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path getExpectedPath() {
|
||||||
|
return expectedPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path getIgnoreFilePath() {
|
||||||
|
return ignoreFilePath;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package org.openapitools.codegen.typescript.aurelia;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractOptionsTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAureliaClientCodegen;
|
||||||
|
import org.openapitools.codegen.options.TypeScriptAureliaClientOptionsProvider;
|
||||||
|
import mockit.Expectations;
|
||||||
|
import mockit.Tested;
|
||||||
|
|
||||||
|
public class TypeScriptAureliaClientOptionsTest extends AbstractOptionsTest {
|
||||||
|
|
||||||
|
@Tested
|
||||||
|
private TypeScriptAureliaClientCodegen clientCodegen;
|
||||||
|
|
||||||
|
public TypeScriptAureliaClientOptionsTest() {
|
||||||
|
super(new TypeScriptAureliaClientOptionsProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return clientCodegen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Override
|
||||||
|
protected void setExpectations() {
|
||||||
|
new Expectations(clientCodegen) {{
|
||||||
|
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(TypeScriptAureliaClientOptionsProvider.SORT_PARAMS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setModelPropertyNaming(TypeScriptAureliaClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setSupportsES6(TypeScriptAureliaClientOptionsProvider.SUPPORTS_ES6_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(TypeScriptAureliaClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
package org.openapitools.codegen.typescript.fetch;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractOptionsTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptFetchClientCodegen;
|
||||||
|
import org.openapitools.codegen.options.TypeScriptFetchClientOptionsProvider;
|
||||||
|
import mockit.Expectations;
|
||||||
|
import mockit.Tested;
|
||||||
|
|
||||||
|
public class TypeScriptFetchClientOptionsTest extends AbstractOptionsTest {
|
||||||
|
|
||||||
|
@Tested
|
||||||
|
private TypeScriptFetchClientCodegen clientCodegen;
|
||||||
|
|
||||||
|
public TypeScriptFetchClientOptionsTest() {
|
||||||
|
super(new TypeScriptFetchClientOptionsProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return clientCodegen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Override
|
||||||
|
protected void setExpectations() {
|
||||||
|
new Expectations(clientCodegen) {{
|
||||||
|
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(TypeScriptFetchClientOptionsProvider.SORT_PARAMS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setModelPropertyNaming(TypeScriptFetchClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setSupportsES6(TypeScriptFetchClientOptionsProvider.SUPPORTS_ES6_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(TypeScriptFetchClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,273 @@
|
|||||||
|
package org.openapitools.codegen.typescript.fetch;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import io.swagger.v3.parser.core.models.ParseOptions;
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.CodegenModel;
|
||||||
|
import org.openapitools.codegen.CodegenProperty;
|
||||||
|
import org.openapitools.codegen.DefaultCodegen;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptFetchClientCodegen;
|
||||||
|
import io.swagger.parser.OpenAPIParser;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.models.OpenAPI;
|
||||||
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.models.media.DateSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.DateTimeSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.IntegerSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import io.swagger.v3.oas.models.media.StringSchema;
|
||||||
|
import io.swagger.parser.OpenAPIParser;
|
||||||
|
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/*
|
||||||
|
import static io.swagger.codegen.CodegenConstants.IS_ENUM_EXT_NAME;
|
||||||
|
import static io.swagger.codegen.languages.helpers.ExtensionHelper.getBooleanValue;
|
||||||
|
import static io.swagger.codegen.utils.ModelUtils.updateCodegenPropertyEnum;
|
||||||
|
*/
|
||||||
|
|
||||||
|
@SuppressWarnings("static-method")
|
||||||
|
public class TypeScriptFetchModelTest {
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert a simple TypeScript Angular model")
|
||||||
|
public void simpleModelTest() {
|
||||||
|
final Schema model = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
|
||||||
|
.addProperties("name", new StringSchema())
|
||||||
|
.addProperties("createdAt", new DateTimeSchema())
|
||||||
|
.addProperties("birthDate", new DateSchema())
|
||||||
|
.addRequiredItem("id")
|
||||||
|
.addRequiredItem("name");
|
||||||
|
|
||||||
|
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
|
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(), 4);
|
||||||
|
|
||||||
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
|
Assert.assertEquals(property1.datatype, "number");
|
||||||
|
Assert.assertEquals(property1.name, "id");
|
||||||
|
Assert.assertEquals(property1.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property1.baseType, "number");
|
||||||
|
Assert.assertTrue(property1.hasMore);
|
||||||
|
Assert.assertTrue(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property2 = cm.vars.get(1);
|
||||||
|
Assert.assertEquals(property2.baseName, "name");
|
||||||
|
Assert.assertEquals(property2.datatype, "string");
|
||||||
|
Assert.assertEquals(property2.name, "name");
|
||||||
|
Assert.assertEquals(property2.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property2.baseType, "string");
|
||||||
|
Assert.assertTrue(property2.hasMore);
|
||||||
|
Assert.assertTrue(property2.required);
|
||||||
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property3 = cm.vars.get(2);
|
||||||
|
Assert.assertEquals(property3.baseName, "createdAt");
|
||||||
|
Assert.assertEquals(property3.complexType, null);
|
||||||
|
Assert.assertEquals(property3.datatype, "Date");
|
||||||
|
Assert.assertEquals(property3.name, "createdAt");
|
||||||
|
Assert.assertEquals(property3.defaultValue, "undefined");
|
||||||
|
Assert.assertTrue(property3.hasMore);
|
||||||
|
Assert.assertFalse(property3.required);
|
||||||
|
Assert.assertTrue(property3.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property4 = cm.vars.get(3);
|
||||||
|
Assert.assertEquals(property4.baseName, "birthDate");
|
||||||
|
Assert.assertEquals(property4.complexType, null);
|
||||||
|
Assert.assertEquals(property4.datatype, "string");
|
||||||
|
Assert.assertEquals(property4.name, "birthDate");
|
||||||
|
Assert.assertEquals(property4.defaultValue, "undefined");
|
||||||
|
Assert.assertFalse(property4.hasMore);
|
||||||
|
Assert.assertFalse(property4.required);
|
||||||
|
Assert.assertTrue(property4.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert a model with list property")
|
||||||
|
public void listPropertyTest() {
|
||||||
|
final Schema model = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
|
||||||
|
.addProperties("urls", new ArraySchema().items(new StringSchema()))
|
||||||
|
.addRequiredItem("id");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
|
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(), 2);
|
||||||
|
|
||||||
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
|
Assert.assertEquals(property1.datatype, "number");
|
||||||
|
Assert.assertEquals(property1.name, "id");
|
||||||
|
Assert.assertEquals(property1.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property1.baseType, "number");
|
||||||
|
Assert.assertTrue(property1.hasMore);
|
||||||
|
Assert.assertTrue(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property2 = cm.vars.get(1);
|
||||||
|
Assert.assertEquals(property2.baseName, "urls");
|
||||||
|
Assert.assertEquals(property2.datatype, "Array<string>");
|
||||||
|
Assert.assertEquals(property2.name, "urls");
|
||||||
|
Assert.assertEquals(property2.baseType, "Array");
|
||||||
|
Assert.assertFalse(property2.hasMore);
|
||||||
|
Assert.assertFalse(property2.required);
|
||||||
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with complex property", enabled = false)
|
||||||
|
public void complexPropertyTest() {
|
||||||
|
final Schema model = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("children", new Schema().$ref("#/definitions/Children"));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
|
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);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with complex list property", enabled = false)
|
||||||
|
public void complexListPropertyTest() {
|
||||||
|
final Schema model = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("children", new ArraySchema()
|
||||||
|
.items(new Schema().$ref("#/definitions/Children")));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
|
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.complexType, "Children");
|
||||||
|
Assert.assertEquals(property1.datatype, "Array<Children>");
|
||||||
|
Assert.assertEquals(property1.name, "children");
|
||||||
|
Assert.assertEquals(property1.baseType, "Array");
|
||||||
|
Assert.assertFalse(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert an array model")
|
||||||
|
public void arrayModelTest() {
|
||||||
|
final Schema model = new ArraySchema()
|
||||||
|
.items(new Schema().$ref("#/definitions/Children"))
|
||||||
|
.description("an array model");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
|
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||||
|
|
||||||
|
Assert.assertEquals(cm.name, "sample");
|
||||||
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
|
Assert.assertEquals(cm.description, "an array model");
|
||||||
|
Assert.assertEquals(cm.vars.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a map model", enabled = false)
|
||||||
|
public void mapModelTest() {
|
||||||
|
final Schema model = new Schema()
|
||||||
|
.description("a map model")
|
||||||
|
.additionalProperties(new Schema().$ref("#/definitions/Children"));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
|
final CodegenModel cm = codegen.fromModel("sample", model);
|
||||||
|
|
||||||
|
Assert.assertEquals(cm.name, "sample");
|
||||||
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
|
Assert.assertEquals(cm.description, "a map model");
|
||||||
|
Assert.assertEquals(cm.vars.size(), 0);
|
||||||
|
Assert.assertEquals(cm.imports.size(), 1);
|
||||||
|
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "test enum array model", enabled = false)
|
||||||
|
public void enumArrayMdoelTest() {
|
||||||
|
// TODO: update yaml file.
|
||||||
|
final OpenAPI openAPI = new OpenAPIParser().readLocation("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
|
final Schema schema = openAPI.getComponents().getSchemas().get("EnumArrays");
|
||||||
|
|
||||||
|
Schema property = (Schema) schema.getProperties().get("array_enum");
|
||||||
|
CodegenProperty prope = codegen.fromProperty("array_enum", property);
|
||||||
|
codegen.updateCodegenPropertyEnum(prope);
|
||||||
|
Assert.assertEquals(prope.datatypeWithEnum, "Array<ArrayEnumEnum>");
|
||||||
|
Assert.assertEquals(prope.enumName, "ArrayEnumEnum");
|
||||||
|
Assert.assertTrue(prope.isEnum);
|
||||||
|
Assert.assertEquals(prope.allowableValues.get("values"), Arrays.asList("fish", "crab"));
|
||||||
|
|
||||||
|
HashMap<String, String> fish = new HashMap<String, String>();
|
||||||
|
fish.put("name", "Fish");
|
||||||
|
fish.put("value", "'fish'");
|
||||||
|
HashMap<String, String> crab = new HashMap<String, String>();
|
||||||
|
crab.put("name", "Crab");
|
||||||
|
crab.put("value", "'crab'");
|
||||||
|
Assert.assertEquals(prope.allowableValues.get("enumVars"), Arrays.asList(fish, crab));
|
||||||
|
|
||||||
|
// assert inner items
|
||||||
|
Assert.assertEquals(prope.datatypeWithEnum, "Array<ArrayEnumEnum>");
|
||||||
|
Assert.assertEquals(prope.enumName, "ArrayEnumEnum");
|
||||||
|
Assert.assertTrue(prope.items.isEnum);
|
||||||
|
Assert.assertEquals(prope.items.allowableValues.get("values"), Arrays.asList("fish", "crab"));
|
||||||
|
Assert.assertEquals(prope.items.allowableValues.get("enumVars"), Arrays.asList(fish, crab));
|
||||||
|
|
||||||
|
//IMPORTANT: these are not final enum values, which may be further updated
|
||||||
|
//by postProcessModels
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "test enum model for values (numeric, string, etc)", enabled = false)
|
||||||
|
public void enumMdoelValueTest() {
|
||||||
|
final OpenAPI openAPI = new OpenAPIParser().readContents("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml", null, new ParseOptions()).getOpenAPI();
|
||||||
|
final DefaultCodegen codegen = new TypeScriptFetchClientCodegen();
|
||||||
|
final Schema schema = openAPI.getComponents().getSchemas().get("Enum_Test");
|
||||||
|
|
||||||
|
Schema property = (Schema) schema.getProperties().get("enum_integer");
|
||||||
|
CodegenProperty prope = codegen.fromProperty("enum_integer", property);
|
||||||
|
codegen.updateCodegenPropertyEnum(prope);
|
||||||
|
Assert.assertEquals(prope.datatypeWithEnum, "EnumIntegerEnum");
|
||||||
|
Assert.assertEquals(prope.enumName, "EnumIntegerEnum");
|
||||||
|
Assert.assertTrue(prope.isEnum);
|
||||||
|
Assert.assertFalse(prope.isContainer);
|
||||||
|
Assert.assertNull(prope.items);
|
||||||
|
Assert.assertEquals(prope.allowableValues.get("values"), Arrays.asList(1, -1));
|
||||||
|
|
||||||
|
HashMap<String, String> one = new HashMap<String, String>();
|
||||||
|
one.put("name", "NUMBER_1");
|
||||||
|
one.put("value", "1");
|
||||||
|
HashMap<String, String> minusOne = new HashMap<String, String>();
|
||||||
|
minusOne.put("name", "NUMBER_MINUS_1");
|
||||||
|
minusOne.put("value", "-1");
|
||||||
|
Assert.assertEquals(prope.allowableValues.get("enumVars"), Arrays.asList(one, minusOne));
|
||||||
|
|
||||||
|
//IMPORTANT: these are not final enum values, which may be further updated
|
||||||
|
//by postProcessModels
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptangular;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractOptionsTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
|
||||||
|
import org.openapitools.codegen.options.TypeScriptAngularClientOptionsProvider;
|
||||||
|
import org.openapitools.codegen.options.TypeScriptAngularClientOptionsProvider;
|
||||||
|
import mockit.Expectations;
|
||||||
|
import mockit.Tested;
|
||||||
|
|
||||||
|
public class TypeScriptAngularClientOptionsTest extends AbstractOptionsTest {
|
||||||
|
|
||||||
|
@Tested
|
||||||
|
private TypeScriptAngularClientCodegen clientCodegen;
|
||||||
|
|
||||||
|
public TypeScriptAngularClientOptionsTest() {
|
||||||
|
super(new TypeScriptAngularClientOptionsProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return clientCodegen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Override
|
||||||
|
protected void setExpectations() {
|
||||||
|
new Expectations(clientCodegen) {{
|
||||||
|
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(TypeScriptAngularClientOptionsProvider.SORT_PARAMS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setModelPropertyNaming(TypeScriptAngularClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setSupportsES6(Boolean.valueOf(TypeScriptAngularClientOptionsProvider.SUPPORTS_ES6_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(TypeScriptAngularClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,197 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptangular;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.models.media.DateSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.DateTimeSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.IntegerSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import io.swagger.v3.oas.models.media.StringSchema;
|
||||||
|
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CodegenModel;
|
||||||
|
import org.openapitools.codegen.CodegenProperty;
|
||||||
|
import org.openapitools.codegen.DefaultCodegen;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
|
||||||
|
|
||||||
|
@SuppressWarnings("static-method")
|
||||||
|
public class TypeScriptAngularModelTest {
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert a simple TypeScript Angular model")
|
||||||
|
public void simpleModelTest() {
|
||||||
|
final Schema model = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
|
||||||
|
.addProperties("name", new StringSchema())
|
||||||
|
.addProperties("createdAt", new DateTimeSchema())
|
||||||
|
.addProperties("birthDate", new DateSchema())
|
||||||
|
.addRequiredItem("id")
|
||||||
|
.addRequiredItem("name");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
|
||||||
|
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(), 4);
|
||||||
|
|
||||||
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
|
Assert.assertEquals(property1.datatype, "number");
|
||||||
|
Assert.assertEquals(property1.name, "id");
|
||||||
|
Assert.assertEquals(property1.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property1.baseType, "number");
|
||||||
|
Assert.assertTrue(property1.hasMore);
|
||||||
|
Assert.assertTrue(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property2 = cm.vars.get(1);
|
||||||
|
Assert.assertEquals(property2.baseName, "name");
|
||||||
|
Assert.assertEquals(property2.datatype, "string");
|
||||||
|
Assert.assertEquals(property2.name, "name");
|
||||||
|
Assert.assertEquals(property2.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property2.baseType, "string");
|
||||||
|
Assert.assertTrue(property2.hasMore);
|
||||||
|
Assert.assertTrue(property2.required);
|
||||||
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property3 = cm.vars.get(2);
|
||||||
|
Assert.assertEquals(property3.baseName, "createdAt");
|
||||||
|
Assert.assertEquals(property3.complexType, null);
|
||||||
|
Assert.assertEquals(property3.datatype, "Date");
|
||||||
|
Assert.assertEquals(property3.name, "createdAt");
|
||||||
|
Assert.assertEquals(property3.baseType, "Date");
|
||||||
|
Assert.assertEquals(property3.defaultValue, "undefined");
|
||||||
|
Assert.assertTrue(property3.hasMore);
|
||||||
|
Assert.assertFalse(property3.required);
|
||||||
|
Assert.assertTrue(property3.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property4 = cm.vars.get(3);
|
||||||
|
Assert.assertEquals(property4.baseName, "birthDate");
|
||||||
|
Assert.assertEquals(property4.complexType, null);
|
||||||
|
Assert.assertEquals(property4.datatype, "string");
|
||||||
|
Assert.assertEquals(property4.name, "birthDate");
|
||||||
|
Assert.assertEquals(property4.baseType, "string");
|
||||||
|
Assert.assertEquals(property4.defaultValue, "undefined");
|
||||||
|
Assert.assertFalse(property4.hasMore);
|
||||||
|
Assert.assertFalse(property4.required);
|
||||||
|
Assert.assertTrue(property4.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with list property", enabled = false)
|
||||||
|
public void listPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
|
||||||
|
.addProperties("urls", new ArraySchema().items(new StringSchema()))
|
||||||
|
.addRequiredItem("id");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
|
||||||
|
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(), 2);
|
||||||
|
|
||||||
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
|
Assert.assertEquals(property1.datatype, "number");
|
||||||
|
Assert.assertEquals(property1.name, "id");
|
||||||
|
Assert.assertEquals(property1.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property1.baseType, "number");
|
||||||
|
Assert.assertTrue(property1.hasMore);
|
||||||
|
Assert.assertTrue(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property2 = cm.vars.get(1);
|
||||||
|
Assert.assertEquals(property2.baseName, "urls");
|
||||||
|
Assert.assertEquals(property2.datatype, "Array<string>");
|
||||||
|
Assert.assertEquals(property2.name, "urls");
|
||||||
|
Assert.assertEquals(property2.baseType, "Array");
|
||||||
|
Assert.assertTrue(property2.hasMore);
|
||||||
|
Assert.assertFalse(property2.required);
|
||||||
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with complex property", enabled = false)
|
||||||
|
public void complexPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("children", new Schema().$ref("#/definitions/Children"));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
|
||||||
|
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);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with complex list property", enabled = false)
|
||||||
|
public void complexListPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("children", new ArraySchema()
|
||||||
|
.items(new Schema().$ref("#/definitions/Children")));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
|
||||||
|
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, "Array<Children>");
|
||||||
|
Assert.assertEquals(property1.name, "children");
|
||||||
|
Assert.assertEquals(property1.baseType, "Array");
|
||||||
|
Assert.assertFalse(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert an array model")
|
||||||
|
public void arrayModelTest() {
|
||||||
|
final Schema schema = new ArraySchema()
|
||||||
|
.items(new Schema().$ref("#/definitions/Children"))
|
||||||
|
.description("an array model");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
|
||||||
|
final CodegenModel cm = codegen.fromModel("sample", schema);
|
||||||
|
|
||||||
|
Assert.assertEquals(cm.name, "sample");
|
||||||
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
|
Assert.assertEquals(cm.description, "an array model");
|
||||||
|
Assert.assertEquals(cm.vars.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a map model", enabled = false)
|
||||||
|
public void mapModelTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a map model")
|
||||||
|
.additionalProperties(new Schema().$ref("#/definitions/Children"));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularClientCodegen();
|
||||||
|
final CodegenModel cm = codegen.fromModel("sample", schema);
|
||||||
|
|
||||||
|
Assert.assertEquals(cm.name, "sample");
|
||||||
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
|
Assert.assertEquals(cm.description, "a map model");
|
||||||
|
Assert.assertEquals(cm.vars.size(), 0);
|
||||||
|
Assert.assertEquals(cm.imports.size(), 1);
|
||||||
|
Assert.assertEquals(cm.additionalPropertiesType, "Children");
|
||||||
|
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptangular;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractIntegrationTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
|
||||||
|
import org.openapitools.codegen.testutils.IntegrationTestPathsConfig;
|
||||||
|
|
||||||
|
public class TypescriptAngularAdditionalPropertiesIntegrationTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return new TypeScriptAngularClientCodegen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> configProperties() {
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
properties.put("npmName", "additionalPropertiesTest");
|
||||||
|
properties.put("npmVersion", "1.0.2");
|
||||||
|
properties.put("snapshot", "false");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IntegrationTestPathsConfig getIntegrationTestPathsConfig() {
|
||||||
|
return new IntegrationTestPathsConfig("typescript/additional-properties");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptangular;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractIntegrationTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
|
||||||
|
import org.openapitools.codegen.testutils.IntegrationTestPathsConfig;
|
||||||
|
|
||||||
|
public class TypescriptAngularArrayAndObjectIntegrationTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return new TypeScriptAngularClientCodegen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> configProperties() {
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
properties.put("npmName", "arrayAndAnyTest");
|
||||||
|
properties.put("npmVersion", "1.0.2");
|
||||||
|
properties.put("snapshot", "false");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IntegrationTestPathsConfig getIntegrationTestPathsConfig() {
|
||||||
|
return new IntegrationTestPathsConfig("typescript/array-and-object");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptangular;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractIntegrationTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularClientCodegen;
|
||||||
|
import org.openapitools.codegen.testutils.IntegrationTestPathsConfig;
|
||||||
|
|
||||||
|
public class TypescriptAngularPestoreIntegrationTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return new TypeScriptAngularClientCodegen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> configProperties() {
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
properties.put("npmName", "petstore-integration-test");
|
||||||
|
properties.put("npmVersion", "1.0.3");
|
||||||
|
properties.put("snapshot", "false");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IntegrationTestPathsConfig getIntegrationTestPathsConfig() {
|
||||||
|
return new IntegrationTestPathsConfig("typescript/petstore");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptangularjs;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractOptionsTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularJsClientCodegen;
|
||||||
|
import org.openapitools.codegen.options.TypeScriptAngularJsClientOptionsProvider;
|
||||||
|
|
||||||
|
import mockit.Expectations;
|
||||||
|
import mockit.Tested;
|
||||||
|
|
||||||
|
public class TypeScriptAngularJsClientOptionsTest extends AbstractOptionsTest {
|
||||||
|
|
||||||
|
@Tested
|
||||||
|
private TypeScriptAngularJsClientCodegen clientCodegen;
|
||||||
|
|
||||||
|
public TypeScriptAngularJsClientOptionsTest() {
|
||||||
|
super(new TypeScriptAngularJsClientOptionsProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return clientCodegen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Override
|
||||||
|
protected void setExpectations() {
|
||||||
|
new Expectations(clientCodegen) {{
|
||||||
|
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(TypeScriptAngularJsClientOptionsProvider.SORT_PARAMS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setModelPropertyNaming(TypeScriptAngularJsClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setSupportsES6(Boolean.valueOf(TypeScriptAngularJsClientOptionsProvider.SUPPORTS_ES6_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(TypeScriptAngularJsClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,193 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptangularjs;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.CodegenModel;
|
||||||
|
import org.openapitools.codegen.CodegenProperty;
|
||||||
|
import org.openapitools.codegen.DefaultCodegen;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularJsClientCodegen;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.models.media.DateSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.DateTimeSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.IntegerSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import io.swagger.v3.oas.models.media.StringSchema;
|
||||||
|
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@SuppressWarnings("static-method")
|
||||||
|
public class TypeScriptAngularJsModelTest {
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert a simple TypeScript Angular model")
|
||||||
|
public void simpleModelTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
|
||||||
|
.addProperties("name", new StringSchema())
|
||||||
|
.addProperties("createdAt", new DateTimeSchema())
|
||||||
|
.addProperties("birthDate", new DateSchema())
|
||||||
|
.addRequiredItem("id")
|
||||||
|
.addRequiredItem("name");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularJsClientCodegen();
|
||||||
|
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(), 4);
|
||||||
|
|
||||||
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
|
Assert.assertEquals(property1.datatype, "number");
|
||||||
|
Assert.assertEquals(property1.name, "id");
|
||||||
|
Assert.assertEquals(property1.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property1.baseType, "number");
|
||||||
|
Assert.assertTrue(property1.hasMore);
|
||||||
|
Assert.assertTrue(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property2 = cm.vars.get(1);
|
||||||
|
Assert.assertEquals(property2.baseName, "name");
|
||||||
|
Assert.assertEquals(property2.datatype, "string");
|
||||||
|
Assert.assertEquals(property2.name, "name");
|
||||||
|
Assert.assertEquals(property2.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property2.baseType, "string");
|
||||||
|
Assert.assertTrue(property2.hasMore);
|
||||||
|
Assert.assertTrue(property2.required);
|
||||||
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property3 = cm.vars.get(2);
|
||||||
|
Assert.assertEquals(property3.baseName, "createdAt");
|
||||||
|
Assert.assertEquals(property3.complexType, null);
|
||||||
|
Assert.assertEquals(property3.datatype, "Date");
|
||||||
|
Assert.assertEquals(property3.name, "createdAt");
|
||||||
|
Assert.assertEquals(property3.defaultValue, "undefined");
|
||||||
|
Assert.assertTrue(property3.hasMore);
|
||||||
|
Assert.assertFalse(property3.required);
|
||||||
|
Assert.assertTrue(property3.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property4 = cm.vars.get(3);
|
||||||
|
Assert.assertEquals(property4.baseName, "birthDate");
|
||||||
|
Assert.assertEquals(property4.complexType, null);
|
||||||
|
Assert.assertEquals(property4.datatype, "string");
|
||||||
|
Assert.assertEquals(property4.name, "birthDate");
|
||||||
|
Assert.assertEquals(property4.defaultValue, "undefined");
|
||||||
|
Assert.assertFalse(property4.hasMore);
|
||||||
|
Assert.assertFalse(property4.required);
|
||||||
|
Assert.assertTrue(property4.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert a model with list property")
|
||||||
|
public void listPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
|
||||||
|
.addProperties("urls", new ArraySchema().items(new StringSchema()))
|
||||||
|
.addRequiredItem("id");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularJsClientCodegen();
|
||||||
|
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(), 2);
|
||||||
|
|
||||||
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
|
Assert.assertEquals(property1.datatype, "number");
|
||||||
|
Assert.assertEquals(property1.name, "id");
|
||||||
|
Assert.assertEquals(property1.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property1.baseType, "number");
|
||||||
|
Assert.assertTrue(property1.hasMore);
|
||||||
|
Assert.assertTrue(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property2 = cm.vars.get(1);
|
||||||
|
Assert.assertEquals(property2.baseName, "urls");
|
||||||
|
Assert.assertEquals(property2.datatype, "Array<string>");
|
||||||
|
Assert.assertEquals(property2.name, "urls");
|
||||||
|
Assert.assertEquals(property2.baseType, "Array");
|
||||||
|
Assert.assertFalse(property2.hasMore);
|
||||||
|
Assert.assertFalse(property2.required);
|
||||||
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with complex property", enabled = false)
|
||||||
|
public void complexPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("children", new Schema().$ref("#/definitions/Children"));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularJsClientCodegen();
|
||||||
|
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);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with complex list property", enabled = false)
|
||||||
|
public void complexListPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("children", new ArraySchema()
|
||||||
|
.items(new Schema().$ref("#/definitions/Children")));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularJsClientCodegen();
|
||||||
|
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, "models.Children");
|
||||||
|
Assert.assertEquals(property1.datatype, "Array<models.Children>");
|
||||||
|
Assert.assertEquals(property1.name, "children");
|
||||||
|
Assert.assertEquals(property1.baseType, "Array");
|
||||||
|
Assert.assertFalse(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert an array model")
|
||||||
|
public void arrayModelTest() {
|
||||||
|
final Schema schema = new ArraySchema()
|
||||||
|
.items(new Schema().$ref("#/definitions/Children"))
|
||||||
|
.description("an array model");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularJsClientCodegen();
|
||||||
|
final CodegenModel cm = codegen.fromModel("sample", schema);
|
||||||
|
|
||||||
|
Assert.assertEquals(cm.name, "sample");
|
||||||
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
|
Assert.assertEquals(cm.description, "an array model");
|
||||||
|
Assert.assertEquals(cm.vars.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a map model", enabled = false)
|
||||||
|
public void mapModelTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a map model")
|
||||||
|
.additionalProperties(new Schema().$ref("#/definitions/Children"));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptAngularJsClientCodegen();
|
||||||
|
final CodegenModel cm = codegen.fromModel("sample", schema);
|
||||||
|
|
||||||
|
Assert.assertEquals(cm.name, "sample");
|
||||||
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
|
Assert.assertEquals(cm.description, "a map model");
|
||||||
|
Assert.assertEquals(cm.vars.size(), 0);
|
||||||
|
Assert.assertEquals(cm.imports.size(), 1);
|
||||||
|
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("models.Children")).size(), 1);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptnode;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractOptionsTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
|
||||||
|
import org.openapitools.codegen.options.TypeScriptNodeClientOptionsProvider;
|
||||||
|
|
||||||
|
import mockit.Expectations;
|
||||||
|
import mockit.Tested;
|
||||||
|
|
||||||
|
public class TypeScriptNodeClientOptionsTest extends AbstractOptionsTest {
|
||||||
|
|
||||||
|
@Tested
|
||||||
|
private TypeScriptNodeClientCodegen clientCodegen;
|
||||||
|
|
||||||
|
public TypeScriptNodeClientOptionsTest() {
|
||||||
|
super(new TypeScriptNodeClientOptionsProvider());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return clientCodegen;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
@Override
|
||||||
|
protected void setExpectations() {
|
||||||
|
new Expectations(clientCodegen) {{
|
||||||
|
clientCodegen.setSortParamsByRequiredFlag(Boolean.valueOf(TypeScriptNodeClientOptionsProvider.SORT_PARAMS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setModelPropertyNaming(TypeScriptNodeClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE);
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setSupportsES6(Boolean.valueOf(TypeScriptNodeClientOptionsProvider.SUPPORTS_ES6_VALUE));
|
||||||
|
times = 1;
|
||||||
|
clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(TypeScriptNodeClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
|
||||||
|
times = 1;
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,193 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptnode;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.CodegenConstants;
|
||||||
|
import org.openapitools.codegen.CodegenModel;
|
||||||
|
import org.openapitools.codegen.CodegenProperty;
|
||||||
|
import org.openapitools.codegen.DefaultCodegen;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptAngularJsClientCodegen;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
|
||||||
|
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import io.swagger.v3.oas.models.media.ArraySchema;
|
||||||
|
import io.swagger.v3.oas.models.media.DateSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.DateTimeSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.IntegerSchema;
|
||||||
|
import io.swagger.v3.oas.models.media.Schema;
|
||||||
|
import io.swagger.v3.oas.models.media.StringSchema;
|
||||||
|
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
@SuppressWarnings("static-method")
|
||||||
|
public class TypeScriptNodeModelTest {
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert a simple TypeScript Node model")
|
||||||
|
public void simpleModelTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
|
||||||
|
.addProperties("name", new StringSchema())
|
||||||
|
.addProperties("createdAt", new DateTimeSchema())
|
||||||
|
.addProperties("birthDate", new DateSchema())
|
||||||
|
.addRequiredItem("id")
|
||||||
|
.addRequiredItem("name");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||||
|
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(), 4);
|
||||||
|
|
||||||
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
|
Assert.assertEquals(property1.datatype, "number");
|
||||||
|
Assert.assertEquals(property1.name, "id");
|
||||||
|
Assert.assertEquals(property1.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property1.baseType, "number");
|
||||||
|
Assert.assertTrue(property1.hasMore);
|
||||||
|
Assert.assertTrue(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property2 = cm.vars.get(1);
|
||||||
|
Assert.assertEquals(property2.baseName, "name");
|
||||||
|
Assert.assertEquals(property2.datatype, "string");
|
||||||
|
Assert.assertEquals(property2.name, "name");
|
||||||
|
Assert.assertEquals(property2.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property2.baseType, "string");
|
||||||
|
Assert.assertTrue(property2.hasMore);
|
||||||
|
Assert.assertTrue(property2.required);
|
||||||
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property3 = cm.vars.get(2);
|
||||||
|
Assert.assertEquals(property3.baseName, "createdAt");
|
||||||
|
Assert.assertEquals(property3.complexType, null);
|
||||||
|
Assert.assertEquals(property3.datatype, "Date");
|
||||||
|
Assert.assertEquals(property3.name, "createdAt");
|
||||||
|
Assert.assertEquals(property3.defaultValue, "undefined");
|
||||||
|
Assert.assertTrue(property3.hasMore);
|
||||||
|
Assert.assertFalse(property3.required);
|
||||||
|
Assert.assertTrue(property3.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property4 = cm.vars.get(3);
|
||||||
|
Assert.assertEquals(property4.baseName, "birthDate");
|
||||||
|
Assert.assertEquals(property4.complexType, null);
|
||||||
|
Assert.assertEquals(property4.datatype, "string");
|
||||||
|
Assert.assertEquals(property4.name, "birthDate");
|
||||||
|
Assert.assertEquals(property4.defaultValue, "undefined");
|
||||||
|
Assert.assertFalse(property4.hasMore);
|
||||||
|
Assert.assertFalse(property4.required);
|
||||||
|
Assert.assertTrue(property4.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert a model with list property")
|
||||||
|
public void listPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("id", new IntegerSchema().format(SchemaTypeUtil.INTEGER64_FORMAT))
|
||||||
|
.addProperties("urls", new ArraySchema().items(new StringSchema()))
|
||||||
|
.addRequiredItem("id");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||||
|
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(), 2);
|
||||||
|
|
||||||
|
final CodegenProperty property1 = cm.vars.get(0);
|
||||||
|
Assert.assertEquals(property1.baseName, "id");
|
||||||
|
Assert.assertEquals(property1.datatype, "number");
|
||||||
|
Assert.assertEquals(property1.name, "id");
|
||||||
|
Assert.assertEquals(property1.defaultValue, "undefined");
|
||||||
|
Assert.assertEquals(property1.baseType, "number");
|
||||||
|
Assert.assertTrue(property1.hasMore);
|
||||||
|
Assert.assertTrue(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
|
||||||
|
final CodegenProperty property2 = cm.vars.get(1);
|
||||||
|
Assert.assertEquals(property2.baseName, "urls");
|
||||||
|
Assert.assertEquals(property2.datatype, "Array<string>");
|
||||||
|
Assert.assertEquals(property2.name, "urls");
|
||||||
|
Assert.assertEquals(property2.baseType, "Array");
|
||||||
|
Assert.assertFalse(property2.hasMore);
|
||||||
|
Assert.assertFalse(property2.required);
|
||||||
|
Assert.assertTrue(property2.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with complex property", enabled = false)
|
||||||
|
public void complexPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("children", new Schema().$ref("#/definitions/Children"));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||||
|
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.baseType, "Children");
|
||||||
|
Assert.assertFalse(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a model with complex list property", enabled = false)
|
||||||
|
public void complexListPropertyTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a sample model")
|
||||||
|
.addProperties("children", new ArraySchema()
|
||||||
|
.items(new Schema().$ref("#/definitions/Children")));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||||
|
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, "Array<Children>");
|
||||||
|
Assert.assertEquals(property1.name, "children");
|
||||||
|
Assert.assertEquals(property1.baseType, "Array");
|
||||||
|
Assert.assertFalse(property1.required);
|
||||||
|
Assert.assertTrue(property1.isNotContainer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(enabled = false, description = "convert an array model")
|
||||||
|
public void arrayModelTest() {
|
||||||
|
final Schema schema = new ArraySchema()
|
||||||
|
.items(new Schema().$ref("#/definitions/Children"))
|
||||||
|
.description("an array model");
|
||||||
|
final DefaultCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||||
|
final CodegenModel cm = codegen.fromModel("sample", schema);
|
||||||
|
|
||||||
|
Assert.assertEquals(cm.name, "sample");
|
||||||
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
|
Assert.assertEquals(cm.description, "an array model");
|
||||||
|
Assert.assertEquals(cm.vars.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(description = "convert a map model", enabled = false)
|
||||||
|
public void mapModelTest() {
|
||||||
|
final Schema schema = new Schema()
|
||||||
|
.description("a map model")
|
||||||
|
.additionalProperties(new Schema().$ref("#/definitions/Children"));
|
||||||
|
final DefaultCodegen codegen = new TypeScriptNodeClientCodegen();
|
||||||
|
final CodegenModel cm = codegen.fromModel("sample", schema);
|
||||||
|
|
||||||
|
Assert.assertEquals(cm.name, "sample");
|
||||||
|
Assert.assertEquals(cm.classname, "Sample");
|
||||||
|
Assert.assertEquals(cm.description, "a map model");
|
||||||
|
Assert.assertEquals(cm.vars.size(), 0);
|
||||||
|
Assert.assertEquals(cm.imports.size(), 1);
|
||||||
|
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("Children")).size(), 1);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package org.openapitools.codegen.typescript.typescriptnode;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.openapitools.codegen.AbstractIntegrationTest;
|
||||||
|
import org.openapitools.codegen.CodegenConfig;
|
||||||
|
import org.openapitools.codegen.languages.TypeScriptNodeClientCodegen;
|
||||||
|
import org.openapitools.codegen.testutils.IntegrationTestPathsConfig;
|
||||||
|
|
||||||
|
public class TypescriptNodeES5IntegrationTest extends AbstractIntegrationTest {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CodegenConfig getCodegenConfig() {
|
||||||
|
return new TypeScriptNodeClientCodegen();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> configProperties() {
|
||||||
|
Map<String, String> properties = new HashMap<>();
|
||||||
|
properties.put("npmName", "node-es6-test");
|
||||||
|
properties.put("npmVersion", "1.0.3");
|
||||||
|
properties.put("snapshot", "false");
|
||||||
|
properties.put("supportsES6", "false");
|
||||||
|
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected IntegrationTestPathsConfig getIntegrationTestPathsConfig() {
|
||||||
|
return new IntegrationTestPathsConfig("typescript/node-es5");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user