(param previewtypes.Parameter)
| 167 | } |
| 168 | |
| 169 | func TemplateVersionParameterFromPreview(param previewtypes.Parameter) (codersdk.TemplateVersionParameter, error) { |
| 170 | descriptionPlaintext, err := render.PlaintextFromMarkdown(param.Description) |
| 171 | if err != nil { |
| 172 | return codersdk.TemplateVersionParameter{}, err |
| 173 | } |
| 174 | |
| 175 | sdkParam := codersdk.TemplateVersionParameter{ |
| 176 | Name: param.Name, |
| 177 | DisplayName: param.DisplayName, |
| 178 | Description: param.Description, |
| 179 | DescriptionPlaintext: descriptionPlaintext, |
| 180 | Type: string(param.Type), |
| 181 | FormType: string(param.FormType), |
| 182 | Mutable: param.Mutable, |
| 183 | DefaultValue: param.DefaultValue.AsString(), |
| 184 | Icon: param.Icon, |
| 185 | Required: param.Required, |
| 186 | Ephemeral: param.Ephemeral, |
| 187 | Options: slice.List(param.Options, TemplateVersionParameterOptionFromPreview), |
| 188 | // Validation set after |
| 189 | } |
| 190 | if len(param.Validations) > 0 { |
| 191 | validation := param.Validations[0] |
| 192 | sdkParam.ValidationError = validation.Error |
| 193 | if validation.Monotonic != nil { |
| 194 | sdkParam.ValidationMonotonic = codersdk.ValidationMonotonicOrder(*validation.Monotonic) |
| 195 | } |
| 196 | if validation.Regex != nil { |
| 197 | sdkParam.ValidationRegex = *validation.Regex |
| 198 | } |
| 199 | if validation.Min != nil { |
| 200 | //nolint:gosec // No other choice |
| 201 | sdkParam.ValidationMin = ptr.Ref(int32(*validation.Min)) |
| 202 | } |
| 203 | if validation.Max != nil { |
| 204 | //nolint:gosec // No other choice |
| 205 | sdkParam.ValidationMax = ptr.Ref(int32(*validation.Max)) |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | return sdkParam, nil |
| 210 | } |
| 211 | |
| 212 | func TemplateVersionParameter(param database.TemplateVersionParameter) (codersdk.TemplateVersionParameter, error) { |
| 213 | options, err := templateVersionParameterOptions(param.Options) |
no test coverage detected