.proto to OpenApi Conversion
Generate OpenAPI v2 (Swagger) files from .proto files.
This package includes the protoc-gen-swagger plugin from the grpc-gateway project. It also makes available the collection of the google common protos.
Installing
npm install -D @accility/protoc-tools
Usage
const protoc = require('@accility/protoc-tools');
const swagger = require('@accility/protoc-swagger-plugin');
const apis = require('google-proto-files');
const path = require('path');
tools.protoc({
includeDirs: [
path.resolve(apis.getProtoPath(), '..'),
path.resolve('./test/protos')
],
files: ['product.proto'],
outDir: path.resolve(__dirname, 'generated'),
outOptions: [
swagger.createSwaggerOptions({ outOptions: 'logtostderr=true' }),
tools.generators.js(),
]
});
Or with the shorthand protoc-swagger-wrapper
const swagger = require('@accility/protoc-swagger-plugin');
const path = require('path');
// The .proto-files from the package google-proto-files is automatically added
// to the include paths since we always need the REST annotations when
// converting from .proto to OpenApi.
swagger.fromProto({
includeDirs: [path.resolve('./test/protos')],
files: ['product.proto'],
outDir: path.resolve(__dirname, 'generated')
});