Skip to content

Commit

Permalink
Add schema to JSONSchemaValidator even without constraints other than…
Browse files Browse the repository at this point in the history
… type
  • Loading branch information
Leskodamus committed Jul 4, 2024
1 parent 54adc8b commit f3c5c46
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 4 additions & 4 deletions openapi/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func (c *Collector) ProvideRequestJSONSchemas(

r := c.Refl()

err := r.WalkRequestJSONSchemas(method, cu, c.jsonSchemaCallback(validator, r), func(oc openapi.OperationContext) {
err := r.WalkRequestJSONSchemas(method, cu, c.jsonSchemaCallback(validator), func(oc openapi.OperationContext) {
fv, ok := validator.(unknownFieldsValidator)
if !ok {
return
Expand Down Expand Up @@ -549,19 +549,19 @@ func (c *Collector) ProvideResponseJSONSchemas(
}

r := c.Refl()
err := r.WalkResponseJSONSchemas(cu, c.jsonSchemaCallback(validator, r), nil)
err := r.WalkResponseJSONSchemas(cu, c.jsonSchemaCallback(validator), nil)

return err
}

func (c *Collector) jsonSchemaCallback(validator rest.JSONSchemaValidator, r openapi.Reflector) openapi.JSONSchemaCallback {
func (c *Collector) jsonSchemaCallback(validator rest.JSONSchemaValidator) openapi.JSONSchemaCallback {
return func(in openapi.In, paramName string, schema *jsonschema.SchemaOrBool, required bool) error {
loc := string(in) + "." + paramName
if loc == "body.body" {
loc = "body"
}

if schema == nil || schema.IsTrivial(r.ResolveJSONSchemaRef) {
if schema == nil {
if err := validator.AddSchema(rest.ParamIn(in), paramName, nil, required); err != nil {
return fmt.Errorf("add validation schema %s: %w", loc, err)
}
Expand Down
4 changes: 1 addition & 3 deletions request/jsonbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ func decodeJSONBody(readJSON func(rd io.Reader, v interface{}) error, tolerateFo
return nil
}

var b *bytes.Buffer

b = bufPool.Get().(*bytes.Buffer) //nolint:errcheck // bufPool is configured to provide *bytes.Buffer.
b := bufPool.Get().(*bytes.Buffer) //nolint:errcheck // bufPool is configured to provide *bytes.Buffer.
defer bufPool.Put(b)
b.Reset()

Expand Down

0 comments on commit f3c5c46

Please sign in to comment.