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