forked from loafle/openapi-generator-original
Merge pull request #2882 from Vrolijkx/feature/integration-test
Adding correct code generation for additional properties in typescript angular2.
This commit is contained in:
commit
2ea40ada8b
@ -199,6 +199,9 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</reporting>
|
||||
<properties>
|
||||
<diffutils-version>1.2.1</diffutils-version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.swagger</groupId>
|
||||
@ -279,6 +282,13 @@
|
||||
<!-- <version>${jmockit-version}</version> -->
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.java-diff-utils</groupId>
|
||||
<artifactId>diffutils</artifactId>
|
||||
<version>${diffutils-version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
@ -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;
|
||||
|
@ -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<String, Object> 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.
|
||||
|
@ -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<String, Property> properties, List<String> required, Model model,
|
||||
Map<String, Model> allDefinitions) {
|
||||
protected void addAdditionPropertiesToCodeGenModel(CodegenModel codegenModel, ModelImpl swaggerModel) {
|
||||
MapProperty mapProperty = new MapProperty(swaggerModel.getAdditionalProperties());
|
||||
addParentContainer(codegenModel, codegenModel.name, mapProperty);
|
||||
}
|
||||
|
||||
protected void addProperties(Map<String, Property> properties, List<String> required, Model model, Map<String, Model> 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);
|
||||
}
|
||||
|
@ -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";
|
||||
|
@ -1,9 +1,7 @@
|
||||
{{#apiInfo}}
|
||||
{{#apis}}
|
||||
{{#operations}}
|
||||
export * from '../api/{{classname}}';
|
||||
export * from './{{ classname }}';
|
||||
{{/operations}}
|
||||
{{/apis}}
|
||||
{{/apiInfo}}
|
||||
|
||||
|
||||
|
@ -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}}
|
||||
|
@ -3,6 +3,3 @@
|
||||
export * from './{{{ classname }}}';
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
|
||||
|
||||
|
@ -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",
|
||||
|
@ -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<String, String> 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());
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
@ -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 {
|
@ -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;
|
@ -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;
|
@ -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;
|
@ -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);
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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;
|
@ -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;
|
@ -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'
|
||||
|
@ -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.
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './UserApi';
|
@ -0,0 +1,2 @@
|
||||
export * from './api/api';
|
||||
export * from './model/models';
|
@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
import * as models from './models';
|
||||
|
||||
export interface User {
|
||||
[key: string]: string | any;
|
||||
|
||||
id?: number;
|
||||
|
||||
/**
|
||||
* User Status
|
||||
*/
|
||||
userStatus?: number;
|
||||
}
|
@ -0,0 +1 @@
|
||||
export * from './User';
|
@ -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"
|
||||
}}
|
@ -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"
|
||||
]
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
{
|
||||
"ambientDependencies": {
|
||||
"core-js": "registry:dt/core-js#0.0.0+20160317120654"
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user