Search in sources :

Example 1 with SwaggerGenerator

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;
}
Also used : SwaggerGenerator(org.apache.servicecomb.swagger.generator.SwaggerGenerator) Swagger(io.swagger.models.Swagger)

Example 2 with SwaggerGenerator

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()));
    });
}
Also used : SwaggerGenerator(org.apache.servicecomb.swagger.generator.SwaggerGenerator)

Example 3 with SwaggerGenerator

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");
}
Also used : SwaggerGenerator(org.apache.servicecomb.swagger.generator.SwaggerGenerator) Swagger(io.swagger.models.Swagger) Test(org.junit.jupiter.api.Test)

Example 4 with SwaggerGenerator

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;
}
Also used : SwaggerGenerator(org.apache.servicecomb.swagger.generator.SwaggerGenerator)

Aggregations

SwaggerGenerator (org.apache.servicecomb.swagger.generator.SwaggerGenerator)4 Swagger (io.swagger.models.Swagger)2 Test (org.junit.jupiter.api.Test)1