use of io.swagger.v3.oas.annotations.enums.Explode in project dotwebstack-framework by dotwebstack.
the class DefaultParamHandlerTest method mockObjectParameter.
@SuppressWarnings({ "rawtypes" })
private void mockObjectParameter(String name, Map<String, String> propertyTypes, String format, boolean explode, Parameter.StyleEnum style) {
when(parameter.getName()).thenReturn(name);
when(parameter.getExplode()).thenReturn(explode);
when(parameter.getStyle()).thenReturn(style);
Schema schema = mock(Schema.class);
when(schema.getType()).thenReturn(OBJECT_TYPE);
Map<String, Schema> properties = propertyTypes.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> mockScalarSchema(e.getValue())));
when(schema.getProperties()).thenReturn(properties);
when(schema.getEnum()).thenReturn(null);
when(parameter.getSchema()).thenReturn(schema);
when(schema.getFormat()).thenReturn(format);
}
use of io.swagger.v3.oas.annotations.enums.Explode in project dotwebstack-framework by dotwebstack.
the class DefaultParamHandlerTest method mockParameter.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void mockParameter(String name, String type, String subType, String format, boolean explode, Parameter.StyleEnum style) {
when(parameter.getName()).thenReturn(name);
when(parameter.getExplode()).thenReturn(explode);
when(parameter.getStyle()).thenReturn(style);
Schema schema;
switch(type) {
case ARRAY_TYPE:
ArraySchema arraySchema = mock(ArraySchema.class);
Schema itemSchema = mockScalarSchema(subType);
when(itemSchema.getEnum()).thenReturn(null);
when(arraySchema.getItems()).thenReturn(itemSchema);
schema = arraySchema;
break;
case OBJECT_TYPE:
schema = mock(ObjectSchema.class);
break;
default:
schema = mockScalarSchema(type);
}
when(schema.getEnum()).thenReturn(null);
when(parameter.getSchema()).thenReturn(schema);
when(schema.getType()).thenReturn(type);
when(schema.getFormat()).thenReturn(format);
}
use of io.swagger.v3.oas.annotations.enums.Explode in project vertx-web by vert-x3.
the class OpenAPI3PathResolver method solve.
/**
* This method returns a pattern only if a pattern is needed, otherwise it returns an empty optional
*
* @return
*/
public Optional<Pattern> solve() {
if (ILLEGAL_PATH_MATCHER.matcher(oasPath).matches())
throw new RouterFactoryException("Path template not supported", RouterFactoryException.ErrorType.INVALID_SPEC_PATH);
Matcher parametersMatcher = OAS_PATH_PARAMETERS_PATTERN.matcher(oasPath);
if (!parameters.isEmpty() && parametersMatcher.find()) {
// Need to create a specific match pattern with path parameters and some string manipulation magic
StringBuilder regex = new StringBuilder();
int lastMatchEnd = 0;
boolean endSlash = oasPath.charAt(oasPath.length() - 1) == '/';
parametersMatcher.reset();
int i = 0;
while (parametersMatcher.find()) {
// Append constant string
String toQuote = oasPath.substring(lastMatchEnd, parametersMatcher.start());
if (toQuote.length() != 0)
regex.append(Pattern.quote(toQuote));
lastMatchEnd = parametersMatcher.end();
String paramName = parametersMatcher.group(1);
Optional<Parameter> parameterOptional = parameters.stream().filter(p -> p.getName().equals(paramName)).findFirst();
if (parameterOptional.isPresent()) {
// For every parameter style I have to generate a different regular expression
Parameter parameter = parameterOptional.get();
String style = solveParamStyle(parameter);
boolean explode = solveParamExplode(parameter);
boolean isObject = OpenApi3Utils.isParameterObjectOrAllOfType(parameter);
boolean isArray = OpenApi3Utils.isParameterArrayType(parameter);
String groupName = "p" + i;
if (style.equals("simple")) {
regex.append(RegexBuilder.create().namedGroup(groupName, RegexBuilder.create().notCharactersClass("!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null).zeroOrMore()).zeroOrOne());
mappedGroups.put(groupName, paramName);
} else if (style.equals("label")) {
if (isObject && explode) {
Map<String, OpenApi3Utils.ObjectField> properties = OpenApi3Utils.solveObjectParameters(parameter.getSchema());
for (Map.Entry<String, OpenApi3Utils.ObjectField> entry : properties.entrySet()) {
groupName = "p" + i;
regex.append(RegexBuilder.create().optionalGroup(RegexBuilder.create().escapeCharacter(".").zeroOrOne().quote(entry.getKey()).append("=").namedGroup(groupName, RegexBuilder.create().notCharactersClass("!", "*", "'", "(", ")", ";", "@", "&", "+", "$", "/", "?", "#", "[", "]", ".", "=").zeroOrMore())));
mappedGroups.put(groupName, entry.getKey());
i++;
}
} else {
regex.append(RegexBuilder.create().escapeCharacter(".").zeroOrOne().namedGroup(groupName, RegexBuilder.create().notCharactersClass("!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]").zeroOrMore()).zeroOrOne());
mappedGroups.put(groupName, paramName);
}
} else if (style.equals("matrix")) {
if (isObject && explode) {
Map<String, OpenApi3Utils.ObjectField> properties = OpenApi3Utils.solveObjectParameters(parameter.getSchema());
for (Map.Entry<String, OpenApi3Utils.ObjectField> entry : properties.entrySet()) {
groupName = "p" + i;
regex.append(RegexBuilder.create().optionalGroup(RegexBuilder.create().escapeCharacter(";").quote(entry.getKey()).append("=").namedGroup(groupName, RegexBuilder.create().notCharactersClass("!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null).zeroOrMore())));
mappedGroups.put(groupName, entry.getKey());
i++;
}
} else if (isArray && explode) {
regex.append(RegexBuilder.create().namedGroup(groupName, RegexBuilder.create().atomicGroup(RegexBuilder.create().append(";").quote(paramName).append("=").notCharactersClass("!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", ",", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null).zeroOrMore()).oneOrMore()));
mappedGroups.put(groupName, paramName);
} else {
regex.append(RegexBuilder.create().append(";").quote(paramName).append("=").namedGroup(groupName, RegexBuilder.create().notCharactersClass("!", "*", "'", "(", ")", ";", "@", "&", "=", "+", "$", "/", "?", "#", "[", "]", (shouldThreatDotAsReserved) ? "." : null).zeroOrMore()).zeroOrOne());
mappedGroups.put(groupName, paramName);
}
}
} else {
throw RouterFactoryException.createSpecInvalidException("Missing parameter description for parameter name: " + paramName);
}
i++;
}
String toAppendQuoted = oasPath.substring(lastMatchEnd, (endSlash) ? oasPath.length() - 1 : oasPath.length());
if (toAppendQuoted.length() != 0)
regex.append(Pattern.quote(toAppendQuoted));
if (endSlash)
regex.append("\\/");
return Optional.of(Pattern.compile(regex.toString()));
} else {
return Optional.empty();
}
}
use of io.swagger.v3.oas.annotations.enums.Explode in project vertx-web by vert-x3.
the class OpenAPI3MultipleFilesValidationTest 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 springdoc-openapi by springdoc.
the class DataRestDelegatingMethodParameterCustomizer method getNewParameterAnnotationForField.
/**
* Gets new parameter annotation for field.
*
* @param methodParameter the method parameter
* @param pageableDefault the pageable default
* @return the new parameter annotation for field
*/
private Optional<Annotation> getNewParameterAnnotationForField(MethodParameter methodParameter, PageableDefault pageableDefault) {
String parameterName = methodParameter.getParameterName();
Field field;
Parameter parameterNew;
try {
field = methodParameter.getContainingClass().getDeclaredField(parameterName);
Parameter parameter = field.getAnnotation(Parameter.class);
parameterNew = new Parameter() {
@Override
public Class<? extends Annotation> annotationType() {
return parameter.annotationType();
}
@Override
public String name() {
return getName(parameterName, parameter.name());
}
@Override
public ParameterIn in() {
return parameter.in();
}
@Override
public String description() {
return parameter.description();
}
@Override
public boolean required() {
return parameter.required();
}
@Override
public boolean deprecated() {
return parameter.deprecated();
}
@Override
public boolean allowEmptyValue() {
return parameter.allowEmptyValue();
}
@Override
public ParameterStyle style() {
return parameter.style();
}
@Override
public Explode explode() {
return parameter.explode();
}
@Override
public boolean allowReserved() {
return parameter.allowReserved();
}
@Override
public Schema schema() {
return new Schema() {
@Override
public Class<? extends Annotation> annotationType() {
return parameter.schema().annotationType();
}
@Override
public Class<?> implementation() {
return parameter.schema().implementation();
}
@Override
public Class<?> not() {
return parameter.schema().not();
}
@Override
public Class<?>[] oneOf() {
return parameter.schema().oneOf();
}
@Override
public Class<?>[] anyOf() {
return parameter.schema().anyOf();
}
@Override
public Class<?>[] allOf() {
return parameter.schema().allOf();
}
@Override
public String name() {
return parameter.schema().name();
}
@Override
public String title() {
return parameter.schema().title();
}
@Override
public double multipleOf() {
return parameter.schema().multipleOf();
}
@Override
public String maximum() {
return parameter.schema().maximum();
}
@Override
public boolean exclusiveMaximum() {
return parameter.schema().exclusiveMaximum();
}
@Override
public String minimum() {
return parameter.schema().minimum();
}
@Override
public boolean exclusiveMinimum() {
return parameter.schema().exclusiveMaximum();
}
@Override
public int maxLength() {
return parameter.schema().maxLength();
}
@Override
public int minLength() {
return parameter.schema().minLength();
}
@Override
public String pattern() {
return parameter.schema().pattern();
}
@Override
public int maxProperties() {
return parameter.schema().maxProperties();
}
@Override
public int minProperties() {
return parameter.schema().minProperties();
}
@Override
public String[] requiredProperties() {
return parameter.schema().requiredProperties();
}
@Override
public boolean required() {
return parameter.schema().required();
}
@Override
public String description() {
return parameter.schema().description();
}
@Override
public String format() {
return parameter.schema().format();
}
@Override
public String ref() {
return parameter.schema().ref();
}
@Override
public boolean nullable() {
return parameter.schema().nullable();
}
@Override
public boolean readOnly() {
return AccessMode.READ_ONLY.equals(parameter.schema().accessMode());
}
@Override
public boolean writeOnly() {
return AccessMode.WRITE_ONLY.equals(parameter.schema().accessMode());
}
@Override
public AccessMode accessMode() {
return parameter.schema().accessMode();
}
@Override
public String example() {
return parameter.schema().example();
}
@Override
public ExternalDocumentation externalDocs() {
return parameter.schema().externalDocs();
}
@Override
public boolean deprecated() {
return parameter.schema().deprecated();
}
@Override
public String type() {
return parameter.schema().type();
}
@Override
public String[] allowableValues() {
return parameter.schema().allowableValues();
}
@Override
public String defaultValue() {
return getDefaultValue(parameterName, pageableDefault, parameter.schema().defaultValue());
}
@Override
public String discriminatorProperty() {
return parameter.schema().discriminatorProperty();
}
@Override
public DiscriminatorMapping[] discriminatorMapping() {
return parameter.schema().discriminatorMapping();
}
@Override
public boolean hidden() {
return parameter.schema().hidden();
}
@Override
public boolean enumAsRef() {
return parameter.schema().enumAsRef();
}
@Override
public Class<?>[] subTypes() {
return parameter.schema().subTypes();
}
@Override
public Extension[] extensions() {
return parameter.schema().extensions();
}
@Override
public AdditionalPropertiesValue additionalProperties() {
return parameter.schema().additionalProperties();
}
};
}
@Override
public ArraySchema array() {
ArraySchema arraySchema = parameter.array();
return new ArraySchema() {
@Override
public Class<? extends Annotation> annotationType() {
return arraySchema.annotationType();
}
@Override
public Schema schema() {
return arraySchema.schema();
}
@Override
public Schema arraySchema() {
Schema schema = arraySchema.arraySchema();
return new Schema() {
@Override
public Class<? extends Annotation> annotationType() {
return schema.annotationType();
}
@Override
public Class<?> implementation() {
return schema.implementation();
}
@Override
public Class<?> not() {
return schema.not();
}
@Override
public Class<?>[] oneOf() {
return schema.oneOf();
}
@Override
public Class<?>[] anyOf() {
return schema.anyOf();
}
@Override
public Class<?>[] allOf() {
return schema.allOf();
}
@Override
public String name() {
return schema.name();
}
@Override
public String title() {
return schema.title();
}
@Override
public double multipleOf() {
return schema.multipleOf();
}
@Override
public String maximum() {
return schema.maximum();
}
@Override
public boolean exclusiveMaximum() {
return schema.exclusiveMaximum();
}
@Override
public String minimum() {
return schema.minimum();
}
@Override
public boolean exclusiveMinimum() {
return schema.exclusiveMinimum();
}
@Override
public int maxLength() {
return schema.maxLength();
}
@Override
public int minLength() {
return schema.minLength();
}
@Override
public String pattern() {
return schema.pattern();
}
@Override
public int maxProperties() {
return schema.maxProperties();
}
@Override
public int minProperties() {
return schema.minProperties();
}
@Override
public String[] requiredProperties() {
return schema.requiredProperties();
}
@Override
public boolean required() {
return schema.required();
}
@Override
public String description() {
return schema.description();
}
@Override
public String format() {
return schema.format();
}
@Override
public String ref() {
return schema.ref();
}
@Override
public boolean nullable() {
return schema.nullable();
}
@Override
public boolean readOnly() {
return AccessMode.READ_ONLY.equals(schema.accessMode());
}
@Override
public boolean writeOnly() {
return AccessMode.WRITE_ONLY.equals(schema.accessMode());
}
@Override
public AccessMode accessMode() {
return schema.accessMode();
}
@Override
public String example() {
return schema.example();
}
@Override
public ExternalDocumentation externalDocs() {
return schema.externalDocs();
}
@Override
public boolean deprecated() {
return schema.deprecated();
}
@Override
public String type() {
return schema.type();
}
@Override
public String[] allowableValues() {
return schema.allowableValues();
}
@Override
public String defaultValue() {
return getArrayDefaultValue(parameterName, pageableDefault, schema.defaultValue());
}
@Override
public String discriminatorProperty() {
return schema.discriminatorProperty();
}
@Override
public DiscriminatorMapping[] discriminatorMapping() {
return schema.discriminatorMapping();
}
@Override
public boolean hidden() {
return schema.hidden();
}
@Override
public boolean enumAsRef() {
return schema.enumAsRef();
}
@Override
public Class<?>[] subTypes() {
return schema.subTypes();
}
@Override
public Extension[] extensions() {
return schema.extensions();
}
@Override
public AdditionalPropertiesValue additionalProperties() {
return schema.additionalProperties();
}
};
}
@Override
public int maxItems() {
return arraySchema.maxItems();
}
@Override
public int minItems() {
return arraySchema.minItems();
}
@Override
public boolean uniqueItems() {
return arraySchema.uniqueItems();
}
@Override
public Extension[] extensions() {
return arraySchema.extensions();
}
};
}
@Override
public Content[] content() {
return parameter.content();
}
@Override
public boolean hidden() {
return parameter.hidden();
}
@Override
public ExampleObject[] examples() {
return parameter.examples();
}
@Override
public String example() {
return parameter.example();
}
@Override
public Extension[] extensions() {
return parameter.extensions();
}
@Override
public String ref() {
return parameter.ref();
}
};
return Optional.of(parameterNew);
} catch (NoSuchFieldException e) {
LOGGER.warn(e.getMessage());
return Optional.empty();
}
}
Aggregations