@@ -11,12 +11,14 @@ import (
1111// StrictValidationType is the validation type for strict mode errors.
1212const StrictValidationType = "strict"
1313
14- // StrictValidationSubTypes for different kinds of undeclared values .
14+ // StrictValidationSubTypes for different kinds of strict validation errors .
1515const (
16- StrictSubTypeProperty = "undeclared-property"
17- StrictSubTypeHeader = "undeclared-header"
18- StrictSubTypeQuery = "undeclared-query-param"
19- StrictSubTypeCookie = "undeclared-cookie"
16+ StrictSubTypeProperty = "undeclared-property"
17+ StrictSubTypeHeader = "undeclared-header"
18+ StrictSubTypeQuery = "undeclared-query-param"
19+ StrictSubTypeCookie = "undeclared-cookie"
20+ StrictSubTypeReadOnlyProperty = "readonly-property"
21+ StrictSubTypeWriteOnlyProperty = "writeonly-property"
2022)
2123
2224// UndeclaredPropertyError creates a ValidationError for an undeclared property.
@@ -132,6 +134,62 @@ func UndeclaredCookieError(
132134 }
133135}
134136
137+ // ReadOnlyPropertyError creates a ValidationError for a readOnly property in a request.
138+ func ReadOnlyPropertyError (
139+ path string ,
140+ name string ,
141+ value any ,
142+ requestPath string ,
143+ requestMethod string ,
144+ specLine int ,
145+ specCol int ,
146+ ) * ValidationError {
147+ return & ValidationError {
148+ ValidationType : StrictValidationType ,
149+ ValidationSubType : StrictSubTypeReadOnlyProperty ,
150+ Message : fmt .Sprintf ("request property '%s' at '%s' is readOnly and should not be sent in the request" ,
151+ name , path ),
152+ Reason : fmt .Sprintf ("Strict mode: property '%s' is marked readOnly in the schema" ,
153+ name ),
154+ HowToFix : fmt .Sprintf ("Remove the readOnly annotation from '%s' in the schema, " +
155+ "remove it from the request, or add '%s' to StrictIgnorePaths" , name , path ),
156+ RequestPath : requestPath ,
157+ RequestMethod : requestMethod ,
158+ ParameterName : name ,
159+ Context : truncateForContext (value ),
160+ SpecLine : specLine ,
161+ SpecCol : specCol ,
162+ }
163+ }
164+
165+ // WriteOnlyPropertyError creates a ValidationError for a writeOnly property in a response.
166+ func WriteOnlyPropertyError (
167+ path string ,
168+ name string ,
169+ value any ,
170+ requestPath string ,
171+ requestMethod string ,
172+ specLine int ,
173+ specCol int ,
174+ ) * ValidationError {
175+ return & ValidationError {
176+ ValidationType : StrictValidationType ,
177+ ValidationSubType : StrictSubTypeWriteOnlyProperty ,
178+ Message : fmt .Sprintf ("response property '%s' at '%s' is writeOnly and should not be returned in the response" ,
179+ name , path ),
180+ Reason : fmt .Sprintf ("Strict mode: property '%s' is marked writeOnly in the schema" ,
181+ name ),
182+ HowToFix : fmt .Sprintf ("Remove the writeOnly annotation from '%s' in the schema, " +
183+ "remove it from the response, or add '%s' to StrictIgnorePaths" , name , path ),
184+ RequestPath : requestPath ,
185+ RequestMethod : requestMethod ,
186+ ParameterName : name ,
187+ Context : truncateForContext (value ),
188+ SpecLine : specLine ,
189+ SpecCol : specCol ,
190+ }
191+ }
192+
135193// truncateForContext creates a truncated string representation for error context.
136194func truncateForContext (v any ) string {
137195 switch val := v .(type ) {
0 commit comments