From 2d2177e474d6f5cad95dcaddbd06a351dd726e18 Mon Sep 17 00:00:00 2001 From: Benji Nguyen <45523555+solidiquis@users.noreply.github.com> Date: Mon, 29 Apr 2024 13:06:41 -0700 Subject: [PATCH] Auto code generation (#14) --- .../options/openapiv2.pb.go | 2 +- makefile | 11 + protos/buf.lock | 8 +- rust/src/gen/google.api.rs | 463 +++++++++ ...pc.gateway.protoc_gen_openapiv2.options.rs | 938 ++++++++++++++++++ rust/src/gen/mod.rs | 18 + scripts/gen.sh | 107 ++ 7 files changed, 1542 insertions(+), 5 deletions(-) create mode 100644 makefile create mode 100644 rust/src/gen/google.api.rs create mode 100644 rust/src/gen/grpc.gateway.protoc_gen_openapiv2.options.rs create mode 100755 scripts/gen.sh diff --git a/go/gen/protos/go/protoc-gen-openapiv2/options/openapiv2.pb.go b/go/gen/protos/go/protoc-gen-openapiv2/options/openapiv2.pb.go index a35f325f..e3dc009c 100644 --- a/go/gen/protos/go/protoc-gen-openapiv2/options/openapiv2.pb.go +++ b/go/gen/protos/go/protoc-gen-openapiv2/options/openapiv2.pb.go @@ -78,7 +78,7 @@ func (Scheme) EnumDescriptor() ([]byte, []int) { return file_protoc_gen_openapiv2_options_openapiv2_proto_rawDescGZIP(), []int{0} } -// `Type` is a a supported HTTP header type. +// `Type` is a supported HTTP header type. // See https://swagger.io/specification/v2/#parameterType. type HeaderParameter_Type int32 diff --git a/makefile b/makefile new file mode 100644 index 00000000..a38a0532 --- /dev/null +++ b/makefile @@ -0,0 +1,11 @@ +gen: + bash scripts/gen.sh + +gen-go: + bash scripts/gen.sh go + +gen-python: + bash scripts/gen.sh python + +gen-rust: + bash scripts/gen.sh rust diff --git a/protos/buf.lock b/protos/buf.lock index 4ffc27f8..2e630a3e 100644 --- a/protos/buf.lock +++ b/protos/buf.lock @@ -4,10 +4,10 @@ deps: - remote: buf.build owner: googleapis repository: googleapis - commit: 7a6bc1e3207144b38e9066861e1de0ff - digest: shake256:d646836485c34192401253703c4e7ce899c826fceec060bf4b2a62c4749bd9976dc960833e134a1f814725e1ffd60b1bb3cf0335a7e99ef0e8cec34b070ffb66 + commit: 4ed3bc159a8b4ac68fe253218760d035 + digest: shake256:7149cf5e9955c692d381e557830555d4e93f205a0f1b8e2dfdae46d029369aa3fc1980e35df0d310f7cc3b622f93e19ad276769a283a967dd3065ddfd3a40e13 - remote: buf.build owner: grpc-ecosystem repository: grpc-gateway - commit: 3f42134f4c564983838425bc43c7a65f - digest: shake256:3d11d4c0fe5e05fda0131afefbce233940e27f0c31c5d4e385686aea58ccd30f72053f61af432fa83f1fc11cda57f5f18ca3da26a29064f73c5a0d076bba8d92 + commit: ca289928665845a7b2f7285d052c739a + digest: shake256:67b115260e12cb2d6c5d5ce8dbbf3a095c86f0e52b84f9dbd16dec9433b218f8694bc9aadb1d45eb6fd52f5a7029977d460e2d58afb3208ab6c680e7b21c80e4 diff --git a/rust/src/gen/google.api.rs b/rust/src/gen/google.api.rs new file mode 100644 index 00000000..071a3cca --- /dev/null +++ b/rust/src/gen/google.api.rs @@ -0,0 +1,463 @@ +// @generated +/// Defines the HTTP configuration for an API service. It contains a list of +/// [HttpRule][google.api.HttpRule], each specifying the mapping of an RPC method +/// to one or more HTTP REST API methods. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Http { + /// A list of HTTP configuration rules that apply to individual API methods. + /// + /// **NOTE:** All service configuration rules follow "last one wins" order. + #[prost(message, repeated, tag="1")] + pub rules: ::prost::alloc::vec::Vec, + /// When set to true, URL path parameters will be fully URI-decoded except in + /// cases of single segment matches in reserved expansion, where "%2F" will be + /// left encoded. + /// + /// The default behavior is to not decode RFC 6570 reserved characters in multi + /// segment matches. + #[prost(bool, tag="2")] + pub fully_decode_reserved_expansion: bool, +} +/// # gRPC Transcoding +/// +/// gRPC Transcoding is a feature for mapping between a gRPC method and one or +/// more HTTP REST endpoints. It allows developers to build a single API service +/// that supports both gRPC APIs and REST APIs. Many systems, including [Google +/// APIs](), +/// [Cloud Endpoints](), [gRPC +/// Gateway](), +/// and [Envoy]() proxy support this feature +/// and use it for large scale production services. +/// +/// `HttpRule` defines the schema of the gRPC/REST mapping. The mapping specifies +/// how different portions of the gRPC request message are mapped to the URL +/// path, URL query parameters, and HTTP request body. It also controls how the +/// gRPC response message is mapped to the HTTP response body. `HttpRule` is +/// typically specified as an `google.api.http` annotation on the gRPC method. +/// +/// Each mapping specifies a URL path template and an HTTP method. The path +/// template may refer to one or more fields in the gRPC request message, as long +/// as each field is a non-repeated field with a primitive (non-message) type. +/// The path template controls how fields of the request message are mapped to +/// the URL path. +/// +/// Example: +/// +/// service Messaging { +/// rpc GetMessage(GetMessageRequest) returns (Message) { +/// option (google.api.http) = { +/// get: "/v1/{name=messages/*}" +/// }; +/// } +/// } +/// message GetMessageRequest { +/// string name = 1; // Mapped to URL path. +/// } +/// message Message { +/// string text = 1; // The resource content. +/// } +/// +/// This enables an HTTP REST to gRPC mapping as below: +/// +/// HTTP | gRPC +/// -----|----- +/// `GET /v1/messages/123456` | `GetMessage(name: "messages/123456")` +/// +/// Any fields in the request message which are not bound by the path template +/// automatically become HTTP query parameters if there is no HTTP request body. +/// For example: +/// +/// service Messaging { +/// rpc GetMessage(GetMessageRequest) returns (Message) { +/// option (google.api.http) = { +/// get:"/v1/messages/{message_id}" +/// }; +/// } +/// } +/// message GetMessageRequest { +/// message SubMessage { +/// string subfield = 1; +/// } +/// string message_id = 1; // Mapped to URL path. +/// int64 revision = 2; // Mapped to URL query parameter `revision`. +/// SubMessage sub = 3; // Mapped to URL query parameter `sub.subfield`. +/// } +/// +/// This enables a HTTP JSON to RPC mapping as below: +/// +/// HTTP | gRPC +/// -----|----- +/// `GET /v1/messages/123456?revision=2&sub.subfield=foo` | +/// `GetMessage(message_id: "123456" revision: 2 sub: SubMessage(subfield: +/// "foo"))` +/// +/// Note that fields which are mapped to URL query parameters must have a +/// primitive type or a repeated primitive type or a non-repeated message type. +/// In the case of a repeated type, the parameter can be repeated in the URL +/// as `...?param=A¶m=B`. In the case of a message type, each field of the +/// message is mapped to a separate parameter, such as +/// `...?foo.a=A&foo.b=B&foo.c=C`. +/// +/// For HTTP methods that allow a request body, the `body` field +/// specifies the mapping. Consider a REST update method on the +/// message resource collection: +/// +/// service Messaging { +/// rpc UpdateMessage(UpdateMessageRequest) returns (Message) { +/// option (google.api.http) = { +/// patch: "/v1/messages/{message_id}" +/// body: "message" +/// }; +/// } +/// } +/// message UpdateMessageRequest { +/// string message_id = 1; // mapped to the URL +/// Message message = 2; // mapped to the body +/// } +/// +/// The following HTTP JSON to RPC mapping is enabled, where the +/// representation of the JSON in the request body is determined by +/// protos JSON encoding: +/// +/// HTTP | gRPC +/// -----|----- +/// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +/// "123456" message { text: "Hi!" })` +/// +/// The special name `*` can be used in the body mapping to define that +/// every field not bound by the path template should be mapped to the +/// request body. This enables the following alternative definition of +/// the update method: +/// +/// service Messaging { +/// rpc UpdateMessage(Message) returns (Message) { +/// option (google.api.http) = { +/// patch: "/v1/messages/{message_id}" +/// body: "*" +/// }; +/// } +/// } +/// message Message { +/// string message_id = 1; +/// string text = 2; +/// } +/// +/// +/// The following HTTP JSON to RPC mapping is enabled: +/// +/// HTTP | gRPC +/// -----|----- +/// `PATCH /v1/messages/123456 { "text": "Hi!" }` | `UpdateMessage(message_id: +/// "123456" text: "Hi!")` +/// +/// Note that when using `*` in the body mapping, it is not possible to +/// have HTTP parameters, as all fields not bound by the path end in +/// the body. This makes this option more rarely used in practice when +/// defining REST APIs. The common usage of `*` is in custom methods +/// which don't use the URL at all for transferring data. +/// +/// It is possible to define multiple HTTP methods for one RPC by using +/// the `additional_bindings` option. Example: +/// +/// service Messaging { +/// rpc GetMessage(GetMessageRequest) returns (Message) { +/// option (google.api.http) = { +/// get: "/v1/messages/{message_id}" +/// additional_bindings { +/// get: "/v1/users/{user_id}/messages/{message_id}" +/// } +/// }; +/// } +/// } +/// message GetMessageRequest { +/// string message_id = 1; +/// string user_id = 2; +/// } +/// +/// This enables the following two alternative HTTP JSON to RPC mappings: +/// +/// HTTP | gRPC +/// -----|----- +/// `GET /v1/messages/123456` | `GetMessage(message_id: "123456")` +/// `GET /v1/users/me/messages/123456` | `GetMessage(user_id: "me" message_id: +/// "123456")` +/// +/// ## Rules for HTTP mapping +/// +/// 1. Leaf request fields (recursive expansion nested messages in the request +/// message) are classified into three categories: +/// - Fields referred by the path template. They are passed via the URL path. +/// - Fields referred by the [HttpRule.body][google.api.HttpRule.body]. They +/// are passed via the HTTP +/// request body. +/// - All other fields are passed via the URL query parameters, and the +/// parameter name is the field path in the request message. A repeated +/// field can be represented as multiple query parameters under the same +/// name. +/// 2. If [HttpRule.body][google.api.HttpRule.body] is "*", there is no URL +/// query parameter, all fields +/// are passed via URL path and HTTP request body. +/// 3. If [HttpRule.body][google.api.HttpRule.body] is omitted, there is no HTTP +/// request body, all +/// fields are passed via URL path and URL query parameters. +/// +/// ### Path template syntax +/// +/// Template = "/" Segments \[ Verb \] ; +/// Segments = Segment { "/" Segment } ; +/// Segment = "*" | "**" | LITERAL | Variable ; +/// Variable = "{" FieldPath \[ "=" Segments \] "}" ; +/// FieldPath = IDENT { "." IDENT } ; +/// Verb = ":" LITERAL ; +/// +/// The syntax `*` matches a single URL path segment. The syntax `**` matches +/// zero or more URL path segments, which must be the last part of the URL path +/// except the `Verb`. +/// +/// The syntax `Variable` matches part of the URL path as specified by its +/// template. A variable template must not contain other variables. If a variable +/// matches a single path segment, its template may be omitted, e.g. `{var}` +/// is equivalent to `{var=*}`. +/// +/// The syntax `LITERAL` matches literal text in the URL path. If the `LITERAL` +/// contains any reserved character, such characters should be percent-encoded +/// before the matching. +/// +/// If a variable contains exactly one path segment, such as `"{var}"` or +/// `"{var=*}"`, when such a variable is expanded into a URL path on the client +/// side, all characters except `\[-_.~0-9a-zA-Z\]` are percent-encoded. The +/// server side does the reverse decoding. Such variables show up in the +/// [Discovery +/// Document]() as +/// `{var}`. +/// +/// If a variable contains multiple path segments, such as `"{var=foo/*}"` +/// or `"{var=**}"`, when such a variable is expanded into a URL path on the +/// client side, all characters except `\[-_.~/0-9a-zA-Z\]` are percent-encoded. +/// The server side does the reverse decoding, except "%2F" and "%2f" are left +/// unchanged. Such variables show up in the +/// [Discovery +/// Document]() as +/// `{+var}`. +/// +/// ## Using gRPC API Service Configuration +/// +/// gRPC API Service Configuration (service config) is a configuration language +/// for configuring a gRPC service to become a user-facing product. The +/// service config is simply the YAML representation of the `google.api.Service` +/// proto message. +/// +/// As an alternative to annotating your proto file, you can configure gRPC +/// transcoding in your service config YAML files. You do this by specifying a +/// `HttpRule` that maps the gRPC method to a REST endpoint, achieving the same +/// effect as the proto annotation. This can be particularly useful if you +/// have a proto that is reused in multiple services. Note that any transcoding +/// specified in the service config will override any matching transcoding +/// configuration in the proto. +/// +/// Example: +/// +/// http: +/// rules: +/// # Selects a gRPC method and applies HttpRule to it. +/// - selector: example.v1.Messaging.GetMessage +/// get: /v1/messages/{message_id}/{sub.subfield} +/// +/// ## Special notes +/// +/// When gRPC Transcoding is used to map a gRPC to JSON REST endpoints, the +/// proto to JSON conversion must follow the [proto3 +/// specification](). +/// +/// While the single segment variable follows the semantics of +/// [RFC 6570]() Section 3.2.2 Simple String +/// Expansion, the multi segment variable **does not** follow RFC 6570 Section +/// 3.2.3 Reserved Expansion. The reason is that the Reserved Expansion +/// does not expand special characters like `?` and `#`, which would lead +/// to invalid URLs. As the result, gRPC Transcoding uses a custom encoding +/// for multi segment variables. +/// +/// The path variables **must not** refer to any repeated or mapped field, +/// because client libraries are not capable of handling such variable expansion. +/// +/// The path variables **must not** capture the leading "/" character. The reason +/// is that the most common use case "{var}" does not capture the leading "/" +/// character. For consistency, all path variables must share the same behavior. +/// +/// Repeated message fields must not be mapped to URL query parameters, because +/// no client library can support such complicated mapping. +/// +/// If an API needs to use a JSON array for request or response body, it can map +/// the request or response body to a repeated field. However, some gRPC +/// Transcoding implementations may not support this feature. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct HttpRule { + /// Selects a method to which this rule applies. + /// + /// Refer to [selector][google.api.DocumentationRule.selector] for syntax + /// details. + #[prost(string, tag="1")] + pub selector: ::prost::alloc::string::String, + /// The name of the request field whose value is mapped to the HTTP request + /// body, or `*` for mapping all request fields not captured by the path + /// pattern to the HTTP body, or omitted for not having any HTTP request body. + /// + /// NOTE: the referred field must be present at the top-level of the request + /// message type. + #[prost(string, tag="7")] + pub body: ::prost::alloc::string::String, + /// Optional. The name of the response field whose value is mapped to the HTTP + /// response body. When omitted, the entire response message will be used + /// as the HTTP response body. + /// + /// NOTE: The referred field must be present at the top-level of the response + /// message type. + #[prost(string, tag="12")] + pub response_body: ::prost::alloc::string::String, + /// Additional HTTP bindings for the selector. Nested bindings must + /// not contain an `additional_bindings` field themselves (that is, + /// the nesting may only be one level deep). + #[prost(message, repeated, tag="11")] + pub additional_bindings: ::prost::alloc::vec::Vec, + /// Determines the URL pattern is matched by this rules. This pattern can be + /// used with any of the {get|put|post|delete|patch} methods. A custom method + /// can be defined using the 'custom' field. + #[prost(oneof="http_rule::Pattern", tags="2, 3, 4, 5, 6, 8")] + pub pattern: ::core::option::Option, +} +/// Nested message and enum types in `HttpRule`. +pub mod http_rule { + /// Determines the URL pattern is matched by this rules. This pattern can be + /// used with any of the {get|put|post|delete|patch} methods. A custom method + /// can be defined using the 'custom' field. + #[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum Pattern { + /// Maps to HTTP GET. Used for listing and getting information about + /// resources. + #[prost(string, tag="2")] + Get(::prost::alloc::string::String), + /// Maps to HTTP PUT. Used for replacing a resource. + #[prost(string, tag="3")] + Put(::prost::alloc::string::String), + /// Maps to HTTP POST. Used for creating a resource or performing an action. + #[prost(string, tag="4")] + Post(::prost::alloc::string::String), + /// Maps to HTTP DELETE. Used for deleting a resource. + #[prost(string, tag="5")] + Delete(::prost::alloc::string::String), + /// Maps to HTTP PATCH. Used for updating a resource. + #[prost(string, tag="6")] + Patch(::prost::alloc::string::String), + /// The custom pattern is used for specifying an HTTP method that is not + /// included in the `pattern` field, such as HEAD, or "*" to leave the + /// HTTP method unspecified for this rule. The wild-card rule is useful + /// for services that provide content to Web (HTML) clients. + #[prost(message, tag="8")] + Custom(super::CustomHttpPattern), + } +} +/// A custom pattern is used for defining custom HTTP verb. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct CustomHttpPattern { + /// The name of this custom HTTP verb. + #[prost(string, tag="1")] + pub kind: ::prost::alloc::string::String, + /// The path matched by this custom verb. + #[prost(string, tag="2")] + pub path: ::prost::alloc::string::String, +} +/// An indicator of the behavior of a given field (for example, that a field +/// is required in requests, or given as output but ignored as input). +/// This **does not** change the behavior in protocol buffers itself; it only +/// denotes the behavior and may affect how API tooling handles the field. +/// +/// Note: This enum **may** receive new values in the future. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum FieldBehavior { + /// Conventional default for enums. Do not use this. + Unspecified = 0, + /// Specifically denotes a field as optional. + /// While all fields in protocol buffers are optional, this may be specified + /// for emphasis if appropriate. + Optional = 1, + /// Denotes a field as required. + /// This indicates that the field **must** be provided as part of the request, + /// and failure to do so will cause an error (usually `INVALID_ARGUMENT`). + Required = 2, + /// Denotes a field as output only. + /// This indicates that the field is provided in responses, but including the + /// field in a request does nothing (the server *must* ignore it and + /// *must not* throw an error as a result of the field's presence). + OutputOnly = 3, + /// Denotes a field as input only. + /// This indicates that the field is provided in requests, and the + /// corresponding field is not included in output. + InputOnly = 4, + /// Denotes a field as immutable. + /// This indicates that the field may be set once in a request to create a + /// resource, but may not be changed thereafter. + Immutable = 5, + /// Denotes that a (repeated) field is an unordered list. + /// This indicates that the service may provide the elements of the list + /// in any arbitrary order, rather than the order the user originally + /// provided. Additionally, the list's order may or may not be stable. + UnorderedList = 6, + /// Denotes that this field returns a non-empty default value if not set. + /// This indicates that if the user provides the empty value in a request, + /// a non-empty value will be returned. The user will not be aware of what + /// non-empty value to expect. + NonEmptyDefault = 7, + /// Denotes that the field in a resource (a message annotated with + /// google.api.resource) is used in the resource name to uniquely identify the + /// resource. For AIP-compliant APIs, this should only be applied to the + /// `name` field on the resource. + /// + /// This behavior should not be applied to references to other resources within + /// the message. + /// + /// The identifier field of resources often have different field behavior + /// depending on the request it is embedded in (e.g. for Create methods name + /// is optional and unused, while for Update methods it is required). Instead + /// of method-specific annotations, only `IDENTIFIER` is required. + Identifier = 8, +} +impl FieldBehavior { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + FieldBehavior::Unspecified => "FIELD_BEHAVIOR_UNSPECIFIED", + FieldBehavior::Optional => "OPTIONAL", + FieldBehavior::Required => "REQUIRED", + FieldBehavior::OutputOnly => "OUTPUT_ONLY", + FieldBehavior::InputOnly => "INPUT_ONLY", + FieldBehavior::Immutable => "IMMUTABLE", + FieldBehavior::UnorderedList => "UNORDERED_LIST", + FieldBehavior::NonEmptyDefault => "NON_EMPTY_DEFAULT", + FieldBehavior::Identifier => "IDENTIFIER", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "FIELD_BEHAVIOR_UNSPECIFIED" => Some(Self::Unspecified), + "OPTIONAL" => Some(Self::Optional), + "REQUIRED" => Some(Self::Required), + "OUTPUT_ONLY" => Some(Self::OutputOnly), + "INPUT_ONLY" => Some(Self::InputOnly), + "IMMUTABLE" => Some(Self::Immutable), + "UNORDERED_LIST" => Some(Self::UnorderedList), + "NON_EMPTY_DEFAULT" => Some(Self::NonEmptyDefault), + "IDENTIFIER" => Some(Self::Identifier), + _ => None, + } + } +} +// @@protoc_insertion_point(module) diff --git a/rust/src/gen/grpc.gateway.protoc_gen_openapiv2.options.rs b/rust/src/gen/grpc.gateway.protoc_gen_openapiv2.options.rs new file mode 100644 index 00000000..1b21e076 --- /dev/null +++ b/rust/src/gen/grpc.gateway.protoc_gen_openapiv2.options.rs @@ -0,0 +1,938 @@ +// @generated +/// `Swagger` is a representation of OpenAPI v2 specification's Swagger object. +/// +/// See: +/// +/// Example: +/// +/// option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { +/// info: { +/// title: "Echo API"; +/// version: "1.0"; +/// description: ""; +/// contact: { +/// name: "gRPC-Gateway project"; +/// url: " +/// email: "none@example.com"; +/// }; +/// license: { +/// name: "BSD 3-Clause License"; +/// url: " +/// }; +/// }; +/// schemes: HTTPS; +/// consumes: "application/json"; +/// produces: "application/json"; +/// }; +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Swagger { + /// Specifies the OpenAPI Specification version being used. It can be + /// used by the OpenAPI UI and other clients to interpret the API listing. The + /// value MUST be "2.0". + #[prost(string, tag="1")] + pub swagger: ::prost::alloc::string::String, + /// Provides metadata about the API. The metadata can be used by the + /// clients if needed. + #[prost(message, optional, tag="2")] + pub info: ::core::option::Option, + /// The host (name or ip) serving the API. This MUST be the host only and does + /// not include the scheme nor sub-paths. It MAY include a port. If the host is + /// not included, the host serving the documentation is to be used (including + /// the port). The host does not support path templating. + #[prost(string, tag="3")] + pub host: ::prost::alloc::string::String, + /// The base path on which the API is served, which is relative to the host. If + /// it is not included, the API is served directly under the host. The value + /// MUST start with a leading slash (/). The basePath does not support path + /// templating. + /// Note that using `base_path` does not change the endpoint paths that are + /// generated in the resulting OpenAPI file. If you wish to use `base_path` + /// with relatively generated OpenAPI paths, the `base_path` prefix must be + /// manually removed from your `google.api.http` paths and your code changed to + /// serve the API from the `base_path`. + #[prost(string, tag="4")] + pub base_path: ::prost::alloc::string::String, + /// The transfer protocol of the API. Values MUST be from the list: "http", + /// "https", "ws", "wss". If the schemes is not included, the default scheme to + /// be used is the one used to access the OpenAPI definition itself. + #[prost(enumeration="Scheme", repeated, tag="5")] + pub schemes: ::prost::alloc::vec::Vec, + /// A list of MIME types the APIs can consume. This is global to all APIs but + /// can be overridden on specific API calls. Value MUST be as described under + /// Mime Types. + #[prost(string, repeated, tag="6")] + pub consumes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + /// A list of MIME types the APIs can produce. This is global to all APIs but + /// can be overridden on specific API calls. Value MUST be as described under + /// Mime Types. + #[prost(string, repeated, tag="7")] + pub produces: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + /// An object to hold responses that can be used across operations. This + /// property does not define global responses for all operations. + #[prost(map="string, message", tag="10")] + pub responses: ::std::collections::HashMap<::prost::alloc::string::String, Response>, + /// Security scheme definitions that can be used across the specification. + #[prost(message, optional, tag="11")] + pub security_definitions: ::core::option::Option, + /// A declaration of which security schemes are applied for the API as a whole. + /// The list of values describes alternative security schemes that can be used + /// (that is, there is a logical OR between the security requirements). + /// Individual operations can override this definition. + #[prost(message, repeated, tag="12")] + pub security: ::prost::alloc::vec::Vec, + /// A list of tags for API documentation control. Tags can be used for logical + /// grouping of operations by resources or any other qualifier. + #[prost(message, repeated, tag="13")] + pub tags: ::prost::alloc::vec::Vec, + /// Additional external documentation. + #[prost(message, optional, tag="14")] + pub external_docs: ::core::option::Option, + /// Custom properties that start with "x-" such as "x-foo" used to describe + /// extra functionality that is not covered by the standard OpenAPI Specification. + /// See: + #[prost(map="string, message", tag="15")] + pub extensions: ::std::collections::HashMap<::prost::alloc::string::String, ::prost_types::Value>, +} +/// `Operation` is a representation of OpenAPI v2 specification's Operation object. +/// +/// See: +/// +/// Example: +/// +/// service EchoService { +/// rpc Echo(SimpleMessage) returns (SimpleMessage) { +/// option (google.api.http) = { +/// get: "/v1/example/echo/{id}" +/// }; +/// +/// option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { +/// summary: "Get a message."; +/// operation_id: "getMessage"; +/// tags: "echo"; +/// responses: { +/// key: "200" +/// value: { +/// description: "OK"; +/// } +/// } +/// }; +/// } +/// } +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Operation { + /// A list of tags for API documentation control. Tags can be used for logical + /// grouping of operations by resources or any other qualifier. + #[prost(string, repeated, tag="1")] + pub tags: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + /// A short summary of what the operation does. For maximum readability in the + /// swagger-ui, this field SHOULD be less than 120 characters. + #[prost(string, tag="2")] + pub summary: ::prost::alloc::string::String, + /// A verbose explanation of the operation behavior. GFM syntax can be used for + /// rich text representation. + #[prost(string, tag="3")] + pub description: ::prost::alloc::string::String, + /// Additional external documentation for this operation. + #[prost(message, optional, tag="4")] + pub external_docs: ::core::option::Option, + /// Unique string used to identify the operation. The id MUST be unique among + /// all operations described in the API. Tools and libraries MAY use the + /// operationId to uniquely identify an operation, therefore, it is recommended + /// to follow common programming naming conventions. + #[prost(string, tag="5")] + pub operation_id: ::prost::alloc::string::String, + /// A list of MIME types the operation can consume. This overrides the consumes + /// definition at the OpenAPI Object. An empty value MAY be used to clear the + /// global definition. Value MUST be as described under Mime Types. + #[prost(string, repeated, tag="6")] + pub consumes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + /// A list of MIME types the operation can produce. This overrides the produces + /// definition at the OpenAPI Object. An empty value MAY be used to clear the + /// global definition. Value MUST be as described under Mime Types. + #[prost(string, repeated, tag="7")] + pub produces: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + /// The list of possible responses as they are returned from executing this + /// operation. + #[prost(map="string, message", tag="9")] + pub responses: ::std::collections::HashMap<::prost::alloc::string::String, Response>, + /// The transfer protocol for the operation. Values MUST be from the list: + /// "http", "https", "ws", "wss". The value overrides the OpenAPI Object + /// schemes definition. + #[prost(enumeration="Scheme", repeated, tag="10")] + pub schemes: ::prost::alloc::vec::Vec, + /// Declares this operation to be deprecated. Usage of the declared operation + /// should be refrained. Default value is false. + #[prost(bool, tag="11")] + pub deprecated: bool, + /// A declaration of which security schemes are applied for this operation. The + /// list of values describes alternative security schemes that can be used + /// (that is, there is a logical OR between the security requirements). This + /// definition overrides any declared top-level security. To remove a top-level + /// security declaration, an empty array can be used. + #[prost(message, repeated, tag="12")] + pub security: ::prost::alloc::vec::Vec, + /// Custom properties that start with "x-" such as "x-foo" used to describe + /// extra functionality that is not covered by the standard OpenAPI Specification. + /// See: + #[prost(map="string, message", tag="13")] + pub extensions: ::std::collections::HashMap<::prost::alloc::string::String, ::prost_types::Value>, + /// Custom parameters such as HTTP request headers. + /// See: + /// and + #[prost(message, optional, tag="14")] + pub parameters: ::core::option::Option, +} +/// `Parameters` is a representation of OpenAPI v2 specification's parameters object. +/// Note: This technically breaks compatibility with the OpenAPI 2 definition structure as we only +/// allow header parameters to be set here since we do not want users specifying custom non-header +/// parameters beyond those inferred from the Protobuf schema. +/// See: +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Parameters { + /// `Headers` is one or more HTTP header parameter. + /// See: + #[prost(message, repeated, tag="1")] + pub headers: ::prost::alloc::vec::Vec, +} +/// `HeaderParameter` a HTTP header parameter. +/// See: +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct HeaderParameter { + /// `Name` is the header name. + #[prost(string, tag="1")] + pub name: ::prost::alloc::string::String, + /// `Description` is a short description of the header. + #[prost(string, tag="2")] + pub description: ::prost::alloc::string::String, + /// `Type` is the type of the object. The value MUST be one of "string", "number", "integer", or "boolean". The "array" type is not supported. + /// See: + #[prost(enumeration="header_parameter::Type", tag="3")] + pub r#type: i32, + /// `Format` The extending format for the previously mentioned type. + #[prost(string, tag="4")] + pub format: ::prost::alloc::string::String, + /// `Required` indicates if the header is optional + #[prost(bool, tag="5")] + pub required: bool, +} +/// Nested message and enum types in `HeaderParameter`. +pub mod header_parameter { + /// `Type` is a supported HTTP header type. + /// See + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] + #[repr(i32)] + pub enum Type { + Unknown = 0, + String = 1, + Number = 2, + Integer = 3, + Boolean = 4, + } + impl Type { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Type::Unknown => "UNKNOWN", + Type::String => "STRING", + Type::Number => "NUMBER", + Type::Integer => "INTEGER", + Type::Boolean => "BOOLEAN", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "UNKNOWN" => Some(Self::Unknown), + "STRING" => Some(Self::String), + "NUMBER" => Some(Self::Number), + "INTEGER" => Some(Self::Integer), + "BOOLEAN" => Some(Self::Boolean), + _ => None, + } + } + } +} +/// `Header` is a representation of OpenAPI v2 specification's Header object. +/// +/// See: +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Header { + /// `Description` is a short description of the header. + #[prost(string, tag="1")] + pub description: ::prost::alloc::string::String, + /// The type of the object. The value MUST be one of "string", "number", "integer", or "boolean". The "array" type is not supported. + #[prost(string, tag="2")] + pub r#type: ::prost::alloc::string::String, + /// `Format` The extending format for the previously mentioned type. + #[prost(string, tag="3")] + pub format: ::prost::alloc::string::String, + /// `Default` Declares the value of the header that the server will use if none is provided. + /// See: + /// Unlike JSON Schema this value MUST conform to the defined type for the header. + #[prost(string, tag="6")] + pub default: ::prost::alloc::string::String, + /// 'Pattern' See + #[prost(string, tag="13")] + pub pattern: ::prost::alloc::string::String, +} +/// `Response` is a representation of OpenAPI v2 specification's Response object. +/// +/// See: +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Response { + /// `Description` is a short description of the response. + /// GFM syntax can be used for rich text representation. + #[prost(string, tag="1")] + pub description: ::prost::alloc::string::String, + /// `Schema` optionally defines the structure of the response. + /// If `Schema` is not provided, it means there is no content to the response. + #[prost(message, optional, tag="2")] + pub schema: ::core::option::Option, + /// `Headers` A list of headers that are sent with the response. + /// `Header` name is expected to be a string in the canonical format of the MIME header key + /// See: + #[prost(map="string, message", tag="3")] + pub headers: ::std::collections::HashMap<::prost::alloc::string::String, Header>, + /// `Examples` gives per-mimetype response examples. + /// See: + #[prost(map="string, string", tag="4")] + pub examples: ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, + /// Custom properties that start with "x-" such as "x-foo" used to describe + /// extra functionality that is not covered by the standard OpenAPI Specification. + /// See: + #[prost(map="string, message", tag="5")] + pub extensions: ::std::collections::HashMap<::prost::alloc::string::String, ::prost_types::Value>, +} +/// `Info` is a representation of OpenAPI v2 specification's Info object. +/// +/// See: +/// +/// Example: +/// +/// option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { +/// info: { +/// title: "Echo API"; +/// version: "1.0"; +/// description: ""; +/// contact: { +/// name: "gRPC-Gateway project"; +/// url: " +/// email: "none@example.com"; +/// }; +/// license: { +/// name: "BSD 3-Clause License"; +/// url: " +/// }; +/// }; +/// ... +/// }; +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Info { + /// The title of the application. + #[prost(string, tag="1")] + pub title: ::prost::alloc::string::String, + /// A short description of the application. GFM syntax can be used for rich + /// text representation. + #[prost(string, tag="2")] + pub description: ::prost::alloc::string::String, + /// The Terms of Service for the API. + #[prost(string, tag="3")] + pub terms_of_service: ::prost::alloc::string::String, + /// The contact information for the exposed API. + #[prost(message, optional, tag="4")] + pub contact: ::core::option::Option, + /// The license information for the exposed API. + #[prost(message, optional, tag="5")] + pub license: ::core::option::Option, + /// Provides the version of the application API (not to be confused + /// with the specification version). + #[prost(string, tag="6")] + pub version: ::prost::alloc::string::String, + /// Custom properties that start with "x-" such as "x-foo" used to describe + /// extra functionality that is not covered by the standard OpenAPI Specification. + /// See: + #[prost(map="string, message", tag="7")] + pub extensions: ::std::collections::HashMap<::prost::alloc::string::String, ::prost_types::Value>, +} +/// `Contact` is a representation of OpenAPI v2 specification's Contact object. +/// +/// See: +/// +/// Example: +/// +/// option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { +/// info: { +/// ... +/// contact: { +/// name: "gRPC-Gateway project"; +/// url: " +/// email: "none@example.com"; +/// }; +/// ... +/// }; +/// ... +/// }; +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Contact { + /// The identifying name of the contact person/organization. + #[prost(string, tag="1")] + pub name: ::prost::alloc::string::String, + /// The URL pointing to the contact information. MUST be in the format of a + /// URL. + #[prost(string, tag="2")] + pub url: ::prost::alloc::string::String, + /// The email address of the contact person/organization. MUST be in the format + /// of an email address. + #[prost(string, tag="3")] + pub email: ::prost::alloc::string::String, +} +/// `License` is a representation of OpenAPI v2 specification's License object. +/// +/// See: +/// +/// Example: +/// +/// option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { +/// info: { +/// ... +/// license: { +/// name: "BSD 3-Clause License"; +/// url: " +/// }; +/// ... +/// }; +/// ... +/// }; +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct License { + /// The license name used for the API. + #[prost(string, tag="1")] + pub name: ::prost::alloc::string::String, + /// A URL to the license used for the API. MUST be in the format of a URL. + #[prost(string, tag="2")] + pub url: ::prost::alloc::string::String, +} +/// `ExternalDocumentation` is a representation of OpenAPI v2 specification's +/// ExternalDocumentation object. +/// +/// See: +/// +/// Example: +/// +/// option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_swagger) = { +/// ... +/// external_docs: { +/// description: "More about gRPC-Gateway"; +/// url: " +/// } +/// ... +/// }; +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ExternalDocumentation { + /// A short description of the target documentation. GFM syntax can be used for + /// rich text representation. + #[prost(string, tag="1")] + pub description: ::prost::alloc::string::String, + /// The URL for the target documentation. Value MUST be in the format + /// of a URL. + #[prost(string, tag="2")] + pub url: ::prost::alloc::string::String, +} +/// `Schema` is a representation of OpenAPI v2 specification's Schema object. +/// +/// See: +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Schema { + #[prost(message, optional, tag="1")] + pub json_schema: ::core::option::Option, + /// Adds support for polymorphism. The discriminator is the schema property + /// name that is used to differentiate between other schema that inherit this + /// schema. The property name used MUST be defined at this schema and it MUST + /// be in the required property list. When used, the value MUST be the name of + /// this schema or any schema that inherits it. + #[prost(string, tag="2")] + pub discriminator: ::prost::alloc::string::String, + /// Relevant only for Schema "properties" definitions. Declares the property as + /// "read only". This means that it MAY be sent as part of a response but MUST + /// NOT be sent as part of the request. Properties marked as readOnly being + /// true SHOULD NOT be in the required list of the defined schema. Default + /// value is false. + #[prost(bool, tag="3")] + pub read_only: bool, + /// Additional external documentation for this schema. + #[prost(message, optional, tag="5")] + pub external_docs: ::core::option::Option, + /// A free-form property to include an example of an instance for this schema in JSON. + /// This is copied verbatim to the output. + #[prost(string, tag="6")] + pub example: ::prost::alloc::string::String, +} +/// `JSONSchema` represents properties from JSON Schema taken, and as used, in +/// the OpenAPI v2 spec. +/// +/// This includes changes made by OpenAPI v2. +/// +/// See: +/// +/// See also: +/// +/// +/// Example: +/// +/// message SimpleMessage { +/// option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_schema) = { +/// json_schema: { +/// title: "SimpleMessage" +/// description: "A simple message." +/// required: \["id"\] +/// } +/// }; +/// +/// // Id represents the message identifier. +/// string id = 1; [ +/// (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_field) = { +/// description: "The unique identifier of the simple message." +/// }]; +/// } +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct JsonSchema { + /// Ref is used to define an external reference to include in the message. + /// This could be a fully qualified proto message reference, and that type must + /// be imported into the protofile. If no message is identified, the Ref will + /// be used verbatim in the output. + /// For example: + /// `ref: ".google.protobuf.Timestamp"`. + #[prost(string, tag="3")] + pub r#ref: ::prost::alloc::string::String, + /// The title of the schema. + #[prost(string, tag="5")] + pub title: ::prost::alloc::string::String, + /// A short description of the schema. + #[prost(string, tag="6")] + pub description: ::prost::alloc::string::String, + #[prost(string, tag="7")] + pub default: ::prost::alloc::string::String, + #[prost(bool, tag="8")] + pub read_only: bool, + /// A free-form property to include a JSON example of this field. This is copied + /// verbatim to the output swagger.json. Quotes must be escaped. + /// This property is the same for 2.0 and 3.0.0 + #[prost(string, tag="9")] + pub example: ::prost::alloc::string::String, + #[prost(double, tag="10")] + pub multiple_of: f64, + /// Maximum represents an inclusive upper limit for a numeric instance. The + /// value of MUST be a number, + #[prost(double, tag="11")] + pub maximum: f64, + #[prost(bool, tag="12")] + pub exclusive_maximum: bool, + /// minimum represents an inclusive lower limit for a numeric instance. The + /// value of MUST be a number, + #[prost(double, tag="13")] + pub minimum: f64, + #[prost(bool, tag="14")] + pub exclusive_minimum: bool, + #[prost(uint64, tag="15")] + pub max_length: u64, + #[prost(uint64, tag="16")] + pub min_length: u64, + #[prost(string, tag="17")] + pub pattern: ::prost::alloc::string::String, + #[prost(uint64, tag="20")] + pub max_items: u64, + #[prost(uint64, tag="21")] + pub min_items: u64, + #[prost(bool, tag="22")] + pub unique_items: bool, + #[prost(uint64, tag="24")] + pub max_properties: u64, + #[prost(uint64, tag="25")] + pub min_properties: u64, + #[prost(string, repeated, tag="26")] + pub required: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + /// Items in 'array' must be unique. + #[prost(string, repeated, tag="34")] + pub array: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + #[prost(enumeration="json_schema::JsonSchemaSimpleTypes", repeated, tag="35")] + pub r#type: ::prost::alloc::vec::Vec, + /// `Format` + #[prost(string, tag="36")] + pub format: ::prost::alloc::string::String, + /// Items in `enum` must be unique + #[prost(string, repeated, tag="46")] + pub r#enum: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + /// Additional field level properties used when generating the OpenAPI v2 file. + #[prost(message, optional, tag="1001")] + pub field_configuration: ::core::option::Option, + /// Custom properties that start with "x-" such as "x-foo" used to describe + /// extra functionality that is not covered by the standard OpenAPI Specification. + /// See: + #[prost(map="string, message", tag="48")] + pub extensions: ::std::collections::HashMap<::prost::alloc::string::String, ::prost_types::Value>, +} +/// Nested message and enum types in `JSONSchema`. +pub mod json_schema { + /// 'FieldConfiguration' provides additional field level properties used when generating the OpenAPI v2 file. + /// These properties are not defined by OpenAPIv2, but they are used to control the generation. + #[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] + pub struct FieldConfiguration { + /// Alternative parameter name when used as path parameter. If set, this will + /// be used as the complete parameter name when this field is used as a path + /// parameter. Use this to avoid having auto generated path parameter names + /// for overlapping paths. + #[prost(string, tag="47")] + pub path_param_name: ::prost::alloc::string::String, + } + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] + #[repr(i32)] + pub enum JsonSchemaSimpleTypes { + Unknown = 0, + Array = 1, + Boolean = 2, + Integer = 3, + Null = 4, + Number = 5, + Object = 6, + String = 7, + } + impl JsonSchemaSimpleTypes { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + JsonSchemaSimpleTypes::Unknown => "UNKNOWN", + JsonSchemaSimpleTypes::Array => "ARRAY", + JsonSchemaSimpleTypes::Boolean => "BOOLEAN", + JsonSchemaSimpleTypes::Integer => "INTEGER", + JsonSchemaSimpleTypes::Null => "NULL", + JsonSchemaSimpleTypes::Number => "NUMBER", + JsonSchemaSimpleTypes::Object => "OBJECT", + JsonSchemaSimpleTypes::String => "STRING", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "UNKNOWN" => Some(Self::Unknown), + "ARRAY" => Some(Self::Array), + "BOOLEAN" => Some(Self::Boolean), + "INTEGER" => Some(Self::Integer), + "NULL" => Some(Self::Null), + "NUMBER" => Some(Self::Number), + "OBJECT" => Some(Self::Object), + "STRING" => Some(Self::String), + _ => None, + } + } + } +} +/// `Tag` is a representation of OpenAPI v2 specification's Tag object. +/// +/// See: +/// +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Tag { + /// The name of the tag. Use it to allow override of the name of a + /// global Tag object, then use that name to reference the tag throughout the + /// OpenAPI file. + #[prost(string, tag="1")] + pub name: ::prost::alloc::string::String, + /// A short description for the tag. GFM syntax can be used for rich text + /// representation. + #[prost(string, tag="2")] + pub description: ::prost::alloc::string::String, + /// Additional external documentation for this tag. + #[prost(message, optional, tag="3")] + pub external_docs: ::core::option::Option, + /// Custom properties that start with "x-" such as "x-foo" used to describe + /// extra functionality that is not covered by the standard OpenAPI Specification. + /// See: + #[prost(map="string, message", tag="4")] + pub extensions: ::std::collections::HashMap<::prost::alloc::string::String, ::prost_types::Value>, +} +/// `SecurityDefinitions` is a representation of OpenAPI v2 specification's +/// Security Definitions object. +/// +/// See: +/// +/// A declaration of the security schemes available to be used in the +/// specification. This does not enforce the security schemes on the operations +/// and only serves to provide the relevant details for each scheme. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct SecurityDefinitions { + /// A single security scheme definition, mapping a "name" to the scheme it + /// defines. + #[prost(map="string, message", tag="1")] + pub security: ::std::collections::HashMap<::prost::alloc::string::String, SecurityScheme>, +} +/// `SecurityScheme` is a representation of OpenAPI v2 specification's +/// Security Scheme object. +/// +/// See: +/// +/// Allows the definition of a security scheme that can be used by the +/// operations. Supported schemes are basic authentication, an API key (either as +/// a header or as a query parameter) and OAuth2's common flows (implicit, +/// password, application and access code). +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct SecurityScheme { + /// The type of the security scheme. Valid values are "basic", + /// "apiKey" or "oauth2". + #[prost(enumeration="security_scheme::Type", tag="1")] + pub r#type: i32, + /// A short description for security scheme. + #[prost(string, tag="2")] + pub description: ::prost::alloc::string::String, + /// The name of the header or query parameter to be used. + /// Valid for apiKey. + #[prost(string, tag="3")] + pub name: ::prost::alloc::string::String, + /// The location of the API key. Valid values are "query" or + /// "header". + /// Valid for apiKey. + #[prost(enumeration="security_scheme::In", tag="4")] + pub r#in: i32, + /// The flow used by the OAuth2 security scheme. Valid values are + /// "implicit", "password", "application" or "accessCode". + /// Valid for oauth2. + #[prost(enumeration="security_scheme::Flow", tag="5")] + pub flow: i32, + /// The authorization URL to be used for this flow. This SHOULD be in + /// the form of a URL. + /// Valid for oauth2/implicit and oauth2/accessCode. + #[prost(string, tag="6")] + pub authorization_url: ::prost::alloc::string::String, + /// The token URL to be used for this flow. This SHOULD be in the + /// form of a URL. + /// Valid for oauth2/password, oauth2/application and oauth2/accessCode. + #[prost(string, tag="7")] + pub token_url: ::prost::alloc::string::String, + /// The available scopes for the OAuth2 security scheme. + /// Valid for oauth2. + #[prost(message, optional, tag="8")] + pub scopes: ::core::option::Option, + /// Custom properties that start with "x-" such as "x-foo" used to describe + /// extra functionality that is not covered by the standard OpenAPI Specification. + /// See: + #[prost(map="string, message", tag="9")] + pub extensions: ::std::collections::HashMap<::prost::alloc::string::String, ::prost_types::Value>, +} +/// Nested message and enum types in `SecurityScheme`. +pub mod security_scheme { + /// The type of the security scheme. Valid values are "basic", + /// "apiKey" or "oauth2". + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] + #[repr(i32)] + pub enum Type { + Invalid = 0, + Basic = 1, + ApiKey = 2, + Oauth2 = 3, + } + impl Type { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Type::Invalid => "TYPE_INVALID", + Type::Basic => "TYPE_BASIC", + Type::ApiKey => "TYPE_API_KEY", + Type::Oauth2 => "TYPE_OAUTH2", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "TYPE_INVALID" => Some(Self::Invalid), + "TYPE_BASIC" => Some(Self::Basic), + "TYPE_API_KEY" => Some(Self::ApiKey), + "TYPE_OAUTH2" => Some(Self::Oauth2), + _ => None, + } + } + } + /// The location of the API key. Valid values are "query" or "header". + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] + #[repr(i32)] + pub enum In { + Invalid = 0, + Query = 1, + Header = 2, + } + impl In { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + In::Invalid => "IN_INVALID", + In::Query => "IN_QUERY", + In::Header => "IN_HEADER", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "IN_INVALID" => Some(Self::Invalid), + "IN_QUERY" => Some(Self::Query), + "IN_HEADER" => Some(Self::Header), + _ => None, + } + } + } + /// The flow used by the OAuth2 security scheme. Valid values are + /// "implicit", "password", "application" or "accessCode". + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] + #[repr(i32)] + pub enum Flow { + Invalid = 0, + Implicit = 1, + Password = 2, + Application = 3, + AccessCode = 4, + } + impl Flow { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Flow::Invalid => "FLOW_INVALID", + Flow::Implicit => "FLOW_IMPLICIT", + Flow::Password => "FLOW_PASSWORD", + Flow::Application => "FLOW_APPLICATION", + Flow::AccessCode => "FLOW_ACCESS_CODE", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "FLOW_INVALID" => Some(Self::Invalid), + "FLOW_IMPLICIT" => Some(Self::Implicit), + "FLOW_PASSWORD" => Some(Self::Password), + "FLOW_APPLICATION" => Some(Self::Application), + "FLOW_ACCESS_CODE" => Some(Self::AccessCode), + _ => None, + } + } + } +} +/// `SecurityRequirement` is a representation of OpenAPI v2 specification's +/// Security Requirement object. +/// +/// See: +/// +/// Lists the required security schemes to execute this operation. The object can +/// have multiple security schemes declared in it which are all required (that +/// is, there is a logical AND between the schemes). +/// +/// The name used for each property MUST correspond to a security scheme +/// declared in the Security Definitions. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct SecurityRequirement { + /// Each name must correspond to a security scheme which is declared in + /// the Security Definitions. If the security scheme is of type "oauth2", + /// then the value is a list of scope names required for the execution. + /// For other security scheme types, the array MUST be empty. + #[prost(map="string, message", tag="1")] + pub security_requirement: ::std::collections::HashMap<::prost::alloc::string::String, security_requirement::SecurityRequirementValue>, +} +/// Nested message and enum types in `SecurityRequirement`. +pub mod security_requirement { + /// If the security scheme is of type "oauth2", then the value is a list of + /// scope names required for the execution. For other security scheme types, + /// the array MUST be empty. + #[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] + pub struct SecurityRequirementValue { + #[prost(string, repeated, tag="1")] + pub scope: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, + } +} +/// `Scopes` is a representation of OpenAPI v2 specification's Scopes object. +/// +/// See: +/// +/// Lists the available scopes for an OAuth2 security scheme. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Scopes { + /// Maps between a name of a scope to a short description of it (as the value + /// of the property). + #[prost(map="string, string", tag="1")] + pub scope: ::std::collections::HashMap<::prost::alloc::string::String, ::prost::alloc::string::String>, +} +/// Scheme describes the schemes supported by the OpenAPI Swagger +/// and Operation objects. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum Scheme { + Unknown = 0, + Http = 1, + Https = 2, + Ws = 3, + Wss = 4, +} +impl Scheme { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + Scheme::Unknown => "UNKNOWN", + Scheme::Http => "HTTP", + Scheme::Https => "HTTPS", + Scheme::Ws => "WS", + Scheme::Wss => "WSS", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "UNKNOWN" => Some(Self::Unknown), + "HTTP" => Some(Self::Http), + "HTTPS" => Some(Self::Https), + "WS" => Some(Self::Ws), + "WSS" => Some(Self::Wss), + _ => None, + } + } +} +// @@protoc_insertion_point(module) diff --git a/rust/src/gen/mod.rs b/rust/src/gen/mod.rs index 06934352..ad88bcfa 100644 --- a/rust/src/gen/mod.rs +++ b/rust/src/gen/mod.rs @@ -1,4 +1,22 @@ // @generated +pub mod google { + // @@protoc_insertion_point(attribute:google.api) + pub mod api { + include!("google.api.rs"); + // @@protoc_insertion_point(google.api) + } +} +pub mod grpc { + pub mod gateway { + pub mod protoc_gen_openapiv2 { + // @@protoc_insertion_point(attribute:grpc.gateway.protoc_gen_openapiv2.options) + pub mod options { + include!("grpc.gateway.protoc_gen_openapiv2.options.rs"); + // @@protoc_insertion_point(grpc.gateway.protoc_gen_openapiv2.options) + } + } + } +} pub mod sift { pub mod annotation_logs { // @@protoc_insertion_point(attribute:sift.annotation_logs.v1) diff --git a/scripts/gen.sh b/scripts/gen.sh new file mode 100755 index 00000000..30abfe71 --- /dev/null +++ b/scripts/gen.sh @@ -0,0 +1,107 @@ +#!/usr/bin/env bash + +cleanup() { + printf "\x1b[?25h" + if [[ -d ./tmp ]]; then + rm -rf "$TMP_DIR" + fi +} + +trap cleanup EXIT INT + +SUPPORTED_LANGS=(go python rust) +TMP_DIR="tmp" +BUF_CONF="protos/buf.yaml" +OUTPUT_PROTOS="${TMP_DIR}/protos" +PYTHON_GEN_DIR="python/gen" + +USAGE=$(cat<... The languages to generate code for; generates code for all languages if omitted + +Options: + -h, --help Print help +EOT) + +for arg in ${@}; do + if [[ "$arg" == "-h" || "$arg" == "--help" ]]; then + echo "$USAGE" + exit 0 + fi +done + +err_and_exit() { + echo "$1" >&2 + exit 1 +} + +gen_python_modules() { + if [[ ! -d "$PYTHON_GEN_DIR" ]]; then + err_and_exit "The '$PYTHON_GEN_DIR' directory could not be located. Failed to generate python modules." + fi + + printf "Generating python modules... " + for dir in $(find "$PYTHON_GEN_DIR" -type d); do + local init_py="$dir/__init__.py" + + if [[ ! -f "$init_py" ]]; then + touch "$init_py" + fi + done + echo "ok" +} + +gen_protos() { + printf "\x1b[?25l" + mkdir "$TMP_DIR" + buf mod update protos + buf export protos --output="$OUTPUT_PROTOS" --config="$BUF_CONF" + + local langs=( "${@}" ) + + if (( ${#langs[@]} == 0 )); then + langs=( "${SUPPORTED_LANGS[@]}" ) + fi + + python_gen=false + + for lang in ${langs[@]}; do + printf "Compiling protocol buffers for $lang... " + buf generate "$OUTPUT_PROTOS" --template "$lang/buf.gen.yaml" --output "$lang" + echo "ok" + + if [[ "$lang" == "python" ]]; then + python_gen=true + fi + done + + if [[ "$python_gen" == true ]]; then + gen_python_modules + fi +} + +if [[ ! -f $(which buf) ]]; then + err_and_exit "Missing 'buf' command. Make sure it is installed and in the path." +fi + +if [[ ! -d protos ]]; then + err_and_exit "Missing 'protos' directory in root of project." +fi + +if [[ ! -f "protos/buf.yaml" ]]; then + err_and_exit "Missing 'buf.yaml' in 'protos' directory." +fi + +for lang in ${SUPPORTED_LANGS[@]}; do + if [[ ! -d "$lang" ]]; then + err_and_exit "Missing '$lang' directory in root of project." + fi +done + +gen_protos ${@}