@accility/protoc-swagger-plugin 中文文档教程
.proto to OpenApi Conversion
:warning: 这个包还处于早期阶段,接口可能会来回变化。 当足够稳定时,它将作为 v1.0 发布。
从 .proto 文件。
此软件包包括 protoc-gen-swagger 插件 来自.com/grpc-ecosystem/grpc-gateway">grpc-gateway 项目。 它还提供了 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(),
]
});
或者使用速记 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')
});
.proto to OpenApi Conversion
:warning: This package is still in early days and the interfaces might change back and forth. When stable enough it will be released as v1.0.
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')
});
更多
你可能也喜欢
- @0x/contracts-erc1155 中文文档教程
- @0x/contracts-zero-ex 中文文档教程
- @100tal-seg/seg-vue-material-template 中文文档教程
- @11ty/eleventy-plugin-vue 中文文档教程
- @4ire-labs/blot.js 中文文档教程
- @4keys/date-fns-utc-locale-es 中文文档教程
- @8base-react/utils 中文文档教程
- @a8k/ssr-koa-middleware 中文文档教程
- @aarmour/console-react-poc 中文文档教程
- @abala/arr2tree 中文文档教程