Merge with upstream

This commit is contained in:
Jakub Malek
2016-06-17 15:22:17 +02:00
committed by Jakub Malek
2118 changed files with 88476 additions and 29372 deletions

View File

@@ -0,0 +1,46 @@
package io.swagger.codegen;
import org.testng.annotations.Test;
import org.testng.reporters.Files;
import java.io.IOException;
import java.util.Map;
import io.swagger.codegen.testutils.IntegrationTestPathsConfig;
import io.swagger.models.Swagger;
import io.swagger.parser.SwaggerParser;
import static io.swagger.codegen.testutils.AssertFile.assertPathEqualsRecursively;
public abstract class AbstractIntegrationTest {
protected abstract IntegrationTestPathsConfig getIntegrationTestPathsConfig();
protected abstract CodegenConfig getCodegenConfig();
protected abstract Map<String, String> configProperties();
// @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();
IntegrationTestPathsConfig integrationTestPathsConfig = getIntegrationTestPathsConfig();
String specContent = Files.readFile(integrationTestPathsConfig.getSpecPath().toFile());
Swagger swagger = new SwaggerParser().parse(specContent);
CodegenConfig codegenConfig = getCodegenConfig();
codegenConfig.setOutputDir(integrationTestPathsConfig.getOutputPath().toString());
ClientOpts clientOpts = new ClientOpts();
clientOpts.setProperties(configProperties());
ClientOptInput opts = new ClientOptInput()
.config(codegenConfig)
.opts(clientOpts)
.swagger(swagger);
codeGen.opts(opts).generate();
assertPathEqualsRecursively(integrationTestPathsConfig.getExpectedPath(), integrationTestPathsConfig.getOutputPath());
}
}

View File

