Debian Codegraph @

requests/request_body.go

raw
1 // Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
2 // SPDX-License-Identifier: MIT
3
4 package requests
5
6 import (
7 "net/http"
8
9 v3 "github.com/pb33f/libopenapi/datamodel/high/v3"
10
11 "github.com/pb33f/libopenapi-validator/config"
12 "github.com/pb33f/libopenapi-validator/errors"
13 )
14
15 // RequestBodyValidator is an interface that defines the methods for validating request bodies for Operations.
16 //
17 // ValidateRequestBodyWithPathItem method accepts an *http.Request and returns true if validation passed,
18 // false if validation failed and a slice of ValidationError pointers.
19 type RequestBodyValidator interface {
20 // ValidateRequestBody will validate the request body for an operation. The first return value will be true if the
21 // request body is valid, false if it is not. The second return value will be a slice of ValidationError pointers if
22 // the body is not valid.
23 ValidateRequestBody(request *http.Request) (bool, []*errors.ValidationError)
24
25 // ValidateRequestBodyWithPathItem will validate the request body for an operation. The first return value will be true if the
26 // request body is valid, false if it is not. The second return value will be a slice of ValidationError pointers if
27 // the body is not valid.
28 ValidateRequestBodyWithPathItem(request *http.Request, pathItem *v3.PathItem, pathValue string) (bool, []*errors.ValidationError)
29 }
30
31 // NewRequestBodyValidator will create a new RequestBodyValidator from an OpenAPI 3+ document
32 func NewRequestBodyValidator(document *v3.Document, opts ...config.Option) RequestBodyValidator {
33 options := config.NewValidationOptions(opts...)
34
35 return &requestBodyValidator{options: options, document: document}
36 }
37
38 type requestBodyValidator struct {
39 options *config.ValidationOptions
40 document *v3.Document
41 }