use of io.gravitee.rest.api.service.impl.swagger.visitor.v3.OAIOperationVisitor in project gravitee-management-rest-api by gravitee-io.
the class OAIToAPIV2Converter method fill.
@Override
protected SwaggerApiEntity fill(SwaggerApiEntity apiEntity, OpenAPI oai) {
// flows
apiEntity.setGraviteeDefinitionVersion(DefinitionVersion.V2.getLabel());
if (swaggerDescriptor.isWithPolicyPaths()) {
List<Flow> allFlows = new ArrayList();
oai.getPaths().forEach((key, pathItem) -> {
String path = key.replaceAll("\\{(.[^/\\}]*)\\}", ":$1");
Map<PathItem.HttpMethod, Operation> operations = pathItem.readOperationsMap();
operations.forEach((httpMethod, operation) -> {
final Flow flow = createFlow(path, Collections.singleton(HttpMethod.valueOf(httpMethod.name())));
getVisitors().forEach((Consumer<OAIOperationVisitor>) oaiOperationVisitor -> {
Optional<Policy> policy = (Optional<Policy>) oaiOperationVisitor.visit(oai, operation);
if (policy.isPresent()) {
final Step step = new Step();
step.setName(policy.get().getName());
step.setEnabled(true);
step.setDescription(operation.getSummary() == null ? (operation.getOperationId() == null ? operation.getDescription() : operation.getOperationId()) : operation.getSummary());
step.setPolicy(policy.get().getName());
String configuration = clearNullValues(policy.get().getConfiguration());
step.setConfiguration(configuration);
String scope = getScope(configuration);
if (scope != null && scope.toLowerCase().equals("response")) {
flow.getPost().add(step);
} else {
flow.getPre().add(step);
}
}
});
allFlows.add(flow);
});
});
apiEntity.setFlows(allFlows);
if (swaggerDescriptor.isWithPathMapping() && allFlows.size() > 0) {
apiEntity.setPathMappings(allFlows.stream().map(flow -> flow.getPath()).collect(Collectors.toSet()));
}
}
final String defaultDeclaredPath = "/";
if (!swaggerDescriptor.isWithPathMapping()) {
apiEntity.setPathMappings(singleton(defaultDeclaredPath));
}
return apiEntity;
}
use of io.gravitee.rest.api.service.impl.swagger.visitor.v3.OAIOperationVisitor in project gravitee-management-rest-api by gravitee-io.
the class SwaggerService_CreateAPITest method setup.
@Before
public void setup() {
PolicyOperationVisitor swaggerPolicyOperationVisitor = mock(PolicyOperationVisitor.class);
when(swaggerPolicyOperationVisitor.getId()).thenReturn("mock");
PolicyOperationVisitor oaiPolicyOperationVisitor = mock(PolicyOperationVisitor.class);
when(oaiPolicyOperationVisitor.getId()).thenReturn("mock");
io.gravitee.policy.api.swagger.v3.OAIOperationVisitor oaiPolicyOperationVisitorImpl = mock(io.gravitee.policy.api.swagger.v3.OAIOperationVisitor.class);
when(policyOperationVisitorManager.getPolicyVisitors()).thenReturn(asList(swaggerPolicyOperationVisitor, oaiPolicyOperationVisitor));
OAIOperationVisitor op = mock(OAIPolicyOperationVisitor.class);
when(op.visit(any(), any())).thenReturn(Optional.of(new Policy()));
when(policyOperationVisitorManager.getOAIOperationVisitor(anyString())).thenReturn(op);
GroupEntity grp1 = new GroupEntity();
grp1.setId("group1");
GroupEntity grp2 = new GroupEntity();
grp2.setId("group2");
when(groupService.findByName("group1")).thenReturn(Arrays.asList(grp1));
when(groupService.findByName("group2")).thenReturn(Arrays.asList(grp2));
TagEntity tag1 = new TagEntity();
tag1.setId("tagId1");
tag1.setName("tag1");
TagEntity tag2 = new TagEntity();
tag2.setId("tagId2");
tag2.setName("tag2");
when(tagService.findByReference(any(), any())).thenReturn(Arrays.asList(tag1, tag2));
}
Aggregations