Class: Gapic::Schema::Field

Inherits:
Proto
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/gapic/schema/wrappers.rb

Overview

Wrapper for a protobuf Field.

Constant Summary collapse

OPTION_EXTENSION_NAMES =
{
  "google.api.field_behavior" => [1052, :enum, :repeated],
  "google.api.resource_reference" => [1055, ::Google::Api::ResourceReference],
  "google.cloud.operation_field" => [1149, :enum],
  "google.cloud.operation_request_field" => [1150, :string],
  "google.cloud.operation_response_field" => [1151, :string]
}.freeze

Instance Attribute Summary collapse

Attributes inherited from Proto

#address, #descriptor, #docs, #parent

Instance Method Summary collapse

Methods inherited from Proto

#containing_api, #containing_file, #leading_comments, #leading_detached_comments, #option_named, #path, #span, #trailing_comments

Constructor Details

#initialize(descriptor, address, docs, message, enum) ⇒ Field

Initializes a message object.

Parameters:

  • descriptor (Google::Protobuf::FieldDescriptorProto)

    the protobuf representation of this service.

  • address (Enumerable<String>)

    The address of the proto. See

    address for more info.

  • docs (Google::Protobuf::SourceCodeInfo::Location)

    The docs of the proto. See #docs for more info.

  • message (Message | nil)

    The message if the field is a message, nil otherwise.

  • enum (Enum | nil)

    The enum if the field is an enum, nil otherwise.



760
761
762
763
764
765
# File 'lib/gapic/schema/wrappers.rb', line 760

def initialize descriptor, address, docs, message, enum
  super descriptor, address, docs
  @message = message
  @enum = enum
  @oneof_siblings = nil
end

Instance Attribute Details

#enumObject

@ return [Enum | nil] The enum if the field is an enum, nil otherwise.



743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
# File 'lib/gapic/schema/wrappers.rb', line 743

