From aac9b3f9120628005ce7a19dc389d65a2d8dd34b Mon Sep 17 00:00:00 2001 From: Frederic BIDON Date: Wed, 28 Feb 2024 19:16:40 +0100 Subject: [PATCH] experiment Signed-off-by: Frederic BIDON --- spec.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spec.go b/spec.go index 6ae2131..f1d3b51 100644 --- a/spec.go +++ b/spec.go @@ -71,7 +71,7 @@ func NewSpecValidator(schema *spec.Schema, formats strfmt.Registry) *SpecValidat for _, o := range []Option{ SwaggerSchema(true), WithRecycleValidators(true), - withRecycleResults(true), + // withRecycleResults(true), } { o(schemaOptions) } @@ -677,17 +677,19 @@ func (s *SpecValidator) validateParameters() *Result { // TODO: should be done after param expansion res.Merge(s.checkUniqueParams(path, method, op)) + // pick the root schema from the swagger specification which describes a parameter origSchema, ok := s.schema.Definitions["parameter"] if !ok { panic("unexpected swagger schema: missing #/definitions/parameter") } + // clone it once to avoid expanding a global schema (e.g. swagger spec) paramSchema, err := deepCloneSchema(origSchema) if err != nil { panic(fmt.Errorf("can't clone schema: %v", err)) } for _, pr := range paramHelp.safeExpandedParamsFor(path, method, op.ID, res, s) { - // An expanded parameter must validate its schema (an unexpanded $ref always passes high-level schema validation) + // An expanded parameter must validate the Parameter schema (an unexpanded $ref always passes high-level schema validation) schv := newSchemaValidator(¶mSchema, s.schema, fmt.Sprintf("%s.%s.parameters.%s", path, method, pr.Name), s.KnownFormats, s.schemaOptions) obj := swag.ToDynamicJSON(pr) res.Merge(schv.Validate(obj))