use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project java-chassis by ServiceComb.
the class SwaggerEnvironment method createConsumer.
public SwaggerConsumer createConsumer(Class<?> consumerIntf, Swagger swagger) {
Map<Class<?>, ContextArgumentMapperFactory> contextFactorys = SPIServiceUtils.getOrLoadSortedService(ConsumerContextArgumentMapperFactory.class).stream().collect(Collectors.toMap(ConsumerContextArgumentMapperFactory::getContextClass, Function.identity()));
ResponseMapperFactorys<ConsumerResponseMapper> consumerResponseMapperFactorys = new ResponseMapperFactorys<>(ConsumerResponseMapperFactory.class);
SwaggerOperations swaggerOperations = new SwaggerOperations(swagger);
SwaggerConsumer consumer = new SwaggerConsumer();
consumer.setConsumerIntf(consumerIntf);
for (Method consumerMethod : MethodUtils.findSwaggerMethods(consumerIntf)) {
String operationId = findOperationId(consumerMethod);
SwaggerOperation swaggerOperation = swaggerOperations.findOperation(operationId);
if (swaggerOperation == null) {
// consumer method set is bigger than contract, it's invalid
// but we need to support consumer upgrade before producer, so only log and ignore it.
LOGGER.warn("consumer method {}:{} not exist in contract.", consumerIntf.getName(), consumerMethod.getName());
continue;
}
ConsumerArgumentsMapperCreator creator = new ConsumerArgumentsMapperCreator(Json.mapper().getSerializationConfig(), contextFactorys, consumerIntf, consumerMethod, swaggerOperation);
ArgumentsMapper argsMapper = creator.createArgumentsMapper();
ConsumerResponseMapper responseMapper = consumerResponseMapperFactorys.createResponseMapper(consumerMethod.getGenericReturnType());
SwaggerConsumerOperation op = new SwaggerConsumerOperation();
op.setConsumerClass(consumerIntf);
op.setConsumerMethod(consumerMethod);
op.setSwaggerOperation(swaggerOperation);
op.setArgumentsMapper(argsMapper);
op.setResponseMapper(responseMapper);
consumer.addOperation(op);
}
return consumer;
}
use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project incubator-servicecomb-java-chassis by apache.
the class ApiOperationProcessorTest method testConvertTags.
@Test
public void testConvertTags() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("function");
assertThat(swaggerOperation.getOperation().getTags(), containsInAnyOrder("tag1", "tag2"));
}
use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project incubator-servicecomb-java-chassis by apache.
the class ApiOperationProcessorTest method testBodyParam.
@Test
public void testBodyParam() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testBodyParam");
Map<String, Property> properties = swaggerOperation.getSwagger().getDefinitions().get("TestBodyBean").getProperties();
assertTrue("Support NotBlank annotation", properties.get("age").getRequired());
assertTrue("Support NotEmpty annotation", properties.get("sexes").getRequired());
assertTrue("Original support NotNull annotation", properties.get("name").getRequired());
}
use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project incubator-servicecomb-java-chassis by apache.
the class ApiOperationProcessorTest method testConvertTagsOnMethodWithNoTag.
@Test
public void testConvertTagsOnMethodWithNoTag() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("functionWithNoTag");
assertNull(swaggerOperation.getOperation().getTags());
}
use of org.apache.servicecomb.swagger.generator.core.model.SwaggerOperation in project incubator-servicecomb-java-chassis by apache.
the class ApiOperationProcessorTest method testMediaType.
@Test
public void testMediaType() {
SwaggerOperation swaggerOperation = swaggerOperations.findOperation("testSingleMediaType");
assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.TEXT_PLAIN));
assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.APPLICATION_XML));
swaggerOperation = swaggerOperations.findOperation("testMultiMediaType");
assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN));
assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML));
swaggerOperation = swaggerOperations.findOperation("testBlankMediaType");
assertNull(swaggerOperation.getOperation().getConsumes());
assertNull(swaggerOperation.getOperation().getProduces());
swaggerOperation.getOperation().addConsumes(MediaType.TEXT_HTML);
swaggerOperation.getOperation().addProduces(MediaType.TEXT_HTML);
assertThat(swaggerOperation.getOperation().getConsumes(), Matchers.contains(MediaType.TEXT_HTML));
assertThat(swaggerOperation.getOperation().getProduces(), Matchers.contains(MediaType.TEXT_HTML));
}
Aggregations