Search in sources :

Example 6 with Proto

use of io.protostuff.compiler.model.Proto in project java-chassis by ServiceComb.

the class TestSwaggerToProtoGenerator method convert.

@Test
public void convert() throws IOException {
    URL url = TestSwaggerToProtoGenerator.class.getClassLoader().getResource("ProtoSchema.proto");
    String protoContent = IOUtils.toString(url, "UTF-8");
    int idx = protoContent.indexOf("syntax = ");
    protoContent = protoContent.substring(idx);
    SpringmvcSwaggerGenerator swaggerGenerator = new SpringmvcSwaggerGenerator(ProtoSchema.class);
    Swagger swagger = swaggerGenerator.generate();
    SwaggerToProtoGenerator generator = new SwaggerToProtoGenerator("a.b", swagger);
    Proto proto = generator.convert();
    Assert.assertEquals(protoContent.replaceAll("\r\n", "\n"), new ProtoToStringGenerator(proto).protoToString().replaceAll("\r\n", "\n"));
}
Also used : Proto(io.protostuff.compiler.model.Proto) Swagger(io.swagger.models.Swagger) URL(java.net.URL) SpringmvcSwaggerGenerator(org.apache.servicecomb.swagger.generator.springmvc.SpringmvcSwaggerGenerator) Test(org.junit.Test)

Example 7 with Proto

use of io.protostuff.compiler.model.Proto in project java-chassis by ServiceComb.

the class ScopedProtobufSchemaManager method getOrCreateProtoMapper.

/**
 * get the ProtoMapper from Swagger
 */
public ProtoMapper getOrCreateProtoMapper(SchemaMeta schemaMeta) {
    return mapperCache.computeIfAbsent(schemaMeta.getSchemaId(), key -> {
        Swagger swagger = schemaMeta.getSwagger();
        SwaggerToProtoGenerator generator = new SwaggerToProtoGenerator(schemaMeta.getMicroserviceQualifiedName(), swagger);
        Proto proto = generator.convert();
        ProtoMapperFactory protoMapperFactory = new ProtoMapperFactory();
        return protoMapperFactory.create(proto);
    });
}
Also used : ProtoMapperFactory(org.apache.servicecomb.foundation.protobuf.ProtoMapperFactory) Proto(io.protostuff.compiler.model.Proto) SwaggerToProtoGenerator(org.apache.servicecomb.codec.protobuf.internal.converter.SwaggerToProtoGenerator) Swagger(io.swagger.models.Swagger)

Example 8 with Proto

use of io.protostuff.compiler.model.Proto in project java-chassis by ServiceComb.

the class TestProtoToStringGenerator method protoToString.

@Test
public void protoToString() {
    ProtoParser protoParser = new ProtoParser();
    Proto proto = protoParser.parseFromContent(content);
    String newContent = new ProtoToStringGenerator(proto).protoToString();
    Assert.assertEquals(content, newContent);
}
Also used : ProtoParser(org.apache.servicecomb.foundation.protobuf.internal.parser.ProtoParser) Proto(io.protostuff.compiler.model.Proto) Test(org.junit.Test)

Aggregations

Proto (io.protostuff.compiler.model.Proto)8 Test (org.junit.Test)6 Swagger (io.swagger.models.Swagger)4 URL (java.net.URL)4 SwaggerToProtoGenerator (org.apache.servicecomb.codec.protobuf.internal.converter.SwaggerToProtoGenerator)2 ProtoMapperFactory (org.apache.servicecomb.foundation.protobuf.ProtoMapperFactory)2 ProtoParser (org.apache.servicecomb.foundation.protobuf.internal.parser.ProtoParser)2 SpringmvcSwaggerGenerator (org.apache.servicecomb.swagger.generator.springmvc.SpringmvcSwaggerGenerator)2