class Field < Proto
  extend Forwardable

  attr_accessor :message
  attr_accessor :enum

  # Initializes a message object.
  # @param descriptor [Google::Protobuf::FieldDescriptorProto] the
  #   protobuf representation of this service.
  # @param address [Enumerable<String>] The address of the proto. See
  #   #address for more info.
  # @param docs [Google::Protobuf::SourceCodeInfo::Location] The docs
  #   of the proto. See #docs for more info.
  # @param message [Message | nil] The message if the field is a message,
  #   nil otherwise.
  # @param enum [Enum | nil] The enum if the field is an enum, nil
  #   otherwise.
  def initialize descriptor, address, docs, message, enum
    super descriptor, address, docs
    @message = message
    @enum = enum
    @oneof_siblings = nil
  end

  OPTION_EXTENSION_NAMES = {
    "google.api.field_behavior" => [1052, :enum, :repeated],
    "google.api.resource_reference" => [1055, ::Google::Api::ResourceReference],
    "google.cloud.operation_field" => [1149, :enum],
    "google.cloud.operation_request_field" => [1150, :string],
    "google.cloud.operation_response_field" => [1151, :string]
  }.freeze

  ##
  # Return a configuration of supported option extensions.
  #
  def option_extension_names
    OPTION_EXTENSION_NAMES
  end

  # Whether this field is a message.
  # @return [Boolean]
  def message?
    return true if @message

    false
  end

  # Whether this field is a repeated field.
  # @return [Boolean]
  def repeated?
    label == :LABEL_REPEATED
  end

  # Whether this field is an enum.
  # @return [Boolean]
  def enum?
    return true if @enum

    false
  end

  # Whether this field is a map
  # @return [Boolean]
  def map?
    return true if repeated? && @message&.map_entry?

    false
  end

  # @return [Field, nil] a key field for this map
  #   or nil if this field is not a map
  def map_key_field
    return nil? unless map?
    @message.fields.find { |f| f.name == "key" }
  end

  # @return [Field, nil] a value field for this map
  #   or nil if this field is not a map
  def map_val_field
    return nil? unless map?
    @message.fields.find { |f| f.name == "value" }
  end

  # @return [String] A reference to another resource message or resource
  #   definition. See `google/api/resource.proto`.
  def resource_reference
    option_named "google.api.resource_reference"
  end

  # @return [Array<Google::Api::FieldBehavior>] A designation of a
  #   specific field behavior (required, output only, etc.) in protobuf
  #   messages.
  def field_behavior
    option_named("google.api.field_behavior") || []
  end

  # @return [String] The full name for this field
  #   (e.g. `google.example.Message.field`).
  #   Useful when matching against other pieces of information
  #   which also reference full proto name.
  def full_name
    @address.join "."
  end

  # Nonstandard LRO annotation.
  # This annotation goes on the field of the request message of the method
  # that intiates a non-standard LRO.
  #
  # This annotation contains a field name of the request message
  # of the LRO polling method. (e.g. `GetRegionOperationRequest`)
  # (let's call it a 'referenced field')
  #
  # When the this method is called, this value should be saved.
  # Later, when when polling for a nonstandard LRO, this saved value should
  # be copied to the referenced field.
  #
  # This typically would be used for something that a caller method knows,
  # but an Operation object might not have, e.g. a 'region_id'.
  #
  # So if this field is `region_id` and the annotation is
  # `(google.cloud.operation_request_field) = "region"`, then:
  #
  #     `get_region_operation_request.region = this_message.region_id`
  #
  # In contrast to the `operation_response_field`, this field
  # - goes onto the fields of the input message of the method that
  #   initiates the LRO
  # - semantically annotates a 'push': the value of this field gets
  #   'pushed' into every LRO poll request.
  #
  # @return [String]
  def operation_request_field
    option_named "google.cloud.operation_request_field"
  end

  # Nonstandard LRO annotation.
  # This annotation goes on the field of the request message of the method
  # that polls for a non-standard LRO.
  #
  # This annotation contains a field name of the LRO object (typically 'Operation')
  # (let's call it a 'referenced field')
  #
  # When polling for a nonstandard LRO, the value of the field
  # that this annotation is on should be copied from the referenced field.
  #
  # This typically would get used for something that is named differently in the
  # operation polling request message vs in the Operation object, e.g. operation's name
  #
  # So if this field is `operation` and the annotation is
  # `(google.cloud.operation_response_field) = "name"`, then:
  #
  #     `get_region_operation_request.operation = operation.name`
  #
  # In contrast to the `operation_request_field`, this field
  # - goes onto the fields of the LRO polling method's input message
  # - semantically annotates a 'pull', the value of the referenced field gets
  #   'pulled' into this one.
  #
  # @return [String]
  def operation_response_field
    option_named "google.cloud.operation_response_field"
  end

  # Nonstandard LRO annotation.
  # This annotation goes on the fields of the nonstandard Operation message
  # Is value can be either `NAME`, `STATUS`, `ERROR_MESSAGE`, or `ERROR_CODE`
  # and the field encodes a corresponding aspect of the LRO behaviour.
  #
  # @return [Integer]
  def operation_field
    option_named "google.cloud.operation_field"
  end

  # Specifically denotes a field as optional. While all fields in protocol
  # buffers are optional, this may be specified for emphasis if
  # appropriate.
  def optional?
    field_behavior&.include? Google::Api::FieldBehavior::OPTIONAL
  end

  # Denotes a field as a part of oneof.
  # oneof_index is an int field so it'll be 0 by default for every field
  # and an index in the message's oneof table for the oneof fields
  # but since the indexes in the message's oneof table start with 0 as well
  # we need this to determine whether the field is a part of the oneof
  def oneof?
    @descriptor.has_oneof_index?
  end

  # 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`).
  def required?
    field_behavior&.include? Google::Api::FieldBehavior::REQUIRED
  end

  # 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).
  def output_only?
    field_behavior&.include? Google::Api::FieldBehavior::OUTPUT_ONLY
  end

  # Denotes a field as input only. This indicates that the field is
  # provided in requests, and the corresponding field is not included in
  # output.
  def input_only?
    field_behavior&.include? Google::Api::FieldBehavior::INPUT_ONLY
  end

  # 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.
  def immutable?
    field_behavior&.include? Google::Api::FieldBehavior::IMMUTABLE
  end

  # Denotes a field as proto3 optional
  def proto3_optional?
    @descriptor.proto3_optional
  end

  # @return [Boolean] True if this field is marked as deprecated, false
  #   otherwise.
  def is_deprecated?
    option_named "deprecated"
  end

  # @private
  # Populate the oneof_siblings array. This is nil if this field is not part
  # of a oneof, otherwise it's an array of fields that are members of the
  # oneof, with the first element being the current field.
  def populate_oneof_siblings! all_fields
    return unless oneof?
    @oneof_siblings = [self]
    all_fields.each do |field|
      @oneof_siblings << field if field != self && field.oneof? && field.oneof_index == oneof_index
    end
  end

  # @private
  # Override this to add a note related to oneofs being mutually exclusive.
  def docs_leading_comments disable_xrefs: false, transport: nil, is_rpc_param: false
    str = super(disable_xrefs: disable_xrefs, transport: transport)
    return str unless @oneof_siblings && @oneof_siblings.size > 1
    siblings = @oneof_siblings.map { |field| "`#{field.name}`" }.join ", "
    note =
      if is_rpc_param
        "Note: The following parameters are mutually exclusive: #{siblings}. " \
          "At most one of these parameters can be set. If more than one is set, " \
          "only one will be used, and it is not defined which one."
      else
        "Note: The following fields are mutually exclusive: #{siblings}. " \
          "If a field in that set is populated, all other fields in the set " \
          "will automatically be cleared."
      end
    str ? "#{str.strip}\n\n#{note}" : note
  end
  # @!method name
  #   @return [String] the unqualified name of the field.
  # @!method number
  #   @return [Integer] the number of the field.
  # @!method label
  #   @return [Google::Protobuf::FieldDescriptorProto::Label]
  #     The label of the field.
  # @!method type
  #   @return [Google::Protobuf::FieldDescriptorProto::Type]
  #     If type_name is set, this need not be set.  If both this and
  #     type_name are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or
  #     TYPE_GROUP.
  # @!method type_name
  #   @return [String]
  #     For message and enum types, this is the name of the type.  If the
  #     name starts with a '.', it is fully-qualified.  Otherwise,
  #     C++-like scoping rules are used to find the type (i.e. first the
  #     nested types within this message are searched, then within the
  #     parent, on up to the root namespace).
  # @!method default_value
  #   @return [String]
  #     For numeric types, contains the original text representation of
  #     the value. For booleans, "true" or "false". For strings, contains
  #     the default text contents (not escaped in any way). For bytes,
  #     contains the C escaped value.  All bytes >= 128 are escaped.
  # @!method oneof_index
  #   @return [Integer]
  #     If set, gives the index of a oneof in the containing type's
  #     oneof_decl list.  This field is a member of that oneof.
  # @!method json_name
  #   @return [String]
  #     JSON name of this field. The value is set by protocol compiler. If
  #     the user has set a "json_name" option on this field, that option's
  #     value will be used. Otherwise, it's deduced from the field's name
  #     by converting it to camelCase.
  # @!method options
  #   @return [Google::Protobuf::FieldOptions] the options of this field.
  def_delegators(
    :descriptor,
    :name,
    :number,
    :label,
    :type,
    :type_name,
    :default_value,
    :oneof_index,
    :json_name,
    :options
  )
