|
1 | 1 | package openapi3filter |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "bytes" |
5 | | - "encoding/json" |
6 | | - "net/http" |
7 | | - "testing" |
| 4 | + "bytes" |
| 5 | + "encoding/json" |
| 6 | + "net/http" |
| 7 | + "testing" |
8 | 8 |
|
9 | | - "github.com/getkin/kin-openapi/openapi3" |
10 | | - "github.com/stretchr/testify/require" |
| 9 | + "github.com/getkin/kin-openapi/openapi3" |
| 10 | + "github.com/stretchr/testify/require" |
11 | 11 | ) |
12 | 12 |
|
13 | 13 | func TestValidatingRequestBodyWithReadOnlyProperty(t *testing.T) { |
14 | | - const spec = `{ |
| 14 | + const spec = `{ |
15 | 15 | "openapi": "3.0.3", |
16 | 16 | "info": { |
17 | 17 | "version": "1.0.0", |
@@ -60,32 +60,32 @@ func TestValidatingRequestBodyWithReadOnlyProperty(t *testing.T) { |
60 | 60 | } |
61 | 61 | ` |
62 | 62 |
|
63 | | - type Request struct { |
64 | | - ID string `json:"_id"` |
65 | | - } |
| 63 | + type Request struct { |
| 64 | + ID string `json:"_id"` |
| 65 | + } |
66 | 66 |
|
67 | | - sl := openapi3.NewSwaggerLoader() |
68 | | - l, err := sl.LoadSwaggerFromData([]byte(spec)) |
69 | | - require.NoError(t, err) |
70 | | - router := NewRouter().WithSwagger(l) |
| 67 | + sl := openapi3.NewSwaggerLoader() |
| 68 | + l, err := sl.LoadSwaggerFromData([]byte(spec)) |
| 69 | + require.NoError(t, err) |
| 70 | + router := NewRouter().WithSwagger(l) |
71 | 71 |
|
72 | | - err = l.CompileSchemas() |
73 | | - require.NoError(t, err) |
| 72 | + err = l.CompileSchemas() |
| 73 | + require.NoError(t, err) |
74 | 74 |
|
75 | | - b, err := json.Marshal(Request{ID: "bt6kdc3d0cvp6u8u3ft0"}) |
76 | | - require.NoError(t, err) |
| 75 | + b, err := json.Marshal(Request{ID: "bt6kdc3d0cvp6u8u3ft0"}) |
| 76 | + require.NoError(t, err) |
77 | 77 |
|
78 | | - httpReq, err := http.NewRequest(http.MethodPost, "/accounts", bytes.NewReader(b)) |
79 | | - require.NoError(t, err) |
80 | | - httpReq.Header.Add("Content-Type", "application/json") |
| 78 | + httpReq, err := http.NewRequest(http.MethodPost, "/accounts", bytes.NewReader(b)) |
| 79 | + require.NoError(t, err) |
| 80 | + httpReq.Header.Add("Content-Type", "application/json") |
81 | 81 |
|
82 | | - route, pathParams, err := router.FindRoute(httpReq.Method, httpReq.URL) |
83 | | - require.NoError(t, err) |
| 82 | + route, pathParams, err := router.FindRoute(httpReq.Method, httpReq.URL) |
| 83 | + require.NoError(t, err) |
84 | 84 |
|
85 | | - err = ValidateRequest(sl.Context, &RequestValidationInput{ |
86 | | - Request: httpReq, |
87 | | - PathParams: pathParams, |
88 | | - Route: route, |
89 | | - }) |
90 | | - require.NoError(t, err) |
| 85 | + err = ValidateRequest(sl.Context, &RequestValidationInput{ |
| 86 | + Request: httpReq, |
| 87 | + PathParams: pathParams, |
| 88 | + Route: route, |
| 89 | + }) |
| 90 | + require.NoError(t, err) |
91 | 91 | } |
0 commit comments