forked from loafle/openapi-generator-original
Add style and explode (#4042)
* Add parameter * Set default value as Parameter.explode could be null * Fix typo * Add a link to the spec * Add tests * Delete unused import * Rename: shouldExplode -> isExplode * Include the new property
This commit is contained in:
committed by
William Cheng
parent
f8d3b9826a
commit
3f3559020a
@@ -26,9 +26,9 @@ import java.util.Objects;
|
||||
public class CodegenParameter {
|
||||
public boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
|
||||
isCookieParam, isBodyParam, hasMore, isContainer,
|
||||
secondaryParam, isCollectionFormatMulti, isPrimitiveType, isModel;
|
||||
secondaryParam, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode;
|
||||
public String baseName, paramName, dataType, datatypeWithEnum, dataFormat,
|
||||
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName;
|
||||
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style;
|
||||
|
||||
public String example; // example value (x-example)
|
||||
public String jsonSchema;
|
||||
@@ -173,6 +173,7 @@ public class CodegenParameter {
|
||||
output.isFreeFormObject = this.isFreeFormObject;
|
||||
output.isListContainer = this.isListContainer;
|
||||
output.isMapContainer = this.isMapContainer;
|
||||
output.isExplode = this.isExplode;
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -247,7 +248,8 @@ public class CodegenParameter {
|
||||
Objects.equals(maxItems, that.maxItems) &&
|
||||
Objects.equals(minItems, that.minItems) &&
|
||||
Objects.equals(uniqueItems, that.uniqueItems) &&
|
||||
Objects.equals(multipleOf, that.multipleOf);
|
||||
Objects.equals(multipleOf, that.multipleOf) &&
|
||||
Objects.equals(isExplode, that.isExplode);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -316,7 +318,8 @@ public class CodegenParameter {
|
||||
maxItems,
|
||||
minItems,
|
||||
uniqueItems,
|
||||
multipleOf);
|
||||
multipleOf,
|
||||
isExplode);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@@ -386,6 +389,7 @@ public class CodegenParameter {
|
||||
", minItems=" + minItems +
|
||||
", uniqueItems=" + uniqueItems +
|
||||
", multipleOf=" + multipleOf +
|
||||
", isExplode=" + isExplode +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
package org.openapitools.codegen;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.samskivert.mustache.Mustache;
|
||||
@@ -3099,7 +3098,15 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
// set default value
|
||||
codegenParameter.defaultValue = toDefaultValue(parameterSchema);
|
||||
|
||||
// TDOO revise collectionFormat
|
||||
if (parameter.getStyle() != null) {
|
||||
codegenParameter.style = parameter.getStyle().toString();
|
||||
}
|
||||
|
||||
// the default value is false
|
||||
// https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-parameterexplode
|
||||
codegenParameter.isExplode = parameter.getExplode() == null ? false : parameter.getExplode();
|
||||
|
||||
// TODO revise collectionFormat
|
||||
String collectionFormat = null;
|
||||
if (ModelUtils.isArraySchema(parameterSchema)) { // for array parameter
|
||||
final ArraySchema arraySchema = (ArraySchema) parameterSchema;
|
||||
|
||||
@@ -27,7 +27,6 @@ import io.swagger.v3.oas.models.Operation;
|
||||
import io.swagger.v3.oas.models.PathItem;
|
||||
import io.swagger.v3.oas.models.headers.Header;
|
||||
import io.swagger.v3.oas.models.media.*;
|
||||
import io.swagger.v3.oas.models.parameters.Parameter;
|
||||
import io.swagger.v3.oas.models.parameters.QueryParameter;
|
||||
import io.swagger.v3.oas.models.parameters.RequestBody;
|
||||
import io.swagger.v3.oas.models.responses.ApiResponse;
|
||||
@@ -43,13 +42,11 @@ import org.openapitools.codegen.utils.ModelUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
|
||||
public class DefaultCodegenTest {
|
||||
|
||||
@@ -1003,4 +1000,35 @@ public class DefaultCodegenTest {
|
||||
assertEquals(codegen.toApiName(""), "DefaultApi");
|
||||
}
|
||||
|
||||
public static class FromParameter {
|
||||
private CodegenParameter codegenParameter(String path) {
|
||||
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/3_0/fromParameter.yaml");
|
||||
new InlineModelResolver().flatten(openAPI);
|
||||
final DefaultCodegen codegen = new DefaultCodegen();
|
||||
codegen.setOpenAPI(openAPI);
|
||||
|
||||
return codegen
|
||||
.fromParameter(
|
||||
openAPI
|
||||
.getPaths()
|
||||
.get(path)
|
||||
.getGet()
|
||||
.getParameters()
|
||||
.get(0),
|
||||
new HashSet<>()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setStyle() {
|
||||
CodegenParameter parameter = codegenParameter("/set_style");
|
||||
assertEquals("form", parameter.style);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setShouldExplode() {
|
||||
CodegenParameter parameter = codegenParameter("/set_should_explode");
|
||||
assertTrue(parameter.isExplode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
openapi: 3.0.0
|
||||
servers:
|
||||
- url: 'localhost:8080'
|
||||
info:
|
||||
version: 1.0.0
|
||||
title: OpenAPI Petstore
|
||||
license:
|
||||
name: Apache-2.0
|
||||
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
|
||||
paths:
|
||||
/set_style:
|
||||
get:
|
||||
operationId: setStyle
|
||||
parameters:
|
||||
- in: query
|
||||
name: setStyleQuery
|
||||
style: form
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
setStyleQueryParam:
|
||||
type: string
|
||||
/set_should_explode:
|
||||
get:
|
||||
operationId: setShouldExplode
|
||||
parameters:
|
||||
- in: query
|
||||
name: setShouldExplodeQuery
|
||||
style: form
|
||||
explode: true
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
setShouldExplodeQueryParam:
|
||||
type: string
|
||||
Reference in New Issue
Block a user