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,8 +27,8 @@ fi
# if you've executed sbt assembly previously it will use that instead. # 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" 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 java $JAVA_OPTS -jar $executable $ags
cp samples.ci/server/petstore/java-play-framework-fake-endpoints/pom.xml samples/server/petstore/java-play-framework-fake-endpoints/pom.xml cp samples.ci/server/petstore/java-play-framework-fake-endpoints/pom.xml samples/server/petstore/java-play-framework-fake-endpoints/pom.xml

View File

@ -4097,12 +4097,7 @@ public class DefaultCodegen implements CodegenConfig {
arraySchema.setItems(inner); 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); codegenParameter = fromFormProperty(entry.getKey(), inner, imports);
CodegenProperty codegenProperty = fromProperty("inner", inner); CodegenProperty codegenProperty = fromProperty("inner", inner);
codegenParameter.items = codegenProperty; codegenParameter.items = codegenProperty;
codegenParameter.baseType = codegenProperty.datatype; codegenParameter.baseType = codegenProperty.datatype;
@ -4110,6 +4105,10 @@ public class DefaultCodegen implements CodegenConfig {
codegenParameter.isListContainer = true; codegenParameter.isListContainer = true;
codegenParameter.description = s.getDescription(); codegenParameter.description = s.getDescription();
codegenParameter.dataType = getTypeDeclaration(s); 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 // recursively add import
while (codegenProperty != null) { while (codegenProperty != null) {
@ -4253,7 +4252,8 @@ public class DefaultCodegen implements CodegenConfig {
} }
codegenParameter.paramName = toParamName(codegenParameter.baseName); codegenParameter.paramName = toParamName(codegenParameter.baseName);
codegenParameter.items = codegenProperty.items; codegenParameter.items = codegenProperty.items;
codegenParameter.dataType = getTypeDeclaration(inner); codegenParameter.dataType = getTypeDeclaration(schema);
LOGGER.info("debugging inline map: " + codegenParameter.dataType);
codegenParameter.baseType = getSchemaType(inner); codegenParameter.baseType = getSchemaType(inner);
codegenParameter.isContainer = Boolean.TRUE; codegenParameter.isContainer = Boolean.TRUE;
codegenParameter.isMapContainer = Boolean.TRUE; codegenParameter.isMapContainer = Boolean.TRUE;

View File

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

View File

@ -58,12 +58,12 @@ public class FakeApiControllerImp implements FakeApiControllerImpInterface {
} }
@Override @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!!! //Do your magic!!!
} }
@Override @Override
public void testInlineAdditionalProperties(String requestBody) throws Exception { public void testInlineAdditionalProperties(Map<String, String> requestBody) throws Exception {
//Do your magic!!! //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 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; void testJsonFormData(String param, String param2) throws Exception;