@@ -27,6 +27,25 @@ type exampleValidator struct {
2727 schemaOptions * SchemaValidatorOptions
2828}
2929
30+ // Validate validates the example values declared in the swagger spec
31+ // Example values MUST conform to their schema.
32+ //
33+ // With Swagger 2.0, examples are supported in:
34+ // - schemas
35+ // - individual property
36+ // - responses
37+ func (ex * exampleValidator ) Validate () * Result {
38+ errs := pools .poolOfResults .BorrowResult ()
39+
40+ if ex == nil || ex .SpecValidator == nil {
41+ return errs
42+ }
43+ ex .resetVisited ()
44+ errs .Merge (ex .validateExampleValueValidAgainstSchema ()) // error -
45+
46+ return errs
47+ }
48+
3049// resetVisited resets the internal state of visited schemas
3150func (ex * exampleValidator ) resetVisited () {
3251 if ex .visitedSchemas == nil {
@@ -51,25 +70,6 @@ func (ex *exampleValidator) isVisited(path string) bool {
5170 return isVisited (path , ex .visitedSchemas )
5271}
5372
54- // Validate validates the example values declared in the swagger spec
55- // Example values MUST conform to their schema.
56- //
57- // With Swagger 2.0, examples are supported in:
58- // - schemas
59- // - individual property
60- // - responses
61- func (ex * exampleValidator ) Validate () * Result {
62- errs := pools .poolOfResults .BorrowResult ()
63-
64- if ex == nil || ex .SpecValidator == nil {
65- return errs
66- }
67- ex .resetVisited ()
68- errs .Merge (ex .validateExampleValueValidAgainstSchema ()) // error -
69-
70- return errs
71- }
72-
7373func (ex * exampleValidator ) validateExampleValueValidAgainstSchema () * Result {
7474 // every example value that is specified must validate against the schema for that property
7575 // in: schemas, properties, object, items
@@ -278,7 +278,7 @@ func (ex *exampleValidator) validateExampleValueSchemaAgainstSchema(path, in str
278278// TODO: Temporary duplicated code. Need to refactor with examples
279279//
280280
281- func (ex * exampleValidator ) validateExampleValueItemsAgainstSchema (path , in string , root interface {} , items * spec.Items ) * Result {
281+ func (ex * exampleValidator ) validateExampleValueItemsAgainstSchema (path , in string , root any , items * spec.Items ) * Result {
282282 res := pools .poolOfResults .BorrowResult ()
283283 s := ex .SpecValidator
284284 if items != nil {
0 commit comments