end

#messageObject

@ return [Message | nil] The message if the field is a message, nil otherwise.



743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
# File 'lib/gapic/schema/wrappers.rb', line 743

class Field < Proto
  extend Forwardable

  attr_accessor :message
  attr_accessor :enum

  # Initializes a message object.
  # @param descriptor [Google::Protobuf::FieldDescriptorProto] the
  #   protobuf representation of this service.
  # @param address [Enumerable<String>] The address of the proto. See
  #   #address for more info.
  # @param docs [Google::Protobuf::SourceCodeInfo::Location] The docs
  #   of the proto. See #docs for more info.
  # @param message [Message | nil] The message if the field is a message,
  #   nil otherwise.
  # @param enum [Enum | nil] The enum if the field is an enum, nil
  #   otherwise.
  def initialize descriptor, address, docs, message, enum
    super descriptor, address, docs
    @message = message
    @enum = enum
    @oneof_siblings = nil
  end

  OPTION_EXTENSION_NAMES = {
    "google.api.field_behavior" => [1052, :enum, :repeated],
    "google.api.resource_reference" => [1055, ::Google::Api::ResourceReference],
    "google.cloud.operation_field" => [1149, :enum],
    "google.cloud.operation_request_field" => [1150, :string],
    "google.cloud.operation_response_field" => [1151, :string]
  }.freeze

  ##
  # Return a configuration of supported option extensions.
  #
  def option_extension_names
    OPTION_EXTENSION_NAMES
  end

  # Whether this field is a message.
  # @return [Boolean]
  def message?
    return true if @message

    false
  end

  # Whether this field is a repeated field.
  # @return [Boolean]
  def repeated?
    label == :LABEL_REPEATED
  end

  # Whether this field is an enum.
  # @return [Boolean]
  def enum?
    return true if @enum

    false
  end

  # Whether this field is a map
  # @return [Boolean]
  def map?
    return true if repeated? && @message&.map_entry?

    false
  end

  # @return [Field, nil] a key field for this map
  #   or nil if this field is not a map
  def map_key_field
    return nil? unless map?
    @message.fields.find { |f| f.name == "key" }
  end

  # @return [Field, nil] a value field for this map
  #   or nil if this field is not a map
  def map_val_field
    return nil? unless map?
    @message.fields.find { |f| f.name == "value" }
  end

  # @return [String] A reference to another resource message or resource
  #   definition. See `google/api/resource.proto`.
  def resource_reference
    option_named "google.api.resource_reference"
  end

  # @return [Array<Google::Api::FieldBehavior>] A designation of a
  #   specific field behavior (required, output only, etc.) in protobuf
  #   messages.
  def field_behavior
    option_named("google.api.field_behavior") || []
  end

  # @return [String] The full name for this field
  #   (e.g. `google.example.Message.field`).
  #   Useful when matching against other pieces of information
  #   which also reference full proto name.
  def full_name
    @address.join "."
  end

  # Nonstandard LRO annotation.
  # This annotation goes on the field of the request message of the method
  # that intiates a non-standard LRO.
  #
  # This annotation contains a field name of the request message
  # of the LRO polling method. (e.g. `GetRegionOperationRequest`)
  # (let's call it a 'referenced field')
  #
  # When the this method is called, this value should be saved.
  # Later, when when polling for a nonstandard LRO, this saved value should
  # be copied to the referenced field.
  #
  # This typically would be used for something that a caller method knows,
  # but an Operation object might not have, e.g. a 'region_id'.
  #
  # So if this field is `region_id` and the annotation is
  # `(google.cloud.operation_request_field) = "region"`, then:
  #
  #     `get_region_operation_request.region = this_message.region_id`
  #
  # In contrast to the `operation_response_field`, this field
  # - goes onto the fields of the input message of the method that
  #   initiates the LRO
  # - semantically annotates a 'push': the value of this field gets
  #   'pushed' into every LRO poll request.
  #
  # @return [String]
  def operation_request_field
    option_named "google.cloud.operation_request_field"
  end

  # Nonstandard LRO annotation.
  # This annotation goes on the field of the request message of the method
  # that polls for a non-standard LRO.
  #
  # This annotation contains a field name of the LRO object (typically 'Operation')
  # (let's call it a 'referenced field')
  #
  # When polling for a nonstandard LRO, the value of the field
  # that this annotation is on should be copied from the referenced field.
  #
  # This typically would get used for something that is named differently in the
  # operation polling request message vs in the Operation object, e.g. operation's name
  #
  # So if this field is `operation` and the annotation is
  # `(google.cloud.operation_response_field) = "name"`, then:
  #
  #     `get_region_operation_request.operation = operation.name`
  #
  # In contrast to the `operation_request_field`, this field
  # - goes onto the fields of the LRO polling method's input message
  # - semantically annotates a 'pull', the value of the referenced field gets
  #   'pulled' into this one.
  #
  # @return [String]
  def operation_response_field
    option_named "google.cloud.operation_response_field"
  end

  # Nonstandard LRO annotation.
  # This annotation goes on the fields of the nonstandard Operation message
  # Is value can be either `NAME`, `STATUS`, `ERROR_MESSAGE`, or `ERROR_CODE`
  # and the field encodes a corresponding aspect of the LRO behaviour.
  #
  # @return [Integer]
  def operation_field
    option_named "google.cloud.operation_field"
  end

  # Specifically denotes a field as optional. While all fields in protocol
  # buffers are optional, this may be specified for emphasis if
  # appropriate.
  def optional?
    field_behavior&.include? Google::Api::FieldBehavior::OPTIONAL
  end

  # Denotes a field as a part of oneof.
  # oneof_index is an int field so it'll be 0 by default for every field
  # and an index in the message's oneof table for the oneof fields
  # but since the indexes in the message's oneof table start with 0 as well
  # we need this to determine whether the field is a part of the oneof
  def oneof?
    @descriptor.has_oneof_index?
  end

  # 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`).
  def required?
    field_behavior&.include? Google::Api::FieldBehavior::REQUIRED
  end

  # 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).
  def output_only?
    field_behavior&.include? Google::Api::FieldBehavior::OUTPUT_ONLY
  end

  # Denotes a field as input only. This indicates that the field is
  # provided in requests, and the corresponding field is not included in
  # output.
  def input_only?
    field_behavior&.include? Google::Api::FieldBehavior::INPUT_ONLY
  end

  # 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.
  def immutable?
    field_behavior&.include? Google::Api::FieldBehavior::IMMUTABLE
  end

  # Denotes a field as proto3 optional
  def proto3_optional?
    @descriptor.proto3_optional
  end

  # @return [Boolean] True if this field is marked as deprecated, false
  #   otherwise.
  def is_deprecated?
    option_named "deprecated"
  end

  # @private
  # Populate the oneof_siblings array. This is nil if this field is not part
  # of a oneof, otherwise it's an array of fields that are members of the
  # oneof, with the first element being the current field.
  def populate_oneof_siblings! all_fields
    return unless oneof?
    @oneof_siblings = [self]
    all_fields.each do |field|
      @oneof_siblings << field if field != self && field.oneof? && field.oneof_index == oneof_index
    end
  end

  # @private
  # Override this to add a note related to oneofs being mutually exclusive.
  def docs_leading_comments disable_xrefs: false, transport: nil, is_rpc_param: false
    str = super(disable_xrefs: disable_xrefs, transport: transport)
    return str unless @oneof_siblings && @oneof_siblings.size > 1
    siblings = @oneof_siblings.map { |field| "`#{field.name}`" }.join ", "
    note =
      if is_rpc_param
        "Note: The following parameters are mutually exclusive: #{siblings}. " \
          "At most one of these parameters can be set. If more than one is set, " \
          "only one will be used, and it is not defined which one."
      else
        "Note: The following fields are mutually exclusive: #{siblings}. " \
          "If a field in that set is populated, all other fields in the set " \
          "will automatically be cleared."
      end
    str ? "#{str.strip}\n\n#{note}" : note
  end
  # @!method name
  #   @return [String] the unqualified name of the field.
  # @!method number
  #   @return [Integer] the number of the field.
  # @!method label
  #   @return [Google::Protobuf::FieldDescriptorProto::Label]
  #     The label of the field.
  # @!method type
  #   @return [Google::Protobuf::FieldDescriptorProto::Type]
  #     If type_name is set, this need not be set.  If both this and
  #     type_name are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or
  #     TYPE_GROUP.
  # @!method type_name
  #   @return [String]
  #     For message and enum types, this is the name of the type.  If the
  #     name starts with a '.', it is fully-qualified.  Otherwise,
  #     C++-like scoping rules are used to find the type (i.e. first the
  #     nested types within this message are searched, then within the
  #     parent, on up to the root namespace).
  # @!method default_value
  #   @return [String]
  #     For numeric types, contains the original text representation of
  #     the value. For booleans, "true" or "false". For strings, contains
  #     the default text contents (not escaped in any way). For bytes,
  #     contains the C escaped value.  All bytes >= 128 are escaped.
  # @!method oneof_index
  #   @return [Integer]
  #     If set, gives the index of a oneof in the containing type's
  #     oneof_decl list.  This field is a member of that oneof.
  # @!method json_name
  #   @return [String]
  #     JSON name of this field. The value is set by protocol compiler. If
  #     the user has set a "json_name" option on this field, that option's
  #     value will be used. Otherwise, it's deduced from the field's name
  #     by converting it to camelCase.
  # @!method options
  #   @return [Google::Protobuf::FieldOptions] the options of this field.
  def_delegators(
    :descriptor,
    :name,
    :number,
    :label,
    :type,
    :type_name,
    :default_value,
    :oneof_index,
    :json_name,
    :options
  )
