use of io.swagger.models.properties.RefProperty in project herd by FINRAOS.
the class RestControllerProcessor method processRestMethodReturnValue.
/**
* Processes the return value of a RequestMapping annotated method.
*
* @param returnType the return type.
* @param operation the operation.
* @param returnDescription the description of the return value.
*
* @throws MojoExecutionException if the return type isn't an XmlType.
*/
private void processRestMethodReturnValue(Class<?> returnType, Operation operation, String returnDescription) throws MojoExecutionException {
log.debug("Processing REST method return value \"" + returnType.getName() + "\".");
// Add the class name to the list of classes which we will create an example for.
exampleClassNames.add(returnType.getSimpleName());
// Add the success response
operation.response(200, new Response().description(returnDescription == null ? "Success" : returnDescription).schema(new RefProperty(getXmlType(returnType).name().trim())));
// If we have an error class, add that as the default response.
if (modelErrorClass != null) {
operation.defaultResponse(new Response().description("General Error").schema(new RefProperty(getXmlType(modelErrorClass).name().trim())));
}
}
use of io.swagger.models.properties.RefProperty in project sql-boot by sql-boot.
the class ApiController method getSwaggerDescription.
private Swagger getSwaggerDescription(HttpServletRequest request, String connectionName) {
FsResourceTypes fsResourceTypes = new FsResourceTypes(dbConnectionList.getConnectionByName(connectionName));
final List<ResourceType> resourceTypes = fsResourceTypes.resourceTypes();
Swagger swagger = new Swagger();
swagger.consumes("application/json");
swagger.host(request.getServerName() + ":" + request.getServerPort());
swagger.setInfo(new Info().version("v1").title("API specification"));
swagger.setSchemes(asList(Scheme.HTTP, Scheme.HTTPS));
swagger.path("/connections", new Path().get(new Operation().tag("connections").response(200, new Response().description("Ok").schema(new ArrayProperty(new RefProperty("connection")))).produces("application/json")));
swagger.model("connection", new ModelImpl().property("name", new StringProperty().description("name")).property("url", new StringProperty().description("url")).property("user", new StringProperty().description("user")).property("driverClassName", new StringProperty().description("driverClassName")).property("configurationFolder", new StringProperty().description("configurationFolder")));
// paths
for (ResourceType resourceType : resourceTypes) {
PathParameter parameter = new PathParameter().required(true).type("string").name("connection_name");
parameter.setDefaultValue(connectionName);
swagger.path("/api/{connection_name}/headers/" + resourceType.name(), new Path().get(new Operation().description(resourceType.name()).tag("db_objects").parameter(parameter).parameter(new QueryParameter().name("select").type("string")).parameter(new QueryParameter().name("distinct").type("boolean")).parameter(new QueryParameter().name("where").type("string")).parameter(new QueryParameter().name("page").type("string").description("get page by mask [page_count:page_size]")).parameter(new QueryParameter().name("limit").type("integer")).parameter(new QueryParameter().name("orderby").type("string")).parameter(new QueryParameter().name("cache").type("boolean")).response(200, new Response().description("Ok").schema(new ArrayProperty(new RefProperty(resourceType.name())))).produces("application/json")));
final List<String> path = resourceType.path();
final List<String> newPath = new ArrayList<>();
for (String s : path) {
newPath.add(s + "_name");
List<Parameter> parameterList = new ArrayList<>();
PathParameter parameterConnection = new PathParameter().required(true).type("string").name("connection_name");
parameterConnection.setDefaultValue(connectionName);
parameterList.add(parameterConnection);
for (String s1 : newPath) {
final PathParameter pathParameter = new PathParameter().required(true).type("string").name(s1);
pathParameter.setDefaultValue("*");
parameterList.add(pathParameter);
}
Operation operation = new Operation();
operation.setParameters(parameterList);
operation.parameter(new QueryParameter().name("select").type("string"));
operation.parameter(new QueryParameter().name("distinct").type("boolean"));
operation.parameter(new QueryParameter().name("where").type("string"));
operation.parameter(new QueryParameter().name("page").type("string").description("get page by mask [page_count:page_size]"));
operation.parameter(new QueryParameter().name("limit").type("integer"));
operation.parameter(new QueryParameter().name("orderby").type("string"));
operation.parameter(new QueryParameter().name("cache").type("boolean"));
swagger.path("/api/{connection_name}/headers/" + resourceType.name() + "/" + newPath.stream().map(v -> "{" + v + "}").collect(joining(".")), new Path().get(operation.description(resourceType.name()).tag("db_objects").response(200, new Response().description("Ok").schema(new ArrayProperty(new RefProperty(resourceType.name())))).produces("application/json")));
}
}
// definitions
for (ResourceType resourceType : resourceTypes) {
ModelImpl model = new ModelImpl();
Map<String, String> stringStringMap = resourceType.metaData();
if (stringStringMap != null) {
Set<Entry<String, String>> entries = stringStringMap.entrySet();
for (Entry<String, String> stringStringEntry : entries) {
model.property(stringStringEntry.getKey(), new StringProperty().description(stringStringEntry.getValue()));
}
}
swagger.model(resourceType.name(), model);
}
return swagger;
}
use of io.swagger.models.properties.RefProperty in project teiid by teiid.
the class SwaggerMetadataProcessor method buildResponse.
private boolean buildResponse(final MetadataFactory mf, final Swagger swagger, final Procedure procedure, final Response resp) throws TranslatorException {
PropertyAction pa = new PropertyAction() {
@Override
public void execute(String name, String nameInSource, Property property, boolean array) {
String type = getPropertyType(property, array);
Column c = mf.addProcedureResultSetColumn(name, type, procedure);
if (!name.equalsIgnoreCase(nameInSource)) {
c.setNameInSource(nameInSource);
}
}
};
Property schema = resp.getSchema();
if (schema != null) {
if (isSimple(schema)) {
boolean array = false;
if (schema instanceof ArrayProperty) {
schema = ((ArrayProperty) schema).getItems();
array = true;
}
if (resp.getHeaders() == null || resp.getHeaders().isEmpty()) {
String type = SwaggerTypeManager.teiidType(schema.getType(), schema.getFormat(), array);
mf.addProcedureParameter("return", type, ProcedureParameter.Type.ReturnValue, procedure);
} else {
Map<String, Property> properties = new LinkedHashMap<String, Property>();
properties.put("return", schema);
walkProperties(swagger, properties, null, null, pa);
}
} else {
// since the return is always a collection unwrap the array without any issues.
if (schema instanceof ArrayProperty) {
schema = ((ArrayProperty) schema).getItems();
}
if (schema instanceof ObjectProperty) {
walkProperties(swagger, ((ObjectProperty) schema).getProperties(), null, null, pa);
} else if (schema instanceof RefProperty) {
String modelName = ((RefProperty) schema).getSimpleRef();
Model model = swagger.getDefinitions().get(modelName);
walkProperties(swagger, model.getProperties(), null, null, pa);
} else if (schema instanceof MapProperty) {
Property property = ((MapProperty) schema).getAdditionalProperties();
String type = SwaggerTypeManager.teiidType(property.getType(), property.getFormat(), false);
Column c = mf.addProcedureResultSetColumn(KEY_NAME, "string", procedure);
c.setNameInSource(KEY_NAME);
c = mf.addProcedureResultSetColumn(KEY_VALUE, type, procedure);
c.setNameInSource(KEY_VALUE);
} else {
throw new TranslatorException("File properties are not supported");
}
}
}
Map<String, Property> headers = resp.getHeaders();
if (headers != null && !headers.isEmpty()) {
walkProperties(swagger, headers, null, null, pa);
}
return procedure.getResultSet() != null;
}
use of io.swagger.models.properties.RefProperty in project teiid by teiid.
the class SwaggerMetadataProcessor method walkProperties.
private void walkProperties(final Swagger swagger, Set<Property> parents, final Map<String, Property> properties, final String namePrefix, final String nisPrefix, final PropertyAction pa) {
if (properties == null) {
return;
}
final PropertyVisitor visitor = new PropertyVisitor() {
@Override
public void visit(String name, Property property) {
pa.execute(fqn(namePrefix, name), nis(nisPrefix, name, false), property, false);
}
@Override
public void visit(String name, ArrayProperty property) {
if (isSimple(property)) {
// the array type defined in the type of the property
pa.execute(fqn(namePrefix, name), nis(nisPrefix, name, false), property.getItems(), true);
} else {
// if Object or Ref, array does not matter as return is already a resultset.
Property items = property.getItems();
parents.add(property);
if (items instanceof ObjectProperty) {
String modelName = ((ObjectProperty) items).getName();
walkProperties(swagger, parents, ((ObjectProperty) items).getProperties(), fqn(fqn(namePrefix, name), modelName), nis(nis(nisPrefix, name, true), modelName, false), pa);
} else if (items instanceof RefProperty) {
String modelName = ((RefProperty) items).getSimpleRef();
Model model = swagger.getDefinitions().get(modelName);
walkProperties(swagger, parents, model.getProperties(), fqn(fqn(namePrefix, name), modelName), nis(nis(nisPrefix, name, true), modelName, false), pa);
} else {
walkProperties(swagger, parents, properties, fqn(namePrefix, name), nis(nisPrefix, name, true), pa);
}
parents.remove(property);
}
}
@Override
public void visit(String name, FileProperty property) {
// TODO:
}
@Override
public void visit(String name, MapProperty property) {
// TODO:
}
@Override
public void visit(String name, ObjectProperty property) {
parents.add(property);
walkProperties(swagger, parents, property.getProperties(), fqn(namePrefix, name), nis(nisPrefix, name, false), pa);
parents.remove(property);
}
@Override
public void visit(String name, RefProperty property) {
parents.add(property);
Model model = swagger.getDefinitions().get(property.getSimpleRef());
walkProperties(swagger, parents, model.getProperties(), fqn(namePrefix, name), nis(nisPrefix, name, false), pa);
parents.remove(property);
}
};
for (Entry<String, Property> p : properties.entrySet()) {
if (parents.contains(p.getValue())) {
// TODO: could be an error condition
continue;
}
visitor.accept(p.getKey(), p.getValue());
}
}
use of io.swagger.models.properties.RefProperty in project endpoints-java by cloudendpoints.
the class SwaggerGenerator method convertToSwaggerProperty.
private Property convertToSwaggerProperty(Field f) {
Property p = null;
Class<? extends Property> propertyClass = FIELD_TYPE_TO_PROPERTY_CLASS_MAP.get(f.type());
if (propertyClass != null) {
try {
p = propertyClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
// cannot happen, as Property subclasses are guaranteed to have a default constructor
}
} else {
if (f.type() == FieldType.OBJECT || f.type() == FieldType.ENUM) {
p = new RefProperty(f.schemaReference().get().name());
} else if (f.type() == FieldType.ARRAY) {
p = new ArrayProperty(convertToSwaggerProperty(f.arrayItemSchema()));
}
}
if (p == null) {
throw new IllegalArgumentException("could not convert field " + f);
}
p.description(f.description());
return p;
}
Aggregations