fix map type and collection format for form parameter (array) (#356)

This commit is contained in:
William Cheng 2018-05-07 18:22:30 +08:00 committed by GitHub
parent e49e8ca169
commit d74b4cdf8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 20 deletions

View File

@ -27,7 +27,7 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/openapi-generator/src/main/resources/JavaPlayFramework -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java-play-framework -o samples/server/petstore/java-play-framework-fake-endpoints -DhideGenerationTimestamp=true"
ags="generate -t modules/openapi-generator/src/main/resources/JavaPlayFramework -i modules/openapi-generator/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml -l java-play-framework -o samples/server/petstore/java-play-framework-fake-endpoints -DhideGenerationTimestamp=true $@"
java $JAVA_OPTS -jar $executable $ags

View File

@ -4097,12 +4097,7 @@ public class DefaultCodegen implements CodegenConfig {
arraySchema.setItems(inner);
}
//TODO fix collectformat for form parameters
//collectionFormat = getCollectionFormat(s);
// default to csv:
collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat;
codegenParameter = fromFormProperty(entry.getKey(), inner, imports);
CodegenProperty codegenProperty = fromProperty("inner", inner);
codegenParameter.items = codegenProperty;
codegenParameter.baseType = codegenProperty.datatype;
@ -4110,6 +4105,10 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.isListContainer = true;
codegenParameter.description = s.getDescription();
codegenParameter.dataType = getTypeDeclaration(s);
//TODO fix collectformat for form parameters
//collectionFormat = getCollectionFormat(s);
// default to csv:
codegenParameter.collectionFormat = StringUtils.isEmpty(collectionFormat) ? "csv" : collectionFormat;
// recursively add import
while (codegenProperty != null) {
@ -4253,7 +4252,8 @@ public class DefaultCodegen implements CodegenConfig {
}
codegenParameter.paramName = toParamName(codegenParameter.baseName);
codegenParameter.items = codegenProperty.items;
codegenParameter.dataType = getTypeDeclaration(inner);
codegenParameter.dataType = getTypeDeclaration(schema);
LOGGER.info("debugging inline map: " + codegenParameter.dataType);
codegenParameter.baseType = getSchemaType(inner);
codegenParameter.isContainer = Boolean.TRUE;
codegenParameter.isMapContainer = Boolean.TRUE;

View File

@ -289,12 +289,14 @@ public class FakeApiController extends Controller {
} else {
enumQueryDouble = null;
}
String valueenumFormStringArray = (request().body().asMultipartFormData().asFormUrlEncoded().get("enum_form_string_array"))[0];
String enumFormStringArray;
if (valueenumFormStringArray != null) {
enumFormStringArray = valueenumFormStringArray;
} else {
enumFormStringArray = "$";
String[] enumFormStringArrayArray = request().body().asMultipartFormData().asFormUrlEncoded().get("enum_form_string_array");
List<String> enumFormStringArrayList = OpenAPIUtils.parametersToList("csv", enumFormStringArrayArray);
List<String> enumFormStringArray = new ArrayList<String>();
for (String curParam : enumFormStringArrayList) {
if (!curParam.isEmpty()) {
//noinspection UseBulkOperation
enumFormStringArray.add(curParam);
}
}
String valueenumFormString = (request().body().asMultipartFormData().asFormUrlEncoded().get("enum_form_string"))[0];
String enumFormString;
@ -326,9 +328,9 @@ public class FakeApiController extends Controller {
@ApiAction
public Result testInlineAdditionalProperties() throws Exception {
JsonNode noderequestBody = request().body().asJson();
String requestBody;
Map<String, String> requestBody;
if (noderequestBody != null) {
requestBody = mapper.readValue(noderequestBody.toString(), new TypeReference<String>(){});
requestBody = mapper.readValue(noderequestBody.toString(), new TypeReference<Map<String, String>>(){});
if (configuration.getBoolean("useInputBeanValidation")) {
for (Map.Entry<String, String> entry : requestBody.entrySet()) {
OpenAPIUtils.validate(entry.getValue());

View File

@ -58,12 +58,12 @@ public class FakeApiControllerImp implements FakeApiControllerImpInterface {
}
@Override
public void testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, String enumFormStringArray, String enumFormString) throws Exception {
public void testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<String> enumFormStringArray, String enumFormString) throws Exception {
//Do your magic!!!
}
@Override
public void testInlineAdditionalProperties(String requestBody) throws Exception {
public void testInlineAdditionalProperties(Map<String, String> requestBody) throws Exception {
//Do your magic!!!
}

View File

@ -32,9 +32,9 @@ public interface FakeApiControllerImpInterface {
void testEndpointParameters(BigDecimal number, Double _double, String patternWithoutDelimiter, byte[] _byte, Integer integer, Integer int32, Long int64, Float _float, String string, Http.MultipartFormData.FilePart binary, LocalDate date, OffsetDateTime dateTime, String password, String paramCallback) throws Exception;
void testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, String enumFormStringArray, String enumFormString) throws Exception;
void testEnumParameters(List<String> enumHeaderStringArray, String enumHeaderString, List<String> enumQueryStringArray, String enumQueryString, Integer enumQueryInteger, Double enumQueryDouble, List<String> enumFormStringArray, String enumFormString) throws Exception;
void testInlineAdditionalProperties(String requestBody) throws Exception;
void testInlineAdditionalProperties(Map<String, String> requestBody) throws Exception;
void testJsonFormData(String param, String param2) throws Exception;