end

Instance Method Details

#default_valueString

Returns For numeric types, contains the original text representation of the value. For booleans, "true" or "false". For strings, contains the default text contents (not escaped in any way). For bytes, contains the C escaped value. All bytes >= 128 are escaped.

Returns:

  • (String)

    For numeric types, contains the original text representation of the value. For booleans, "true" or "false". For strings, contains the default text contents (not escaped in any way). For bytes, contains the C escaped value. All bytes >= 128 are escaped.



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)

#enum?Boolean

Whether this field is an enum.

Returns:

  • (Boolean)


798
799
800
801
802
# File 'lib/gapic/schema/wrappers.rb', line 798

def enum?
  return true if @enum

  false
end

#field_behaviorArray<Google::Api::FieldBehavior>

Returns A designation of a specific field behavior (required, output only, etc.) in protobuf messages.

Returns:

  • (Array<Google::Api::FieldBehavior>)

    A designation of a specific field behavior (required, output only, etc.) in protobuf messages.



835
836
837
# File 'lib/gapic/schema/wrappers.rb', line 835

def field_behavior
  option_named("google.api.field_behavior") || []
end

#full_nameString

Returns The full name for this field (e.g. google.example.Message.field). Useful when matching against other pieces of information which also reference full proto name.

Returns:

  • (String)

    The full name for this field (e.g. google.example.Message.field). Useful when matching against other pieces of information which also reference full proto name.



