Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/dependabot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ updates:
patterns:
- "github.com/stretchr/testify"

golang.org-dependencies:
golang-org-dependencies:
patterns:
- "golang.org/*"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}

- name: Auto-merge dependabot PRs for golang.org updates
if: contains(steps.metadata.outputs.dependency-group, 'golang.org-dependencies')
if: contains(steps.metadata.outputs.dependency-group, 'golang-org-dependencies')
run: gh pr merge --auto --rebase "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
Expand Down
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ linters:
- gocognit
- godot
- godox
- gomoddirectives
- gosmopolitan
- inamedparam
- intrange # disabled while < go1.22
- ireturn
- lll
- musttag
- nestif
- nlreturn
- nonamedreturns
- noinlineerr
- paralleltest
- recvcheck
- testpackage
- thelper
- tparallel
Expand All @@ -31,6 +35,7 @@ linters:
- whitespace
- wrapcheck
- wsl
- wsl_v5
settings:
dupl:
threshold: 200
Expand Down Expand Up @@ -60,3 +65,12 @@ formatters:
- third_party$
- builtin$
- examples$
issues:
# Maximum issues count per one linter.
# Set to 0 to disable.
# Default: 50
max-issues-per-linter: 0
# Maximum count of issues with the same text.
# Set to 0 to disable.
# Default: 3
max-same-issues: 0
26 changes: 13 additions & 13 deletions default_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ type defaultValidator struct {
schemaOptions *SchemaValidatorOptions
}

// Validate validates the default values declared in the swagger spec
func (d *defaultValidator) Validate() *Result {
errs := pools.poolOfResults.BorrowResult() // will redeem when merged

if d == nil || d.SpecValidator == nil {
return errs
}
d.resetVisited()
errs.Merge(d.validateDefaultValueValidAgainstSchema()) // error -
return errs
}

// resetVisited resets the internal state of visited schemas
func (d *defaultValidator) resetVisited() {
if d.visitedSchemas == nil {
Expand Down Expand Up @@ -82,18 +94,6 @@ func (d *defaultValidator) isVisited(path string) bool {
return isVisited(path, d.visitedSchemas)
}

// Validate validates the default values declared in the swagger spec
func (d *defaultValidator) Validate() *Result {
errs := pools.poolOfResults.BorrowResult() // will redeem when merged

if d == nil || d.SpecValidator == nil {
return errs
}
d.resetVisited()
errs.Merge(d.validateDefaultValueValidAgainstSchema()) // error -
return errs
}

func (d *defaultValidator) validateDefaultValueValidAgainstSchema() *Result {
// every default value that is specified must validate against the schema for that property
// headers, items, parameters, schema
Expand Down Expand Up @@ -285,7 +285,7 @@ func (d *defaultValidator) validateDefaultValueSchemaAgainstSchema(path, in stri

// TODO: Temporary duplicated code. Need to refactor with examples

func (d *defaultValidator) validateDefaultValueItemsAgainstSchema(path, in string, root interface{}, items *spec.Items) *Result {
func (d *defaultValidator) validateDefaultValueItemsAgainstSchema(path, in string, root any, items *spec.Items) *Result {
res := pools.poolOfResults.BorrowResult()
s := d.SpecValidator
if items != nil {
Expand Down
40 changes: 20 additions & 20 deletions example_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,25 @@ type exampleValidator struct {
schemaOptions *SchemaValidatorOptions
}

// Validate validates the example values declared in the swagger spec
// Example values MUST conform to their schema.
//
// With Swagger 2.0, examples are supported in:
// - schemas
// - individual property
// - responses
func (ex *exampleValidator) Validate() *Result {
errs := pools.poolOfResults.BorrowResult()

if ex == nil || ex.SpecValidator == nil {
return errs
}
ex.resetVisited()
errs.Merge(ex.validateExampleValueValidAgainstSchema()) // error -

return errs
}

// resetVisited resets the internal state of visited schemas
func (ex *exampleValidator) resetVisited() {
if ex.visitedSchemas == nil {
Expand All @@ -51,25 +70,6 @@ func (ex *exampleValidator) isVisited(path string) bool {
return isVisited(path, ex.visitedSchemas)
}

// Validate validates the example values declared in the swagger spec
// Example values MUST conform to their schema.
//
// With Swagger 2.0, examples are supported in:
// - schemas
// - individual property
// - responses
func (ex *exampleValidator) Validate() *Result {
errs := pools.poolOfResults.BorrowResult()

if ex == nil || ex.SpecValidator == nil {
return errs
}
ex.resetVisited()
errs.Merge(ex.validateExampleValueValidAgainstSchema()) // error -

return errs
}

func (ex *exampleValidator) validateExampleValueValidAgainstSchema() *Result {
// every example value that is specified must validate against the schema for that property
// in: schemas, properties, object, items
Expand Down Expand Up @@ -278,7 +278,7 @@ func (ex *exampleValidator) validateExampleValueSchemaAgainstSchema(path, in str
// TODO: Temporary duplicated code. Need to refactor with examples
//

func (ex *exampleValidator) validateExampleValueItemsAgainstSchema(path, in string, root interface{}, items *spec.Items) *Result {
func (ex *exampleValidator) validateExampleValueItemsAgainstSchema(path, in string, root any, items *spec.Items) *Result {
res := pools.poolOfResults.BorrowResult()
s := ex.SpecValidator
if items != nil {
Expand Down
2 changes: 1 addition & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (h *paramHelper) checkExpandedParam(pr *spec.Parameter, path, in, operation
simpleZero := spec.SimpleSchema{}
// Try to explain why... best guess
switch {
case pr.In == swaggerBody && (pr.SimpleSchema != simpleZero && pr.SimpleSchema.Type != objectType):
case pr.In == swaggerBody && (pr.SimpleSchema != simpleZero && pr.Type != objectType):
if isRef {
// Most likely, a $ref with a sibling is an unwanted situation: in itself this is a warning...
// but we detect it because of the following error:
Expand Down
Loading
Loading