use of io.swagger.models.Operation in project swagger-core by swagger-api.
the class SpecFilter method filterOperation.
public Operation filterOperation(SwaggerSpecFilter filter, Operation op, ApiDescription api, Map<String, List<String>> params, Map<String, String> cookies, Map<String, List<String>> headers) {
Operation clonedOperation = new Operation().summary(op.getSummary()).description(op.getDescription()).operationId(op.getOperationId()).schemes(op.getSchemes()).consumes(op.getConsumes()).produces(op.getProduces()).tags(op.getTags()).externalDocs(op.getExternalDocs()).vendorExtensions(op.getVendorExtensions()).deprecated(op.isDeprecated());
List<Parameter> clonedParams = new ArrayList<Parameter>();
if (op.getParameters() != null) {
for (Parameter param : op.getParameters()) {
if (filter.isParamAllowed(param, op, api, params, cookies, headers)) {
clonedParams.add(param);
}
}
}
clonedOperation.setParameters(clonedParams);
clonedOperation.setSecurity(op.getSecurity());
clonedOperation.setResponses(op.getResponses());
return clonedOperation;
}
use of io.swagger.models.Operation in project swagger-core by swagger-api.
the class ReaderTest method readerTest1.
@Test
public void readerTest1() {
final Swagger swagger = new Swagger();
Reader.read(swagger, Collections.<Class<?>>singleton(ResourceWithAnnotations.class));
Assert.assertNotNull(swagger);
final Info info = swagger.getInfo();
Assert.assertNotNull(info);
Assert.assertEquals(info.getTitle(), "Test title");
Assert.assertEquals(info.getDescription(), "Test description");
Assert.assertEquals(info.getVersion(), "1.0.0");
Assert.assertEquals(info.getTermsOfService(), "link_to_terms");
Assert.assertEquals(info.getContact().getName(), "Author");
Assert.assertEquals(info.getContact().getEmail(), "author@mail");
Assert.assertEquals(info.getContact().getUrl(), "site");
Assert.assertEquals(info.getLicense().getName(), "License");
Assert.assertEquals(info.getLicense().getUrl(), "license_url");
Assert.assertEquals(info.getVendorExtensions().get("x-ext1_prop1"), "ext1_val1");
Assert.assertEquals(info.getVendorExtensions().get("x-ext1_prop2"), "x-ext1_val2");
Assert.assertEquals(swagger.getHost(), "host");
Assert.assertEquals(swagger.getBasePath(), "/api");
Assert.assertNotNull(swagger.getPath("/resources/testMethod3"));
Assert.assertNotNull(swagger.getDefinitions().get("SampleData"));
Assert.assertEquals(swagger.getExternalDocs().getDescription(), "docs");
Assert.assertEquals(swagger.getExternalDocs().getUrl(), "url_to_docs");
Path path = swagger.getPath("/resources/testMethod3");
Assert.assertNotNull(path);
Operation get = path.getGet();
Assert.assertNotNull(get);
Assert.assertEquals("value", get.getVendorExtensions().get("x-name"));
}
use of io.swagger.models.Operation in project swagger-core by swagger-api.
the class Reader method read.
private void read(ReaderContext context) {
final SwaggerDefinition swaggerDefinition = context.getCls().getAnnotation(SwaggerDefinition.class);
if (swaggerDefinition != null) {
readSwaggerConfig(swaggerDefinition);
}
for (Method method : context.getCls().getMethods()) {
if (ReflectionUtils.isOverriddenMethod(method, context.getCls())) {
continue;
}
final Operation operation = new Operation();
String operationPath = null;
String httpMethod = null;
final Type[] genericParameterTypes = method.getGenericParameterTypes();
final Annotation[][] paramAnnotations = method.getParameterAnnotations();
for (ReaderExtension extension : ReaderExtensions.getExtensions()) {
if (operationPath == null) {
operationPath = extension.getPath(context, method);
}
if (httpMethod == null) {
httpMethod = extension.getHttpMethod(context, method);
}
if (operationPath == null || httpMethod == null) {
continue;
}
if (extension.isReadable(context)) {
extension.setDeprecated(operation, method);
extension.applyConsumes(context, operation, method);
extension.applyProduces(context, operation, method);
extension.applyOperationId(operation, method);
extension.applySummary(operation, method);
extension.applyDescription(operation, method);
extension.applySchemes(context, operation, method);
extension.applySecurityRequirements(context, operation, method);
extension.applyTags(context, operation, method);
extension.applyResponses(context, operation, method);
extension.applyImplicitParameters(context, operation, method);
extension.applyExtensions(context, operation, method);
for (int i = 0; i < genericParameterTypes.length; i++) {
extension.applyParameters(context, operation, genericParameterTypes[i], paramAnnotations[i]);
}
}
}
if (httpMethod != null) {
if (operation.getResponses() == null) {
operation.defaultResponse(new Response().description("successful operation"));
}
final Map<String, String> regexMap = new HashMap<String, String>();
final String parsedPath = PathUtils.parsePath(operationPath, regexMap);
Path path = swagger.getPath(parsedPath);
if (path == null) {
path = new Path();
swagger.path(parsedPath, path);
}
path.set(httpMethod.toLowerCase(), operation);
}
}
}
use of io.swagger.models.Operation in project swagger-core by swagger-api.
the class ConsumesProducesTest method applyConsumesProducesTest1.
@Test(dataProvider = "resourceWithAnnotations")
public void applyConsumesProducesTest1(String methodName, List<String> expected) throws NoSuchMethodException {
final Operation operation = new Operation();
final ReaderContext context = createDefaultContext();
final Method method = findMethod(context, methodName);
extension.applyConsumes(context, operation, method);
extension.applyProduces(context, operation, method);
Assert.assertEquals(operation.getConsumes(), expected);
Assert.assertEquals(operation.getProduces(), expected);
}
use of io.swagger.models.Operation in project swagger-core by swagger-api.
the class DeprecatedMethodTest method setDeprecatedTest.
@Test(dataProvider = "resources")
public void setDeprecatedTest(String methodName, Boolean expected) throws NoSuchMethodException {
final Operation operation = new Operation();
extension.setDeprecated(operation, ResourceWithAnnotations.class.getMethod(methodName));
Assert.assertEquals(operation.isDeprecated(), expected);
}
Aggregations