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 getArraySchema.
private static SchemaImpl getArraySchema(AnnotatedElement element, ApiContext context) {
SchemaImpl arraySchema = new SchemaImpl();
List<ParameterizedType> parameterizedType;
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
org.glassfish.hk2.classmodel.reflect.Parameter parameter = (org.glassfish.hk2.classmodel.reflect.Parameter) element;
parameterizedType = parameter.getParameterizedTypes();
} else {
FieldModel field = (FieldModel) element;
parameterizedType = field.getParameterizedTypes();
}
arraySchema.setType(ModelUtils.getSchemaType(parameterizedType.get(0).getTypeName(), context));
return arraySchema;
}
use of org.eclipse.microprofile.openapi.models.parameters.Parameter in project Payara by payara.
the class ApplicationProcessor method addParameter.
private static void addParameter(AnnotatedElement element, ApiContext context, String name, In in, Boolean required) {
Boolean hidden = false;
AnnotationModel paramAnnotation = element.getAnnotation(org.eclipse.microprofile.openapi.annotations.parameters.Parameter.class.getName());
if (paramAnnotation != null) {
hidden = paramAnnotation.getValue("hidden", Boolean.class);
}
if (hidden != null && hidden) {
return;
}
Parameter newParameter = new ParameterImpl();
newParameter.setName(name);
newParameter.setIn(in);
newParameter.setRequired(required);
SchemaImpl schema = new SchemaImpl();
String defaultValue = getDefaultValueIfPresent(element);
if (element instanceof org.glassfish.hk2.classmodel.reflect.Parameter) {
org.glassfish.hk2.classmodel.reflect.Parameter parameter = (org.glassfish.hk2.classmodel.reflect.Parameter) element;
schema.setType(ModelUtils.getSchemaType(parameter.getTypeName(), context));
} else {
FieldModel field = (FieldModel) element;
schema.setType(ModelUtils.getSchemaType(field.getTypeName(), context));
}
if (schema.getType() == SchemaType.ARRAY) {
schema.setItems(getArraySchema(element, context));
if (defaultValue != null) {
schema.getItems().setDefaultValue(defaultValue);
}
} else if (defaultValue != null) {
schema.setDefaultValue(defaultValue);
}
newParameter.setSchema(schema);
final Operation workingOperation = context.getWorkingOperation();
if (workingOperation != null) {
for (Parameter parameter : workingOperation.getParameters()) {
final String parameterName = parameter.getName();
if (parameterName != null && parameterName.equals(newParameter.getName())) {
ParameterImpl.merge(newParameter, parameter, false, context);
return;
}
}
workingOperation.addParameter(newParameter);
} else {
LOGGER.log(SEVERE, "Couldn''t add {0} parameter, \"{1}\" to the OpenAPI Document. This is usually caused by declaring parameter under a method with an unsupported annotation.", new Object[] { newParameter.getIn(), newParameter.getName() });
}
}
Aggregations