cuelang.org/go@v0.13.0/encoding/jsonschema/constraints_string.go (about) 1 // Copyright 2019 CUE Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package jsonschema 16 17 import ( 18 "cuelang.org/go/cue" 19 "cuelang.org/go/cue/ast" 20 "cuelang.org/go/cue/token" 21 ) 22 23 // String constraints 24 25 func constraintContentEncoding(key string, n cue.Value, s *state) { 26 // TODO: only mark as used if it generates something. 27 // 7bit, 8bit, binary, quoted-printable and base64. 28 // RFC 2054, part 6.1. 29 // https://tools.ietf.org/html/rfc2045 30 // TODO: at least handle bytes. 31 } 32 33 func constraintContentMediaType(key string, n cue.Value, s *state) { 34 // TODO: only mark as used if it generates something. 35 } 36 37 func constraintMaxLength(key string, n cue.Value, s *state) { 38 max := s.uint(n) 39 strings := s.addImport(n, "strings") 40 s.add(n, stringType, ast.NewCall(ast.NewSel(strings, "MaxRunes"), max)) 41 } 42 43 func constraintMinLength(key string, n cue.Value, s *state) { 44 min := s.uint(n) 45 strings := s.addImport(n, "strings") 46 s.add(n, stringType, ast.NewCall(ast.NewSel(strings, "MinRunes"), min)) 47 } 48 49 func constraintPattern(key string, n cue.Value, s *state) { 50 str, ok := s.regexpValue(n) 51 if !ok { 52 return 53 } 54 s.add(n, stringType, &ast.UnaryExpr{Op: token.MAT, X: str}) 55 }