843
844
845
# File 'lib/gapic/schema/wrappers.rb', line 843

def full_name
  @address.join "."
end

#immutable?Boolean

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.

Returns:

  • (Boolean)


957
958
959
# File 'lib/gapic/schema/wrappers.rb', line 957

def immutable?
  field_behavior&.include? Google::Api::FieldBehavior::IMMUTABLE
end

#input_only?Boolean

Denotes a field as input only. This indicates that the field is provided in requests, and the corresponding field is not included in output.

Returns:

  • (Boolean)


950
951
952
# File 'lib/gapic/schema/wrappers.rb', line 950

def input_only?
  field_behavior&.include? Google::Api::FieldBehavior::INPUT_ONLY
end

#is_deprecated?Boolean

Returns True if this field is marked as deprecated, false otherwise.

Returns:

  • (Boolean)

    True if this field is marked as deprecated, false otherwise.



968
969
970
# File 'lib/gapic/schema/wrappers.rb', line 968

def is_deprecated?
  option_named "deprecated"
end

#json_nameString

Returns JSON name of this field. The value is set by protocol compiler. If the user has set a "json_name" option on this field, that option's value will be used. Otherwise, it's deduced from the field's name by converting it to camelCase.

Returns:

  • (String)

    JSON name of this field. The value is set by protocol compiler. If the user has set a "json_name" option on this field, that option's value will be used. Otherwise, it's deduced from the field's name by converting it to camelCase.



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)

