use of io.swagger.models.properties.ArrayProperty in project swagger-parser by swagger-api.
the class SwaggerParserTest method testLoadRecursiveExternalDef.
@Test
public void testLoadRecursiveExternalDef() throws Exception {
SwaggerParser parser = new SwaggerParser();
final Swagger swagger = parser.read("src/test/resources/file-reference-to-recursive-defs/b.yaml");
Map<String, Model> definitions = swagger.getDefinitions();
assertEquals(((RefProperty) ((ArrayProperty) definitions.get("v").getProperties().get("children")).getItems()).get$ref(), "#/definitions/v");
assertTrue(definitions.containsKey("y"));
assertEquals(((RefProperty) ((ArrayProperty) definitions.get("x").getProperties().get("children")).getItems()).get$ref(), "#/definitions/y");
}
use of io.swagger.models.properties.ArrayProperty in project swagger-parser by swagger-api.
the class SwaggerCompatConverter method convertParameter.
public Parameter convertParameter(io.swagger.models.apideclaration.Parameter param) {
Parameter output = null;
List<String> _enum = param.getEnumValues();
if (ParamType.PATH.equals(param.getParamType())) {
PathParameter p = new PathParameter();
p.setDefaultValue(param.getDefaultValue());
p.setEnum(_enum);
output = p;
} else if (ParamType.QUERY.equals(param.getParamType())) {
QueryParameter p = new QueryParameter();
p.setDefaultValue(param.getDefaultValue());
p.setEnum(_enum);
output = p;
} else if (ParamType.HEADER.equals(param.getParamType())) {
HeaderParameter p = new HeaderParameter();
p.setDefaultValue(param.getDefaultValue());
p.setEnum(_enum);
output = p;
} else if (ParamType.BODY.equals(param.getParamType())) {
BodyParameter p = new BodyParameter();
output = p;
} else if (ParamType.FORM.equals(param.getParamType())) {
FormParameter p = new FormParameter();
p.setDefaultValue(param.getDefaultValue());
p.setEnum(_enum);
output = p;
}
output.setName(param.getName());
output.setDescription(param.getDescription());
if (param.getRequired() != null) {
output.setRequired(param.getRequired());
}
Property property = null;
String type = param.getType() == null ? null : param.getType().toString();
String format = param.getFormat() == null ? null : param.getFormat().toString();
if (null == type) {
LOGGER.warn("Empty type in Param: " + param);
}
if (output instanceof BodyParameter) {
BodyParameter bp = (BodyParameter) output;
bp.setSchema(modelFromExtendedTypedObject(param));
} else if (output instanceof SerializableParameter) {
SerializableParameter sp = (SerializableParameter) output;
Property p = null;
if (param.getAllowMultiple() != null && param.getAllowMultiple() == true) {
ArrayProperty arrayProperty = new ArrayProperty();
Property innerType = PropertyBuilder.build(type, format, null);
arrayProperty.setItems(innerType);
p = arrayProperty;
} else {
p = propertyFromTypedObject(param);
if (p == null) {
LOGGER.warn(String.format("WARNING! No property detected for parameter '%s' (%s)! Falling back to string!", param.getName(), param.getParamType()));
p = new StringProperty();
}
}
if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;
sp.setType("array");
sp.setCollectionFormat("csv");
sp.setItems(ap.getItems());
} else {
sp.setType(p.getType());
sp.setFormat(p.getFormat());
}
}
// all path parameters are required
if (output instanceof PathParameter) {
((PathParameter) output).setRequired(true);
}
return output;
}
use of io.swagger.models.properties.ArrayProperty in project cxf by apache.
the class JaxRs2Extension method enforcePrimitive.
private Property enforcePrimitive(final Property in, final int level) {
if (in instanceof RefProperty) {
return new StringProperty();
}
if (in instanceof ArrayProperty) {
if (level == 0) {
final ArrayProperty array = (ArrayProperty) in;
array.setItems(enforcePrimitive(array.getItems(), level + 1));
} else {
return new StringProperty();
}
}
return in;
}
use of io.swagger.models.properties.ArrayProperty in project swagger-parser by swagger-api.
the class SwaggerInventory method process.
public void process(Property property) {
this.properties.add(property);
if (property instanceof ArrayProperty) {
ArrayProperty p = (ArrayProperty) property;
Property ap = p.getItems();
this.process(ap);
} else if (property instanceof MapProperty) {
MapProperty p1 = (MapProperty) property;
} else if (property instanceof ObjectProperty) {
ObjectProperty p2 = (ObjectProperty) property;
if (p2.getProperties() != null) {
Iterator ap1 = p2.getProperties().keySet().iterator();
while (ap1.hasNext()) {
String name = (String) ap1.next();
Property ip = (Property) p2.getProperties().get(name);
this.process(ip);
}
}
}
}
use of io.swagger.models.properties.ArrayProperty 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