use of io.swagger.models.properties.BooleanProperty in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method addResourceParameters.
/**
* Creates parameters in the swagger operation using the parameters in the ballerina resource definition.
* @param resource The ballerina resource definition.
* @param operationAdaptor The swagger operation.
*/
private void addResourceParameters(ResourceNode resource, OperationAdaptor operationAdaptor) {
if (!"get".equalsIgnoreCase(operationAdaptor.getHttpOperation())) {
// Creating request body - required.
ModelImpl messageModel = new ModelImpl();
messageModel.setType("object");
Map<String, Model> definitions = new HashMap<>();
if (!definitions.containsKey("Request")) {
definitions.put("Request", messageModel);
this.swaggerDefinition.setDefinitions(definitions);
}
// Creating "Request rq" parameter
BodyParameter messageParameter = new BodyParameter();
messageParameter.setName(resource.getParameters().get(0).getName().getValue());
RefModel refModel = new RefModel();
refModel.setReference("Request");
messageParameter.setSchema(refModel);
operationAdaptor.getOperation().addParameter(messageParameter);
}
for (int i = 2; i < resource.getParameters().size(); i++) {
VariableNode parameterDef = resource.getParameters().get(i);
String typeName = parameterDef.getTypeNode().toString().toLowerCase(Locale.getDefault());
PathParameter pathParameter = new PathParameter();
// Set in value
pathParameter.setIn("path");
// Set parameter name
String parameterName = parameterDef.getName().getValue();
pathParameter.setName(parameterName);
// Set type
if (typeName.contains("[]")) {
pathParameter.setType("array");
switch(typeName.replace("[]", "").trim()) {
case "string":
pathParameter.items(new StringProperty());
break;
case "int":
pathParameter.items(new IntegerProperty());
break;
case "boolean":
pathParameter.items(new BooleanProperty());
break;
default:
break;
}
} else if ("int".equals(typeName)) {
pathParameter.setType("integer");
} else {
pathParameter.setType(typeName);
}
// Note: 'format' to be added using annotations, hence skipped here.
operationAdaptor.getOperation().addParameter(pathParameter);
}
}
use of io.swagger.models.properties.BooleanProperty in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method createHeadersModel.
/**
* Creates headers definitions for swagger response.
*
* @param annotationAttributeValue The annotation attribute value which has the headers.
* @param response The swagger response.
*/
private void createHeadersModel(AnnAttributeValue annotationAttributeValue, Response response) {
if (null != annotationAttributeValue) {
AnnAttributeValue[] headersValueArray = annotationAttributeValue.getAttributeValueArray();
for (AnnAttributeValue headersValue : headersValueArray) {
AnnAttachmentInfo headerAnnotationAttachment = headersValue.getAnnotationAttachmentValue();
Map<String, AnnAttributeValue> headerAnnAttributeValueMap = SwaggerUtils.convertToAttributeMap(headerAnnotationAttachment);
Map<String, Property> headers = new HashMap<>();
if (null != headerAnnAttributeValueMap.get("name") && null != headerAnnAttributeValueMap.get("headerType")) {
String headerName = headerAnnAttributeValueMap.get("name").getStringValue();
String type = headerAnnAttributeValueMap.get("headerType").getStringValue();
Property property = null;
if ("string".equals(type)) {
property = new StringProperty();
} else if ("number".equals(type) || "integer".equals(type)) {
property = new IntegerProperty();
} else if ("boolean".equals(type)) {
property = new BooleanProperty();
} else if ("array".equals(type)) {
property = new ArrayProperty();
}
if (null != property) {
if (null != headerAnnAttributeValueMap.get("description")) {
property.setDescription(headerAnnAttributeValueMap.get("description").getStringValue());
}
headers.put(headerName, property);
}
}
response.setHeaders(headers);
}
}
}
use of io.swagger.models.properties.BooleanProperty in project herd by FINRAOS.
the class DefinitionGenerator method getPropertyFromType.
/**
* Gets a property from the given fieldType. This method may be called recursively.
*
* @param fieldType the field type class.
*
* @return the property.
* @throws MojoExecutionException if any problems were encountered.
*/
private Property getPropertyFromType(Class<?> fieldType) throws MojoExecutionException {
Property property;
if (String.class.isAssignableFrom(fieldType)) {
property = new StringProperty();
} else if (Integer.class.isAssignableFrom(fieldType) || int.class.isAssignableFrom(fieldType)) {
property = new IntegerProperty();
} else if (Long.class.isAssignableFrom(fieldType) || long.class.isAssignableFrom(fieldType)) {
property = new LongProperty();
} else if (BigDecimal.class.isAssignableFrom(fieldType)) {
property = new DecimalProperty();
} else if (XMLGregorianCalendar.class.isAssignableFrom(fieldType)) {
property = new DateTimeProperty();
} else if (Boolean.class.isAssignableFrom(fieldType) || boolean.class.isAssignableFrom(fieldType)) {
property = new BooleanProperty();
} else if (Collection.class.isAssignableFrom(fieldType)) {
property = new ArrayProperty(new StringProperty());
} else if (fieldType.getAnnotation(XmlEnum.class) != null) {
/*
* Enums are a string property which have enum constants
*/
List<String> enums = new ArrayList<>();
for (Enum<?> anEnum : (Enum<?>[]) fieldType.getEnumConstants()) {
enums.add(anEnum.name());
}
property = new StringProperty()._enum(enums);
} else /*
* Recursively process complex objects which is a XmlType
*/
if (fieldType.getAnnotation(XmlType.class) != null) {
processDefinitionClass(fieldType);
property = new RefProperty(fieldType.getAnnotation(XmlType.class).name());
} else {
// Default to a string property in other cases.
property = new StringProperty();
}
log.debug("Field type \"" + fieldType.getName() + "\" is a property type \"" + property.getType() + "\".");
return property;
}
use of io.swagger.models.properties.BooleanProperty in project ballerina by ballerina-lang.
the class SwaggerResourceMapper method createHeadersModel.
/**
* Creates headers definitions for swagger response.
* @param annotationAttributeValue The annotation attribute value which has the headers.
* @param response The swagger response.
*/
private void createHeadersModel(AnnotationAttachmentAttributeValueNode annotationAttributeValue, Response response) {
if (null != annotationAttributeValue) {
List<? extends AnnotationAttachmentAttributeValueNode> headersValueArray = annotationAttributeValue.getValueArray();
for (AnnotationAttachmentAttributeValueNode headersValue : headersValueArray) {
if (headersValue instanceof AnnotationAttachmentNode) {
AnnotationAttachmentNode headerAnnotationAttachment = (AnnotationAttachmentNode) headersValue;
Map<String, Property> headers = new HashMap<>();
Map<String, AnnotationAttachmentAttributeValueNode> headersAttributes = this.listToMap(headerAnnotationAttachment);
if (headersAttributes.containsKey("name") && headersAttributes.containsKey("headerType")) {
String headerName = this.getStringLiteralValue(headersAttributes.get("name"));
String type = this.getStringLiteralValue(headersAttributes.get("headerType"));
Property property = null;
if ("string".equals(type)) {
property = new StringProperty();
} else if ("number".equals(type) || "integer".equals(type)) {
property = new IntegerProperty();
} else if ("boolean".equals(type)) {
property = new BooleanProperty();
} else if ("array".equals(type)) {
property = new ArrayProperty();
}
if (null != property) {
if (headersAttributes.containsKey("description")) {
property.setDescription(this.getStringLiteralValue(headersAttributes.get("description")));
}
headers.put(headerName, property);
}
}
response.setHeaders(headers);
}
}
}
}
Aggregations