#labelGoogle::Protobuf::FieldDescriptorProto::Label

Returns The label of the field.

Returns:

  • (Google::Protobuf::FieldDescriptorProto::Label)

    The label of the field.



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)

#map?Boolean

Whether this field is a map

Returns:

  • (Boolean)


806
807
808
809
810
# File 'lib/gapic/schema/wrappers.rb', line 806

def map?
  return true if repeated? && @message&.map_entry?

  false
end

#map_key_fieldField?

Returns a key field for this map or nil if this field is not a map.

Returns:

  • (Field, nil)

    a key field for this map or nil if this field is not a map



814
815
816
817
# File 'lib/gapic/schema/wrappers.rb', line 814

def map_key_field
  return nil? unless map?
  @message.fields.find { |f| f.name == "key" }
end

#map_val_fieldField?

Returns a value field for this map or nil if this field is not a map.

Returns:

  • (Field, nil)

    a value field for this map or nil if this field is not a map



821
822
823
824
# File 'lib/gapic/schema/wrappers.rb', line 821

def map_val_field
  return nil? unless map?
  @message.fields.find { |f| f.name == "value" }
end

#message?Boolean

Whether this field is a message.

Returns:

  • (Boolean)


784
785
786
787
788
# File 'lib/gapic/schema/wrappers.rb', line 784

