use of io.swagger.v3.oas.annotations.enums.Explode in project vertx-web by vert-x3.
the class OpenAPI3MultipleFilesValidationTest method testQueryOptionalFormExplodeObjectFailure.
/**
* Test: query_optional_form_explode_object Expected parameters sent: color:
* R=100&G=200&B=150&alpha=50 Expected response: Validation failure
*/
@Test
public void testQueryOptionalFormExplodeObjectFailure() throws Exception {
Operation op = testSpec.getPaths().get("/query/form/explode/object").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache);
loadHandlers("/query/form/explode/object", HttpMethod.GET, true, validationHandler, routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
RequestParameter colorQueryParam = params.queryParameter("color");
assertNotNull(colorQueryParam);
assertTrue(colorQueryParam.isObject());
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json").end(((JsonObject) colorQueryParam.toJson()).encode());
});
String requestURI = "/query/form/explode/object?R=100&G=200&B=150&alpha=aaa";
testRequest(HttpMethod.GET, requestURI, 400, errorMessage(ValidationException.ErrorType.NO_MATCH));
}
use of io.swagger.v3.oas.annotations.enums.Explode in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testQueryOptionalFormExplodeObject.
/**
* Test: query_optional_form_explode_object
* Expected parameters sent:
* color: R=100&G=200&B=150&alpha=50
* Expected response: {"color":{"R":"100","G":"200","B":"150","alpha":"50"}}
*/
@Test
public void testQueryOptionalFormExplodeObject() throws Exception {
Operation op = testSpec.getPaths().get("/query/form/explode/object").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache);
loadHandlers("/query/form/explode/object", HttpMethod.GET, false, validationHandler, routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
RequestParameter colorQueryParam = params.queryParameter("color");
assertNotNull(colorQueryParam);
assertTrue(colorQueryParam.isObject());
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json").end(((JsonObject) colorQueryParam.toJson()).encode());
});
String requestURI = "/query/form/explode/object?R=100&G=200&B=150&alpha=50";
testEmptyRequestWithJSONObjectResponse(HttpMethod.GET, requestURI, 200, "OK", new JsonObject("{\"R\":\"100\",\"G\":\"200\",\"B\":\"150\",\"alpha\":50}"));
}
use of io.swagger.v3.oas.annotations.enums.Explode in project vertx-web by vert-x3.
the class OpenAPI3ValidationTest method testQueryOptionalFormExplodeObjectFailure.
/**
* Test: query_optional_form_explode_object
* Expected parameters sent:
* color: R=100&G=200&B=150&alpha=50
* Expected response: Validation failure
*/
@Test
public void testQueryOptionalFormExplodeObjectFailure() throws Exception {
Operation op = testSpec.getPaths().get("/query/form/explode/object").getGet();
OpenAPI3RequestValidationHandler validationHandler = new OpenAPI3RequestValidationHandlerImpl(op, op.getParameters(), testSpec, refsCache);
loadHandlers("/query/form/explode/object", HttpMethod.GET, true, validationHandler, routingContext -> {
RequestParameters params = routingContext.get("parsedParameters");
RequestParameter colorQueryParam = params.queryParameter("color");
assertNotNull(colorQueryParam);
assertTrue(colorQueryParam.isObject());
routingContext.response().setStatusCode(200).setStatusMessage("OK").putHeader("content-type", "application/json").end(((JsonObject) colorQueryParam.toJson()).encode());
});
String requestURI = "/query/form/explode/object?R=100&G=200&B=150&alpha=aaa";
testRequest(HttpMethod.GET, requestURI, 400, errorMessage(ValidationException.ErrorType.NO_MATCH));
}
use of io.swagger.v3.oas.annotations.enums.Explode in project swagger-parser by swagger-api.
the class OpenAPIV3ParserTest method testIssue292WithCSVCollectionFormat.
@Test
public void testIssue292WithCSVCollectionFormat() {
String yaml = "openapi: '3.0.0'\n" + "info:\n" + " version: '0.0.0'\n" + " title: nada\n" + "paths:\n" + " /persons:\n" + " get:\n" + " parameters:\n" + " - name: testParam\n" + " in: query\n" + " type: array\n" + " items:\n" + " type: string\n" + " explode: false\n" + " responses:\n" + " 200:\n" + " description: Successful response";
OpenAPIV3Parser parser = new OpenAPIV3Parser();
SwaggerParseResult result = parser.readContents(yaml, null, null);
OpenAPI openAPI = result.getOpenAPI();
Parameter param = openAPI.getPaths().get("/persons").getGet().getParameters().get(0);
QueryParameter qp = (QueryParameter) param;
assertTrue(qp.getStyle().toString().equals("form"));
Assert.assertFalse(qp.getExplode());
}
use of io.swagger.v3.oas.annotations.enums.Explode in project swagger-parser by swagger-api.
the class OpenAPIDeserializer method getParameter.
public Parameter getParameter(ObjectNode obj, String location, ParseResult result) {
if (obj == null) {
return null;
}
Parameter parameter = null;
JsonNode ref = obj.get("$ref");
if (ref != null) {
if (ref.getNodeType().equals(JsonNodeType.STRING)) {
parameter = new Parameter();
String mungedRef = mungedRef(ref.textValue());
if (mungedRef != null) {
parameter.set$ref(mungedRef);
} else {
parameter.set$ref(ref.textValue());
}
if (result.isOpenapi31()) {
String desc = getString("description", obj, false, location, result);
if (StringUtils.isNotBlank(desc)) {
parameter.setDescription(desc);
}
}
return parameter;
} else {
result.invalidType(location, "$ref", "string", obj);
return null;
}
}
String l = null;
JsonNode ln = obj.get("name");
if (ln != null) {
l = ln.asText();
} else {
l = "['unknown']";
}
location += ".[" + l + "]";
String value = getString("in", obj, true, location, result);
if (!result.isAllowEmptyStrings() && StringUtils.isBlank(value) || result.isAllowEmptyStrings() && value == null) {
return null;
}
if (QUERY_PARAMETER.equals(value)) {
parameter = new QueryParameter();
} else if (HEADER_PARAMETER.equals(value)) {
parameter = new HeaderParameter();
} else if (PATH_PARAMETER.equals(value)) {
parameter = new PathParameter();
} else if (COOKIE_PARAMETER.equals(value)) {
parameter = new CookieParameter();
}
if (parameter == null) {
result.invalidType(location, "in", "[query|header|path|cookie]", obj);
return null;
}
parameter.setIn(value);
value = getString("name", obj, true, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
parameter.setName(value);
}
value = getString("description", obj, false, location, result);
if ((result.isAllowEmptyStrings() && value != null) || (!result.isAllowEmptyStrings() && !StringUtils.isBlank(value))) {
parameter.setDescription(value);
}
Boolean required = getBoolean("required", obj, false, location, result);
if (required != null) {
parameter.setRequired(required);
} else {
parameter.setRequired(false);
}
Boolean deprecated = getBoolean("deprecated", obj, false, location, result);
if (deprecated != null) {
parameter.setDeprecated(deprecated);
}
if (parameter instanceof QueryParameter) {
Boolean allowEmptyValue = getBoolean("allowEmptyValue", obj, false, location, result);
if (allowEmptyValue != null) {
parameter.setAllowEmptyValue(allowEmptyValue);
}
}
ObjectNode parameterObject = getObject("schema", obj, false, location, result);
if (parameterObject != null) {
parameter.setSchema(getSchema(parameterObject, String.format("%s.%s", location, "schemas"), result));
}
ObjectNode examplesObject = getObject("examples", obj, false, location, result);
if (examplesObject != null) {
parameter.setExamples(getExamples(examplesObject, String.format("%s.%s", location, "examples"), result, false));
}
Object example = getAnyType("example", obj, location, result);
if (example != null) {
if (examplesObject != null) {
result.warning(location, "examples already defined -- ignoring \"example\" field");
} else {
parameter.setExample(example instanceof NullNode ? null : example);
}
}
Boolean allowReserved = getBoolean("allowReserved", obj, false, location, result);
if (allowReserved != null) {
parameter.setAllowReserved(allowReserved);
}
ObjectNode contentNode = getObject("content", obj, false, location, result);
if (contentNode != null) {
Content content = getContent(contentNode, String.format("%s.%s", location, "content"), result);
if (content.size() == 0) {
result.unsupported(location, "content with no media type", contentNode);
result.invalid();
} else if (content.size() > 1) {
result.unsupported(location, "content with multiple media types", contentNode);
result.invalid();
} else if (parameter.getSchema() != null) {
result.unsupported(location, "content when schema defined", contentNode);
result.invalid();
} else {
parameter.setContent(content);
}
} else if (parameter.getSchema() == null) {
result.missing(location, "content");
}
value = getString("style", obj, false, location, result);
if (parameter.getContent() == null) {
setStyle(value, parameter, location, obj, result);
Boolean explode = getBoolean("explode", obj, false, location, result);
if (explode != null) {
parameter.setExplode(explode);
} else if (StyleEnum.FORM.equals(parameter.getStyle())) {
parameter.setExplode(Boolean.TRUE);
} else {
parameter.setExplode(Boolean.FALSE);
}
}
Map<String, Object> extensions = getExtensions(obj);
if (extensions != null && extensions.size() > 0) {
parameter.setExtensions(extensions);
}
Set<String> keys = getKeys(obj);
Map<String, Set<String>> specKeys = KEYS.get(result.isOpenapi31() ? "openapi31" : "openapi30");
for (String key : keys) {
if (!specKeys.get("PARAMETER_KEYS").contains(key) && !key.startsWith("x-")) {
result.extra(location, key, obj.get(key));
}
validateReservedKeywords(specKeys, key, location, result);
}
return parameter;
}
Aggregations