MCPcopy Index your code
hub / github.com/coder/coder / Validate

Method Validate

codersdk/aiproviders.go:206–256  ·  view source on GitHub ↗

Validate returns the field-level validation errors for a create request. An empty slice indicates the request is valid.

()

Source from the content-addressed store, hash-verified

204// Validate returns the field-level validation errors for a create
205// request. An empty slice indicates the request is valid.
206func (req CreateAIProviderRequest) Validate() []ValidationError {
207 var validations []ValidationError
208 switch req.Type {
209 case AIProviderTypeOpenAI,
210 AIProviderTypeAnthropic,
211 AIProviderTypeAzure,
212 AIProviderTypeBedrock,
213 AIProviderTypeCopilot,
214 AIProviderTypeGoogle,
215 AIProviderTypeOpenAICompat,
216 AIProviderTypeOpenrouter,
217 AIProviderTypeVercel:
218 case "":
219 validations = append(validations, ValidationError{Field: "type", Detail: "type is required"})
220 default:
221 validations = append(validations, ValidationError{
222 Field: "type",
223 Detail: fmt.Sprintf("unsupported provider type %q", req.Type),
224 })
225 }
226 validations = append(validations, validateAIProviderName(req.Name)...)
227 validations = append(validations, validateRequiredAIProviderBaseURL(req.BaseURL)...)
228 validations = append(validations, validateAIProviderAPIKeys(req.APIKeys)...)
229 if req.Settings.Bedrock != nil &&
230 req.Type != AIProviderTypeAnthropic &&
231 req.Type != AIProviderTypeBedrock {
232 validations = append(validations, ValidationError{
233 Field: "settings",
234 Detail: "bedrock settings are only valid for type=anthropic or type=bedrock",
235 })
236 }
237 if req.Type == AIProviderTypeBedrock && (req.Settings.Bedrock == nil || !req.Settings.Bedrock.IsConfigured()) {
238 validations = append(validations, ValidationError{
239 Field: "settings",
240 Detail: "type=bedrock requires bedrock settings",
241 })
242 }
243 if req.Type == AIProviderTypeBedrock && len(req.APIKeys) > 0 {
244 validations = append(validations, ValidationError{
245 Field: "api_keys",
246 Detail: "type=bedrock does not accept api_keys",
247 })
248 }
249 if req.Type == AIProviderTypeCopilot && len(req.APIKeys) > 0 {
250 validations = append(validations, ValidationError{
251 Field: "api_keys",
252 Detail: "type=copilot does not accept api_keys",
253 })
254 }
255 return validations
256}
257
258// UpdateAIProviderRequest is the payload for partially updating an
259// AI provider. At least one field must be non-nil. Pointer fields

Callers 1

aiProvidersCreateMethod · 0.95

Calls 4

validateAIProviderNameFunction · 0.85
IsConfiguredMethod · 0.80

Tested by

no test coverage detected