You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for OpenAPI configuration file and schema customization.
Motivation:
Enable enhanced flexibility in OpenAPI schema generation by allowing users to provide a custom YAML/JSON configuration file for overriding and merging API specification details like metadata, servers, security, and tags.
Changes:
- Added a `schema-config` option in `GenerationOptions` to specify the OpenAPI configuration file path.
- Updated `SchemaModelBuilder` to merge generated schemas with user-provided configuration values.
- Introduced `SchemaConfigLoader` for loading and parsing configuration files.
- Enhanced `SchemaGenerator` to handle schema customization during the generation process.
- Updated documentation with examples for using the `schema-config` option.
- Added integration tests to verify the functionality of schema customization using configuration files.
- Refactored relevant classes and methods to support the new feature.
Signed-off-by: Daniel Fiala <danfiala23@gmail.com>
Copy file name to clipboardExpand all lines: vertx-grpc-docs/src/main/asciidoc/plugin.adoc
+148Lines changed: 148 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,12 +165,160 @@ By default, the plugin generates both client and service files. If you need only
165
165
- _[--]grpc-transcoding[=true/false]_: whether to generate transcoding options for methods with HTTP annotations
166
166
- _[--]vertx-codegen[=true/false]_: whether to add Vert.x annotations to the generated classes (`@VertxGen`) By default, this is disabled
167
167
- _[--]service-prefix[=Your Name]_: generate service classes with a prefix. For example, if you set it to `MyService`, the generated service class will be `MyServiceGreeterService` instead of `GreeterService`.
168
+
- _[--]schema-output-format[=openapi-json+openapi-yaml]_: generate OpenAPI specification files. Use `openapi-json` for JSON format, `openapi-yaml` for YAML format, or combine both with `+` (e.g., `openapi-json+openapi-yaml`). Not generated by default.
169
+
- _[--]schema-allow-merge[=true/false]_: when generating OpenAPI specs, merge all services into a single file (`openapi.json`/`openapi.yaml`). When set to `false`, generates separate files per service (`ServiceName-openapi.json`/`ServiceName-openapi.yaml`). Default is `true`.
170
+
- _[--]schema-config[=/path/to/config.yaml]_: path to an OpenAPI configuration file (YAML or JSON) that customizes the generated specification. The config file can override info, servers, security, tags, externalDocs, and add securitySchemes. See <<openapi-configuration-file>> for details.
168
171
169
172
* [--] This means the argument can be prefixed with `--` when used as JVM arguments, but should be used without `--` when specified in the options tag. If possible, users should use plugin options as a more universal protoc plugin approach.
170
173
* [=value] This means the argument can optionally specify a value. For boolean arguments (true/false), if no value is specified, the default is `true` when the argument is present. For string arguments like `service-prefix`, a value must be provided.
171
174
172
175
If no specific generation options are provided, both client and service files will be generated by default. By default, all extensions (currently only 'http') are supported.
173
176
177
+
=== OpenAPI Specification Generation
178
+
179
+
The plugin can generate OpenAPI 3.0 specification files from your gRPC service definitions. This is useful when using <<grpc-transcoding,gRPC transcoding>> to expose your services as REST APIs.
180
+
181
+
OpenAPI specs are generated for services that have HTTP annotations (`google.api.http`). Services and methods without HTTP annotations are skipped.
182
+
183
+
= OpenAPI specification generation
184
+
185
+
The plugin generates OpenAPI 3.0 specification files from your gRPC service definitions. This is useful when you use <<grpc-transcoding,gRPC transcoding>> to expose services as REST APIs.
186
+
187
+
The plugin only generates specs for services with HTTP annotations (`google.api.http`).
188
+
189
+
== Enabling OpenAPI generation
190
+
191
+
To start generating specs, add the `schema-output-format` option to your plugin configuration:
To generate both at once, combine them with a `+` symbol:
212
+
`schema-output-format=openapi-json+openapi-yaml`
213
+
214
+
== Merge vs split mode
215
+
216
+
By default, the plugin combines all services into a single OpenAPI file (`openapi.json` or `openapi.yaml`). If you prefer a separate file for each service, set `schema-allow-merge` to `false`.
217
+
218
+
=== Merge mode (default)
219
+
All services are bundled into one file.
220
+
221
+
[source]
222
+
----
223
+
schema-allow-merge=true
224
+
----
225
+
226
+
=== Split mode
227
+
Each service gets its own file, such as `GreeterService-openapi.json` or `AnotherService-openapi.yaml`.
228
+
229
+
[source]
230
+
----
231
+
schema-allow-merge=false
232
+
----
233
+
234
+
[[openapi-configuration-file]]
235
+
== Configuration file
236
+
237
+
You can customize the output by providing a YAML or JSON configuration file. This allows you to set or override these fields:
238
+
239
+
* `info`: API metadata like title, version, and contact info.
The plugin produces an OpenAPI spec for the `/v1/hello` endpoints, including the request and response schemas. You can find the output in the protobuf output root folder.
321
+
174
322
If you're using Gradle you need to add the plugin:
0 commit comments