diff --git a/modules/swagger-codegen/pom.xml b/modules/swagger-codegen/pom.xml index 9ea75ad3c88..b4defc425cb 100644 --- a/modules/swagger-codegen/pom.xml +++ b/modules/swagger-codegen/pom.xml @@ -199,6 +199,9 @@ + + 1.2.1 + io.swagger @@ -279,6 +282,13 @@ test + + com.googlecode.java-diff-utils + diffutils + ${diffutils-version} + test + + diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOpts.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOpts.java index 1087de5786d..172a057ea43 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOpts.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/ClientOpts.java @@ -1,10 +1,10 @@ package io.swagger.codegen; -import io.swagger.codegen.auth.AuthMethod; - import java.util.HashMap; import java.util.Map; +import io.swagger.codegen.auth.AuthMethod; + public class ClientOpts { protected String uri; protected String target; diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java index 438eb191294..05883df4cfc 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenModel.java @@ -1,7 +1,13 @@ package io.swagger.codegen; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + import io.swagger.models.ExternalDocs; -import java.util.*; + public class CodegenModel { public String parent, parentSchema; @@ -32,6 +38,9 @@ public class CodegenModel { public Map vendorExtensions; + //The type of the value from additional properties. Used in map like objects. + public String additionalPropertiesType; + { // By default these are the same collections. Where the code generator supports inheritance, composed models // store the complete closure of owned and inherited properties in allVars and allMandatory. diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 8f3fc7be632..15eed39154a 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -2,25 +2,76 @@ package io.swagger.codegen; import com.google.common.base.Function; import com.google.common.collect.Lists; -import io.swagger.codegen.examples.ExampleGenerator; -import io.swagger.models.*; -import io.swagger.models.auth.*; -import io.swagger.models.parameters.*; -import io.swagger.models.properties.*; -import io.swagger.models.properties.PropertyBuilder.PropertyId; -import io.swagger.util.Json; + import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import javax.annotation.Nullable; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; +import java.util.Set; +import java.util.TreeSet; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.annotation.Nullable; + +import io.swagger.codegen.examples.ExampleGenerator; +import io.swagger.models.ArrayModel; +import io.swagger.models.ComposedModel; +import io.swagger.models.Model; +import io.swagger.models.ModelImpl; +import io.swagger.models.Operation; +import io.swagger.models.RefModel; +import io.swagger.models.Response; +import io.swagger.models.Swagger; +import io.swagger.models.auth.ApiKeyAuthDefinition; +import io.swagger.models.auth.BasicAuthDefinition; +import io.swagger.models.auth.In; +import io.swagger.models.auth.OAuth2Definition; +import io.swagger.models.auth.SecuritySchemeDefinition; +import io.swagger.models.parameters.BodyParameter; +import io.swagger.models.parameters.CookieParameter; +import io.swagger.models.parameters.FormParameter; +import io.swagger.models.parameters.HeaderParameter; +import io.swagger.models.parameters.Parameter; +import io.swagger.models.parameters.PathParameter; +import io.swagger.models.parameters.QueryParameter; +import io.swagger.models.parameters.SerializableParameter; +import io.swagger.models.properties.AbstractNumericProperty; +import io.swagger.models.properties.ArrayProperty; +import io.swagger.models.properties.BaseIntegerProperty; +import io.swagger.models.properties.BinaryProperty; +import io.swagger.models.properties.BooleanProperty; +import io.swagger.models.properties.ByteArrayProperty; +import io.swagger.models.properties.DateProperty; +import io.swagger.models.properties.DateTimeProperty; +import io.swagger.models.properties.DecimalProperty; +import io.swagger.models.properties.DoubleProperty; +import io.swagger.models.properties.FloatProperty; +import io.swagger.models.properties.IntegerProperty; +import io.swagger.models.properties.LongProperty; +import io.swagger.models.properties.MapProperty; +import io.swagger.models.properties.Property; +import io.swagger.models.properties.PropertyBuilder; +import io.swagger.models.properties.PropertyBuilder.PropertyId; +import io.swagger.models.properties.RefProperty; +import io.swagger.models.properties.StringProperty; +import io.swagger.models.properties.UUIDProperty; +import io.swagger.util.Json; + public class DefaultCodegen { protected static final Logger LOGGER = LoggerFactory.getLogger(DefaultCodegen.class); @@ -1207,8 +1258,7 @@ public class DefaultCodegen { m.dataType = getSwaggerType(p); } if (impl.getAdditionalProperties() != null) { - MapProperty mapProperty = new MapProperty(impl.getAdditionalProperties()); - addParentContainer(m, name, mapProperty); + addAdditionPropertiesToCodeGenModel(m, impl); } addVars(m, impl.getProperties(), impl.getRequired()); } @@ -1221,8 +1271,12 @@ public class DefaultCodegen { return m; } - protected void addProperties(Map properties, List required, Model model, - Map allDefinitions) { + protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, ModelImpl swaggerModel) { + MapProperty mapProperty = new MapProperty(swaggerModel.getAdditionalProperties()); + addParentContainer(codegenModel, codegenModel.name, mapProperty); + } + + protected void addProperties(Map properties, List required, Model model, Map allDefinitions) { if (model instanceof ModelImpl) { ModelImpl mi = (ModelImpl) model; @@ -2460,7 +2514,7 @@ public class DefaultCodegen { } } - private void addImport(CodegenModel m, String type) { + protected void addImport(CodegenModel m, String type) { if (type != null && needToImport(type)) { m.imports.add(type); } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java index a80e0f66ae0..aa14a565d10 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java @@ -5,8 +5,10 @@ import java.text.SimpleDateFormat; import java.util.Date; import io.swagger.codegen.CliOption; +import io.swagger.codegen.CodegenModel; import io.swagger.codegen.CodegenParameter; import io.swagger.codegen.SupportingFile; +import io.swagger.models.ModelImpl; import io.swagger.models.properties.ArrayProperty; import io.swagger.models.properties.BooleanProperty; import io.swagger.models.properties.FileProperty; @@ -43,6 +45,12 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString())); } + @Override + protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, ModelImpl swaggerModel) { + codegenModel.additionalPropertiesType = getSwaggerType(swaggerModel.getAdditionalProperties()); + addImport(codegenModel, codegenModel.additionalPropertiesType); + } + @Override public String getName() { return "typescript-angular2"; diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache index 05b5c6ec2ea..9a39b864538 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/apis.mustache @@ -1,9 +1,7 @@ {{#apiInfo}} {{#apis}} {{#operations}} -export * from '../api/{{classname}}'; +export * from './{{ classname }}'; {{/operations}} {{/apis}} -{{/apiInfo}} - - +{{/apiInfo}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache index 4170b2d1594..e8ce6c3642b 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/model.mustache @@ -9,6 +9,7 @@ import * as models from './models'; */ {{/description}} export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent}}{ + {{#additionalPropertiesType}}[key: string]: {{{additionalPropertiesType}}}{{#hasVars}} | any{{/hasVars}};{{/additionalPropertiesType}} {{#vars}} {{#description}} @@ -19,7 +20,6 @@ export interface {{classname}} {{#parent}}extends models.{{{parent}}} {{/parent} {{name}}?: {{#isEnum}}{{classname}}.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}}; {{/vars}} } - {{#hasEnums}} export namespace {{classname}} { {{#vars}} @@ -33,4 +33,4 @@ export namespace {{classname}} { } {{/hasEnums}} {{/model}} -{{/models}} +{{/models}} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/models.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/models.mustache index 677b6b87328..ace053bd55b 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/models.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/models.mustache @@ -3,6 +3,3 @@ export * from './{{{ classname }}}'; {{/model}} {{/models}} - - - diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache index 547200a6695..28a18bfb91b 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/package.mustache @@ -16,15 +16,8 @@ "build": "typings install && tsc" }, "peerDependencies": { - "@angular/common": "^2.0.0-rc.1", - "@angular/compiler": "^2.0.0-rc.1", "@angular/core": "^2.0.0-rc.1", - "@angular/http": "^2.0.0-rc.1", - "@angular/platform-browser": "^2.0.0-rc.1", - "@angular/platform-browser-dynamic": "^2.0.0-rc.1", - "core-js": "^2.3.0", - "rxjs": "^5.0.0-beta.6", - "zone.js": "^0.6.12" + "@angular/http": "^2.0.0-rc.1" }, "devDependencies": { "@angular/common": "^2.0.0-rc.1", diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/AbstractIntegrationTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/AbstractIntegrationTest.java new file mode 100644 index 00000000000..fa4d2e9da53 --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/AbstractIntegrationTest.java @@ -0,0 +1,45 @@ +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 configProperties(); + + @Test + 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()); + } +} diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/testutils/AssertFile.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/testutils/AssertFile.java new file mode 100644 index 00000000000..f810e20eb0a --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/testutils/AssertFile.java @@ -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.
+ * There will be a textual comparison of all files under expected with all files under actual. File attributes will + * not be considered.
+ * Missing or additional files are considered an error.
+ * + * @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() { + + @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 expectedLines = Files.readAllLines(expected, Charset.defaultCharset()); + List actualLines = Files.readAllLines(actual, Charset.defaultCharset()); + Patch diff = DiffUtils.diff(expectedLines, actualLines); + List 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); + } + } +} + diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/testutils/IntegrationTestPathsConfig.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/testutils/IntegrationTestPathsConfig.java new file mode 100644 index 00000000000..4335c69dd2d --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/testutils/IntegrationTestPathsConfig.java @@ -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; + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptfetch/TypeScriptFetchClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/fetch/TypeScriptFetchClientOptionsTest.java similarity index 96% rename from modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptfetch/TypeScriptFetchClientOptionsTest.java rename to modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/fetch/TypeScriptFetchClientOptionsTest.java index 09f16799ad9..c2744cc8258 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptfetch/TypeScriptFetchClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/fetch/TypeScriptFetchClientOptionsTest.java @@ -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; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptfetch/TypeScriptFetchModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/fetch/TypeScriptFetchModelTest.java similarity index 96% rename from modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptfetch/TypeScriptFetchModelTest.java rename to modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/fetch/TypeScriptFetchModelTest.java index d2173fdb710..d1b0a4be233 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptfetch/TypeScriptFetchModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/fetch/TypeScriptFetchModelTest.java @@ -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 { diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java similarity index 95% rename from modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularClientOptionsTest.java rename to modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java index 70cfb3d250d..2a68ab37110 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java @@ -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; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularModelTest.java similarity index 99% rename from modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularModelTest.java rename to modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularModelTest.java index 26e8f841be9..75ab210966d 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular/TypeScriptAngularModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularModelTest.java @@ -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; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypeScriptAngular2ClientOptionsTest.java similarity index 95% rename from modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ClientOptionsTest.java rename to modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypeScriptAngular2ClientOptionsTest.java index 74e575c4496..73ace65a207 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypeScriptAngular2ClientOptionsTest.java @@ -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; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypeScriptAngular2ModelTest.java similarity index 98% rename from modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ModelTest.java rename to modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypeScriptAngular2ModelTest.java index 3aa33df7da4..685495f03c2 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptangular2/TypeScriptAngular2ModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypeScriptAngular2ModelTest.java @@ -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); } } diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypescriptAngular2AdditionalPropertiesIntegrationTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypescriptAngular2AdditionalPropertiesIntegrationTest.java new file mode 100644 index 00000000000..8b23105f28c --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular2/TypescriptAngular2AdditionalPropertiesIntegrationTest.java @@ -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 configProperties() { + Map 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"); + } +} diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptnode/TypeScriptNodeClientOptionsTest.java similarity index 95% rename from modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeClientOptionsTest.java rename to modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptnode/TypeScriptNodeClientOptionsTest.java index 72b55b0b39d..4872e1d419d 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptnode/TypeScriptNodeClientOptionsTest.java @@ -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; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptnode/TypeScriptNodeModelTest.java similarity index 99% rename from modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeModelTest.java rename to modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptnode/TypeScriptNodeModelTest.java index 81a67e87b87..37e4fb688e0 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescriptnode/TypeScriptNodeModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptnode/TypeScriptNodeModelTest.java @@ -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; diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index b9fa750d38a..6b4fc91b50e 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -944,6 +944,22 @@ definitions: enum: - 1.1 - -1.2 + AdditionalPropertiesClass: + type: object + additionalProperties: + type: string + MixedPropertiesAndAdditionalPropertiesClass: + type: object + properties: + uuid: + type: string + format: uuid + dateTime: + type: string + format: date-time + additionalProperties: + type: string + $ref: '#/definitions/Animal' externalDocs: description: Find out more about Swagger url: 'http://swagger.io' diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/README.md b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/README.md new file mode 100644 index 00000000000..b5338574869 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/README.md @@ -0,0 +1,33 @@ +## additionalPropertiesTest@1.0.2 + +### Building + +To build an compile the typescript sources to javascript use: +``` +npm install +npm run build +``` + +### publishing + +First build the package than run ```npm publish``` + +### consuming + +navigate to the folder of your consuming project and run one of next commando's. + +_published:_ + +``` +npm install additionalPropertiesTest@1.0.2 --save +``` + +_unPublished (not recommended):_ + +``` +npm install PATH_TO_GENERATED_PACKAGE --save +``` + +In your angular2 project: + +TODO: paste example. diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/api/UserApi.ts b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/api/UserApi.ts new file mode 100644 index 00000000000..77b6c013a8b --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/api/UserApi.ts @@ -0,0 +1,64 @@ +import {Http, Headers, RequestOptionsArgs, Response, URLSearchParams} from '@angular/http'; +import {Injectable, Optional} from '@angular/core'; +import {Observable} from 'rxjs/Observable'; +import * as models from '../model/models'; +import 'rxjs/Rx'; + +/* tslint:disable:no-unused-variable member-ordering */ + +'use strict'; + +@Injectable() +export class UserApi { + protected basePath = 'http://additional-properties.swagger.io/v2'; + public defaultHeaders : Headers = new Headers(); + + constructor(protected http: Http, @Optional() basePath: string) { + if (basePath) { + this.basePath = basePath; + } + } + + /** + * Add a new User to the store + * + * @param body User object that needs to be added to the store + */ + public addUser (body?: models.User, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/user'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'POST', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + + /** + * Update an existing User + * + * @param body User object that needs to be added to the store + */ + public updateUser (body?: models.User, extraHttpRequestParams?: any ) : Observable<{}> { + const path = this.basePath + '/user'; + + let queryParameters: any = ""; // This should probably be an object in the future + let headerParams = this.defaultHeaders; + let requestOptions: RequestOptionsArgs = { + method: 'PUT', + headers: headerParams, + search: queryParameters + }; + requestOptions.body = JSON.stringify(body); + + return this.http.request(path, requestOptions) + .map((response: Response) => response.json()); + } + +} diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/api/api.ts b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/api/api.ts new file mode 100644 index 00000000000..d3bd8432806 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/api/api.ts @@ -0,0 +1 @@ +export * from './UserApi'; diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/index.ts b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/index.ts new file mode 100644 index 00000000000..cdfea183ad3 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/index.ts @@ -0,0 +1,2 @@ +export * from './api/api'; +export * from './model/models'; diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/model/User.ts b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/model/User.ts new file mode 100644 index 00000000000..66f270cea01 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/model/User.ts @@ -0,0 +1,13 @@ +'use strict'; +import * as models from './models'; + +export interface User { + [key: string]: string | any; + + id?: number; + + /** + * User Status + */ + userStatus?: number; +} diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/model/models.ts b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/model/models.ts new file mode 100644 index 00000000000..f6b9f36c6e1 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/model/models.ts @@ -0,0 +1 @@ +export * from './User'; diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/package.json b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/package.json new file mode 100644 index 00000000000..36ec153321d --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/package.json @@ -0,0 +1,36 @@ +{ + "name": "additionalPropertiesTest", + "version": "1.0.2", + "description": "swagger client for additionalPropertiesTest", + "author": "Swagger Codegen Contributors", + "keywords": [ + "swagger-client" + ], + "license": "MIT", + "files": [ + "lib" + ], + "main": "./lib/index.js", + "typings": "./lib/index.d.ts", + "scripts": { + "build": "typings install && tsc" + }, + "peerDependencies": { + "@angular/core": "^2.0.0-rc.1", + "@angular/http": "^2.0.0-rc.1" + }, + "devDependencies": { + "@angular/common": "^2.0.0-rc.1", + "@angular/compiler": "^2.0.0-rc.1", + "@angular/core": "^2.0.0-rc.1", + "@angular/http": "^2.0.0-rc.1", + "@angular/platform-browser": "^2.0.0-rc.1", + "@angular/platform-browser-dynamic": "^2.0.0-rc.1", + "core-js": "^2.3.0", + "rxjs": "^5.0.0-beta.6", + "zone.js": "^0.6.12", + "typescript": "^1.8.10", + "typings": "^0.8.1", + "es6-shim": "^0.35.0", + "es7-reflect-metadata": "^1.6.0" + }} diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/tsconfig.json b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/tsconfig.json new file mode 100644 index 00000000000..07fbdf7e1b1 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "module": "commonjs", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "outDir": "./lib", + "noLib": false, + "declaration": true + }, + "exclude": [ + "node_modules", + "typings/main.d.ts", + "typings/main", + "lib" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts", + "typings/browser.d.ts" + ] +} diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/typings.json b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/typings.json new file mode 100644 index 00000000000..0848dcffe31 --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-expected/typings.json @@ -0,0 +1,5 @@ +{ + "ambientDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160317120654" + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-spec.json b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-spec.json new file mode 100644 index 00000000000..3a06b88986c --- /dev/null +++ b/modules/swagger-codegen/src/test/resources/integrationtests/typescript/additional-properties-spec.json @@ -0,0 +1,110 @@ +{ + "swagger": "2.0", + "info": { + "description": "This is a test spec", + "version": "1.0.0", + "title": "Swagger Additional Properties", + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "apiteam@swagger.io" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + } + }, + "host": "additional-properties.swagger.io", + "basePath": "/v2", + "schemes": [ + "http" + ], + "paths": { + "/user": { + "post": { + "tags": [ + "user" + ], + "summary": "Add a new User to the store", + "description": "", + "operationId": "addUser", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "User object that needs to be added to the store", + "required": false, + "schema": { + "$ref": "#/definitions/User" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + } + }, + "put": { + "tags": [ + "user" + ], + "summary": "Update an existing User", + "description": "", + "operationId": "updateUser", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "body", + "description": "User object that needs to be added to the store", + "required": false, + "schema": { + "$ref": "#/definitions/User" + } + } + ], + "responses": { + "405": { + "description": "Validation exception" + }, + "404": { + "description": "User not found" + }, + "400": { + "description": "Invalid ID supplied" + } + } + } + } + }, + "definitions": { + "User": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "userStatus": { + "type": "integer", + "format": "int32", + "description": "User Status" + } + }, + "additionalProperties": { + "type": "string" + } + } + } +}