Search in sources :

Example 1 with Proto

use of io.protostuff.compiler.model.Proto in project incubator-servicecomb-java-chassis by apache.

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 2 with Proto

use of io.protostuff.compiler.model.Proto in project incubator-servicecomb-java-chassis by apache.

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)

Example 3 with Proto

use of io.protostuff.compiler.model.Proto in project incubator-servicecomb-java-chassis by apache.

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 4 with Proto

use of io.protostuff.compiler.model.Proto in project incubator-servicecomb-java-chassis by apache.

the class TestProtoParser method parse.

@Test
public void parse() throws IOException {
    URL url = Thread.currentThread().getContextClassLoader().getResource("protobufRoot.proto");
    String content = IOUtils.toString(url, StandardCharsets.UTF_8);
    ProtoParser parser = new ProtoParser();
    Proto protoFromContent = parser.parseFromContent(content);
    Proto protoFromName = parser.parse("protobufRoot.proto");
    Assert.assertNotNull(protoFromContent.getMessage("Root"));
    Assert.assertNotNull(protoFromContent.getMessage("User"));
    Assert.assertEquals(MoreObjects.toStringHelper(protoFromContent).omitNullValues().add("messages", protoFromContent.getMessages()).toString(), MoreObjects.toStringHelper(protoFromName).omitNullValues().add("messages", protoFromName.getMessages()).toString());
}
Also used : Proto(io.protostuff.compiler.model.Proto) URL(java.net.URL) Test(org.junit.Test)

Example 5 with Proto

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

the class TestProtoParser method parse.

@Test
public void parse() throws IOException {
    URL url = Thread.currentThread().getContextClassLoader().getResource("protobufRoot.proto");
    String content = IOUtils.toString(url, StandardCharsets.UTF_8);
    ProtoParser parser = new ProtoParser();
    Proto protoFromContent = parser.parseFromContent(content);
    Proto protoFromName = parser.parse("protobufRoot.proto");
    Assert.assertNotNull(protoFromContent.getMessage("Root"));
    Assert.assertNotNull(protoFromContent.getMessage("User"));
    Assert.assertEquals(MoreObjects.toStringHelper(protoFromContent).omitNullValues().add("messages", protoFromContent.getMessages()).toString(), MoreObjects.toStringHelper(protoFromName).omitNullValues().add("messages", protoFromName.getMessages()).toString());
}
Also used : Proto(io.protostuff.compiler.model.Proto) URL(java.net.URL) 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