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

Function initAttributeValidation

http/codegen/openapi/json_schema.go:520–564  ·  view source on GitHub ↗

initAttributeValidation initializes validation rules for an attribute.

(s *Schema, at *expr.AttributeExpr)

Source from the content-addressed store, hash-verified

518
519// initAttributeValidation initializes validation rules for an attribute.
520func initAttributeValidation(s *Schema, at *expr.AttributeExpr) {
521 val := at.Validation
522 if val == nil {
523 return
524 }
525 s.Enum = val.Values
526 if val.Format != "" {
527 s.Format = string(val.Format)
528 }
529 s.Pattern = val.Pattern
530 if val.ExclusiveMinimum != nil {
531 s.ExclusiveMinimum = val.ExclusiveMinimum
532 }
533 if val.Minimum != nil {
534 s.Minimum = val.Minimum
535 }
536 if val.ExclusiveMaximum != nil {
537 s.ExclusiveMaximum = val.ExclusiveMaximum
538 }
539 if val.Maximum != nil {
540 s.Maximum = val.Maximum
541 }
542 if val.MinLength != nil {
543 if _, ok := at.Type.(*expr.Array); ok {
544 s.MinItems = val.MinLength
545 } else {
546 s.MinLength = val.MinLength
547 }
548 }
549 if val.MaxLength != nil {
550 if _, ok := at.Type.(*expr.Array); ok {
551 s.MaxItems = val.MaxLength
552 } else {
553 s.MaxLength = val.MaxLength
554 }
555 }
556 for _, v := range val.Required {
557 if a := at.Find(v); a != nil {
558 if !MustGenerate(a.Meta) {
559 continue
560 }
561 }
562 s.Required = append(s.Required, v)
563 }
564}
565
566// toSchemaHrefs produces hrefs that replace the path wildcards with JSON
567// schema references when appropriate.

Callers 2

buildAttributeSchemaFunction · 0.85

Calls 2

MustGenerateFunction · 0.85
FindMethod · 0.80

Tested by

no test coverage detected