@@ -7,17 +7,121 @@ import (
77 "github.com/google/uuid"
88
99 "github.com/coder/coder/v2/codersdk/wsjson"
10- previewtypes "github.com/coder/preview/types"
1110 "github.com/coder/websocket"
1211)
1312
14- // FriendlyDiagnostic is included to guarantee it is generated in the output
15- // types. This is used as the type override for `previewtypes.Diagnostic`.
16- type FriendlyDiagnostic = previewtypes.FriendlyDiagnostic
13+ type ParameterFormType string
1714
18- // NullHCLString is included to guarantee it is generated in the output
19- // types. This is used as the type override for `previewtypes.HCLString`.
20- type NullHCLString = previewtypes.NullHCLString
15+ const (
16+ ParameterFormTypeDefault ParameterFormType = ""
17+ ParameterFormTypeRadio ParameterFormType = "radio"
18+ ParameterFormTypeSlider ParameterFormType = "slider"
19+ ParameterFormTypeInput ParameterFormType = "input"
20+ ParameterFormTypeDropdown ParameterFormType = "dropdown"
21+ ParameterFormTypeCheckbox ParameterFormType = "checkbox"
22+ ParameterFormTypeSwitch ParameterFormType = "switch"
23+ ParameterFormTypeMultiSelect ParameterFormType = "multi-select"
24+ ParameterFormTypeTagSelect ParameterFormType = "tag-select"
25+ ParameterFormTypeTextArea ParameterFormType = "textarea"
26+ ParameterFormTypeError ParameterFormType = "error"
27+ )
28+
29+ type OptionType string
30+
31+ const (
32+ OptionTypeString OptionType = "string"
33+ OptionTypeNumber OptionType = "number"
34+ OptionTypeBoolean OptionType = "bool"
35+ OptionTypeListString OptionType = "list(string)"
36+ )
37+
38+ type DiagnosticSeverityString string
39+
40+ const (
41+ DiagnosticSeverityError DiagnosticSeverityString = "error"
42+ DiagnosticSeverityWarning DiagnosticSeverityString = "warning"
43+ )
44+
45+ // FriendlyDiagnostic == previewtypes.FriendlyDiagnostic
46+ // Copied to avoid import deps
47+ type FriendlyDiagnostic struct {
48+ Severity DiagnosticSeverityString `json:"severity"`
49+ Summary string `json:"summary"`
50+ Detail string `json:"detail"`
51+
52+ Extra DiagnosticExtra `json:"extra"`
53+ }
54+
55+ type DiagnosticExtra struct {
56+ Code string `json:"code"`
57+ }
58+
59+ // NullHCLString == `previewtypes.NullHCLString`.
60+ type NullHCLString struct {
61+ Value string `json:"value"`
62+ Valid bool `json:"valid"`
63+ }
64+
65+ type PreviewParameter struct {
66+ PreviewParameterData
67+ Value NullHCLString `json:"value"`
68+ Diagnostics []FriendlyDiagnostic `json:"diagnostics"`
69+ }
70+
71+ type PreviewParameterData struct {
72+ Name string `json:"name"`
73+ DisplayName string `json:"display_name"`
74+ Description string `json:"description"`
75+ Type OptionType `json:"type"`
76+ FormType ParameterFormType `json:"form_type"`
77+ Styling PreviewParameterStyling `json:"styling"`
78+ Mutable bool `json:"mutable"`
79+ DefaultValue NullHCLString `json:"default_value"`
80+ Icon string `json:"icon"`
81+ Options []PreviewParameterOption `json:"options"`
82+ Validations []PreviewParameterValidation `json:"validations"`
83+ Required bool `json:"required"`
84+ // legacy_variable_name was removed (= 14)
85+ Order int64 `json:"order"`
86+ Ephemeral bool `json:"ephemeral"`
87+ }
88+
89+ type PreviewParameterStyling struct {
90+ Placeholder * string `json:"placeholder,omitempty"`
91+ Disabled * bool `json:"disabled,omitempty"`
92+ Label * string `json:"label,omitempty"`
93+ }
94+
95+ type PreviewParameterOption struct {
96+ Name string `json:"name"`
97+ Description string `json:"description"`
98+ Value NullHCLString `json:"value"`
99+ Icon string `json:"icon"`
100+ }
101+
102+ type PreviewParameterValidation struct {
103+ Error string `json:"validation_error"`
104+
105+ // All validation attributes are optional.
106+ Regex * string `json:"validation_regex"`
107+ Min * int64 `json:"validation_min"`
108+ Max * int64 `json:"validation_max"`
109+ Monotonic * string `json:"validation_monotonic"`
110+ }
111+
112+ type DynamicParametersRequest struct {
113+ // ID identifies the request. The response contains the same
114+ // ID so that the client can match it to the request.
115+ ID int `json:"id"`
116+ Inputs map [string ]string `json:"inputs"`
117+ }
118+
119+ type DynamicParametersResponse struct {
120+ ID int `json:"id"`
121+ Diagnostics []FriendlyDiagnostic `json:"diagnostics"`
122+ Parameters []PreviewParameter `json:"parameters"`
123+ // TODO: Workspace tags
124+ }
21125
22126func (c * Client ) TemplateVersionDynamicParameters (ctx context.Context , userID , version uuid.UUID ) (* wsjson.Stream [DynamicParametersResponse , DynamicParametersRequest ], error ) {
23127 conn , err := c .Dial (ctx , fmt .Sprintf ("/api/v2/users/%s/templateversions/%s/parameters" , userID , version ), nil )
0 commit comments