use of org.apache.servicecomb.swagger.generator.SwaggerGenerator in project java-chassis by ServiceComb.
the class UnitTestSwaggerUtils method testSwagger.
public static SwaggerGenerator testSwagger(String resPath, Class<?> cls, String... methods) {
SwaggerGenerator generator = SwaggerGenerator.create(cls);
generator.replaceMethodWhiteList(methods);
generator.getSwaggerGeneratorFeature().setPackageName("gen.cse.ms.ut");
Swagger swagger = generator.generate();
String schema = pretty(swagger);
String expectSchema = loadExpect(resPath).replace("\r\n", "\n");
int offset = expectSchema.indexOf("---\nswagger: \"2.0\"");
if (offset > 0) {
expectSchema = expectSchema.substring(offset);
}
if (!Objects.equals(expectSchema, schema)) {
Assert.assertEquals(expectSchema, schema);
}
return generator;
}
use of org.apache.servicecomb.swagger.generator.SwaggerGenerator in project java-chassis by ServiceComb.
the class LocalRegistryStore method addSchemaInterface.
private void addSchemaInterface(RegistryBean bean, Microservice microservice) {
bean.getSchemaInterfaces().forEach((k, v) -> {
SwaggerGenerator generator = SwaggerGenerator.create(v);
microservice.getSchemaMap().put(k, SwaggerUtils.swaggerToString(generator.generate()));
});
}
use of org.apache.servicecomb.swagger.generator.SwaggerGenerator in project java-chassis by ServiceComb.
the class EndpointTest method should_ignore_endpoint_when_generate_swagger.
@Test
void should_ignore_endpoint_when_generate_swagger() {
SwaggerGenerator generator = SwaggerGenerator.create(TestSchema.class);
generator.getSwaggerGeneratorFeature().setExtJavaInterfaceInVendor(false).setExtJavaClassInVendor(false);
Swagger swagger = generator.generate();
assertThat(SwaggerUtils.swaggerToString(swagger)).isEqualTo("---\n" + "swagger: \"2.0\"\n" + "info:\n" + " version: \"1.0.0\"\n" + " title: \"swagger definition for org.apache.servicecomb.core.invocation.endpoint.EndpointTest$TestSchema\"\n" + "basePath: \"/TestSchema\"\n" + "consumes:\n" + "- \"application/json\"\n" + "produces:\n" + "- \"application/json\"\n" + "paths:\n" + " /say:\n" + " post:\n" + " operationId: \"say\"\n" + " parameters: []\n" + " responses:\n" + " \"200\":\n" + " description: \"response of 200\"\n");
}
use of org.apache.servicecomb.swagger.generator.SwaggerGenerator in project java-chassis by ServiceComb.
the class UnitTestSwaggerUtils method getException.
public static Throwable getException(Class<?> cls, String... methods) {
try {
SwaggerGenerator generator = SwaggerGenerator.create(cls);
generator.replaceMethodWhiteList(methods);
generator.generate();
} catch (Throwable e) {
return e;
}
// 不允许成功
Assert.assertEquals("not allowed run to here", "run to here");
return null;
}
Aggregations