@@ -77,6 +77,40 @@ public class InlineModelResolverTest {
assertTrue(model.getProperties().get("name") instanceof StringProperty);
}
@Test
public void testInlineResponseModelWithTitle() throws Exception {
Swagger swagger = new Swagger();
String responseTitle = "GetBarResponse";
swagger.path("/foo/bar", new Path()
.get(new Operation()
.response(200, new Response()
.description("it works!")
.schema(new ObjectProperty().title(responseTitle)
.property("name", new StringProperty())))))
.path("/foo/baz", new Path()
.get(new Operation()
.response(200, new Response()
.vendorExtension("x-foo", "bar")
.description("it works!")
.schema(new ObjectProperty()
.property("name", new StringProperty())))));
new InlineModelResolver().flatten(swagger);
Map<String, Response> responses = swagger.getPaths().get("/foo/bar").getGet().getResponses();
Response response = responses.get("200");
assertNotNull(response);
assertTrue(response.getSchema() instanceof RefProperty);
ModelImpl model = (ModelImpl)swagger.getDefinitions().get(responseTitle);
assertTrue(model.getProperties().size() == 1);
assertNotNull(model.getProperties().get("name"));
assertTrue(model.getProperties().get("name") instanceof StringProperty);
}
@Test
public void resolveInlineArrayModel() throws Exception {
Swagger swagger = new Swagger();
@@ -128,6 +162,35 @@ public class InlineModelResolverTest {
ModelImpl impl = (ModelImpl) body;
assertNotNull(impl.getProperties().get("address"));
}
@Test
public void resolveInlineBodyParameterWithTitle() throws Exception {
Swagger swagger = new Swagger();
ModelImpl addressModelItem = new ModelImpl();
String addressModelName = "DetailedAddress";
addressModelItem.setTitle(addressModelName);
swagger.path("/hello", new Path()
.get(new Operation()
.parameter(new BodyParameter()
.name("body")
.schema(addressModelItem
.property("address", new ObjectProperty()
.property("street", new StringProperty()))
.property("name", new StringProperty())))));
new InlineModelResolver().flatten(swagger);
Operation operation = swagger.getPaths().get("/hello").getGet();
BodyParameter bp = (BodyParameter)operation.getParameters().get(0);
assertTrue(bp.getSchema() instanceof RefModel);
Model body = swagger.getDefinitions().get(addressModelName);
assertTrue(body instanceof ModelImpl);
ModelImpl impl = (ModelImpl) body;
assertNotNull(impl.getProperties().get("address"));
}
@Test
public void notResolveNonModelBodyParameter() throws Exception {
@@ -245,6 +308,50 @@ public class InlineModelResolverTest {
assertTrue(impl.getProperties().get("name") instanceof StringProperty);
}
@Test
public void resolveInlineArrayResponseWithTitle() throws Exception {
Swagger swagger = new Swagger();
swagger.path("/foo/baz", new Path()
.get(new Operation()
.response(200, new Response()
.vendorExtension("x-foo", "bar")
.description("it works!")
.schema(new ArrayProperty()
.items(
new ObjectProperty()
.title("FooBar")
.property("name", new StringProperty()))))));
new InlineModelResolver().flatten(swagger);
Response response = swagger.getPaths().get("/foo/baz").getGet().getResponses().get("200");
assertNotNull(response);
assertNotNull(response.getSchema());
Property responseProperty = response.getSchema();
// no need to flatten more
assertTrue(responseProperty instanceof ArrayProperty);
ArrayProperty ap = (ArrayProperty) responseProperty;
Property p = ap.getItems();
assertNotNull(p);
RefProperty rp = (RefProperty) p;
assertEquals(rp.getType(), "ref");
assertEquals(rp.get$ref(), "#/definitions/"+ "FooBar");
assertEquals(rp.getSimpleRef(), "FooBar");
Model inline = swagger.getDefinitions().get("FooBar");
assertNotNull(inline);
assertTrue(inline instanceof ModelImpl);
ModelImpl impl = (ModelImpl) inline;
assertNotNull(impl.getProperties().get("name"));
assertTrue(impl.getProperties().get("name") instanceof StringProperty);
}
@Test
public void testInlineMapResponse() throws Exception {
Swagger swagger = new Swagger();

View File

@@ -0,0 +1,152 @@
package io.swagger.codegen.ignore;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.SystemUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.*;
import static org.testng.Assert.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class CodegenIgnoreProcessorTest {
private static final Logger LOGGER = LoggerFactory.getLogger(CodegenIgnoreProcessorTest.class);
private Boolean allowed;
private Boolean skip = false;
private final String filename;
private final String ignoreDefinition;
private final String description;
private String outputDir;
private File target;
private Path temp;
private CodegenIgnoreProcessorTest(String filename, String ignoreDefinition, String description) throws IOException {
this.filename = filename;
this.ignoreDefinition = ignoreDefinition;
this.description = description;
}
CodegenIgnoreProcessorTest allowed() {
this.allowed = true;
return this;
}
CodegenIgnoreProcessorTest skipOnCondition(Boolean condition) {
this.skip = Boolean.TRUE.equals(condition);
return this;
}
CodegenIgnoreProcessorTest ignored() {
this.allowed = false;
return this;
}
private void prepareTestFiles() throws IOException {
// NOTE: Each test needs its own directory because .swagger-codegen-ignore needs to exist at the root.
temp = Files.createTempDirectory(getClass().getSimpleName());
this.outputDir = temp.toFile().getAbsolutePath();
target = new File(this.outputDir, this.filename);
boolean mkdirs = target.getParentFile().mkdirs();
if(!mkdirs) {
LOGGER.warn("Failed to create directories for CodegenIgnoreProcessorTest test file. Directory may already exist.");
}
Path created = Files.createFile(target.toPath());
if(!created.toFile().exists()) {
throw new IOException("Failed to write CodegenIgnoreProcessorTest test file.");
}
// System.out.print(String.format("Created codegen ignore processor test file: %s\n", created.toAbsolutePath()));
File ignoreFile = new File(this.outputDir, ".swagger-codegen-ignore");
try (FileOutputStream stream = new FileOutputStream(ignoreFile)) {
stream.write(this.ignoreDefinition.getBytes());
}
}
@AfterTest
public void afterTest() throws IOException {
if(temp != null && temp.toFile().exists() && temp.toFile().isDirectory()) {
FileUtils.deleteDirectory(temp.toFile());
}
}
@Test
public void evaluate() {
if(this.skip) {
return;
}
// Arrange
try {
// Lazily setup files to avoid conflicts and creation when these tests may not even run.
prepareTestFiles();
} catch (IOException e) {
e.printStackTrace();
fail("Failed to prepare test files. " + e.getMessage());
}
CodegenIgnoreProcessor processor = new CodegenIgnoreProcessor(outputDir);
Boolean actual = null;
// Act
actual = processor.allowsFile(target);
// Assert
assertEquals(actual, this.allowed, this.description);
}
@Factory
public static Object[] factoryMethod() throws IOException {
return new Object[] {
// Matching filenames
new CodegenIgnoreProcessorTest("build.sh", "build.sh", "A file when matching should ignore.").ignored(),
new CodegenIgnoreProcessorTest("src/build.sh", "**/build.sh", "A file when matching nested files should ignore.").ignored(),
new CodegenIgnoreProcessorTest("Build.sh", "build.sh", "A file when non-matching should allow.").allowed().skipOnCondition(SystemUtils.IS_OS_WINDOWS),
new CodegenIgnoreProcessorTest("build.sh", "/build.sh", "A rooted file when matching should ignore.").ignored(),
new CodegenIgnoreProcessorTest("nested/build.sh", "/build.sh", "A rooted file definition when non-matching should allow.").allowed(),
new CodegenIgnoreProcessorTest("src/IO.Swagger.Test/Model/AnimalFarmTests.cs", "src/IO.Swagger.Test/Model/AnimalFarmTests.cs", "A file when matching exactly should ignore.").ignored(),
// Matching spaces in filenames
new CodegenIgnoreProcessorTest("src/properly escaped.txt", "**/properly escaped.txt", "A file when matching nested files with spaces in the name should ignore.").ignored(),
new CodegenIgnoreProcessorTest("src/improperly escaped.txt", "**/improperly\\ escaped.txt", "A file when matching nested files with spaces in the name (improperly escaped rule) should allow.").allowed(),
// Match All
new CodegenIgnoreProcessorTest("docs/somefile.md", "docs/**", "A recursive file (0 level) when matching should ignore.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/somefile.md", "docs/**", "A recursive file (1 level) when matching should ignore.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/2/3/somefile.md", "docs/**", "A recursive file (n level) when matching should ignore.").ignored(),
// Match Any
new CodegenIgnoreProcessorTest("docs/1/2/3/somefile.md", "docs/**/somefile.*", "A recursive file with match-any extension when matching should ignore.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/2/3/somefile.java", "docs/**/*.java", "A recursive file with match-any file name when matching should ignore.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/2/3/4/somefile.md", "docs/**/*", "A recursive file with match-any file name when matching should ignore.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/2/3/4/5/somefile.md", "docs/**/anyfile.*", "A recursive file with match-any extension when non-matching should allow.").allowed(),
// Directory matches
new CodegenIgnoreProcessorTest("docs/1/Users/a", "docs/**/Users/", "A directory rule when matching should be ignored.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/Users1/a", "docs/**/Users/", "A directory rule when non-matching should be allowed.").allowed(),
// Negation of excluded recursive files
new CodegenIgnoreProcessorTest("docs/UserApi.md", "docs/**\n!docs/UserApi.md", "A pattern negating a previous ignore FILE rule should be allowed.").allowed(),
// Negation of excluded directories
new CodegenIgnoreProcessorTest("docs/1/Users/UserApi.md", "docs/**/Users/\n!docs/1/Users/UserApi.md", "A pattern negating a previous ignore DIRECTORY rule should be ignored.").ignored(),
// Other matches which may not be parsed for correctness, but are free because of PathMatcher
new CodegenIgnoreProcessorTest("docs/1/2/3/Some99File.md", "**/*[0-9]*", "A file when matching against simple regex patterns when matching should be ignored.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/2/3/SomeFile.md", "**/*.{java,md}", "A file when matching against grouped subpatterns for extension when matching (md) should be ignored.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/2/3/SomeFile.java", "**/*.{java,md}", "A file when matching against grouped subpatterns for extension when matching (java) should be ignored.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/2/3/SomeFile.txt", "**/*.{java,md}", "A file when matching against grouped subpatterns for extension when non-matching should be allowed.").allowed(),
new CodegenIgnoreProcessorTest("docs/1/2/3/foo.c", "**/*.?", "A file when matching against required single-character extension when matching should be ignored.").ignored(),
new CodegenIgnoreProcessorTest("docs/1/2/3/foo.cc", "**/*.?", "A file when matching against required single-character extension when non-matching should be allowed.").allowed()
};
}
}

View File

@@ -0,0 +1,70 @@
package io.swagger.codegen.ignore.rules;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
public class FileRuleTest {
@Test
public void testMatchComplex() throws Exception {
// Arrange
final String definition = "path/to/**/complex/*.txt";
final String relativePath = "path/to/some/nested/complex/xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "path"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "to"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.MATCH_ALL),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "complex"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".txt")
);
Rule rule = new FileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchComplex() throws Exception {
// Arrange
final String definition = "path/to/**/complex/*.txt";
final String relativePath = "path/to/some/nested/invalid/xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "path"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "to"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.MATCH_ALL),
new Part(IgnoreLineParser.Token.TEXT, "complex"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".txt")
);
Rule rule = new FileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
}

View File

@@ -0,0 +1,158 @@
package io.swagger.codegen.ignore.rules;
import org.testng.annotations.Test;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import static org.testng.Assert.*;
public class IgnoreLineParserTest {
private IgnoreLineParser.Token verifyInputToSingleToken(final String input, IgnoreLineParser.Token token) throws ParserException {
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
assertNotNull(result);
assertEquals(result.size(), 1);
IgnoreLineParser.Token actual = result.get(0).getToken();
assertEquals(actual, token);
return actual;
}
@Test
public void parseMatchAll() throws Exception {
verifyInputToSingleToken("**", IgnoreLineParser.Token.MATCH_ALL);
}
@Test
public void parseMatchAny() throws Exception {
verifyInputToSingleToken("*", IgnoreLineParser.Token.MATCH_ANY);
}
@Test(expectedExceptions = ParserException.class,
expectedExceptionsMessageRegExp = "Negation with no negated pattern\\.")
public void parseNegate() throws Exception {
verifyInputToSingleToken("!", IgnoreLineParser.Token.NEGATE);
// Assert
fail("Expected simple pattern '!' to throw a ParserException.");
}
@Test
public void parseComment() throws Exception {
// Arrange
final String input = "# This is a comment";
Part actual = null;
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
assertEquals(result.size(), 1);
actual = result.get(0);
assertEquals(actual.getToken(), IgnoreLineParser.Token.COMMENT);
assertEquals(actual.getValue(), input);
}
@Test
public void parseEscapedExclamation() throws Exception {
final String input = "\\!";
verifyInputToSingleToken(input, IgnoreLineParser.Token.ESCAPED_EXCLAMATION);
}
@Test
public void parseEscapedSpace() throws Exception {
final String input = "\\ ";
verifyInputToSingleToken(input, IgnoreLineParser.Token.ESCAPED_SPACE);
}
@Test
public void parseDirectoryMarker() throws Exception {
// Arrange
final String input = "foo/";
Part actual = null;
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
assertEquals(result.size(), 2);
actual = result.get(0);
assertEquals(actual.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(actual.getValue(), "foo");
actual = result.get(1);
assertEquals(actual.getToken(), IgnoreLineParser.Token.DIRECTORY_MARKER);
}
@Test
public void parseRooted() throws Exception {
// Arrange
final String input = "/abcd";
Part actual = null;
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
assertEquals(result.size(), 2);
actual = result.get(0);
assertEquals(actual.getToken(), IgnoreLineParser.Token.ROOTED_MARKER);
actual = result.get(1);
assertEquals(actual.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(actual.getValue(), "abcd");
}
@Test
public void parseComplex() throws Exception {
// Arrange
final String input = "**/abcd/**/foo/bar/sample.txt";
Part current = null;
// Act
Queue<Part> result = new LinkedList<>(IgnoreLineParser.parse(input));
// Assert
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.MATCH_ALL);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(current.getValue(), "abcd");
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.MATCH_ALL);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(current.getValue(), "foo");
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(current.getValue(), "bar");
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.PATH_DELIM);
current = result.remove();
assertEquals(current.getToken(), IgnoreLineParser.Token.TEXT);
assertEquals(current.getValue(), "sample.txt");
}
@Test(expectedExceptions = ParserException.class,
expectedExceptionsMessageRegExp = "The pattern \\*\\*\\* is invalid\\.")
public void parseTripleStarPattern() throws Exception {
// Arrange
final String input = "should/throw/***/anywhere";
// Act
List<Part> result = IgnoreLineParser.parse(input);
// Assert
fail("Expected pattern containing '***' to throw a ParserException.");
}
}

View File

@@ -0,0 +1,285 @@
package io.swagger.codegen.ignore.rules;
import org.testng.annotations.Test;
import java.util.Arrays;
import java.util.List;
import static org.testng.Assert.*;
public class RootedFileRuleTest {
@Test
public void testMatchFilenameOnly() throws Exception {
// Arrange
final String definition = "/foo";
final String relativePath = "foo";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameOnly() throws Exception {
// Arrange
final String definition = "/foo";
final String relativePath = "bar";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchFilenameAndExtension() throws Exception {
// Arrange
final String definition = "/foo.txt";
final String relativePath = "foo.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameAndExtension() throws Exception {
// Arrange
final String definition = "/foo.txt";
final String relativePath = "bar.baz";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchFilenameWithGlob() throws Exception {
// Arrange
final String definition = "/foo*";
final String relativePath = "foobarbaz";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY)
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameWithGlob() throws Exception {
// Arrange
final String definition = "/foo*";
final String relativePath = "boobarbaz";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY)
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchFilenameAndExtensionWithFilenameGlob() throws Exception {
// Arrange
final String definition = "/foo*.txt";
final String relativePath = "foobarbaz.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameAndExtensionWithFilenameGlob() throws Exception {
// Arrange
final String definition = "/foo*qux.txt";
final String relativePath = "foobarbaz.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, "qux.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchFilenameAndExtensionWithExtensionGlob() throws Exception {
// Arrange
final String definition = "/foo.*";
final String relativePath = "foo.bak";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo."),
new Part(IgnoreLineParser.Token.MATCH_ANY)
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testMatchFilenameAndExtensionWithMultiplePeriods() throws Exception {
// Arrange
final String definition = "/foo*.xyzzy.txt";
final String relativePath = "foo.bar.baz.xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".xyzzy.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testNonMatchFilenameAndExtensionWithMultiplePeriods() throws Exception {
// Arrange
final String definition = "/foo*.xyzzy.txt";
final String relativePath = "foo.bar.baz.qux.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".xyzzy.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
@Test
public void testMatchWithoutLeadingForwardSlash() throws Exception {
// Arrange
final String definition = "foo*.xyzzy.txt";
final String relativePath = "foo.bar.baz.xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "foo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".xyzzy.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertTrue(actual);
}
@Test
public void testMatchesOnlyRooted() throws Exception {
// Arrange
final String definition = "/path/to/some/foo*.xyzzy.txt";
final String relativePath = "foo.bar.baz.xyzzy.txt";
final List<Part> syntax = Arrays.asList(
new Part(IgnoreLineParser.Token.ROOTED_MARKER),
new Part(IgnoreLineParser.Token.TEXT, "path"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "to"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "some"),
new Part(IgnoreLineParser.Token.PATH_DELIM),
new Part(IgnoreLineParser.Token.TEXT, "oo"),
new Part(IgnoreLineParser.Token.MATCH_ANY),
new Part(IgnoreLineParser.Token.TEXT, ".xyzzy.txt")
);
Rule rule = new RootedFileRule(syntax, definition);
Boolean actual = null;
// Act
actual = rule.matches(relativePath);
// Assert
assertFalse(actual);
}
}

View File

@@ -17,7 +17,7 @@ import java.nio.charset.StandardCharsets;
public class AllowableValuesTest {
private static final String TEMPLATE_FILE = "JavaJaxRS/jersey1_18/allowableValues.mustache";
private static final String TEMPLATE_FILE = "JavaJaxRS/libraries/jersey1/allowableValues.mustache";
private static final String PROVIDER_NAME = "operations";
private static String loadClassResource(Class<?> cls, String name) throws IOException {

View File

@@ -46,7 +46,8 @@ public class JaxRSServerOptionsTest extends JavaClientOptionsTest {
times = 1;
clientCodegen.setSerializableModel(Boolean.valueOf(JaxRSServerOptionsProvider.SERIALIZABLE_MODEL_VALUE));
times = 1;
clientCodegen.setLibrary(JaxRSServerOptionsProvider.DEFAULT_LIBRARY_VALUE);
//clientCodegen.setLibrary(JaxRSServerOptionsProvider.JAXRS_LIBRARY_VALUE);
clientCodegen.setLibrary("jersey1");
times = 1;
clientCodegen.setFullJavaUtil(Boolean.valueOf(JaxRSServerOptionsProvider.FULL_JAVA_UTIL_VALUE));
times = 1;

View File

@@ -34,6 +34,6 @@ public class JaxrsJava8ModelTest {
Json.prettyPrint(cm);
assertEquals(cm.vars.get(0).datatype, "Long");
assertEquals(cm.vars.get(1).datatype, "LocalDate");
assertEquals(cm.vars.get(2).datatype, "LocalDateTime");
assertEquals(cm.vars.get(2).datatype, "OffsetDateTime");
}
}

View File

@@ -38,8 +38,6 @@ public class ObjcClientOptionsTest extends AbstractOptionsTest {
times = 1;
clientCodegen.setGitRepoURL(ObjcClientOptionsProvider.GIT_REPO_URL_VALUE);
times = 1;
clientCodegen.setLicense(ObjcClientOptionsProvider.LICENSE_VALUE);
times = 1;
}};
}
}

View File

@@ -1,21 +1,9 @@
package io.swagger.codegen.objc;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenOperation;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.DefaultCodegen;
import io.swagger.codegen.*;
import io.swagger.codegen.languages.ObjcClientCodegen;
import io.swagger.models.ArrayModel;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.Path;
import io.swagger.models.Swagger;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.DateTimeProperty;
import io.swagger.models.properties.LongProperty;
import io.swagger.models.properties.MapProperty;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import io.swagger.models.*;
import io.swagger.models.properties.*;
import io.swagger.parser.SwaggerParser;
import com.google.common.collect.Sets;
@@ -279,6 +267,57 @@ public class ObjcModelTest {
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("SWGChildren")).size(), 1);
}
@Test(description = "test udid")
public void udidAndPasswordDataModelTest() {
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml");
final DefaultCodegen codegen = new ObjcClientCodegen();
final Model definition = model.getDefinitions().get("format_test");
Property property = definition.getProperties().get("uuid");
CodegenProperty prope = codegen.fromProperty("uuid", property);
Assert.assertEquals(prope.baseType, "NSString");
prope = codegen.fromProperty("password", property);
Assert.assertEquals(prope.baseType, "NSString");
}
@Test(description = "test mixedProperties")
public void mixedPropertiesDataModelTest() {
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml");
final DefaultCodegen codegen = new ObjcClientCodegen();
final Model definition = model.getDefinitions().get("MixedPropertiesAndAdditionalPropertiesClass");
Property property = definition.getProperties().get("map");
CodegenProperty prope = codegen.fromProperty("map", property);
Assert.assertEquals(prope.baseType, "NSDictionary");
}
@Test(description = "test isArrayModel")
public void isArrayModelModelTest() {
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml");
final DefaultCodegen codegen = new ObjcClientCodegen();
final Model definition = model.getDefinitions().get("AnimalFarm");
final CodegenModel codegenModel = codegen.fromModel("AnimalFarm",definition);
Assert.assertEquals(codegenModel.isArrayModel,Boolean.TRUE);
Assert.assertEquals(codegenModel.arrayModelType,"SWGAnimal");
}
@Test(description = "test binary data")
public void binaryDataModelTest() {
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/binaryDataTest.json");
final DefaultCodegen codegen = new ObjcClientCodegen();
final String path = "/tests/binaryResponse";
final Operation p = model.getPaths().get(path).getPost();
final CodegenOperation op = codegen.fromOperation(path, "post", p, model.getDefinitions());
Assert.assertEquals(op.returnType, "NSData*");
Assert.assertEquals(op.bodyParam.dataType, "NSData*");
Assert.assertTrue(op.bodyParam.isBinary);
Assert.assertTrue(op.responses.get(0).isBinary);
}
@Test(description = "create proper imports per #316")
public void issue316Test() {
final Swagger model = new SwaggerParser().read("src/test/resources/2_0/postBodyTest.json");

View File

@@ -0,0 +1,30 @@
package io.swagger.codegen.options;
import io.swagger.codegen.CodegenConstants;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
public class GoServerOptionsProvider implements OptionsProvider {
public static final String SORT_PARAMS_VALUE = "false";
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
@Override
public String getLanguage() {
return "go-server";
}
@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)
.build();
}
@Override
public boolean isServer() {
return true;
}
}

View File

@@ -2,12 +2,27 @@ package io.swagger.codegen.options;
import com.google.common.collect.ImmutableMap;
import io.swagger.codegen.CodegenConstants;
import io.swagger.codegen.languages.JavaClientCodegen;
import java.util.Map;
public class JaxRSServerOptionsProvider extends JavaOptionsProvider {
public class JaxRSServerOptionsProvider implements OptionsProvider {
public static final String ARTIFACT_ID_VALUE = "swagger-java-client-test";
public static final String MODEL_PACKAGE_VALUE = "package";
public static final String API_PACKAGE_VALUE = "apiPackage";
public static final String INVOKER_PACKAGE_VALUE = "io.swagger.client.test";
public static final String SORT_PARAMS_VALUE = "false";
public static final String GROUP_ID_VALUE = "io.swagger.test";
public static final String ARTIFACT_VERSION_VALUE = "1.0.0-SNAPSHOT";
public static final String SOURCE_FOLDER_VALUE = "src/main/java/test";
public static final String LOCAL_PREFIX_VALUE = "tst";
public static final String DEFAULT_LIBRARY_VALUE = "jersey2";
public static final String SERIALIZABLE_MODEL_VALUE = "false";
public static final String FULL_JAVA_UTIL_VALUE = "true";
public static final String ENSURE_UNIQUE_PARAMS_VALUE = "true";
public static final String JODA_DATE_LIBRARY = "joda";
public static final String IMPL_FOLDER_VALUE = "src/main/java/impl";
public static final String IMPL_FOLDER_VALUE = "src/main/java/impl";
public static final String JAXRS_DEFAULT_LIBRARY_VALUE = "jersey1";
@Override
public boolean isServer() {
@@ -21,13 +36,27 @@ public class JaxRSServerOptionsProvider extends JavaOptionsProvider {
@Override
public Map<String, String> createOptions() {
Map<String, String> options = super.createOptions();
ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<String, String>();
builder.putAll(options)
.put(CodegenConstants.IMPL_FOLDER, IMPL_FOLDER_VALUE)
//.put(JavaJaxRSJersey1ServerCodegen.DATE_LIBRARY, "joda") //java.lang.IllegalArgumentException: Multiple entries with same key: dateLibrary=joda and dateLibrary=joda
.put("title", "Test title");
builder.put(CodegenConstants.IMPL_FOLDER, IMPL_FOLDER_VALUE)
.put(JavaClientCodegen.DATE_LIBRARY, "joda") //java.lang.IllegalArgumentException: Multiple entries with same key: dateLibrary=joda and dateLibrary=joda
.put("title", "Test title")
.put(CodegenConstants.MODEL_PACKAGE, MODEL_PACKAGE_VALUE)
.put(CodegenConstants.API_PACKAGE, API_PACKAGE_VALUE)
.put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, SORT_PARAMS_VALUE)
.put(CodegenConstants.ENSURE_UNIQUE_PARAMS, ENSURE_UNIQUE_PARAMS_VALUE)
.put(CodegenConstants.INVOKER_PACKAGE, INVOKER_PACKAGE_VALUE)
.put(CodegenConstants.GROUP_ID, GROUP_ID_VALUE)
.put(CodegenConstants.ARTIFACT_ID, ARTIFACT_ID_VALUE)
.put(CodegenConstants.ARTIFACT_VERSION, ARTIFACT_VERSION_VALUE)
.put(CodegenConstants.SOURCE_FOLDER, SOURCE_FOLDER_VALUE)
.put(CodegenConstants.LOCAL_VARIABLE_PREFIX, LOCAL_PREFIX_VALUE)
.put(CodegenConstants.SERIALIZABLE_MODEL, SERIALIZABLE_MODEL_VALUE)
.put(JavaClientCodegen.FULL_JAVA_UTIL, FULL_JAVA_UTIL_VALUE)
.put(CodegenConstants.LIBRARY, JAXRS_DEFAULT_LIBRARY_VALUE)
.put(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, "true")
.put(JavaClientCodegen.USE_RX_JAVA, "false")
//.put(JavaClientCodegen.DATE_LIBRARY, "joda")
.put("hideGenerationTimestamp", "true");
return builder.build();
}

View File

@@ -9,12 +9,12 @@ import java.util.Map;
public class ObjcClientOptionsProvider implements OptionsProvider {
public static final String CLASS_PREFIX_VALUE = "SWGObjc";
public static final String CORE_DATA_VALUE = "n";
public static final String POD_NAME_VALUE = "SwaggerClientObjc";
public static final String POD_VERSION_VALUE = "1.0.0-SNAPSHOT";
public static final String AUTHOR_NAME_VALUE = "SwaggerObjc";
public static final String AUTHOR_EMAIL_VALUE = "objc@swagger.io";
public static final String GIT_REPO_URL_VALUE = "https://github.com/swagger-api/swagger-codegen";
public static final String LICENSE_VALUE = "MIT";
@Override
public String getLanguage() {
@@ -30,7 +30,7 @@ public class ObjcClientOptionsProvider implements OptionsProvider {
.put(ObjcClientCodegen.AUTHOR_NAME, AUTHOR_NAME_VALUE)
.put(ObjcClientCodegen.AUTHOR_EMAIL, AUTHOR_EMAIL_VALUE)
.put(ObjcClientCodegen.GIT_REPO_URL, GIT_REPO_URL_VALUE)
.put(ObjcClientCodegen.LICENSE, LICENSE_VALUE)
.put(ObjcClientCodegen.CORE_DATA, CORE_DATA_VALUE)
.build();
}

View File

@@ -18,6 +18,8 @@ public class PhpClientOptionsProvider implements OptionsProvider {
public static final String SRC_BASE_PATH_VALUE = "libPhp";
public static final String COMPOSER_VENDOR_NAME_VALUE = "swaggerPhp";
public static final String COMPOSER_PROJECT_NAME_VALUE = "swagger-client-php";
public static final String GIT_USER_ID_VALUE = "gitSwaggerPhp";
public static final String GIT_REPO_ID_VALUE = "git-swagger-client-php";
public static final String ARTIFACT_VERSION_VALUE = "1.0.0-SNAPSHOT";
@Override
@@ -37,7 +39,9 @@ public class PhpClientOptionsProvider implements OptionsProvider {
.put(PhpClientCodegen.PACKAGE_PATH, PACKAGE_PATH_VALUE)
.put(PhpClientCodegen.SRC_BASE_PATH, SRC_BASE_PATH_VALUE)
.put(PhpClientCodegen.COMPOSER_VENDOR_NAME, COMPOSER_VENDOR_NAME_VALUE)
.put(CodegenConstants.GIT_USER_ID, GIT_USER_ID_VALUE)
.put(PhpClientCodegen.COMPOSER_PROJECT_NAME, COMPOSER_PROJECT_NAME_VALUE)
.put(CodegenConstants.GIT_REPO_ID, GIT_REPO_ID_VALUE)
.put(CodegenConstants.ARTIFACT_VERSION, ARTIFACT_VERSION_VALUE)
.build();
}

View File

@@ -10,6 +10,10 @@ public class SpringBootServerOptionsProvider extends JavaOptionsProvider {
public static final String CONFIG_PACKAGE_VALUE = "configPackage";
public static final String BASE_PACKAGE_VALUE = "basePackage";
public static final String LIBRARY_VALUE = "j8-async"; //FIXME hidding value from super class
public static final String INTERFACE_ONLY = "true";
public static final String SINGLE_CONTENT_TYPES = "true";
public static final String JAVA_8 = "true";
public static final String ASYNC = "true";
@Override
public String getLanguage() {
@@ -22,6 +26,11 @@ public class SpringBootServerOptionsProvider extends JavaOptionsProvider {
options.put(SpringBootServerCodegen.CONFIG_PACKAGE, CONFIG_PACKAGE_VALUE);
options.put(SpringBootServerCodegen.BASE_PACKAGE, BASE_PACKAGE_VALUE);
options.put(CodegenConstants.LIBRARY, LIBRARY_VALUE);
options.put(SpringBootServerCodegen.INTERFACE_ONLY, INTERFACE_ONLY);
options.put(SpringBootServerCodegen.SINGLE_CONTENT_TYPES, SINGLE_CONTENT_TYPES);
options.put(SpringBootServerCodegen.JAVA_8, JAVA_8);
options.put(SpringBootServerCodegen.ASYNC, ASYNC);
return options;
}

View File

@@ -42,8 +42,12 @@ public class PhpClientOptionsTest extends AbstractOptionsTest {
times = 1;
clientCodegen.setComposerVendorName(PhpClientOptionsProvider.COMPOSER_VENDOR_NAME_VALUE);
times = 1;
clientCodegen.setGitUserId(PhpClientOptionsProvider.GIT_USER_ID_VALUE);
times = 1;
clientCodegen.setComposerProjectName(PhpClientOptionsProvider.COMPOSER_PROJECT_NAME_VALUE);
times = 1;
clientCodegen.setGitRepoId(PhpClientOptionsProvider.GIT_REPO_ID_VALUE);
times = 1;
clientCodegen.setArtifactVersion(PhpClientOptionsProvider.ARTIFACT_VERSION_VALUE);
times = 1;
}};

View File

@@ -54,6 +54,14 @@ public class SpringBootServerOptionsTest extends JavaClientOptionsTest {
times = 1;
clientCodegen.setBasePackage(SpringBootServerOptionsProvider.BASE_PACKAGE_VALUE);
times = 1;
clientCodegen.setInterfaceOnly(Boolean.valueOf(SpringBootServerOptionsProvider.INTERFACE_ONLY));
times = 1;
clientCodegen.setSingleContentTypes(Boolean.valueOf(SpringBootServerOptionsProvider.SINGLE_CONTENT_TYPES));
times = 1;
clientCodegen.setJava8(Boolean.valueOf(SpringBootServerOptionsProvider.JAVA_8));
times = 1;
clientCodegen.setAsync(Boolean.valueOf(SpringBootServerOptionsProvider.ASYNC));
times = 1;
}};
}

View File

@@ -0,0 +1,132 @@
package io.swagger.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.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));
}
assertEquals(expectedDir.toFile().list(),
actualDir.toFile().list(),
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: '" + expected.toAbsolutePath().toString() + "' \n");
stringBuilder.append("\tfile: '" + actual.toAbsolutePath().toString() + "' \n");
stringBuilder.append("\tdiffs:\n");
for (Delta delta: deltas) {
stringBuilder.append(delta.toString() + "\n");
}
fail(stringBuilder.toString());
}
} catch (IOException e) {
fail(e.getMessage(), e);
}
}
}

View File

@@ -0,0 +1,33 @@
package io.swagger.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;
public IntegrationTestPathsConfig(String location) {
this(location + "-spec.json", location + "-result", location + "-expected");
}
public IntegrationTestPathsConfig(String specLocation, String outputLocation, String expectedLocation) {
outputPath = INTEGRATION_TEST_PATH.resolve(outputLocation);
expectedPath = INTEGRATION_TEST_PATH.resolve(expectedLocation);
specPath = INTEGRATION_TEST_PATH.resolve(specLocation);
}
public Path getOutputPath() {
return outputPath;
}
public Path getSpecPath() {
return specPath;
}
public Path getExpectedPath() {
return expectedPath;
}
}

View File

@@ -1,4 +1,4 @@
package io.swagger.codegen.typescriptfetch;
package io.swagger.codegen.typescript.fetch;
import io.swagger.codegen.AbstractOptionsTest;
import io.swagger.codegen.CodegenConfig;

View File

@@ -1,6 +1,10 @@
package io.swagger.codegen.typescriptfetch;
package io.swagger.codegen.typescript.fetch;
import com.google.common.collect.Sets;
import org.testng.Assert;
import org.testng.annotations.Test;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenProperty;
import io.swagger.codegen.DefaultCodegen;
@@ -8,9 +12,11 @@ import io.swagger.codegen.languages.TypeScriptFetchClientCodegen;
import io.swagger.models.ArrayModel;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.properties.*;
import org.testng.Assert;
import org.testng.annotations.Test;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.DateTimeProperty;
import io.swagger.models.properties.LongProperty;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
@SuppressWarnings("static-method")
public class TypeScriptFetchModelTest {

View File

@@ -1,4 +1,4 @@
package io.swagger.codegen.typescriptangular;
package io.swagger.codegen.typescript.typescriptangular;
import io.swagger.codegen.AbstractOptionsTest;
import io.swagger.codegen.CodegenConfig;

View File

@@ -1,4 +1,4 @@
package io.swagger.codegen.typescriptangular;
package io.swagger.codegen.typescript.typescriptangular;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenProperty;

View File

@@ -1,4 +1,4 @@
package io.swagger.codegen.typescriptangular2;
package io.swagger.codegen.typescript.typescriptangular2;
import io.swagger.codegen.AbstractOptionsTest;
import io.swagger.codegen.CodegenConfig;

View File

@@ -1,4 +1,4 @@
package io.swagger.codegen.typescriptangular2;
package io.swagger.codegen.typescript.typescriptangular2;
import com.google.common.collect.Sets;
@@ -178,6 +178,7 @@ public class TypeScriptAngular2ModelTest {
Assert.assertEquals(cm.description, "a map model");
Assert.assertEquals(cm.vars.size(), 0);
Assert.assertEquals(cm.imports.size(), 1);
Assert.assertEquals(cm.additionalPropertiesType, "models.Children");
Assert.assertEquals(Sets.intersection(cm.imports, Sets.newHashSet("models.Children")).size(), 1);
}
}

View File

@@ -0,0 +1,32 @@
package io.swagger.codegen.typescript.typescriptangular2;
import java.util.HashMap;
import java.util.Map;
import io.swagger.codegen.AbstractIntegrationTest;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.languages.TypeScriptAngular2ClientCodegen;
import io.swagger.codegen.testutils.IntegrationTestPathsConfig;
public class TypescriptAngular2AdditionalPropertiesIntegrationTest extends AbstractIntegrationTest {
@Override
protected CodegenConfig getCodegenConfig() {
return new TypeScriptAngular2ClientCodegen();
}
@Override
protected Map<String, String> configProperties() {
Map<String, String> propeties = new HashMap<>();
propeties.put("npmName", "additionalPropertiesTest");
propeties.put("npmVersion", "1.0.2");
propeties.put("snapshot", "false");
return propeties;
}
@Override
protected IntegrationTestPathsConfig getIntegrationTestPathsConfig() {
return new IntegrationTestPathsConfig("typescript/additional-properties");
}
}

View File

@@ -0,0 +1,32 @@
package io.swagger.codegen.typescript.typescriptangular2;
import java.util.HashMap;
import java.util.Map;
import io.swagger.codegen.AbstractIntegrationTest;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.languages.TypeScriptAngular2ClientCodegen;
import io.swagger.codegen.testutils.IntegrationTestPathsConfig;
public class TypescriptAngular2ArrayAndObjectTest extends AbstractIntegrationTest {
@Override
protected CodegenConfig getCodegenConfig() {
return new TypeScriptAngular2ClientCodegen();
}
@Override
protected Map<String, String> configProperties() {
Map<String, String> propeties = new HashMap<>();
propeties.put("npmName", "arrayAndAnyTest");
propeties.put("npmVersion", "1.0.2");
propeties.put("snapshot", "false");
return propeties;
}
@Override
protected IntegrationTestPathsConfig getIntegrationTestPathsConfig() {
return new IntegrationTestPathsConfig("typescript/array-and-object");
}
}

View File

@@ -1,4 +1,4 @@
package io.swagger.codegen.typescriptnode;
package io.swagger.codegen.typescript.typescriptnode;
import io.swagger.codegen.AbstractOptionsTest;
import io.swagger.codegen.CodegenConfig;

View File

@@ -1,4 +1,4 @@
package io.swagger.codegen.typescriptnode;
package io.swagger.codegen.typescript.typescriptnode;
import io.swagger.codegen.CodegenModel;
import io.swagger.codegen.CodegenProperty;

View File

@@ -0,0 +1,33 @@
package io.swagger.codegen.typescript.typescriptnode;
import java.util.HashMap;
import java.util.Map;
import io.swagger.codegen.AbstractIntegrationTest;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.languages.TypeScriptNodeClientCodegen;
import io.swagger.codegen.testutils.IntegrationTestPathsConfig;
public class TypescriptNodeES5IntegrationTest extends AbstractIntegrationTest {
@Override
protected CodegenConfig getCodegenConfig() {
return new TypeScriptNodeClientCodegen();
}
@Override
protected Map<String, String> configProperties() {
Map<String, String> propeties = new HashMap<>();
propeties.put("npmName", "node-es6-test");
propeties.put("npmVersion", "1.0.3");
propeties.put("snapshot", "false");
propeties.put("supportsES6", "false");
return propeties;
}
@Override
protected IntegrationTestPathsConfig getIntegrationTestPathsConfig() {
return new IntegrationTestPathsConfig("typescript/node-es5");
}
}