fix, tests for #2500

This commit is contained in:
Tony Tam 2016-04-05 14:48:37 -07:00
parent a1c978751a
commit 3ea911dd74
3 changed files with 30 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package io.swagger.generator.model;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.AuthorizationValue;
import io.swagger.models.auth.SecuritySchemeDefinition; import io.swagger.models.auth.SecuritySchemeDefinition;
import java.util.Map; import java.util.Map;
@ -11,6 +12,15 @@ public class GeneratorInput {
private Map<String, String> options; private Map<String, String> options;
private String swaggerUrl; private String swaggerUrl;
private SecuritySchemeDefinition auth; private SecuritySchemeDefinition auth;
private AuthorizationValue authorizationValue;
public AuthorizationValue getAuthorizationValue() {
return authorizationValue;
}
public void setAuthorizationValue(AuthorizationValue authorizationValue) {
this.authorizationValue = authorizationValue;
}
@ApiModelProperty(dataType = "Object") @ApiModelProperty(dataType = "Object")
public JsonNode getSpec() { public JsonNode getSpec() {
@ -38,10 +48,12 @@ public class GeneratorInput {
this.swaggerUrl = url; this.swaggerUrl = url;
} }
@Deprecated
public SecuritySchemeDefinition getSecurityDefinition() { public SecuritySchemeDefinition getSecurityDefinition() {
return auth; return auth;
} }
@Deprecated
public void setSecurityDefinition(SecuritySchemeDefinition auth) { public void setSecurityDefinition(SecuritySchemeDefinition auth) {
this.auth = auth; this.auth = auth;
} }

View File

@ -1,22 +1,16 @@
package io.swagger.generator.online; package io.swagger.generator.online;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.codegen.*;
import io.swagger.codegen.CliOption;
import io.swagger.codegen.ClientOptInput;
import io.swagger.codegen.ClientOpts;
import io.swagger.codegen.Codegen;
import io.swagger.codegen.CodegenConfig;
import io.swagger.codegen.CodegenConfigLoader;
import io.swagger.generator.exception.ApiException; import io.swagger.generator.exception.ApiException;
import io.swagger.generator.exception.BadRequestException; import io.swagger.generator.exception.BadRequestException;
import io.swagger.generator.model.GeneratorInput; import io.swagger.generator.model.GeneratorInput;
import io.swagger.generator.model.InputOption; import io.swagger.generator.model.InputOption;
import io.swagger.generator.util.ZipUtil; import io.swagger.generator.util.ZipUtil;
import io.swagger.models.Swagger; import io.swagger.models.Swagger;
import io.swagger.models.auth.AuthorizationValue;
import io.swagger.parser.SwaggerParser; import io.swagger.parser.SwaggerParser;
import io.swagger.util.Json; import io.swagger.util.Json;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -79,11 +73,24 @@ public class Generator {
Swagger swagger; Swagger swagger;
if (node == null) { if (node == null) {
if (opts.getSwaggerUrl() != null) { if (opts.getSwaggerUrl() != null) {
swagger = new SwaggerParser().read(opts.getSwaggerUrl()); if(opts.getAuthorizationValue() != null) {
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
authorizationValues.add(opts.getAuthorizationValue());
swagger = new SwaggerParser().read(opts.getSwaggerUrl(), authorizationValues, true);
}
else {
swagger = new SwaggerParser().read(opts.getSwaggerUrl());
}
} else { } else {
throw new BadRequestException("No swagger specification was supplied"); throw new BadRequestException("No swagger specification was supplied");
} }
} else { } else if(opts.getAuthorizationValue() != null) {
List<AuthorizationValue> authorizationValues = new ArrayList<AuthorizationValue>();
authorizationValues.add(opts.getAuthorizationValue());
swagger = new SwaggerParser().read(node, authorizationValues, true);
}
else {
swagger = new SwaggerParser().read(node, true); swagger = new SwaggerParser().read(node, true);
} }
if (swagger == null) { if (swagger == null) {

View File

@ -559,7 +559,7 @@
</repository> </repository>
</repositories> </repositories>
<properties> <properties>
<swagger-parser-version>1.0.18</swagger-parser-version> <swagger-parser-version>1.0.19-SNAPSHOT</swagger-parser-version>
<scala-version>2.11.1</scala-version> <scala-version>2.11.1</scala-version>
<felix-version>2.3.4</felix-version> <felix-version>2.3.4</felix-version>
<swagger-core-version>1.5.8</swagger-core-version> <swagger-core-version>1.5.8</swagger-core-version>