Skip to content

Commit c662277

Browse files
authored
chore: Fix comments/imports (#789)
* Format yaml * Format imports * Fix comments * Format yamls * Tidy * Renames * Generate * Revert generated
1 parent e5ad496 commit c662277

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

oapi_validate.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21-
"os"
2221
"net/http"
22+
"os"
2323
"strings"
2424

2525
"github.com/getkin/kin-openapi/openapi3"
@@ -35,10 +35,9 @@ const (
3535
UserDataKey = "oapi-codegen/user-data"
3636
)
3737

38-
// This is an Echo middleware function which validates incoming HTTP requests
38+
// OapiValidatorFromYamlFile is an Echo middleware function which validates incoming HTTP requests
3939
// to make sure that they conform to the given OAPI 3.0 specification. When
4040
// OAPI validation fails on the request, we return an HTTP/400.
41-
4241
// Create validator middleware from a YAML file path
4342
func OapiValidatorFromYamlFile(path string) (echo.MiddlewareFunc, error) {
4443
data, err := os.ReadFile(path)
@@ -54,7 +53,7 @@ func OapiValidatorFromYamlFile(path string) (echo.MiddlewareFunc, error) {
5453
return OapiRequestValidator(swagger), nil
5554
}
5655

57-
// Create a validator from a swagger object.
56+
// OapiRequestValidator creates a validator from a swagger object.
5857
func OapiRequestValidator(swagger *openapi3.T) echo.MiddlewareFunc {
5958
return OapiRequestValidatorWithOptions(swagger, nil)
6059
}
@@ -183,7 +182,7 @@ func ValidateRequestFromContext(ctx echo.Context, router routers.Router, options
183182
return nil
184183
}
185184

186-
// Helper function to get the echo context from within requests. It returns
185+
// GetEchoContext gets the echo context from within requests. It returns
187186
// nil if not found or wrong type.
188187
func GetEchoContext(c context.Context) echo.Context {
189188
iface := c.Value(EchoContextKey)

oapi_validate_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,13 @@ import (
2424
"net/url"
2525
"testing"
2626

27+
"github.com/deepmap/oapi-codegen/pkg/testutil"
2728
"github.com/getkin/kin-openapi/openapi3"
2829
"github.com/getkin/kin-openapi/openapi3filter"
2930
"github.com/labstack/echo/v4"
3031
echomiddleware "github.com/labstack/echo/v4/middleware"
3132
"github.com/stretchr/testify/assert"
3233
"github.com/stretchr/testify/require"
33-
34-
"github.com/deepmap/oapi-codegen/pkg/testutil"
3534
)
3635

3736
//go:embed test_spec.yaml
@@ -208,7 +207,7 @@ func TestOapiRequestValidator(t *testing.T) {
208207
}
209208

210209
func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
211-
swagger, err := openapi3.NewLoader().LoadFromData([]byte(testSchema))
210+
swagger, err := openapi3.NewLoader().LoadFromData(testSchema)
212211
require.NoError(t, err, "Error initializing swagger")
213212

214213
// Create a new echo router
@@ -309,7 +308,7 @@ func TestOapiRequestValidatorWithOptionsMultiError(t *testing.T) {
309308
}
310309

311310
func TestOapiRequestValidatorWithOptionsMultiErrorAndCustomHandler(t *testing.T) {
312-
swagger, err := openapi3.NewLoader().LoadFromData([]byte(testSchema))
311+
swagger, err := openapi3.NewLoader().LoadFromData(testSchema)
313312
require.NoError(t, err, "Error initializing swagger")
314313

315314
// Create a new echo router

test_spec.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,15 @@ paths:
8686
maximum: 100
8787
responses:
8888
'200':
89-
description: success
90-
content:
91-
application/json:
92-
schema:
93-
properties:
94-
name:
95-
type: string
96-
id:
97-
type: integer
89+
description: success
90+
content:
91+
application/json:
92+
schema:
93+
properties:
94+
name:
95+
type: string
96+
id:
97+
type: integer
9898
components:
9999
securitySchemes:
100100
BearerAuth:

0 commit comments

Comments
 (0)