Skip to content

Commit

Permalink
experiment
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic BIDON <[email protected]>
  • Loading branch information
fredbi committed Feb 28, 2024
1 parent 908a79b commit aac9b3f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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))

Check warning on line 688 in spec.go

View check run for this annotation

Codecov / codecov/patch

spec.go#L688

Added line #L688 was not covered by tests
}

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(&paramSchema, 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))
Expand Down

0 comments on commit aac9b3f

Please sign in to comment.