File tree Expand file tree Collapse file tree 4 files changed +42
-6
lines changed Expand file tree Collapse file tree 4 files changed +42
-6
lines changed Original file line number Diff line number Diff line change @@ -1722,11 +1722,8 @@ func (err *SchemaError) Error() string {
17221722 }
17231723 }
17241724
1725- if err .Origin != nil {
1726- return err .Origin .Error ()
1727- }
1728-
17291725 buf := bytes .NewBuffer (make ([]byte , 0 , 256 ))
1726+
17301727 if len (err .reversePath ) > 0 {
17311728 buf .WriteString (`Error at "` )
17321729 reversePath := err .reversePath
@@ -1736,6 +1733,13 @@ func (err *SchemaError) Error() string {
17361733 }
17371734 buf .WriteString (`": ` )
17381735 }
1736+
1737+ if err .Origin != nil {
1738+ buf .WriteString (err .Origin .Error ())
1739+
1740+ return buf .String ()
1741+ }
1742+
17391743 reason := err .Reason
17401744 if reason == "" {
17411745 buf .WriteString (`Doesn't match schema "` )
@@ -1744,6 +1748,7 @@ func (err *SchemaError) Error() string {
17441748 } else {
17451749 buf .WriteString (reason )
17461750 }
1751+
17471752 if ! SchemaErrorDetailsDisabled {
17481753 buf .WriteString ("\n Schema:\n " )
17491754 encoder := json .NewEncoder (buf )
@@ -1756,6 +1761,7 @@ func (err *SchemaError) Error() string {
17561761 panic (err )
17571762 }
17581763 }
1764+
17591765 return buf .String ()
17601766}
17611767
Original file line number Diff line number Diff line change @@ -75,3 +75,33 @@ func TestFormatCallback_WrapError(t *testing.T) {
7575
7676 delete (SchemaStringFormats , "foobar" )
7777}
78+
79+ func TestReversePathInMessageSchemaError (t * testing.T ) {
80+ DefineIPv4Format ()
81+
82+ SchemaErrorDetailsDisabled = true
83+
84+ const spc = `
85+ components:
86+ schemas:
87+ Something:
88+ type: object
89+ properties:
90+ ip:
91+ type: string
92+ format: ipv4
93+ `
94+ l := NewLoader ()
95+
96+ doc , err := l .LoadFromData ([]byte (spc ))
97+ require .NoError (t , err )
98+
99+ err = doc .Components .Schemas ["Something" ].Value .VisitJSON (map [string ]interface {}{
100+ `ip` : `123.0.0.11111` ,
101+ })
102+
103+ require .EqualError (t , err , `Error at "/ip": Not an IP address` )
104+
105+ delete (SchemaStringFormats , "ipv4" )
106+ SchemaErrorDetailsDisabled = false
107+ }
Original file line number Diff line number Diff line change @@ -35,5 +35,5 @@ openapi: "3.0.1"
3535 "name" : "kin-openapi" ,
3636 "address" : "127.0.0.1" ,
3737 })
38- require .EqualError (t , err , ErrOneOfConflict . Error () )
38+ require .ErrorIs (t , err , ErrOneOfConflict )
3939}
Original file line number Diff line number Diff line change 7272 name : "failed allof object array" ,
7373 spec : allOfArraySpec ,
7474 req : `/items?test=1.2,3.1` ,
75- errStr : `parameter "test" in query has an error: Value must be an integer` ,
75+ errStr : `parameter "test" in query has an error: Error at "/0": Value must be an integer` ,
7676 },
7777 {
7878 name : "success oneof object array" ,
You can’t perform that action at this time.
0 commit comments