use of org.eclipse.microprofile.openapi.models.parameters.Parameter in project wildfly-swarm by wildfly-swarm.
the class OpenApiParser method readParameters.
/**
* Reads the {@link Parameter} OpenAPI nodes.
* @param node
*/
private Map<String, Parameter> readParameters(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
Map<String, Parameter> models = new LinkedHashMap<>();
for (Iterator<String> fieldNames = node.fieldNames(); fieldNames.hasNext(); ) {
String fieldName = fieldNames.next();
JsonNode childNode = node.get(fieldName);
models.put(fieldName, readParameter(childNode));
}
return models;
}
use of org.eclipse.microprofile.openapi.models.parameters.Parameter in project wildfly-swarm by wildfly-swarm.
the class OpenApiParser method readParameter.
/**
* Reads a {@link Parameter} OpenAPI node.
* @param node
*/
private Parameter readParameter(JsonNode node) {
if (node == null || !node.isObject()) {
return null;
}
Parameter model = new ParameterImpl();
model.setRef(JsonUtil.stringProperty(node, OpenApiConstants.PROP_$REF));
model.setName(JsonUtil.stringProperty(node, OpenApiConstants.PROP_NAME));
model.setIn(readParameterIn(node.get(OpenApiConstants.PROP_IN)));
model.setDescription(JsonUtil.stringProperty(node, OpenApiConstants.PROP_DESCRIPTION));
model.setRequired(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_REQUIRED));
model.setSchema(readSchema(node.get(OpenApiConstants.PROP_SCHEMA)));
model.setAllowEmptyValue(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_ALLOW_EMPTY_VALUE));
model.setDeprecated(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_DEPRECATED));
model.setStyle(readParameterStyle(node.get(OpenApiConstants.PROP_STYLE)));
model.setExplode(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_EXPLODE));
model.setAllowReserved(JsonUtil.booleanProperty(node, OpenApiConstants.PROP_ALLOW_RESERVED));
model.setExample(readObject(node.get(OpenApiConstants.PROP_EXAMPLE)));
model.setExamples(readExamples(node.get(OpenApiConstants.PROP_EXAMPLES)));
model.setContent(readContent(node.get(OpenApiConstants.PROP_CONTENT)));
readExtensions(node, model);
return model;
}
use of org.eclipse.microprofile.openapi.models.parameters.Parameter in project wildfly-swarm by wildfly-swarm.
the class FilterUtil method filterParameterList.
/**
* Filters the given models.
* @param filter
* @param models
*/
private static void filterParameterList(OASFilter filter, List<Parameter> models) {
if (models == null) {
return;
}
ListIterator<Parameter> iterator = models.listIterator();
while (iterator.hasNext()) {
Parameter model = iterator.next();
filterParameter(filter, model);
if (filter.filterParameter(model) == null) {
iterator.remove();
}
}
}
use of org.eclipse.microprofile.openapi.models.parameters.Parameter in project Payara by payara.
the class ApplicationProcessor method findOperationParameterFor.
private static Parameter findOperationParameterFor(Parameter parameter, MethodModel annotated, ApiContext context) {
String name = parameter.getName();
// If the parameter reference is valid
if (name != null && !name.isEmpty()) {
// Get all parameters with the same name
List<org.glassfish.hk2.classmodel.reflect.Parameter> matchingMethodParameters = annotated.getParameters().stream().filter(x -> name.equals(ModelUtils.getParameterName(context, x))).collect(Collectors.toList());
// If there is more than one match, filter it further
In in = parameter.getIn();
if (matchingMethodParameters.size() > 1 && in != null) {
// Remove all parameters of the wrong input type
matchingMethodParameters.removeIf(x -> ModelUtils.getParameterType(context, x) != In.valueOf(in.name()));
}
if (matchingMethodParameters.isEmpty()) {
return null;
}
// If there's only one matching parameter, handle it immediately
String matchingMethodParamName = ModelUtils.getParameterName(context, matchingMethodParameters.get(0));
// Find the matching operation parameter
for (Parameter operationParam : context.getWorkingOperation().getParameters()) {
if (operationParam.getName().equals(matchingMethodParamName)) {
return operationParam;
}
}
}
return null;
}
use of org.eclipse.microprofile.openapi.models.parameters.Parameter in project Payara by payara.
the class ApplicationProcessor method visitSchemaParameter.
private static void visitSchemaParameter(AnnotationModel schemaAnnotation, org.glassfish.hk2.classmodel.reflect.Parameter parameter, ApiContext context) {
// If this is being parsed at the start, ignore it as the path doesn't exist
if (context.getWorkingOperation() == null) {
return;
}
// Check if it's a request body
if (ModelUtils.isRequestBody(context, parameter)) {
if (context.getWorkingOperation().getRequestBody() == null) {
context.getWorkingOperation().setRequestBody(new RequestBodyImpl());
}
// Insert the schema to the request body media type
MediaType mediaType = context.getWorkingOperation().getRequestBody().getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
Schema schema = SchemaImpl.createInstance(schemaAnnotation, context);
SchemaImpl.merge(schema, mediaType.getSchema(), true, context);
if (schema.getRef() != null && !schema.getRef().isEmpty()) {
mediaType.setSchema(new SchemaImpl().ref(schema.getRef()));
}
} else if (ModelUtils.getParameterType(context, parameter) != null) {
for (Parameter param : context.getWorkingOperation().getParameters()) {
if (param.getName().equals(ModelUtils.getParameterName(context, parameter))) {
Schema schema = SchemaImpl.createInstance(schemaAnnotation, context);
SchemaImpl.merge(schema, param.getSchema(), true, context);
if (schema.getRef() != null && !schema.getRef().isEmpty()) {
param.setSchema(new SchemaImpl().ref(schema.getRef()));
}
}
}
}
}
Aggregations