forked from loafle/openapi-generator-original
Merge branch 'swagger-codegen_renamed' into 'master' (#183)
* Added vendorExtensions.x-isPrimitive. (#7991) * Added vendorExtensions.x-isPrimitive. Switch template for constructFromObject. * Reflect review indication. * [typescript-angular] AOT-compatible API client (via ng-packagr and ngc) (#7984) * typescript-angular: uses ng-packagr for the build see https://github.com/swagger-api/swagger-codegen/issues/6722 see https://github.com/swagger-api/swagger-codegen/pull/6735/ * this should make everybody happy: Angular 2/4/5 AOT support - uses ngc when targeting Angular 2 (as seen in https://github.com/swagger-api/swagger-codegen/pull/6735) - uses ng-packagr 1 when targeting Angular 4 - uses ng-packagr 2 when targeting Angular 5 * removes bogus import * cleans / updates Petstore samples, adds a new sample for Angular 5 * typo in README * fixes broken travis build. adds pom.xml files again This reverts commit 471d248a2e9b5d8eed10c71644c222c053e007b0. * makes usage of `dist` more clear and i feel generally better when `npm run build` is called explicitly. - for ng-packagr 2 is doesn't matter, since the final package.json does not have any scripts - for old ng-packagr 1 it matters, scripts are copied to the final package.json which breaks installation via `npm install {{npmName}} --save` (it runs `npm run build` again) * typescript-angular: small improvements as suggested by @macjohnny * angular-typescript: updated petstore samples, 3rd try * Issue 5542, always generate pom and readme (#7977) * Issue 5542, generate pom.xml with separate parameter. InterfaceOnly=true for not generating pom.xml not works in every situation. * Issue 5542, generate pom.xml with separate parameter. InterfaceOnly=true for not generating pom.xml not works in every situation. * Issue #5542 Always generate pom.xml and README.md * [TypeScript][Angular] fix date path parameters (#7476, #7302) (#7479) * #7476, #7302: [TypeScript][Angular] fix date path parameters, fix path parameters with :.+ in it * #7476, #7302: [TypeScript][Angular] fix date path parameters, fix path parameters with :.+ in it * #7476, #7302: [TypeScript][Angular] fix date path parameters, fix path parameters with :.+ in it * #7476: generate samples * code cleanup * #7476: improve variable description * #7302: revert character skipping, since it will now have the same parameter name in the method signature and in the api path * #7302: generate samples * typescript-angular: added Interfaces to api exports if withInterfaces is selected (#7975) * added Interfaces to api exports if withInterfaces is selected * removed import of interface classes * added gererated petstore example api.ts * Fix Issue 8014 * Adapted to work with Angular2 Http and Angular 4.3+ HttpClient * removed unnecessary (others) for ng HttpClient from Interface * Golang Client Refactor (body and model in errors, typed optional parameters) (#7987) * Return abstracted errors with model data if available. * update tests with error models. * Return error models on the abstract type. * dont leak FH * duplicate of PR #7752 for issue #7511 * Change optional parameters to structs. * update documentation * fix circleCI failure * [typescript][angular] query parameter with null value should not be set (#8033) * #7893: [typescript][angular] fix optional query parameter null value * #7893: [typescript][angular] generate samples * #7893: [typescript][angular] generate samples * Version rest-assured has been updated to 3.1.0 (#8052) * [Dart] Fixes TypeError in Dart 2 mode (#7959) * Properly convert lists to dart types * Updated sample petstore client * Fixed maps in Dart strong mode Fixed list parsing for null-elements * change parseDate in es6/APIClient (#7973) * [PHP] Improve duplicated validation logic (#7954) * Improve duplicated validation logic * Update the samples
This commit is contained in:
parent
35f0cc221d
commit
07dfbad29d
@ -79,12 +79,11 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
typeMapping.put("UUID", "string");
|
typeMapping.put("UUID", "string");
|
||||||
|
|
||||||
importMapping = new HashMap<String, String>();
|
importMapping = new HashMap<String, String>();
|
||||||
importMapping.put("time.Time", "time");
|
|
||||||
importMapping.put("*os.File", "os");
|
|
||||||
|
|
||||||
cliOptions.clear();
|
cliOptions.clear();
|
||||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
|
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
|
||||||
.defaultValue("swagger"));
|
.defaultValue("swagger"));
|
||||||
|
|
||||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
|
||||||
.defaultValue(Boolean.TRUE.toString()));
|
.defaultValue(Boolean.TRUE.toString()));
|
||||||
}
|
}
|
||||||
@ -96,8 +95,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
* @return the escaped term
|
* @return the escaped term
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String escapeReservedWord(String name)
|
public String escapeReservedWord(String name) {
|
||||||
{
|
|
||||||
// Can't start with an underscore, as our fields need to start with an
|
// Can't start with an underscore, as our fields need to start with an
|
||||||
// UppercaseLetter so that Go treats them as public/visible.
|
// UppercaseLetter so that Go treats them as public/visible.
|
||||||
|
|
||||||
@ -181,7 +179,8 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
|
|
||||||
// model name starts with number
|
// model name starts with number
|
||||||
if (name.matches("^\\d.*")) {
|
if (name.matches("^\\d.*")) {
|
||||||
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + ("model_" + name));
|
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to "
|
||||||
|
+ ("model_" + name));
|
||||||
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
|
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,19 +209,17 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
// Give the base class a chance to process
|
// Give the base class a chance to process
|
||||||
super.postProcessParameter(parameter);
|
super.postProcessParameter(parameter);
|
||||||
|
|
||||||
char firstChar = parameter.paramName.charAt(0);
|
char nameFirstChar = parameter.paramName.charAt(0);
|
||||||
|
if (Character.isUpperCase(nameFirstChar)) {
|
||||||
if (Character.isUpperCase(firstChar)) {
|
|
||||||
// First char is already uppercase, just use paramName.
|
// First char is already uppercase, just use paramName.
|
||||||
parameter.vendorExtensions.put("x-exportParamName", parameter.paramName);
|
parameter.vendorExtensions.put("x-exportParamName", parameter.paramName);
|
||||||
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
// It's a lowercase first char, let's convert it to uppercase
|
// It's a lowercase first char, let's convert it to uppercase
|
||||||
StringBuilder sb = new StringBuilder(parameter.paramName);
|
StringBuilder sb = new StringBuilder(parameter.paramName);
|
||||||
sb.setCharAt(0, Character.toUpperCase(firstChar));
|
sb.setCharAt(0, Character.toUpperCase(nameFirstChar));
|
||||||
parameter.vendorExtensions.put("x-exportParamName", sb.toString());
|
parameter.vendorExtensions.put("x-exportParamName", sb.toString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getTypeDeclaration(Schema p) {
|
public String getTypeDeclaration(Schema p) {
|
||||||
@ -263,8 +260,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
type = typeMapping.get(openAPIType);
|
type = typeMapping.get(openAPIType);
|
||||||
if (languageSpecificPrimitives.contains(type))
|
if (languageSpecificPrimitives.contains(type))
|
||||||
return (type);
|
return (type);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
type = openAPIType;
|
type = openAPIType;
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -275,7 +271,8 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
|
|
||||||
// method name cannot use reserved keyword, e.g. return
|
// method name cannot use reserved keyword, e.g. return
|
||||||
if (isReservedWord(sanitizedOperationId)) {
|
if (isReservedWord(sanitizedOperationId)) {
|
||||||
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize("call_" + operationId));
|
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to "
|
||||||
|
+ camelize("call_" + operationId));
|
||||||
sanitizedOperationId = "call_" + sanitizedOperationId;
|
sanitizedOperationId = "call_" + sanitizedOperationId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,16 +302,6 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if their is a return type, import encoding/json and if needed encoding/xml
|
|
||||||
for (CodegenOperation operation : operations) {
|
|
||||||
if(operation.returnBaseType != null ) {
|
|
||||||
imports.add(createMapping("import", "encoding/json"));
|
|
||||||
if (withXml)
|
|
||||||
imports.add(createMapping("import", "encoding/xml"));
|
|
||||||
break; //just need to import once
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// this will only import "fmt" if there are items in pathParams
|
// this will only import "fmt" if there are items in pathParams
|
||||||
for (CodegenOperation operation : operations) {
|
for (CodegenOperation operation : operations) {
|
||||||
if (operation.pathParams != null && operation.pathParams.size() > 0) {
|
if (operation.pathParams != null && operation.pathParams.size() > 0) {
|
||||||
@ -323,6 +310,43 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean addedOptionalImport = false;
|
||||||
|
boolean addedTimeImport = false;
|
||||||
|
boolean addedOSImport = false;
|
||||||
|
for (CodegenOperation operation : operations) {
|
||||||
|
for (CodegenParameter param : operation.allParams) {
|
||||||
|
// import "os" if the operation uses files
|
||||||
|
if (!addedOSImport && param.dataType == "*os.File") {
|
||||||
|
imports.add(createMapping("import", "os"));
|
||||||
|
addedOSImport = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// import "time" if the operation has a required time parameter.
|
||||||
|
if (param.required) {
|
||||||
|
if (!addedTimeImport && param.dataType == "time.Time") {
|
||||||
|
imports.add(createMapping("import", "time"));
|
||||||
|
addedTimeImport = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// import "optionals" package if the parameter is primitive and optional
|
||||||
|
if (!param.required && param.isPrimitiveType) {
|
||||||
|
if (!addedOptionalImport) {
|
||||||
|
imports.add(createMapping("import", "github.com/antihax/optional"));
|
||||||
|
addedOptionalImport = true;
|
||||||
|
}
|
||||||
|
// We need to specially map Time type to the optionals package
|
||||||
|
if (param.dataType == "time.Time") {
|
||||||
|
param.vendorExtensions.put("x-optionalDataType", "Time");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Map optional type to dataType
|
||||||
|
param.vendorExtensions.put("x-optionalDataType",
|
||||||
|
param.dataType.substring(0, 1).toUpperCase() + param.dataType.substring(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// recursively add import for mapping one type to multiple imports
|
// recursively add import for mapping one type to multiple imports
|
||||||
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
||||||
if (recursiveImports == null)
|
if (recursiveImports == null)
|
||||||
@ -353,6 +377,25 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean addedTimeImport = false;
|
||||||
|
boolean addedOSImport = false;
|
||||||
|
List<Map<String, Object>> models = (List<Map<String, Object>>) objs.get("models");
|
||||||
|
for (Map<String, Object> m : models) {
|
||||||
|
Object v = m.get("model");
|
||||||
|
if (v instanceof CodegenModel) {
|
||||||
|
CodegenModel model = (CodegenModel) v;
|
||||||
|
for (CodegenProperty param : model.vars) {
|
||||||
|
if (!addedTimeImport && param.baseType == "time.Time") {
|
||||||
|
imports.add(createMapping("import", "time"));
|
||||||
|
addedTimeImport = true;
|
||||||
|
}
|
||||||
|
if (!addedOSImport && param.baseType == "*os.File") {
|
||||||
|
imports.add(createMapping("import", "os"));
|
||||||
|
addedOSImport = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// recursively add import for mapping one type to multiple imports
|
// recursively add import for mapping one type to multiple imports
|
||||||
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
||||||
if (recursiveImports == null)
|
if (recursiveImports == null)
|
||||||
@ -379,8 +422,7 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean needToImport(String type) {
|
protected boolean needToImport(String type) {
|
||||||
return !defaultIncludes.contains(type)
|
return !defaultIncludes.contains(type) && !languageSpecificPrimitives.contains(type);
|
||||||
&& !languageSpecificPrimitives.contains(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPackageName(String packageName) {
|
public void setPackageName(String packageName) {
|
||||||
|
@ -82,7 +82,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
|||||||
supportedLibraries.put("resteasy", "HTTP client: Resteasy client 3.1.3.Final. JSON processing: Jackson 2.8.9");
|
supportedLibraries.put("resteasy", "HTTP client: Resteasy client 3.1.3.Final. JSON processing: Jackson 2.8.9");
|
||||||
supportedLibraries.put("vertx", "HTTP client: VertX client 3.2.4. JSON processing: Jackson 2.8.9");
|
supportedLibraries.put("vertx", "HTTP client: VertX client 3.2.4. JSON processing: Jackson 2.8.9");
|
||||||
supportedLibraries.put("google-api-client", "HTTP client: Google API client 1.23.0. JSON processing: Jackson 2.8.9");
|
supportedLibraries.put("google-api-client", "HTTP client: Google API client 1.23.0. JSON processing: Jackson 2.8.9");
|
||||||
supportedLibraries.put("rest-assured", "HTTP client: rest-assured : 3.0.6. JSON processing: Gson 2.6.1. Only for Java8");
|
supportedLibraries.put("rest-assured", "HTTP client: rest-assured : 3.1.0. JSON processing: Gson 2.6.1. Only for Java8");
|
||||||
|
|
||||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||||
libraryOption.setEnum(supportedLibraries);
|
libraryOption.setEnum(supportedLibraries);
|
||||||
|
@ -810,6 +810,11 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
if (model.getAdditionalProperties() != null) {
|
if (model.getAdditionalProperties() != null) {
|
||||||
codegenModel.getVendorExtensions().put("x-isMap", true);
|
codegenModel.getVendorExtensions().put("x-isMap", true);
|
||||||
codegenModel.getVendorExtensions().put("x-itemType", getSchemaType((Schema) model.getAdditionalProperties()));
|
codegenModel.getVendorExtensions().put("x-itemType", getSchemaType((Schema) model.getAdditionalProperties()));
|
||||||
|
} else {
|
||||||
|
String type = model.getType();
|
||||||
|
if (isPrimitiveType(type)){
|
||||||
|
codegenModel.vendorExtensions.put("x-isPrimitive", true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -894,6 +899,11 @@ public class JavascriptClientCodegen extends DefaultCodegen implements CodegenCo
|
|||||||
return !Boolean.TRUE.equals(co.returnTypeIsPrimitive);
|
return !Boolean.TRUE.equals(co.returnTypeIsPrimitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isPrimitiveType(String type) {
|
||||||
|
final String[] primitives = {"number", "integer", "string", "boolean", "null"};
|
||||||
|
return Arrays.asList(primitives).contains(type);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||||
|
@ -217,10 +217,11 @@ public class SpringCodegen extends AbstractJavaCodegen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.interfaceOnly) {
|
|
||||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||||
|
|
||||||
|
if (!this.interfaceOnly) {
|
||||||
|
|
||||||
if (library.equals(DEFAULT_LIBRARY)) {
|
if (library.equals(DEFAULT_LIBRARY)) {
|
||||||
supportingFiles.add(new SupportingFile("homeController.mustache",
|
supportingFiles.add(new SupportingFile("homeController.mustache",
|
||||||
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
(sourceFolder + File.separator + configPackage).replace(".", java.io.File.separator), "HomeController.java"));
|
||||||
|
@ -57,8 +57,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
apiPackage = "api";
|
apiPackage = "api";
|
||||||
modelPackage = "model";
|
modelPackage = "model";
|
||||||
|
|
||||||
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package"));
|
this.cliOptions.add(new CliOption(NPM_NAME, "The name under which you want to publish generated npm package." +
|
||||||
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package"));
|
" Required to generate a full angular package"));
|
||||||
|
this.cliOptions.add(new CliOption(NPM_VERSION, "The version of your npm package. Default is '1.0.0'"));
|
||||||
this.cliOptions.add(new CliOption(NPM_REPOSITORY,
|
this.cliOptions.add(new CliOption(NPM_REPOSITORY,
|
||||||
"Use this property to set an url your private npmRepo in the package.json"));
|
"Use this property to set an url your private npmRepo in the package.json"));
|
||||||
this.cliOptions.add(new CliOption(SNAPSHOT,
|
this.cliOptions.add(new CliOption(SNAPSHOT,
|
||||||
@ -86,7 +87,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHelp() {
|
public String getHelp() {
|
||||||
return "Generates a TypeScript Angular (2.x or 4.x) client library.";
|
return "Generates a TypeScript Angular (2.x - 5.x) client library.";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -105,8 +106,18 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||||
supportingFiles.add(new SupportingFile("README.mustache", getIndexDirectory(), "README.md"));
|
supportingFiles.add(new SupportingFile("README.mustache", getIndexDirectory(), "README.md"));
|
||||||
|
|
||||||
|
// determine NG version
|
||||||
|
SemVer ngVersion;
|
||||||
|
if (additionalProperties.containsKey(NG_VERSION)) {
|
||||||
|
ngVersion = new SemVer(additionalProperties.get(NG_VERSION).toString());
|
||||||
|
} else {
|
||||||
|
ngVersion = new SemVer("4.3.0");
|
||||||
|
LOGGER.info("generating code for Angular {} ...", ngVersion);
|
||||||
|
LOGGER.info(" (you can select the angular version by setting the additionalProperty ngVersion)");
|
||||||
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||||
addNpmPackageGeneration();
|
addNpmPackageGeneration(ngVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey(WITH_INTERFACES)) {
|
if (additionalProperties.containsKey(WITH_INTERFACES)) {
|
||||||
@ -120,15 +131,6 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
taggedUnions = Boolean.parseBoolean(additionalProperties.get(TAGGED_UNIONS).toString());
|
taggedUnions = Boolean.parseBoolean(additionalProperties.get(TAGGED_UNIONS).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// determine NG version
|
|
||||||
SemVer ngVersion;
|
|
||||||
if (additionalProperties.containsKey(NG_VERSION)) {
|
|
||||||
ngVersion = new SemVer(additionalProperties.get(NG_VERSION).toString());
|
|
||||||
} else {
|
|
||||||
ngVersion = new SemVer("4.3.0");
|
|
||||||
LOGGER.info("generating code for Angular {} ...", ngVersion);
|
|
||||||
LOGGER.info(" (you can select the angular version by setting the additionalProperty ngVersion)");
|
|
||||||
}
|
|
||||||
additionalProperties.put(NG_VERSION, ngVersion);
|
additionalProperties.put(NG_VERSION, ngVersion);
|
||||||
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
|
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
|
||||||
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));
|
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));
|
||||||
@ -138,7 +140,8 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNpmPackageGeneration() {
|
private void addNpmPackageGeneration(SemVer ngVersion) {
|
||||||
|
|
||||||
if (additionalProperties.containsKey(NPM_NAME)) {
|
if (additionalProperties.containsKey(NPM_NAME)) {
|
||||||
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
this.setNpmName(additionalProperties.get(NPM_NAME).toString());
|
||||||
}
|
}
|
||||||
@ -157,6 +160,20 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
|
this.setNpmRepository(additionalProperties.get(NPM_REPOSITORY).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for Angular 2 AOT support we will use good-old ngc,
|
||||||
|
// Angular Package format wasn't invented at this time and building was much more easier
|
||||||
|
if (!ngVersion.atLeast("4.0.0")) {
|
||||||
|
LOGGER.warn("Please update your legacy Angular " + ngVersion + " project to benefit from 'Angular Package Format' support.");
|
||||||
|
additionalProperties.put("useNgPackagr", false);
|
||||||
|
} else {
|
||||||
|
additionalProperties.put("useNgPackagr", true);
|
||||||
|
supportingFiles.add(new SupportingFile("ng-package.mustache", getIndexDirectory(), "ng-package.json"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Libraries generated with v1.x of ng-packagr will ship with AoT metadata in v3, which is intended for Angular v4.
|
||||||
|
// Libraries generated with v2.x of ng-packagr will ship with AoT metadata in v4, which is intended for Angular v5 (and Angular v6).
|
||||||
|
additionalProperties.put("useOldNgPackagr", !ngVersion.atLeast("5.0.0"));
|
||||||
|
|
||||||
//Files for building our lib
|
//Files for building our lib
|
||||||
supportingFiles.add(new SupportingFile("package.mustache", getIndexDirectory(), "package.json"));
|
supportingFiles.add(new SupportingFile("package.mustache", getIndexDirectory(), "package.json"));
|
||||||
supportingFiles.add(new SupportingFile("typings.mustache", getIndexDirectory(), "typings.json"));
|
supportingFiles.add(new SupportingFile("typings.mustache", getIndexDirectory(), "typings.json"));
|
||||||
@ -280,15 +297,20 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
insideCurly--;
|
insideCurly--;
|
||||||
|
|
||||||
// Add the more complicated component instead of just the brace.
|
// Add the more complicated component instead of just the brace.
|
||||||
|
CodegenParameter parameter = findPathParameterByName(op, parameterName.toString());
|
||||||
pathBuffer.append(toVarName(parameterName.toString()));
|
pathBuffer.append(toVarName(parameterName.toString()));
|
||||||
|
if (parameter != null && parameter.isDateTime) {
|
||||||
|
pathBuffer.append(".toISOString()");
|
||||||
|
}
|
||||||
pathBuffer.append("))}");
|
pathBuffer.append("))}");
|
||||||
parameterName.setLength(0);
|
parameterName.setLength(0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
char nextChar = op.path.charAt(i);
|
||||||
if (insideCurly > 0) {
|
if (insideCurly > 0) {
|
||||||
parameterName.append(op.path.charAt(i));
|
parameterName.append(nextChar);
|
||||||
} else {
|
} else {
|
||||||
pathBuffer.append(op.path.charAt(i));
|
pathBuffer.append(nextChar);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -308,6 +330,21 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
|
|||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds and returns a path parameter of an operation by its name
|
||||||
|
* @param operation
|
||||||
|
* @param parameterName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private CodegenParameter findPathParameterByName(CodegenOperation operation, String parameterName) {
|
||||||
|
for(CodegenParameter param : operation.pathParams) {
|
||||||
|
if (param.baseName.equals(parameterName)) {
|
||||||
|
return param;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
Map<String, Object> result = super.postProcessModels(objs);
|
Map<String, Object> result = super.postProcessModels(objs);
|
||||||
|
@ -30,11 +30,8 @@ public class {{classname}} {
|
|||||||
|
|
||||||
private RequestSpecBuilder reqSpec;
|
private RequestSpecBuilder reqSpec;
|
||||||
|
|
||||||
private JSON json;
|
|
||||||
|
|
||||||
private {{classname}}(RequestSpecBuilder reqSpec) {
|
private {{classname}}(RequestSpecBuilder reqSpec) {
|
||||||
this.reqSpec = reqSpec;
|
this.reqSpec = reqSpec;
|
||||||
this.json = new JSON();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static {{classname}} {{classVarName}}(RequestSpecBuilder reqSpec) {
|
public static {{classname}} {{classVarName}}(RequestSpecBuilder reqSpec) {
|
||||||
@ -53,26 +50,6 @@ public class {{classname}} {
|
|||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get JSON
|
|
||||||
*
|
|
||||||
* @return JSON object
|
|
||||||
*/
|
|
||||||
public JSON getJSON() {
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set JSON
|
|
||||||
*
|
|
||||||
* @param json JSON object
|
|
||||||
* @return {{classname}}
|
|
||||||
*/
|
|
||||||
public {{classname}} setJSON(JSON json) {
|
|
||||||
this.json = json;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Customise request specification
|
* Customise request specification
|
||||||
*/
|
*/
|
||||||
@ -152,7 +129,7 @@ public class {{classname}} {
|
|||||||
*/
|
*/
|
||||||
public {{{returnType}}} executeAs(Function<Response, Response> handler) {
|
public {{{returnType}}} executeAs(Function<Response, Response> handler) {
|
||||||
Type type = new TypeToken<{{{returnType}}}>(){}.getType();
|
Type type = new TypeToken<{{{returnType}}}>(){}.getType();
|
||||||
return getJSON().deserialize(execute(handler).asString(), type);
|
return execute(handler).as(type);
|
||||||
}
|
}
|
||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
{{#bodyParams}}
|
{{#bodyParams}}
|
||||||
@ -161,7 +138,7 @@ public class {{classname}} {
|
|||||||
* @param {{paramName}} ({{{dataType}}}) {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
* @param {{paramName}} ({{{dataType}}}) {{description}}{{#required}} (required){{/required}}{{^required}} (optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
|
||||||
*/
|
*/
|
||||||
public {{operationIdCamelCase}}Oper body({{{dataType}}} {{paramName}}) {
|
public {{operationIdCamelCase}}Oper body({{{dataType}}} {{paramName}}) {
|
||||||
reqSpec.setBody(getJSON().serialize({{paramName}}));
|
reqSpec.setBody({{paramName}});
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
{{/bodyParams}}
|
{{/bodyParams}}
|
||||||
|
@ -95,7 +95,7 @@ if(hasProperty('target') && target == 'android') {
|
|||||||
|
|
||||||
ext {
|
ext {
|
||||||
swagger_annotations_version = "1.5.15"
|
swagger_annotations_version = "1.5.15"
|
||||||
rest_assured_version = "3.0.6"
|
rest_assured_version = "3.1.0"
|
||||||
junit_version = "4.12"
|
junit_version = "4.12"
|
||||||
gson_version = "2.6.1"
|
gson_version = "2.6.1"
|
||||||
gson_fire_version = "1.8.2"
|
gson_fire_version = "1.8.2"
|
||||||
|
@ -10,7 +10,7 @@ lazy val root = (project in file(".")).
|
|||||||
resolvers += Resolver.mavenLocal,
|
resolvers += Resolver.mavenLocal,
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"io.swagger" % "swagger-annotations" % "1.5.15",
|
"io.swagger" % "swagger-annotations" % "1.5.15",
|
||||||
"io.rest-assured" % "scala-support" % "3.0.6",
|
"io.rest-assured" % "scala-support" % "3.1.0",
|
||||||
"com.google.code.gson" % "gson" % "2.6.1",
|
"com.google.code.gson" % "gson" % "2.6.1",
|
||||||
"io.gsonfire" % "gson-fire" % "1.8.2" % "compile",
|
"io.gsonfire" % "gson-fire" % "1.8.2" % "compile",
|
||||||
{{#joda}}
|
{{#joda}}
|
||||||
|
@ -246,7 +246,7 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<swagger-core-version>1.5.15</swagger-core-version>
|
<swagger-core-version>1.5.15</swagger-core-version>
|
||||||
<rest-assured.version>3.0.6</rest-assured.version>
|
<rest-assured.version>3.1.0</rest-assured.version>
|
||||||
<gson-version>2.6.1</gson-version>
|
<gson-version>2.6.1</gson-version>
|
||||||
<gson-fire-version>1.8.2</gson-fire-version>
|
<gson-fire-version>1.8.2</gson-fire-version>
|
||||||
<maven-plugin-version>1.0.0</maven-plugin-version>
|
<maven-plugin-version>1.0.0</maven-plugin-version>
|
||||||
|
@ -505,7 +505,7 @@ export default class ApiClient {
|
|||||||
* @returns {Date} The parsed date object.
|
* @returns {Date} The parsed date object.
|
||||||
*/{{/emitJSDoc}}
|
*/{{/emitJSDoc}}
|
||||||
static parseDate(str) {
|
static parseDate(str) {
|
||||||
return new Date(str.replace(/T/i, ' '));
|
return new Date(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#emitJSDoc}}/**
|
{{#emitJSDoc}}/**
|
||||||
|
@ -36,6 +36,12 @@
|
|||||||
* @return {{=< >=}}{module:<#invokerPackage><invokerPackage>/</invokerPackage><#modelPackage><modelPackage>/</modelPackage><classname>}<={{ }}=> The populated <code>{{classname}}</code> instance.
|
* @return {{=< >=}}{module:<#invokerPackage><invokerPackage>/</invokerPackage><#modelPackage><modelPackage>/</modelPackage><classname>}<={{ }}=> The populated <code>{{classname}}</code> instance.
|
||||||
*/
|
*/
|
||||||
{{/emitJSDoc}}
|
{{/emitJSDoc}}
|
||||||
|
{{#vendorExtensions.x-isPrimitive}}
|
||||||
|
exports.constructFromObject = function(data, obj) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
{{/vendorExtensions.x-isPrimitive}}
|
||||||
|
{{^vendorExtensions.x-isPrimitive}}
|
||||||
exports.constructFromObject = function(data, obj) {
|
exports.constructFromObject = function(data, obj) {
|
||||||
if (data){{! TODO: support polymorphism: discriminator property on data determines class to instantiate.}} {
|
if (data){{! TODO: support polymorphism: discriminator property on data determines class to instantiate.}} {
|
||||||
obj = obj || new exports();
|
obj = obj || new exports();
|
||||||
@ -48,6 +54,7 @@
|
|||||||
{{/vars}} }
|
{{/vars}} }
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
{{/vendorExtensions.x-isPrimitive}}
|
||||||
{{#useInheritance}}{{#parentModel}}
|
{{#useInheritance}}{{#parentModel}}
|
||||||
exports.prototype = Object.create({{classname}}.prototype);
|
exports.prototype = Object.create({{classname}}.prototype);
|
||||||
exports.prototype.constructor = exports;
|
exports.prototype.constructor = exports;
|
||||||
|
@ -90,7 +90,18 @@ class {{classname}} {
|
|||||||
if(response.statusCode >= 400) {
|
if(response.statusCode >= 400) {
|
||||||
throw new ApiException(response.statusCode, response.body);
|
throw new ApiException(response.statusCode, response.body);
|
||||||
} else if(response.body != null) {
|
} else if(response.body != null) {
|
||||||
return {{#returnType}}apiClient.deserialize(response.body, '{{{returnType}}}') as {{{returnType}}} {{/returnType}};
|
return
|
||||||
|
{{#isListContainer}}
|
||||||
|
{{#returnType}}(apiClient.deserialize(response.body, '{{{returnType}}}') as List).map((item) => item as {{returnBaseType}}).toList();{{/returnType}}
|
||||||
|
{{/isListContainer}}
|
||||||
|
{{^isListContainer}}
|
||||||
|
{{#isMapContainer}}
|
||||||
|
{{#returnType}}new {{{returnType}}}.from(apiClient.deserialize(response.body, '{{{returnType}}}')) {{/returnType}};
|
||||||
|
{{/isMapContainer}}
|
||||||
|
{{^isMapContainer}}
|
||||||
|
{{#returnType}}apiClient.deserialize(response.body, '{{{returnType}}}') as {{{returnType}}} {{/returnType}};
|
||||||
|
{{/isMapContainer}}
|
||||||
|
{{/isListContainer}}
|
||||||
} else {
|
} else {
|
||||||
return {{#returnType}}null{{/returnType}};
|
return {{#returnType}}null{{/returnType}};
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,14 @@ class {{classname}} {
|
|||||||
{{#isMapContainer}}{{complexType}}.mapFromJson(json['{{name}}']){{/isMapContainer}}
|
{{#isMapContainer}}{{complexType}}.mapFromJson(json['{{name}}']){{/isMapContainer}}
|
||||||
{{^isMapContainer}}new {{complexType}}.fromJson(json['{{name}}']){{/isMapContainer}}{{/isListContainer}}
|
{{^isMapContainer}}new {{complexType}}.fromJson(json['{{name}}']){{/isMapContainer}}{{/isListContainer}}
|
||||||
{{/complexType}}
|
{{/complexType}}
|
||||||
{{^complexType}}json['{{name}}']{{/complexType}};
|
{{^complexType}}
|
||||||
|
{{#isListContainer}}
|
||||||
|
(json['{{name}}'] as List).map((item) => item as {{items.datatype}}).toList()
|
||||||
|
{{/isListContainer}}
|
||||||
|
{{^isListContainer}}
|
||||||
|
json['{{name}}']
|
||||||
|
{{/isListContainer}}
|
||||||
|
{{/complexType}};
|
||||||
{{/isDateTime}}
|
{{/isDateTime}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
}
|
}
|
||||||
@ -36,12 +43,8 @@ class {{classname}} {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<{{classname}}> listFromJson(List<Map<String, dynamic>> json) {
|
static List<{{classname}}> listFromJson(List<dynamic> json) {
|
||||||
var list = new List<{{classname}}>();
|
return json == null ? new List<{{classname}}>() : json.map((value) => new {{classname}}.fromJson(value)).toList();
|
||||||
if (json != null && json.length > 0) {
|
|
||||||
json.forEach((Map<String, dynamic> value) => list.add(new {{classname}}.fromJson(value)));
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Map<String, {{classname}}> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
static Map<String, {{classname}}> mapFromJson(Map<String, Map<String, dynamic>> json) {
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
"golang.org/x/net/context"
|
"context"
|
||||||
{{#imports}} "{{import}}"
|
{{#imports}} "{{import}}"
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
)
|
)
|
||||||
@ -20,22 +20,30 @@ var (
|
|||||||
type {{classname}}Service service
|
type {{classname}}Service service
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
|
|
||||||
/* {{{classname}}}Service{{#summary}} {{.}}{{/summary}}{{#notes}}
|
/*
|
||||||
|
{{{classname}}}Service{{#summary}} {{.}}{{/summary}}{{#notes}}
|
||||||
{{notes}}{{/notes}}
|
{{notes}}{{/notes}}
|
||||||
* @param ctx context.Context for authentication, logging, tracing, etc.
|
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
||||||
{{#allParams}}{{#required}}@param {{paramName}}{{#description}} {{.}}{{/description}}
|
{{#allParams}}{{#required}} * @param {{paramName}}{{#description}} {{.}}{{/description}}
|
||||||
{{/required}}{{/allParams}}{{#hasOptionalParams}}@param optional (nil or map[string]interface{}) with one or more of:
|
{{/required}}{{/allParams}}{{#hasOptionalParams}} * @param optional nil or *{{{nickname}}}Opts - Optional Parameters:
|
||||||
{{#allParams}}{{^required}} @param "{{paramName}}" ({{dataType}}){{#description}} {{.}}{{/description}}
|
{{#allParams}}{{^required}} * @param "{{vendorExtensions.x-exportParamName}}" ({{#isPrimitiveType}}optional.{{vendorExtensions.x-optionalDataType}}{{/isPrimitiveType}}{{^isPrimitiveType}}optional.Interface of {{dataType}}{{/isPrimitiveType}}) - {{#description}} {{.}}{{/description}}
|
||||||
{{/required}}{{/allParams}}{{/hasOptionalParams}}@return {{#returnType}}{{{returnType}}}{{/returnType}}*/
|
{{/required}}{{/allParams}}{{/hasOptionalParams}}
|
||||||
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals map[string]interface{}{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {
|
{{#returnType}}@return {{{returnType}}}{{/returnType}}
|
||||||
|
*/
|
||||||
|
{{#hasOptionalParams}}
|
||||||
|
|
||||||
|
type {{{nickname}}}Opts struct { {{#allParams}}{{^required}}
|
||||||
|
{{#isPrimitiveType}} {{vendorExtensions.x-exportParamName}} optional.{{vendorExtensions.x-optionalDataType}}{{/isPrimitiveType}}{{^isPrimitiveType}} {{vendorExtensions.x-exportParamName}} optional.Interface{{/isPrimitiveType}}{{/required}}{{/allParams}}
|
||||||
|
}
|
||||||
|
|
||||||
|
{{/hasOptionalParams}}
|
||||||
|
func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#required}}{{paramName}} {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/required}}{{/allParams}}{{#hasOptionalParams}}localVarOptionals *{{{nickname}}}Opts{{/hasOptionalParams}}) ({{#returnType}}{{{returnType}}}, {{/returnType}}*http.Response, error) {
|
||||||
var (
|
var (
|
||||||
localVarHttpMethod = strings.ToUpper("{{httpMethod}}")
|
localVarHttpMethod = strings.ToUpper("{{httpMethod}}")
|
||||||
localVarPostBody interface{}
|
localVarPostBody interface{}
|
||||||
localVarFileName string
|
localVarFileName string
|
||||||
localVarFileBytes []byte
|
localVarFileBytes []byte
|
||||||
{{#returnType}}
|
{{#returnType}}localVarReturnValue {{{returnType}}}{{/returnType}}
|
||||||
successPayload {{returnType}}
|
|
||||||
{{/returnType}}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// create path and map variables
|
// create path and map variables
|
||||||
@ -46,32 +54,25 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
localVarQueryParams := url.Values{}
|
localVarQueryParams := url.Values{}
|
||||||
localVarFormParams := url.Values{}
|
localVarFormParams := url.Values{}
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
{{^required}}
|
|
||||||
{{#isPrimitiveType}}
|
|
||||||
if err := typeCheckParameter(localVarOptionals["{{paramName}}"], "{{{dataType}}}", "{{paramName}}"); err != nil {
|
|
||||||
return {{#returnType}}successPayload, {{/returnType}}nil, err
|
|
||||||
}
|
|
||||||
{{/isPrimitiveType}}
|
|
||||||
{{/required}}
|
|
||||||
{{#required}}
|
{{#required}}
|
||||||
{{#minItems}}
|
{{#minItems}}
|
||||||
if len({{paramName}}) < {{minItems}} {
|
if len({{paramName}}) < {{minItems}} {
|
||||||
return {{#returnType}}successPayload, {{/returnType}}nil, reportError("{{paramName}} must have at least {{minItems}} elements")
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("{{paramName}} must have at least {{minItems}} elements")
|
||||||
}
|
}
|
||||||
{{/minItems}}
|
{{/minItems}}
|
||||||
{{#maxItems}}
|
{{#maxItems}}
|
||||||
if len({{paramName}}) > {{maxItems}} {
|
if len({{paramName}}) > {{maxItems}} {
|
||||||
return {{#returnType}}successPayload, {{/returnType}}nil, reportError("{{paramName}} must have less than {{maxItems}} elements")
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("{{paramName}} must have less than {{maxItems}} elements")
|
||||||
}
|
}
|
||||||
{{/maxItems}}
|
{{/maxItems}}
|
||||||
{{#minLength}}
|
{{#minLength}}
|
||||||
if strlen({{paramName}}) < {{minLength}} {
|
if strlen({{paramName}}) < {{minLength}} {
|
||||||
return {{#returnType}}successPayload, {{/returnType}}nil, reportError("{{paramName}} must have at least {{minLength}} elements")
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("{{paramName}} must have at least {{minLength}} elements")
|
||||||
}
|
}
|
||||||
{{/minLength}}
|
{{/minLength}}
|
||||||
{{#maxLength}}
|
{{#maxLength}}
|
||||||
if strlen({{paramName}}) > {{maxLength}} {
|
if strlen({{paramName}}) > {{maxLength}} {
|
||||||
return {{#returnType}}successPayload, {{/returnType}}nil, reportError("{{paramName}} must have less than {{maxLength}} elements")
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("{{paramName}} must have less than {{maxLength}} elements")
|
||||||
}
|
}
|
||||||
{{/maxLength}}
|
{{/maxLength}}
|
||||||
{{#minimum}}
|
{{#minimum}}
|
||||||
@ -82,7 +83,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
{{^isString}}
|
{{^isString}}
|
||||||
if {{paramName}} < {{minimum}} {
|
if {{paramName}} < {{minimum}} {
|
||||||
{{/isString}}
|
{{/isString}}
|
||||||
return {{#returnType}}successPayload, {{/returnType}}nil, reportError("{{paramName}} must be greater than {{minimum}}")
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("{{paramName}} must be greater than {{minimum}}")
|
||||||
}
|
}
|
||||||
{{/minimum}}
|
{{/minimum}}
|
||||||
{{#maximum}}
|
{{#maximum}}
|
||||||
@ -93,7 +94,7 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
{{^isString}}
|
{{^isString}}
|
||||||
if {{paramName}} > {{maximum}} {
|
if {{paramName}} > {{maximum}} {
|
||||||
{{/isString}}
|
{{/isString}}
|
||||||
return {{#returnType}}successPayload, {{/returnType}}nil, reportError("{{paramName}} must be less than {{maximum}}")
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("{{paramName}} must be less than {{maximum}}")
|
||||||
}
|
}
|
||||||
{{/maximum}}
|
{{/maximum}}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
@ -105,8 +106,8 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
localVarQueryParams.Add("{{baseName}}", parameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
|
localVarQueryParams.Add("{{baseName}}", parameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOk {
|
if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() {
|
||||||
localVarQueryParams.Add("{{baseName}}", parameterToString(localVarTempParam, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
|
localVarQueryParams.Add("{{baseName}}", parameterToString(localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value(), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
|
||||||
}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/queryParams}}
|
{{/queryParams}}
|
||||||
@ -138,8 +139,8 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
localVarHeaderParams["{{baseName}}"] = parameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")
|
localVarHeaderParams["{{baseName}}"] = parameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOk {
|
if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() {
|
||||||
localVarHeaderParams["{{baseName}}"] = parameterToString(localVarTempParam, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")
|
localVarHeaderParams["{{baseName}}"] = parameterToString(localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value(), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}")
|
||||||
}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/headerParams}}
|
{{/headerParams}}
|
||||||
@ -148,9 +149,13 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
{{#formParams}}
|
{{#formParams}}
|
||||||
{{#isFile}}
|
{{#isFile}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
var localVarFile ({{dataType}})
|
var localVarFile {{dataType}}
|
||||||
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOk {
|
if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() {
|
||||||
localVarFile = localVarTempParam
|
localVarFileOk := false
|
||||||
|
localVarFile, localVarFileOk = localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value().({{dataType}})
|
||||||
|
if !localVarFileOk {
|
||||||
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("{{paramName}} should be {{dataType}}")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
if localVarFile != nil {
|
if localVarFile != nil {
|
||||||
@ -165,8 +170,8 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
localVarFormParams.Add("{{baseName}}", parameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
|
localVarFormParams.Add("{{baseName}}", parameterToString({{paramName}}, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOk {
|
if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() {
|
||||||
localVarFormParams.Add("{{baseName}}", parameterToString(localVarTempParam, "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
|
localVarFormParams.Add("{{baseName}}", parameterToString(localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value(), "{{#collectionFormat}}{{collectionFormat}}{{/collectionFormat}}"))
|
||||||
}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/isFile}}
|
{{/isFile}}
|
||||||
@ -178,8 +183,13 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
localVarPostBody = &{{paramName}}
|
localVarPostBody = &{{paramName}}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{^required}}
|
{{^required}}
|
||||||
if localVarTempParam, localVarOk := localVarOptionals["{{paramName}}"].({{dataType}}); localVarOk {
|
if localVarOptionals != nil && localVarOptionals.{{vendorExtensions.x-exportParamName}}.IsSet() {
|
||||||
localVarPostBody = &localVarTempParam
|
{{#isPrimitiveType}}localVarPostBody = &localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value(){{/isPrimitiveType}}
|
||||||
|
{{^isPrimitiveType}}localVarOptional{{vendorExtensions.x-exportParamName}}, localVarOptional{{vendorExtensions.x-exportParamName}}ok := localVarOptionals.{{vendorExtensions.x-exportParamName}}.Value().({{{dataType}}})
|
||||||
|
if !localVarOptional{{vendorExtensions.x-exportParamName}}ok {
|
||||||
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, reportError("{{paramName}} should be {{dataType}}")
|
||||||
|
}
|
||||||
|
localVarPostBody = &localVarOptional{{vendorExtensions.x-exportParamName}}{{/isPrimitiveType}}
|
||||||
}
|
}
|
||||||
{{/required}}
|
{{/required}}
|
||||||
{{/bodyParams}}
|
{{/bodyParams}}
|
||||||
@ -195,42 +205,63 @@ func (a *{{{classname}}}Service) {{{nickname}}}(ctx context.Context{{#hasParams}
|
|||||||
} else {
|
} else {
|
||||||
key = auth.Key
|
key = auth.Key
|
||||||
}
|
}
|
||||||
{{#isKeyInHeader}}localVarHeaderParams["{{keyParamName}}"] = key{{/isKeyInHeader}}{{#isKeyInQuery}}localVarQueryParams.Add("{{keyParamName}}", key){{/isKeyInQuery}}
|
{{#isKeyInHeader}}localVarHeaderParams["{{keyParamName}}"] = key{{/isKeyInHeader}}
|
||||||
|
{{#isKeyInQuery}}localVarQueryParams.Add("{{keyParamName}}", key){{/isKeyInQuery}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/isApiKey}}
|
{{/isApiKey}}
|
||||||
{{/authMethods}}
|
{{/authMethods}}
|
||||||
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
|
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return {{#returnType}}successPayload, {{/returnType}}nil, err
|
return {{#returnType}}localVarReturnValue, {{/returnType}}nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
localVarHttpResponse, err := a.client.callAPI(r)
|
localVarHttpResponse, err := a.client.callAPI(r)
|
||||||
if err != nil || localVarHttpResponse == nil {
|
if err != nil || localVarHttpResponse == nil {
|
||||||
return {{#returnType}}successPayload, {{/returnType}}localVarHttpResponse, err
|
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
|
||||||
}
|
}
|
||||||
defer localVarHttpResponse.Body.Close()
|
|
||||||
if localVarHttpResponse.StatusCode >= 300 {
|
localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
|
||||||
bodyBytes, _ := ioutil.ReadAll(localVarHttpResponse.Body)
|
localVarHttpResponse.Body.Close()
|
||||||
return {{#returnType}}successPayload, {{/returnType}}localVarHttpResponse, reportError("Status: %v, Body: %s", localVarHttpResponse.Status, bodyBytes)
|
if err != nil {
|
||||||
|
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#returnType}}
|
{{#returnType}}
|
||||||
{{#withXml}}
|
if localVarHttpResponse.StatusCode < 300 {
|
||||||
contentType := localVarHttpResponse.Header.Get("content-type")
|
// If we succeed, return the data, otherwise pass on to decode error.
|
||||||
if strings.Contains(contentType, "application/xml") {
|
err = a.client.decode(&localVarReturnValue, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
|
||||||
if err = xml.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
|
if err == nil {
|
||||||
return successPayload, localVarHttpResponse, err
|
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return successPayload, localVarHttpResponse, err
|
|
||||||
}
|
}
|
||||||
{{/withXml}}
|
|
||||||
|
|
||||||
if err = json.NewDecoder(localVarHttpResponse.Body).Decode(&successPayload); err != nil {
|
|
||||||
return {{#returnType}}successPayload, {{/returnType}}localVarHttpResponse, err
|
|
||||||
}
|
|
||||||
|
|
||||||
{{/returnType}}
|
{{/returnType}}
|
||||||
return {{#returnType}}successPayload, {{/returnType}}localVarHttpResponse, err
|
|
||||||
|
if localVarHttpResponse.StatusCode >= 300 {
|
||||||
|
newErr := GenericSwaggerError{
|
||||||
|
body: localVarBody,
|
||||||
|
error: localVarHttpResponse.Status,
|
||||||
|
}
|
||||||
|
{{#responses}}{{#dataType}}
|
||||||
|
if localVarHttpResponse.StatusCode == {{{code}}} {
|
||||||
|
localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
|
||||||
|
if err != nil {
|
||||||
|
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var v {{{dataType}}}
|
||||||
|
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
|
||||||
|
if err != nil {
|
||||||
|
newErr.error = err.Error()
|
||||||
|
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, newErr
|
||||||
|
}
|
||||||
|
newErr.model = v
|
||||||
|
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, newErr
|
||||||
|
}
|
||||||
|
{{/dataType}}{{/responses}}
|
||||||
|
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, newErr
|
||||||
|
}
|
||||||
|
|
||||||
|
return {{#returnType}}localVarReturnValue, {{/returnType}}localVarHttpResponse, nil
|
||||||
}
|
}
|
||||||
{{/operation}}{{/operations}}
|
{{/operation}}{{/operations}}
|
@ -20,16 +20,16 @@ Method | HTTP request | Description
|
|||||||
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
{{^allParams}}This endpoint does not need any parameter.{{/allParams}}{{#allParams}}{{#-last}}
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------- | ------------- | ------------- | -------------
|
------------- | ------------- | ------------- | -------------
|
||||||
**ctx** | **context.Context** | context for logging, tracing, authentication, etc.{{/-last}}{{/allParams}}{{#allParams}}{{#required}}
|
**ctx** | **context.Context** | context for authentication, logging, cancellation, deadlines, tracing, etc.{{/-last}}{{/allParams}}{{#allParams}}{{#required}}
|
||||||
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
|
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/required}}{{/allParams}}{{#hasOptionalParams}}
|
||||||
**optional** | **map[string]interface{}** | optional parameters | nil if no parameters
|
**optional** | ***{{{nickname}}}Opts** | optional parameters | nil if no parameters
|
||||||
|
|
||||||
### Optional Parameters
|
### Optional Parameters
|
||||||
Optional parameters are passed through a map[string]interface{}.
|
Optional parameters are passed through a pointer to a {{{nickname}}}Opts struct
|
||||||
{{#allParams}}{{#-last}}
|
{{#allParams}}{{#-last}}
|
||||||
Name | Type | Description | Notes
|
Name | Type | Description | Notes
|
||||||
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}}
|
------------- | ------------- | ------------- | -------------{{/-last}}{{/allParams}}{{#allParams}}
|
||||||
**{{paramName}}** | {{#isFile}}**{{dataType}}**{{/isFile}}{{#isPrimitiveType}}**{{dataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**{{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/allParams}}{{/hasOptionalParams}}
|
{{^required}} **{{paramName}}** | {{#isFile}}**optional.Interface of {{dataType}}**{{/isFile}}{{#isPrimitiveType}}**optional.{{vendorExtensions.x-optionalDataType}}**{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isFile}}[**optional.Interface of {{dataType}}**]({{baseType}}.md){{/isFile}}{{/isPrimitiveType}}| {{description}} | {{#defaultValue}}[default to {{defaultValue}}]{{/defaultValue}}{{/required}}{{/allParams}}{{/hasOptionalParams}}
|
||||||
|
|
||||||
### Return type
|
### Return type
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"context"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -303,6 +303,21 @@ func (c *APIClient) prepareRequest(
|
|||||||
return localVarRequest, nil
|
return localVarRequest, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
|
||||||
|
if strings.Contains(contentType, "application/xml") {
|
||||||
|
if err = xml.Unmarshal(b, v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
} else if strings.Contains(contentType, "application/json") {
|
||||||
|
if err = json.Unmarshal(b, v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New("undefined response type")
|
||||||
|
}
|
||||||
|
|
||||||
// Add a file to the multipart request
|
// Add a file to the multipart request
|
||||||
func addFile(w *multipart.Writer, fieldName, path string) error {
|
func addFile(w *multipart.Writer, fieldName, path string) error {
|
||||||
file, err := os.Open(path)
|
file, err := os.Open(path)
|
||||||
@ -337,6 +352,8 @@ func setBody(body interface{}, contentType string) (bodyBuf *bytes.Buffer, err e
|
|||||||
_, err = bodyBuf.Write(b)
|
_, err = bodyBuf.Write(b)
|
||||||
} else if s, ok := body.(string); ok {
|
} else if s, ok := body.(string); ok {
|
||||||
_, err = bodyBuf.WriteString(s)
|
_, err = bodyBuf.WriteString(s)
|
||||||
|
} else if s, ok := body.(*string); ok {
|
||||||
|
_, err = bodyBuf.WriteString(*s)
|
||||||
} else if jsonCheck.MatchString(contentType) {
|
} else if jsonCheck.MatchString(contentType) {
|
||||||
err = json.NewEncoder(bodyBuf).Encode(body)
|
err = json.NewEncoder(bodyBuf).Encode(body)
|
||||||
} else if xmlCheck.MatchString(contentType) {
|
} else if xmlCheck.MatchString(contentType) {
|
||||||
@ -427,3 +444,25 @@ func CacheExpires(r *http.Response) time.Time {
|
|||||||
func strlen(s string) int {
|
func strlen(s string) int {
|
||||||
return utf8.RuneCountInString(s)
|
return utf8.RuneCountInString(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GenericSwaggerError Provides access to the body, error and model on returned errors.
|
||||||
|
type GenericSwaggerError struct {
|
||||||
|
body []byte
|
||||||
|
error string
|
||||||
|
model interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error returns non-empty string if there was an error.
|
||||||
|
func (e GenericSwaggerError) Error() string {
|
||||||
|
return e.error
|
||||||
|
}
|
||||||
|
|
||||||
|
// Body returns the raw bytes of the response
|
||||||
|
func (e GenericSwaggerError) Body() []byte {
|
||||||
|
return e.body
|
||||||
|
}
|
||||||
|
|
||||||
|
// Model returns the unpacked model of the error
|
||||||
|
func (e GenericSwaggerError) Model() interface{} {
|
||||||
|
return e.model
|
||||||
|
}
|
@ -12,7 +12,6 @@ const (
|
|||||||
{{#allowableValues}}
|
{{#allowableValues}}
|
||||||
{{#enumVars}}
|
{{#enumVars}}
|
||||||
{{^-first}}
|
{{^-first}}
|
||||||
|
|
||||||
{{/-first}}
|
{{/-first}}
|
||||||
{{name}} {{{classname}}} = "{{{value}}}"
|
{{name}} {{{classname}}} = "{{{value}}}"
|
||||||
{{/enumVars}}
|
{{/enumVars}}
|
||||||
@ -22,7 +21,6 @@ const (
|
|||||||
type {{classname}} struct {
|
type {{classname}} struct {
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
{{^-first}}
|
{{^-first}}
|
||||||
|
|
||||||
{{/-first}}
|
{{/-first}}
|
||||||
{{#description}}
|
{{#description}}
|
||||||
// {{{description}}}
|
// {{{description}}}
|
||||||
|
@ -259,65 +259,7 @@ class {{classname}} {{#parentSchema}}extends {{{parent}}} {{/parentSchema}}{{^pa
|
|||||||
*/
|
*/
|
||||||
public function valid()
|
public function valid()
|
||||||
{
|
{
|
||||||
{{#parent}}
|
return count($this->listInvalidProperties()) === 0;
|
||||||
if (!parent::valid()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/parent}}
|
|
||||||
|
|
||||||
{{#vars}}
|
|
||||||
{{#required}}
|
|
||||||
if ($this->container['{{name}}'] === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/required}}
|
|
||||||
{{#isEnum}}
|
|
||||||
{{^isContainer}}
|
|
||||||
$allowedValues = $this->{{getter}}AllowableValues();
|
|
||||||
if (!is_null($this->container['{{name}}']) && !in_array($this->container['{{name}}'], $allowedValues, true)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/isContainer}}
|
|
||||||
{{/isEnum}}
|
|
||||||
{{#hasValidation}}
|
|
||||||
{{#maxLength}}
|
|
||||||
if (mb_strlen($this->container['{{name}}']) > {{maxLength}}) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/maxLength}}
|
|
||||||
{{#minLength}}
|
|
||||||
if (mb_strlen($this->container['{{name}}']) < {{minLength}}) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/minLength}}
|
|
||||||
{{#maximum}}
|
|
||||||
if ($this->container['{{name}}'] >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{maximum}}) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/maximum}}
|
|
||||||
{{#minimum}}
|
|
||||||
if ($this->container['{{name}}'] <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{minimum}}) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/minimum}}
|
|
||||||
{{#pattern}}
|
|
||||||
if (!preg_match("{{{pattern}}}", $this->container['{{name}}'])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/pattern}}
|
|
||||||
{{#maxItems}}
|
|
||||||
if (count($this->container['{{name}}']) > {{maxItems}}) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/maxItems}}
|
|
||||||
{{#minItems}}
|
|
||||||
if (count($this->container['{{name}}']) < {{minItems}}) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
{{/minItems}}
|
|
||||||
{{/hasValidation}}
|
|
||||||
{{/vars}}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
### Building
|
### Building
|
||||||
|
|
||||||
To build an compile the typescript sources to javascript use:
|
To install the required dependencies and to build the typescript sources run:
|
||||||
```
|
```
|
||||||
npm install
|
npm install
|
||||||
npm run build
|
npm run build
|
||||||
@ -10,11 +10,16 @@ npm run build
|
|||||||
|
|
||||||
### publishing
|
### publishing
|
||||||
|
|
||||||
|
{{#useNgPackagr}}
|
||||||
|
First build the package than run ```npm publish dist``` (don't forget to specify the `dist` folder!)
|
||||||
|
{{/useNgPackagr}}
|
||||||
|
{{^useNgPackagr}}
|
||||||
First build the package than run ```npm publish```
|
First build the package than run ```npm publish```
|
||||||
|
{{/useNgPackagr}}
|
||||||
|
|
||||||
### consuming
|
### consuming
|
||||||
|
|
||||||
navigate to the folder of your consuming project and run one of next commando's.
|
Navigate to the folder of your consuming project and run one of next commands.
|
||||||
|
|
||||||
_published:_
|
_published:_
|
||||||
|
|
||||||
@ -22,24 +27,41 @@ _published:_
|
|||||||
npm install {{npmName}}@{{npmVersion}} --save
|
npm install {{npmName}}@{{npmVersion}} --save
|
||||||
```
|
```
|
||||||
|
|
||||||
_unPublished (not recommended):_
|
_without publishing (not recommended):_
|
||||||
|
|
||||||
```
|
```
|
||||||
|
{{#useNgPackagr}}
|
||||||
|
npm install PATH_TO_GENERATED_PACKAGE/dist --save
|
||||||
|
{{/useNgPackagr}}
|
||||||
|
{{^useNgPackagr}}
|
||||||
npm install PATH_TO_GENERATED_PACKAGE --save
|
npm install PATH_TO_GENERATED_PACKAGE --save
|
||||||
|
{{/useNgPackagr}}
|
||||||
```
|
```
|
||||||
|
|
||||||
_using `npm link`:_
|
_using `npm link`:_
|
||||||
|
|
||||||
|
{{#useNgPackagr}}
|
||||||
|
In PATH_TO_GENERATED_PACKAGE/dist:
|
||||||
|
{{/useNgPackagr}}
|
||||||
|
{{^useNgPackagr}}
|
||||||
In PATH_TO_GENERATED_PACKAGE:
|
In PATH_TO_GENERATED_PACKAGE:
|
||||||
|
{{/useNgPackagr}}
|
||||||
```
|
```
|
||||||
npm link
|
npm link
|
||||||
```
|
```
|
||||||
|
|
||||||
In your project:
|
In your project:
|
||||||
```
|
```
|
||||||
npm link {{npmName}}@{{npmVersion}}
|
npm link {{npmName}}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
__Note for Windows users:__ The Angular CLI has troubles to use linked npm packages.
|
||||||
|
Please refer to this issue https://github.com/angular/angular-cli/issues/8284 for a solution / workaround.
|
||||||
|
Published packages are not effected by this issue.
|
||||||
|
|
||||||
|
|
||||||
|
#### General usage
|
||||||
|
|
||||||
In your Angular project:
|
In your Angular project:
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ import { {{classname}} } from '../{{filename}}';
|
|||||||
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
|
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
|
||||||
import { Configuration } from '../configuration';
|
import { Configuration } from '../configuration';
|
||||||
{{#withInterfaces}}
|
{{#withInterfaces}}
|
||||||
import { {{classname}}Interface } from './{{classname}}Interface';
|
import { {{classname}}Interface } from './{{classFilename}}Interface';
|
||||||
{{/withInterfaces}}
|
{{/withInterfaces}}
|
||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
@ -149,7 +149,7 @@ export class {{classname}} {
|
|||||||
}
|
}
|
||||||
{{/isListContainer}}
|
{{/isListContainer}}
|
||||||
{{^isListContainer}}
|
{{^isListContainer}}
|
||||||
if ({{paramName}} !== undefined) {
|
if ({{paramName}} !== undefined && {{paramName}} !== null) {
|
||||||
{{#isDateTime}}
|
{{#isDateTime}}
|
||||||
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', <any>{{paramName}}.toISOString());
|
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', <any>{{paramName}}.toISOString());
|
||||||
{{/isDateTime}}
|
{{/isDateTime}}
|
||||||
|
@ -1,9 +1,19 @@
|
|||||||
{{>licenseInfo}}
|
{{>licenseInfo}}
|
||||||
|
{{#useHttpClient}}
|
||||||
|
import { HttpHeaders } from '@angular/common/http';
|
||||||
|
{{/useHttpClient}}
|
||||||
|
{{^useHttpClient}}
|
||||||
import { Headers } from '@angular/http';
|
import { Headers } from '@angular/http';
|
||||||
|
{{/useHttpClient}}
|
||||||
|
|
||||||
import { Observable } from 'rxjs/Observable';
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
import * as models from '../model/models';
|
|
||||||
|
{{#imports}}
|
||||||
|
import { {{classname}} } from '../{{filename}}';
|
||||||
|
{{/imports}}
|
||||||
|
|
||||||
|
|
||||||
import { Configuration } from '../configuration';
|
import { Configuration } from '../configuration';
|
||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
@ -14,9 +24,9 @@ import { Configuration } from '../configurat
|
|||||||
*/
|
*/
|
||||||
{{/description}}
|
{{/description}}
|
||||||
export interface {{classname}}Interface {
|
export interface {{classname}}Interface {
|
||||||
defaultHeaders: Headers;
|
defaultHeaders: {{#useHttpClient}}Http{{/useHttpClient}}Headers;
|
||||||
configuration: Configuration;
|
configuration: Configuration;
|
||||||
[others: string]: any;
|
{{^useHttpClient}}[others: string]: any;{{/useHttpClient}}
|
||||||
|
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,9 @@
|
|||||||
export * from './{{ classFilename }}';
|
export * from './{{ classFilename }}';
|
||||||
import { {{ classname }} } from './{{ classFilename }}';
|
import { {{ classname }} } from './{{ classFilename }}';
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
|
{{#withInterfaces}}
|
||||||
|
export * from './{{ classFilename }}Interface'
|
||||||
|
{{/withInterfaces}}
|
||||||
{{/apis}}
|
{{/apis}}
|
||||||
export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}];
|
export const APIS = [{{#apis}}{{#operations}}{{ classname }}{{/operations}}{{^-last}}, {{/-last}}{{/apis}}];
|
||||||
{{/apiInfo}}
|
{{/apiInfo}}
|
||||||
|
@ -28,8 +28,8 @@ export class Configuration {
|
|||||||
* Select the correct content-type to use for a request.
|
* Select the correct content-type to use for a request.
|
||||||
* Uses {@link Configuration#isJsonMime} to determine the correct content-type.
|
* Uses {@link Configuration#isJsonMime} to determine the correct content-type.
|
||||||
* If no content type is found return the first found type if the contentTypes is not empty
|
* If no content type is found return the first found type if the contentTypes is not empty
|
||||||
* @param {string[]} contentTypes - the array of content types that are available for selection
|
* @param contentTypes - the array of content types that are available for selection
|
||||||
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
|
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
|
||||||
*/
|
*/
|
||||||
public selectHeaderContentType (contentTypes: string[]): string | undefined {
|
public selectHeaderContentType (contentTypes: string[]): string | undefined {
|
||||||
if (contentTypes.length == 0) {
|
if (contentTypes.length == 0) {
|
||||||
@ -47,8 +47,8 @@ export class Configuration {
|
|||||||
* Select the correct accept content-type to use for a request.
|
* Select the correct accept content-type to use for a request.
|
||||||
* Uses {@link Configuration#isJsonMime} to determine the correct accept content-type.
|
* Uses {@link Configuration#isJsonMime} to determine the correct accept content-type.
|
||||||
* If no content type is found return the first found type if the contentTypes is not empty
|
* If no content type is found return the first found type if the contentTypes is not empty
|
||||||
* @param {string[]} accepts - the array of content types that are available for selection.
|
* @param accepts - the array of content types that are available for selection.
|
||||||
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
|
* @returns the selected content-type or <code>undefined</code> if no selection could be made.
|
||||||
*/
|
*/
|
||||||
public selectHeaderAccept(accepts: string[]): string | undefined {
|
public selectHeaderAccept(accepts: string[]): string | undefined {
|
||||||
if (accepts.length == 0) {
|
if (accepts.length == 0) {
|
||||||
@ -69,8 +69,8 @@ export class Configuration {
|
|||||||
* application/json; charset=UTF8
|
* application/json; charset=UTF8
|
||||||
* APPLICATION/JSON
|
* APPLICATION/JSON
|
||||||
* application/vnd.company+json
|
* application/vnd.company+json
|
||||||
* @param {string} mime - MIME (Multipurpose Internet Mail Extensions)
|
* @param mime - MIME (Multipurpose Internet Mail Extensions)
|
||||||
* @return {boolean} True if the given MIME is JSON, false otherwise.
|
* @return True if the given MIME is JSON, false otherwise.
|
||||||
*/
|
*/
|
||||||
public isJsonMime(mime: string): boolean {
|
public isJsonMime(mime: string): boolean {
|
||||||
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
|
||||||
|
"lib": {
|
||||||
|
"entryFile": "index.ts"
|
||||||
|
}
|
||||||
|
}
|
@ -7,12 +7,20 @@
|
|||||||
"swagger-client"
|
"swagger-client"
|
||||||
],
|
],
|
||||||
"license": "Unlicense",
|
"license": "Unlicense",
|
||||||
|
{{#useNgPackagr}}
|
||||||
|
"scripts": {
|
||||||
|
"build": "ng-packagr -p ng-package.json"
|
||||||
|
},
|
||||||
|
{{/useNgPackagr}}
|
||||||
|
{{^useNgPackagr}}
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"module": "dist/index.js",
|
||||||
"typings": "dist/index.d.ts",
|
"typings": "dist/index.d.ts",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc --outDir dist/",
|
"build": "ngc",
|
||||||
"postinstall": "npm run build"
|
"postinstall": "npm run build"
|
||||||
},
|
},
|
||||||
|
{{/useNgPackagr}}
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@angular/core": "^{{ngVersion}}",
|
"@angular/core": "^{{ngVersion}}",
|
||||||
"@angular/http": "^{{ngVersion}}",
|
"@angular/http": "^{{ngVersion}}",
|
||||||
@ -24,11 +32,13 @@
|
|||||||
"zone.js": "^0.7.6"
|
"zone.js": "^0.7.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@angular/compiler-cli": "^{{ngVersion}}",
|
||||||
"@angular/core": "^{{ngVersion}}",
|
"@angular/core": "^{{ngVersion}}",
|
||||||
"@angular/http": "^{{ngVersion}}",
|
"@angular/http": "^{{ngVersion}}",
|
||||||
"@angular/common": "^{{ngVersion}}",
|
"@angular/common": "^{{ngVersion}}",
|
||||||
"@angular/compiler": "^{{ngVersion}}",
|
"@angular/compiler": "^{{ngVersion}}",
|
||||||
"@angular/platform-browser": "^{{ngVersion}}",
|
"@angular/platform-browser": "^{{ngVersion}}",{{#useNgPackagr}}
|
||||||
|
"ng-packagr": {{#useOldNgPackagr}}"^1.6.0"{{/useOldNgPackagr}}{{^useOldNgPackagr}}"^2.4.1"{{/useOldNgPackagr}},{{/useNgPackagr}}
|
||||||
"reflect-metadata": "^0.1.3",
|
"reflect-metadata": "^0.1.3",
|
||||||
"rxjs": "^5.4.0",
|
"rxjs": "^5.4.0",
|
||||||
"zone.js": "^0.7.6",
|
"zone.js": "^0.7.6",
|
||||||
|
@ -21,5 +21,9 @@
|
|||||||
"filesGlob": [
|
"filesGlob": [
|
||||||
"./model/*.ts",
|
"./model/*.ts",
|
||||||
"./api/*.ts"
|
"./api/*.ts"
|
||||||
]
|
]{{^useNgPackagr}},
|
||||||
|
"angularCompilerOptions": {
|
||||||
|
"genDir": "dist",
|
||||||
|
"skipTemplateCodegen": true
|
||||||
|
}{{/useNgPackagr}}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user