def message?
  return true if @message

  false
end

#nameString

Returns the unqualified name of the field.

Returns:

  • (String)

    the unqualified name of the field.



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)

#numberInteger

Returns the number of the field.

Returns:

  • (Integer)

    the number of the field.



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)

#oneof?Boolean

Denotes a field as a part of oneof. oneof_index is an int field so it'll be 0 by default for every field and an index in the message's oneof table for the oneof fields but since the indexes in the message's oneof table start with 0 as well we need this to determine whether the field is a part of the oneof

Returns:

  • (Boolean)


928
929
930
# File 'lib/gapic/schema/wrappers.rb', line 928

def oneof?
  @descriptor.has_oneof_index?
end

#oneof_indexInteger

Returns If set, gives the index of a oneof in the containing type's oneof_decl list. This field is a member of that oneof.

Returns:

  • (Integer)

    If set, gives the index of a oneof in the containing type's oneof_decl list. This field is a member of that oneof.



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)

#operation_fieldInteger

Nonstandard LRO annotation. This annotation goes on the fields of the nonstandard Operation message Is value can be either NAME, STATUS, ERROR_MESSAGE, or ERROR_CODE and the field encodes a corresponding aspect of the LRO behaviour.

Returns:

  • (Integer)


912
913
914
# File 'lib/gapic/schema/wrappers.rb', line 912

def operation_field
  option_named "google.cloud.operation_field"
end

#operation_request_fieldString

Nonstandard LRO annotation. This annotation goes on the field of the request message of the method that intiates a non-standard LRO.

