Debian Codegraph @

errors/urlencoded_errors.go

raw
1 package errors
2
3 import (
4 "fmt"
5
6 "github.com/pb33f/libopenapi-validator/helpers"
7 "github.com/pb33f/libopenapi/datamodel/high/base"
8 )
9
10 func InvalidURLEncodedParsing(reason, referenceObject string) *ValidationError {
11 return &ValidationError{
12 ValidationType: helpers.URLEncodedValidation,
13 ValidationSubType: helpers.Schema,
14 Message: "Unable to parse form-urlencoded body",
15 Reason: fmt.Sprintf("failed to parse form-urlencoded: %s", reason),
16 SchemaValidationErrors: []*SchemaValidationFailure{{
17 Reason: reason,
18 ReferenceSchema: "",
19 ReferenceObject: referenceObject,
20 }},
21 HowToFix: HowToFixInvalidUrlEncoded,
22 }
23 }
24
25 func InvalidTypeEncoding(schema *base.Schema, name, contentType string) *ValidationError {
26 line := 1
27 col := 0
28 if low := schema.GoLow(); low != nil && low.Type.KeyNode != nil {
29 line = low.Type.KeyNode.Line
30 col = low.Type.KeyNode.Column
31 }
32
33 return &ValidationError{
34 ValidationType: helpers.URLEncodedValidation,
35 ValidationSubType: helpers.InvalidTypeEncoding,
36 Message: fmt.Sprintf("The value '%s' could not be parsed to the defined encoding", name),
37 Reason: fmt.Sprintf("The value '%s' is encoded as '%s' in the schema, however the value could not be parsed", name, contentType),
38 SpecLine: line,
39 SpecCol: col,
40 Context: schema,
41 HowToFix: HowToFixInvalidTypeEncoding,
42 }
43 }
44
45 func ReservedURLEncodedValue(schema *base.Schema, name, value string) *ValidationError {
46 line := 1
47 col := 0
48 if schema != nil {
49 if low := schema.GoLow(); low != nil && low.Type.KeyNode != nil {
50 line = low.Type.KeyNode.Line
51 col = low.Type.KeyNode.Column
52 }
53 }
54
55 return &ValidationError{
56 ValidationType: helpers.URLEncodedValidation,
57 ValidationSubType: helpers.ReservedValues,
58 Message: fmt.Sprintf("Form value '%s' contains reserved characters", name),
59 Reason: fmt.Sprintf("The form value '%s' contains reserved characters but allowReserved is false. Value: '%s'", name, value),
60 SpecLine: line,
61 SpecCol: col,
62 Context: schema,
63 HowToFix: HowToFixFormDataReservedCharacters,
64 }
65 }