Skip to content

Commit ce74da3

Browse files
authored
Merge pull request #320 from port-labs/task_t7nvy9/add-labeled-url
Added support for object formats - for labeledUrl
2 parents a76ad7b + 173d9c6 commit ce74da3

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

docs/resources/port_blueprint.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ Optional:
409409
Optional:
410410

411411
- `default` (List of String) The default of the items
412+
- `format` (String) The format of the object items
412413

413414

414415
<a id="nestedatt--properties--array_props--string_items"></a>
@@ -459,6 +460,7 @@ Optional:
459460

460461
- `default` (String) The default of the object property
461462
- `description` (String) The description of the property
463+
- `format` (String) The format of the object property
462464
- `icon` (String) The icon of the property
463465
- `required` (Boolean) Whether the property is required
464466
- `spec` (String) The spec of the object property

docs/resources/port_system_blueprint.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Optional:
121121
Optional:
122122

123123
- `default` (List of String) The default of the items
124+
- `format` (String) The format of the object items
124125

125126

126127
<a id="nestedatt--properties--array_props--string_items"></a>
@@ -171,6 +172,7 @@ Optional:
171172

172173
- `default` (String) The default of the object property
173174
- `description` (String) The description of the property
175+
- `format` (String) The format of the object property
174176
- `icon` (String) The icon of the property
175177
- `required` (Boolean) Whether the property is required
176178
- `spec` (String) The spec of the object property

port/blueprint/array.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ func arrayPropResourceToBody(ctx context.Context, state *PropertiesModel, props
112112
if prop.ObjectItems != nil {
113113
items := map[string]interface{}{}
114114
items["type"] = "object"
115+
if !prop.ObjectItems.Format.IsNull() {
116+
items["format"] = prop.ObjectItems.Format.ValueString()
117+
}
115118
if !prop.ObjectItems.Default.IsNull() {
116119
defaultList, err := utils.TerraformListToGoArray(ctx, prop.ObjectItems.Default, "object")
117120
if err != nil {
@@ -205,6 +208,9 @@ func AddArrayPropertiesToState(ctx context.Context, v *cli.BlueprintProperty, js
205208

206209
case "object":
207210
arrayProp.ObjectItems = &ObjectItems{}
211+
if value, ok := v.Items["format"]; ok && value != nil {
212+
arrayProp.ObjectItems.Format = types.StringValue(v.Items["format"].(string))
213+
}
208214
if v.Default != nil {
209215
objectArray := make([]map[string]interface{}, len(v.Default.([]interface{})))
210216
for i, v := range v.Default.([]interface{}) {

port/blueprint/model.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ type TeamInheritanceModel struct {
1313
}
1414

1515
type OwnershipModel struct {
16-
Type types.String `tfsdk:"type"`
17-
Path types.String `tfsdk:"path"`
16+
Type types.String `tfsdk:"type"`
17+
Path types.String `tfsdk:"path"`
1818
Title types.String `tfsdk:"title"`
1919
}
2020

@@ -61,11 +61,11 @@ type BooleanPropModel struct {
6161
}
6262

6363
type StringItems struct {
64-
Format types.String `tfsdk:"format"`
65-
Default types.List `tfsdk:"default"`
66-
Pattern types.String `tfsdk:"pattern"`
67-
Enum types.List `tfsdk:"enum"`
68-
EnumColors types.Map `tfsdk:"enum_colors"`
64+
Format types.String `tfsdk:"format"`
65+
Default types.List `tfsdk:"default"`
66+
Pattern types.String `tfsdk:"pattern"`
67+
Enum types.List `tfsdk:"enum"`
68+
EnumColors types.Map `tfsdk:"enum_colors"`
6969
}
7070

7171
type NumberItems struct {
@@ -77,7 +77,8 @@ type BooleanItems struct {
7777
}
7878

7979
type ObjectItems struct {
80-
Default types.List `tfsdk:"default"`
80+
Default types.List `tfsdk:"default"`
81+
Format types.String `tfsdk:"format"`
8182
}
8283

8384
type ArrayPropModel struct {
@@ -100,6 +101,7 @@ type ObjectPropModel struct {
100101
Required types.Bool `tfsdk:"required"`
101102
Default types.String `tfsdk:"default"`
102103
Spec types.String `tfsdk:"spec"`
104+
Format types.String `tfsdk:"format"`
103105
}
104106

105107
type PropertiesModel struct {

port/blueprint/object.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ func objectPropResourceToBody(state *PropertiesModel, props map[string]cli.Bluep
4646
property.Spec = &spec
4747
}
4848

49+
if !prop.Format.IsNull() {
50+
format := prop.Format.ValueString()
51+
property.Format = &format
52+
}
53+
4954
props[propIdentifier] = property
5055
}
5156

@@ -62,5 +67,9 @@ func AddObjectPropertiesToState(v *cli.BlueprintProperty) *ObjectPropModel {
6267
objectProp.Spec = types.StringValue(*v.Spec)
6368
}
6469

70+
if v.Format != nil {
71+
objectProp.Format = types.StringValue(*v.Format)
72+
}
73+
6574
return objectProp
6675
}

port/blueprint/schema.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ func ArrayPropertySchema() schema.MapNestedAttribute {
252252
MarkdownDescription: "The items of the array property",
253253
Optional: true,
254254
Attributes: map[string]schema.Attribute{
255+
"format": schema.StringAttribute{
256+
MarkdownDescription: "The format of the object items",
257+
Optional: true,
258+
},
255259
"default": schema.ListAttribute{
256260
MarkdownDescription: "The default of the items",
257261
Optional: true,
@@ -307,6 +311,10 @@ func ObjectPropertySchema() schema.MapNestedAttribute {
307311
stringvalidator.OneOf("async-api", "open-api"),
308312
},
309313
},
314+
"format": schema.StringAttribute{
315+
MarkdownDescription: "The format of the object property",
316+
Optional: true,
317+
},
310318
"default": schema.StringAttribute{
311319
Optional: true,
312320
MarkdownDescription: "The default of the object property",

0 commit comments

Comments
 (0)