// Copyright 2025 Envoy Project Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package envoy.extensions.filters.http.grpc_json_reverse_transcoder.v3;

import "google/protobuf/wrappers.proto";

import "udpa/annotations/status.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.filters.http.grpc_json_reverse_transcoder.v3";
option java_outer_classname = "TranscoderProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/http/grpc_json_reverse_transcoder/v3;grpc_json_reverse_transcoderv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: gRPC-JSON reverse transcoder]
// gRPC-JSON reverse transcoder :ref:`configuration overview <config_http_filters_grpc_json_reverse_transcoder>`.
// [#extension: envoy.filters.http.grpc_json_reverse_transcoder]

// [#next-free-field: 7]
// ``GrpcJsonReverseTranscoder`` is the filter configuration for the gRPC JSON
// reverse transcoder. The reverse transcoder acts as a bridge between a gRPC
// client and an HTTP/JSON server, converting the gRPC request into HTTP/JSON
// for the HTTP backend and the HTTP/JSON response back to gRPC for the gRPC
// client. This effectively reverses the behavior of the
// :ref:`grpc_json_transcoder filter <config_http_filters_grpc_json_transcoder>`,
// allowing a gRPC client to communicate with an HTTP/JSON server.
message GrpcJsonReverseTranscoder {
  message PrintOptions {
    // Whether to always print primitive fields. By default primitive
    // fields with default values will be omitted in JSON output. For
    // example, an int32 field set to 0 will be omitted. Setting this flag to
    // true will override the default behavior and print primitive fields
    // regardless of their values. Defaults to false.
    bool always_print_primitive_fields = 1;

    // Whether to always print enums as ints. By default they are rendered
    // as strings. Defaults to false.
    bool always_print_enums_as_ints = 2;

    // Whether to convert the proto field names to ``json_name`` annotation value, or lower camel case,
    // in absence of ``json_name``. By default the field names will be preserved after conversion.
    // Setting this flag will convert the field names to their canonical form. Defaults to false.
    //
    // Example:
    //
    // .. code-block:: proto
    //
    //     message Author {
    //       int64 id = 1;
    //       enum Gender {
    //         UNKNOWN = 0;
    //         MALE = 1;
    //         FEMALE = 2;
    //       };
    //       Gender gender = 2;
    //       string first_name = 3;
    //       string last_name = 4 [json_name = "lname"];
    //     }
    //
    // The above proto message after being transcoded to JSON with
    // ``use_canonical_field_names`` set to ``false`` will have the
    // field names same as in the proto message, as follows:
    //
    // .. code-block:: json
    //
    //     {
    //       "id": "12345",
    //       "gender": "MALE",
    //       "first_name": "John",
    //       "last_name": "Doe"
    //     }
    //
    // and with the ``use_canonical_field_names`` set to ``true``, the
    // transcoded JSON will have ``first_name`` converted to camelCase
    // and ``last_name`` converted to its ``json_name`` annotation value,
    // as follows:
    //
    // .. code-block:: json
    //
    //     {
    //       "id": "12345",
    //       "gender": "MALE",
    //       "firstName": "John",
    //       "lname": "Doe"
    //     }
    //
    bool use_canonical_field_names = 3;
  }

  // Supplies the filename of
  // :ref:`the proto descriptor set
  // <config_grpc_json_reverse_transcoder_generate_proto_descriptor_set>` for the gRPC services.
  // If set, takes precedence over the ``descriptor_binary`` field.
  string descriptor_path = 1;

  // Supplies the binary content of
  // :ref:`the proto descriptor set
  // <config_grpc_json_reverse_transcoder_generate_proto_descriptor_set>` for the gRPC services.
  // If ``descriptor_path`` is set, this field is not used.
  bytes descriptor_binary = 2;

  // The maximum size of a request body to be transcoded, in bytes. A body exceeding this size will
  // provoke a ``gRPC status: ResourceExhausted`` response.
  //
  // Large values may cause envoy to use a lot of memory if there are many
  // concurrent requests.
  //
  // If unset, the current stream buffer size is used.
  google.protobuf.UInt32Value max_request_body_size = 3 [(validate.rules).uint32 = {gt: 0}];

  // The maximum size of a response body to be transcoded, in bytes. A body exceeding this size will
  // provoke a ``gRPC status: Internal`` response.
  //
  // Large values may cause envoy to use a lot of memory if there are many
  // concurrent requests.
  //
  // If unset, the current stream buffer size is used.
  google.protobuf.UInt32Value max_response_body_size = 4 [(validate.rules).uint32 = {gt: 0}];

  // The name of the header field that has the API version of the request.
  string api_version_header = 5;

  // Control options for upstream request JSON. These options are passed directly to
  // `JsonPrintOptions <https://developers.google.com/protocol-buffers/docs/reference/cpp/
  // google.protobuf.util.json_util#JsonPrintOptions>`_.
  PrintOptions request_json_print_options = 6;
}
