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);
});
}
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);
}
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"));
}
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());
}
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());
}
Aggregations