mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-05 07:01:01 +00:00
Merge branch 'www2k-feature/file-response'
This commit is contained in:
commit
43515ba79b
@ -14,7 +14,7 @@ public class CodegenOperation {
|
|||||||
public boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams,
|
public boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, hasOptionalParams,
|
||||||
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMapContainer,
|
returnTypeIsPrimitive, returnSimpleType, subresourceOperation, isMapContainer,
|
||||||
isListContainer, isMultipart, hasMore = true,
|
isListContainer, isMultipart, hasMore = true,
|
||||||
isResponseBinary = false, hasReference = false,
|
isResponseBinary = false, isResponseFile = false, hasReference = false,
|
||||||
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
|
isRestfulIndex, isRestfulShow, isRestfulCreate, isRestfulUpdate, isRestfulDestroy,
|
||||||
isRestful;
|
isRestful;
|
||||||
public String path, operationId, returnType, httpMethod, returnBaseType,
|
public String path, operationId, returnType, httpMethod, returnBaseType,
|
||||||
@ -217,6 +217,8 @@ public class CodegenOperation {
|
|||||||
return false;
|
return false;
|
||||||
if (hasReference != that.hasReference)
|
if (hasReference != that.hasReference)
|
||||||
return false;
|
return false;
|
||||||
|
if (isResponseFile != that.isResponseFile)
|
||||||
|
return false;
|
||||||
if (path != null ? !path.equals(that.path) : that.path != null)
|
if (path != null ? !path.equals(that.path) : that.path != null)
|
||||||
return false;
|
return false;
|
||||||
if (operationId != null ? !operationId.equals(that.operationId) : that.operationId != null)
|
if (operationId != null ? !operationId.equals(that.operationId) : that.operationId != null)
|
||||||
@ -297,6 +299,7 @@ public class CodegenOperation {
|
|||||||
result = 31 * result + (isMultipart ? 13:31);
|
result = 31 * result + (isMultipart ? 13:31);
|
||||||
result = 31 * result + (hasMore ? 13:31);
|
result = 31 * result + (hasMore ? 13:31);
|
||||||
result = 31 * result + (isResponseBinary ? 13:31);
|
result = 31 * result + (isResponseBinary ? 13:31);
|
||||||
|
result = 31 * result + (isResponseFile ? 13:31);
|
||||||
result = 31 * result + (hasReference ? 13:31);
|
result = 31 * result + (hasReference ? 13:31);
|
||||||
result = 31 * result + (path != null ? path.hashCode() : 0);
|
result = 31 * result + (path != null ? path.hashCode() : 0);
|
||||||
result = 31 * result + (operationId != null ? operationId.hashCode() : 0);
|
result = 31 * result + (operationId != null ? operationId.hashCode() : 0);
|
||||||
|
@ -37,7 +37,7 @@ public class CodegenProperty implements Cloneable {
|
|||||||
public boolean hasMore, required, secondaryParam;
|
public boolean hasMore, required, secondaryParam;
|
||||||
public boolean hasMoreNonReadOnly; // for model constructor, true if next properyt is not readonly
|
public boolean hasMoreNonReadOnly; // for model constructor, true if next properyt is not readonly
|
||||||
public boolean isPrimitiveType, isContainer, isNotContainer;
|
public boolean isPrimitiveType, isContainer, isNotContainer;
|
||||||
public boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isBoolean, isDate, isDateTime;
|
public boolean isString, isInteger, isLong, isFloat, isDouble, isByteArray, isBinary, isFile, isBoolean, isDate, isDateTime;
|
||||||
public boolean isListContainer, isMapContainer;
|
public boolean isListContainer, isMapContainer;
|
||||||
public boolean isEnum;
|
public boolean isEnum;
|
||||||
public boolean isReadOnly = false;
|
public boolean isReadOnly = false;
|
||||||
@ -108,6 +108,7 @@ public class CodegenProperty implements Cloneable {
|
|||||||
result = prime * result + ((isDouble ? 13:31));
|
result = prime * result + ((isDouble ? 13:31));
|
||||||
result = prime * result + ((isByteArray ? 13:31));
|
result = prime * result + ((isByteArray ? 13:31));
|
||||||
result = prime * result + ((isBinary ? 13:31));
|
result = prime * result + ((isBinary ? 13:31));
|
||||||
|
result = prime * result + ((isFile ? 13:31));
|
||||||
result = prime * result + ((isBoolean ? 13:31));
|
result = prime * result + ((isBoolean ? 13:31));
|
||||||
result = prime * result + ((isDate ? 13:31));
|
result = prime * result + ((isDate ? 13:31));
|
||||||
result = prime * result + ((isDateTime ? 13:31));
|
result = prime * result + ((isDateTime ? 13:31));
|
||||||
@ -264,6 +265,9 @@ public class CodegenProperty implements Cloneable {
|
|||||||
if (this.isBinary != other.isBinary) {
|
if (this.isBinary != other.isBinary) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (this.isFile != other.isFile) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (this.isListContainer != other.isListContainer) {
|
if (this.isListContainer != other.isListContainer) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ public class CodegenResponse {
|
|||||||
public Boolean isMapContainer;
|
public Boolean isMapContainer;
|
||||||
public Boolean isListContainer;
|
public Boolean isListContainer;
|
||||||
public Boolean isBinary = Boolean.FALSE;
|
public Boolean isBinary = Boolean.FALSE;
|
||||||
|
public Boolean isFile = Boolean.FALSE;
|
||||||
public Object schema;
|
public Object schema;
|
||||||
public String jsonSchema;
|
public String jsonSchema;
|
||||||
|
|
||||||
@ -63,6 +64,8 @@ public class CodegenResponse {
|
|||||||
return false;
|
return false;
|
||||||
if (isBinary != null ? !isBinary.equals(that.isBinary) : that.isBinary != null)
|
if (isBinary != null ? !isBinary.equals(that.isBinary) : that.isBinary != null)
|
||||||
return false;
|
return false;
|
||||||
|
if (isFile != null ? !isFile.equals(that.isFile) : that.isFile != null)
|
||||||
|
return false;
|
||||||
if (schema != null ? !schema.equals(that.schema) : that.schema != null)
|
if (schema != null ? !schema.equals(that.schema) : that.schema != null)
|
||||||
return false;
|
return false;
|
||||||
return jsonSchema != null ? jsonSchema.equals(that.jsonSchema) : that.jsonSchema == null;
|
return jsonSchema != null ? jsonSchema.equals(that.jsonSchema) : that.jsonSchema == null;
|
||||||
@ -85,6 +88,7 @@ public class CodegenResponse {
|
|||||||
result = 31 * result + (isMapContainer != null ? isMapContainer.hashCode() : 0);
|
result = 31 * result + (isMapContainer != null ? isMapContainer.hashCode() : 0);
|
||||||
result = 31 * result + (isListContainer != null ? isListContainer.hashCode() : 0);
|
result = 31 * result + (isListContainer != null ? isListContainer.hashCode() : 0);
|
||||||
result = 31 * result + (isBinary != null ? isBinary.hashCode() : 0);
|
result = 31 * result + (isBinary != null ? isBinary.hashCode() : 0);
|
||||||
|
result = 31 * result + (isFile != null ? isFile.hashCode() : 0);
|
||||||
result = 31 * result + (schema != null ? schema.hashCode() : 0);
|
result = 31 * result + (schema != null ? schema.hashCode() : 0);
|
||||||
result = 31 * result + (jsonSchema != null ? jsonSchema.hashCode() : 0);
|
result = 31 * result + (jsonSchema != null ? jsonSchema.hashCode() : 0);
|
||||||
return result;
|
return result;
|
||||||
|
@ -36,6 +36,7 @@ import io.swagger.models.properties.DateProperty;
|
|||||||
import io.swagger.models.properties.DateTimeProperty;
|
import io.swagger.models.properties.DateTimeProperty;
|
||||||
import io.swagger.models.properties.DecimalProperty;
|
import io.swagger.models.properties.DecimalProperty;
|
||||||
import io.swagger.models.properties.DoubleProperty;
|
import io.swagger.models.properties.DoubleProperty;
|
||||||
|
import io.swagger.models.properties.FileProperty;
|
||||||
import io.swagger.models.properties.FloatProperty;
|
import io.swagger.models.properties.FloatProperty;
|
||||||
import io.swagger.models.properties.IntegerProperty;
|
import io.swagger.models.properties.IntegerProperty;
|
||||||
import io.swagger.models.properties.LongProperty;
|
import io.swagger.models.properties.LongProperty;
|
||||||
@ -783,6 +784,7 @@ public class DefaultCodegen {
|
|||||||
typeMapping.put("integer", "Integer");
|
typeMapping.put("integer", "Integer");
|
||||||
typeMapping.put("ByteArray", "byte[]");
|
typeMapping.put("ByteArray", "byte[]");
|
||||||
typeMapping.put("binary", "byte[]");
|
typeMapping.put("binary", "byte[]");
|
||||||
|
typeMapping.put("file", "File");
|
||||||
|
|
||||||
|
|
||||||
instantiationTypes = new HashMap<String, String>();
|
instantiationTypes = new HashMap<String, String>();
|
||||||
@ -1087,6 +1089,8 @@ public class DefaultCodegen {
|
|||||||
datatype = "ByteArray";
|
datatype = "ByteArray";
|
||||||
} else if (p instanceof BinaryProperty) {
|
} else if (p instanceof BinaryProperty) {
|
||||||
datatype = "binary";
|
datatype = "binary";
|
||||||
|
} else if (p instanceof FileProperty) {
|
||||||
|
datatype = "file";
|
||||||
} else if (p instanceof BooleanProperty) {
|
} else if (p instanceof BooleanProperty) {
|
||||||
datatype = "boolean";
|
datatype = "boolean";
|
||||||
} else if (p instanceof DateProperty) {
|
} else if (p instanceof DateProperty) {
|
||||||
@ -1566,6 +1570,9 @@ public class DefaultCodegen {
|
|||||||
if (p instanceof BinaryProperty) {
|
if (p instanceof BinaryProperty) {
|
||||||
property.isBinary = true;
|
property.isBinary = true;
|
||||||
}
|
}
|
||||||
|
if (p instanceof FileProperty) {
|
||||||
|
property.isFile = true;
|
||||||
|
}
|
||||||
if (p instanceof UUIDProperty) {
|
if (p instanceof UUIDProperty) {
|
||||||
property.isString = true;
|
property.isString = true;
|
||||||
}
|
}
|
||||||
@ -1994,6 +2001,9 @@ public class DefaultCodegen {
|
|||||||
if (r.isBinary && r.isDefault){
|
if (r.isBinary && r.isDefault){
|
||||||
op.isResponseBinary = Boolean.TRUE;
|
op.isResponseBinary = Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
if (r.isFile && r.isDefault){
|
||||||
|
op.isResponseFile = Boolean.TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
op.responses.get(op.responses.size() - 1).hasMore = false;
|
op.responses.get(op.responses.size() - 1).hasMore = false;
|
||||||
|
|
||||||
@ -2193,6 +2203,7 @@ public class DefaultCodegen {
|
|||||||
}
|
}
|
||||||
r.dataType = cm.datatype;
|
r.dataType = cm.datatype;
|
||||||
r.isBinary = isDataTypeBinary(cm.datatype);
|
r.isBinary = isDataTypeBinary(cm.datatype);
|
||||||
|
r.isFile = isDataTypeFile(cm.datatype);
|
||||||
if (cm.isContainer) {
|
if (cm.isContainer) {
|
||||||
r.simpleType = false;
|
r.simpleType = false;
|
||||||
r.containerType = cm.containerType;
|
r.containerType = cm.containerType;
|
||||||
@ -2382,6 +2393,7 @@ public class DefaultCodegen {
|
|||||||
p.dataType = cp.datatype;
|
p.dataType = cp.datatype;
|
||||||
p.isPrimitiveType = cp.isPrimitiveType;
|
p.isPrimitiveType = cp.isPrimitiveType;
|
||||||
p.isBinary = isDataTypeBinary(cp.datatype);
|
p.isBinary = isDataTypeBinary(cp.datatype);
|
||||||
|
p.isFile = isDataTypeFile(cp.datatype);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set boolean flag (e.g. isString)
|
// set boolean flag (e.g. isString)
|
||||||
@ -2474,6 +2486,8 @@ public class DefaultCodegen {
|
|||||||
p.example = "BINARY_DATA_HERE";
|
p.example = "BINARY_DATA_HERE";
|
||||||
} else if (Boolean.TRUE.equals(p.isByteArray)) {
|
} else if (Boolean.TRUE.equals(p.isByteArray)) {
|
||||||
p.example = "B";
|
p.example = "B";
|
||||||
|
} else if (Boolean.TRUE.equals(p.isFile)) {
|
||||||
|
p.example = "/path/to/file.txt";
|
||||||
} else if (Boolean.TRUE.equals(p.isDate)) {
|
} else if (Boolean.TRUE.equals(p.isDate)) {
|
||||||
p.example = "2013-10-20";
|
p.example = "2013-10-20";
|
||||||
} else if (Boolean.TRUE.equals(p.isDateTime)) {
|
} else if (Boolean.TRUE.equals(p.isDateTime)) {
|
||||||
@ -2494,6 +2508,10 @@ public class DefaultCodegen {
|
|||||||
return dataType.toLowerCase().startsWith("byte");
|
return dataType.toLowerCase().startsWith("byte");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDataTypeFile(String dataType) {
|
||||||
|
return dataType.toLowerCase().equals("file");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert map of Swagger SecuritySchemeDefinition objects to a list of Codegen Security objects
|
* Convert map of Swagger SecuritySchemeDefinition objects to a list of Codegen Security objects
|
||||||
*
|
*
|
||||||
@ -3289,6 +3307,9 @@ public class DefaultCodegen {
|
|||||||
} else if (Boolean.TRUE.equals(property.isBinary)) {
|
} else if (Boolean.TRUE.equals(property.isBinary)) {
|
||||||
parameter.isByteArray = true;
|
parameter.isByteArray = true;
|
||||||
parameter.isPrimitiveType = true;
|
parameter.isPrimitiveType = true;
|
||||||
|
} else if (Boolean.TRUE.equals(property.isFile)) {
|
||||||
|
parameter.isFile = true;
|
||||||
|
parameter.isPrimitiveType = true;
|
||||||
} else if (Boolean.TRUE.equals(property.isDate)) {
|
} else if (Boolean.TRUE.equals(property.isDate)) {
|
||||||
parameter.isDate = true;
|
parameter.isDate = true;
|
||||||
parameter.isPrimitiveType = true;
|
parameter.isPrimitiveType = true;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package io.swagger.codegen.languages;
|
package io.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import io.swagger.models.properties.FileProperty;
|
||||||
|
import io.swagger.models.properties.Property;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@ -27,6 +29,8 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
public TypeScriptNodeClientCodegen() {
|
public TypeScriptNodeClientCodegen() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
typeMapping.put("file", "Buffer");
|
||||||
|
|
||||||
// clear import mapping (from default generator) as TS does not use it
|
// clear import mapping (from default generator) as TS does not use it
|
||||||
// at the moment
|
// at the moment
|
||||||
importMapping.clear();
|
importMapping.clear();
|
||||||
@ -92,6 +96,19 @@ public class TypeScriptNodeClientCodegen extends AbstractTypeScriptClientCodegen
|
|||||||
return "Generates a TypeScript nodejs client library.";
|
return "Generates a TypeScript nodejs client library.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDataTypeFile(final String dataType) {
|
||||||
|
return dataType != null && dataType.equals("Buffer");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeDeclaration(Property p) {
|
||||||
|
if (p instanceof FileProperty) {
|
||||||
|
return "Buffer";
|
||||||
|
}
|
||||||
|
return super.getTypeDeclaration(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setNpmName(String npmName) {
|
public void setNpmName(String npmName) {
|
||||||
this.npmName = npmName;
|
this.npmName = npmName;
|
||||||
|
@ -237,7 +237,12 @@ export class {{classname}} {
|
|||||||
headers: headerParams,
|
headers: headerParams,
|
||||||
uri: localVarPath,
|
uri: localVarPath,
|
||||||
useQuerystring: this._useQuerystring,
|
useQuerystring: this._useQuerystring,
|
||||||
|
{{^isResponseFile}}
|
||||||
json: true,
|
json: true,
|
||||||
|
{{/isResponseFile}}
|
||||||
|
{{#isResponseFile}}
|
||||||
|
encoding: null,
|
||||||
|
{{/isResponseFile}}
|
||||||
{{#bodyParam}}
|
{{#bodyParam}}
|
||||||
body: {{paramName}},
|
body: {{paramName}},
|
||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
|
@ -43,7 +43,7 @@ public class CodegenTest {
|
|||||||
|
|
||||||
final CodegenParameter file = op.formParams.get(1);
|
final CodegenParameter file = op.formParams.get(1);
|
||||||
Assert.assertTrue(file.isFormParam);
|
Assert.assertTrue(file.isFormParam);
|
||||||
Assert.assertEquals(file.dataType, "file");
|
Assert.assertEquals(file.dataType, "File");
|
||||||
Assert.assertNull(file.required);
|
Assert.assertNull(file.required);
|
||||||
Assert.assertTrue(file.isFile);
|
Assert.assertTrue(file.isFile);
|
||||||
Assert.assertNull(file.hasMore);
|
Assert.assertNull(file.hasMore);
|
||||||
@ -188,6 +188,19 @@ public class CodegenTest {
|
|||||||
Assert.assertTrue(op.responses.get(0).isBinary);
|
Assert.assertTrue(op.responses.get(0).isBinary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(description = "return file when response format is file")
|
||||||
|
public void fileResponeseTest() {
|
||||||
|
final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/fileResponseTest.json");
|
||||||
|
final DefaultCodegen codegen = new DefaultCodegen();
|
||||||
|
final String path = "/tests/fileResponse";
|
||||||
|
final Operation p = model.getPaths().get(path).getGet();
|
||||||
|
final CodegenOperation op = codegen.fromOperation(path, "get", p, model.getDefinitions());
|
||||||
|
|
||||||
|
Assert.assertEquals(op.returnType, "File");
|
||||||
|
Assert.assertTrue(op.responses.get(0).isFile);
|
||||||
|
Assert.assertTrue(op.isResponseFile);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(description = "discriminator is present")
|
@Test(description = "discriminator is present")
|
||||||
public void discriminatorTest() {
|
public void discriminatorTest() {
|
||||||
final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/discriminatorTest.json");
|
final Swagger model = parseAndPrepareSwagger("src/test/resources/2_0/discriminatorTest.json");
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"swagger": "2.0",
|
||||||
|
"info": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"title": "File Response Test",
|
||||||
|
"license": {
|
||||||
|
"name": "Apache 2.0",
|
||||||
|
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"basePath": "/v2",
|
||||||
|
"schemes": [
|
||||||
|
"http"
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"/tests/fileResponse": {
|
||||||
|
"get": {
|
||||||
|
"operationId": "fileresponsetest",
|
||||||
|
"produces": [
|
||||||
|
"application/octet-stream"
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "OutputFileData",
|
||||||
|
"schema": {
|
||||||
|
"type": "file"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user