Uploaded image for project: 'Puppet'
  1. Puppet
  2. PUP-8078

Make it possible to create parameterized Object data types



    • Bug
    • Status: Closed
    • Normal
    • Resolution: Fixed
    • None
    • PUP 5.4.0
    • None
    • None
    • Platform Core
    • 5
    • Tasks Kanban
    • Not Needed
    • This is mostly an internal concern when implementing new types (needed this for Bolt related data types like Error).
    • No Action


      It is currently not possible to create an Object data type that is parameterized. The type itself can thus only be used to filter instances based on their type, not on contents. This is highly desirable in some cases.

      A first implementation should allow parameterized types to be created with filtering logic implemented in Ruby. Later, we might add predefined filters such as using Pattern, String, or Enum to match string attributes, min/max filters for magnitudes, or Boolean filters to match if attributes have a value or not.

      The parameters for an Object type can be added using a new top level property named type_parameters. The value of this property is a hash similar to attributes where a parameter declaration is a subset of an attribute declaration. The parameter can have a type and a value but is different from an attribute in that a parameter is always optional (a required parameter would break the current pattern where a fully generalized type exists for each parameterized type).

      A parameterized `Object` type, when serialized, must retain the values of its parameters.


      type Error = Object[
        type_parameters => {
          kind => Variant[String, Regexp, Type[Enum], Type[Pattern]],
          issue_code => Variant[String, Regexp, Type[Enum], Type[Pattern]]
        attributes => {
          message => String[1],
          kind => { type => Optional[String[1]], value => undef },
          issue_code => { type => Optional[String[1]], value => 'ERROR' },
          partial_result => { type => Data, value => undef },
          details => { type => Optional[Hash[String[1],Data]], value => undef },

      The above declaration makes it possible to create a parameterized Error by either providing no parameters at all, one Hash parameter with named arguments, or one or two anonymous (positional) arguments.


        Issue Links



              Unassigned Unassigned
              thomas.hallgren Thomas Hallgren
              0 Vote for this issue
              4 Start watching this issue



                Zendesk Support