This annotation contains a field name of the request message of the LRO polling method. (e.g. GetRegionOperationRequest) (let's call it a 'referenced field')

When the this method is called, this value should be saved. Later, when when polling for a nonstandard LRO, this saved value should be copied to the referenced field.

This typically would be used for something that a caller method knows, but an Operation object might not have, e.g. a 'region_id'.

So if this field is region_id and the annotation is (google.cloud.operation_request_field) = "region", then:

`get_region_operation_request.region = this_message.region_id`

In contrast to the operation_response_field, this field

  • goes onto the fields of the input message of the method that initiates the LRO
  • semantically annotates a 'push': the value of this field gets 'pushed' into every LRO poll request.

Returns:

  • (String)


874
875
876
# File 'lib/gapic/schema/wrappers.rb', line 874

def operation_request_field
  option_named "google.cloud.operation_request_field"
end

#operation_response_fieldString

Nonstandard LRO annotation. This annotation goes on the field of the request message of the method that polls for a non-standard LRO.

This annotation contains a field name of the LRO object (typically 'Operation') (let's call it a 'referenced field')

When polling for a nonstandard LRO, the value of the field that this annotation is on should be copied from the referenced field.

This typically would get used for something that is named differently in the operation polling request message vs in the Operation object, e.g. operation's name

So if this field is operation and the annotation is (google.cloud.operation_response_field) = "name", then:

`get_region_operation_request.operation = operation.name`

In contrast to the operation_request_field, this field

  • goes onto the fields of the LRO polling method's input message
  • semantically annotates a 'pull', the value of the referenced field gets 'pulled' into this one.

Returns:

  • (String)


902
903
904
# File 'lib/gapic/schema/wrappers.rb', line 902

def operation_response_field
  option_named "google.cloud.operation_response_field"
end

#option_extension_namesObject

Return a configuration of supported option extensions.



778
779
780
# File 'lib/gapic/schema/wrappers.rb', line 778

def option_extension_names
  OPTION_EXTENSION_NAMES
end

#optional?Boolean

Specifically denotes a field as optional. While all fields in protocol buffers are optional, this may be specified for emphasis if appropriate.

Returns:

  • (Boolean)


919
920
921
# File 'lib/gapic/schema/wrappers.rb', line 919

def optional?
  field_behavior&.include? Google::Api::FieldBehavior::OPTIONAL
end

#optionsGoogle::Protobuf::FieldOptions

Returns the options of this field.

Returns:

  • (Google::Protobuf::FieldOptions)

    the options of this field.



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)

#output_only?Boolean

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).

Returns:

  • (Boolean)


943
944
945
# File 'lib/gapic/schema/wrappers.rb', line 943

def output_only?
  field_behavior&.include? Google::Api::FieldBehavior::OUTPUT_ONLY
end

#proto3_optional?Boolean

Denotes a field as proto3 optional

Returns:

  • (Boolean)


962
963
964
# File 'lib/gapic/schema/wrappers.rb', line 962

def proto3_optional?
  @descriptor.proto3_optional
end

#repeated?Boolean

Whether this field is a repeated field.

Returns:

  • (Boolean)


792
793
794
# File 'lib/gapic/schema/wrappers.rb', line 792

def repeated?
  label == :LABEL_REPEATED
end

#required?Boolean

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).

Returns:

  • (Boolean)


935
936
937
# File 'lib/gapic/schema/wrappers.rb', line 935

def required?
  field_behavior&.include? Google::Api::FieldBehavior::REQUIRED
end

#resource_referenceString

Returns A reference to another resource message or resource definition. See google/api/resource.proto.

Returns:

  • (String)

    A reference to another resource message or resource definition. See google/api/resource.proto.



828
829
830
# File 'lib/gapic/schema/wrappers.rb', line 828

def resource_reference
  option_named "google.api.resource_reference"
end

#typeGoogle::Protobuf::FieldDescriptorProto::Type

Returns If type_name is set, this need not be set. If both this and type_name are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.

Returns:

  • (Google::Protobuf::FieldDescriptorProto::Type)

    If type_name is set, this need not be set. If both this and type_name are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)

#type_nameString

Returns For message and enum types, this is the name of the type. If the name starts with a '.', it is fully-qualified. Otherwise, C++-like scoping rules are used to find the type (i.e. first the nested types within this message are searched, then within the parent, on up to the root namespace).

Returns:

  • (String)

    For message and enum types, this is the name of the type. If the name starts with a '.', it is fully-qualified. Otherwise, C++-like scoping rules are used to find the type (i.e. first the nested types within this message are searched, then within the parent, on up to the root namespace).



1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'lib/gapic/schema/wrappers.rb', line 1039

def_delegators(
  :descriptor,
  :name,
  :number,
  :label,
  :type,
  :type_name,
  :default_value,
  :oneof_index,
  :json_name,
  :options
)