|
| 1 | +package client |
| 2 | + |
| 3 | +// Attribute describes an attribute available when accessing a resource of a given type. |
| 4 | +type Attribute struct { |
| 5 | + // Path expression to read this attribute from a resource payload. |
| 6 | + Path string |
| 7 | + |
| 8 | + // Type of the attribute. It doesn't match exactly to action parameter types |
| 9 | + // because JSON doesn't differentiate between integers and floating point |
| 10 | + // numbers so it's up to interpretation. |
| 11 | + Type AttributeType |
| 12 | + |
| 13 | + // Cardinality determines how many values would be returned when applying the |
| 14 | + // given JSONPath. Only attributes with a cardinality of "one" can be used as |
| 15 | + // tool parameter values. |
| 16 | + Cardinality AttributeCardinality |
| 17 | + |
| 18 | + // Description is an optional human-readable description of the attribute. |
| 19 | + Description string |
| 20 | + |
| 21 | + // IsTopLevel is true if the attribute is a top-level field (direct child of the root). |
| 22 | + IsTopLevel bool |
| 23 | + |
| 24 | + // Name is the name of the field, e.g.: |
| 25 | + // - "id" for `$.id` |
| 26 | + // - "quantity" for `$.items[*].quantity` |
| 27 | + Name string |
| 28 | +} |
| 29 | + |
| 30 | +// AttributeCardinality determines how many values would be returned when |
| 31 | +// applying an attribute's JSONPath to a resource payload. |
| 32 | +type AttributeCardinality string |
| 33 | + |
| 34 | +const ( |
| 35 | + // AttributeCardinalityOne means the attribute represents one value (e.g. |
| 36 | + // `$.id` or `$.name`). |
| 37 | + AttributeCardinalityOne AttributeCardinality = "one" |
| 38 | + |
| 39 | + // AttributeCardinalityMany means the attribute represents many values (e.g. |
| 40 | + // `$.items[*].quantity`). |
| 41 | + AttributeCardinalityMany AttributeCardinality = "many" |
| 42 | +) |
| 43 | + |
| 44 | +// AttributeType describes the data type of the attribute. |
| 45 | +type AttributeType string |
| 46 | + |
| 47 | +const ( |
| 48 | + // AttributeTypeString means the attribute is a string. |
| 49 | + AttributeTypeString AttributeType = "string" |
| 50 | + |
| 51 | + // AttributeTypeDate means the attribute is a date in the string form: |
| 52 | + // YYYY-MM-DD. |
| 53 | + AttributeTypeDate AttributeType = "date" |
| 54 | + |
| 55 | + // AttributeTypeTimestamp means the attribute is a timestamp in the RFC3339 form. |
| 56 | + AttributeTypeTimestamp AttributeType = "timestamp" |
| 57 | + |
| 58 | + // AttributeTypeBoolean means the attribute is a boolean value. |
| 59 | + AttributeTypeBoolean AttributeType = "boolean" |
| 60 | + |
| 61 | + // AttributeTypeNumber means the attribute is a numeric value. JSON doesn't |
| 62 | + // differentiate between integers and floating point numbers, so it's up to |
| 63 | + // the user to interpret this. |
| 64 | + AttributeTypeNumber AttributeType = "number" |
| 65 | + |
| 66 | + // AttributeTypeArray means the attribute is an array of primitive values. |
| 67 | + // |
| 68 | + // Note: an array of primitive values will still have a cardinality of "one" |
| 69 | + // because there is one value available (the array itself). |
| 70 | + AttributeTypeArray AttributeType = "array" |
| 71 | + |
| 72 | + // AttributeTypeComplex means the attribute could be many types, which we don't |
| 73 | + // support yet. |
| 74 | + AttributeTypeComplex AttributeType = "complex" |
| 75 | +) |
0 commit comments