MCPcopy Create free account
hub / github.com/goadesign/goa / Validate

Method Validate

expr/http_endpoint.go:371–739  ·  view source on GitHub ↗

Validate validates the endpoint expression.

()

Source from the content-addressed store, hash-verified

369
370// Validate validates the endpoint expression.
371func (e *HTTPEndpointExpr) Validate() error {
372 verr := new(eval.ValidationErrors)
373 // Name cannot be empty
374 if e.Name() == "" {
375 verr.Add(e, "Endpoint name cannot be empty")
376 }
377
378 // SkipRequestBodyEncodeDecode is not compatible with gRPC or WebSocket
379 if e.SkipRequestBodyEncodeDecode {
380 if s := Root.API.GRPC.Service(e.Service.Name()); s != nil {
381 if s.Endpoint(e.Name()) != nil {
382 verr.Add(e, "Endpoint cannot use SkipRequestBodyEncodeDecode and define a gRPC transport.")
383 }
384 }
385 if e.MethodExpr.IsPayloadStreaming() {
386 verr.Add(e, "Endpoint cannot use SkipRequestBodyEncodeDecode when method defines a StreamingPayload.")
387 }
388 if e.MethodExpr.IsResultStreaming() {
389 verr.Add(e, "Endpoint cannot use SkipRequestBodyEncodeDecode when method defines a StreamingResult. Use SkipResponseBodyEncodeDecode instead.")
390 }
391 }
392
393 // SkipResponseBodyEncodeDecode is not compatible with gRPC or WebSocket.
394 if e.SkipResponseBodyEncodeDecode {
395 if s := Root.API.GRPC.Service(e.Service.Name()); s != nil {
396 if s.Endpoint(e.Name()) != nil {
397 verr.Add(e, "Endpoint response cannot use SkipResponseBodyEncodeDecode and define a gRPC transport.")
398 }
399 }
400 if e.MethodExpr.IsPayloadStreaming() {
401 verr.Add(e, "Endpoint cannot use SkipResponseBodyEncodeDecode when method defines a StreamingPayload. Use SkipRequestBodyEncodeDecode instead.")
402 }
403 if e.MethodExpr.IsResultStreaming() {
404 verr.Add(e, "Endpoint cannot use SkipResponseBodyEncodeDecode when method defines a StreamingResult.")
405 }
406 if rt, ok := e.MethodExpr.Result.Type.(*ResultTypeExpr); ok {
407 if len(rt.Views) > 1 {
408 verr.Add(e, "Endpoint cannot use SkipResponseBodyEncodeDecode when method result type defines multiple views.")
409 }
410 }
411 }
412
413 // Validate streaming endpoints for SSE compatibility
414 if e.MethodExpr.Stream == ServerStreamKind {
415 if e.SSE != nil {
416 if err := e.SSE.Validate(e.MethodExpr); err != nil {
417 var valErr *eval.ValidationErrors
418 if errors.As(err, &valErr) {
419 verr.Merge(valErr)
420 }
421 }
422 }
423 }
424
425 // Validate mixed results configuration
426 if e.MethodExpr.HasMixedResults() {
427 // Mixed results (different Result and StreamingResult types) requires SSE
428 if e.SSE == nil {

Callers

nothing calls this directly

Calls 15

NameMethod · 0.95
IsJSONRPCMethod · 0.95
validateParamsMethod · 0.95
hasJSONRPCIDFieldFunction · 0.85
IsObjectFunction · 0.85
IsArrayFunction · 0.85
IsPrimitiveFunction · 0.85
AsArrayFunction · 0.85
AsMapFunction · 0.85
IsMapFunction · 0.85
AsObjectFunction · 0.85

Tested by

no test coverage detected