@@ -16,95 +16,24 @@ package middleware
1616
1717import (
1818 "context"
19+ _ "embed"
1920 "errors"
2021 "net/http"
2122 "net/http/httptest"
2223 "net/url"
2324 "testing"
2425
25- "github.com/deepmap/oapi-codegen/pkg/testutil"
2626 "github.com/getkin/kin-openapi/openapi3"
2727 "github.com/getkin/kin-openapi/openapi3filter"
2828 "github.com/gin-gonic/gin"
2929 "github.com/stretchr/testify/assert"
3030 "github.com/stretchr/testify/require"
31+
32+ "github.com/deepmap/oapi-codegen/pkg/testutil"
3133)
3234
33- var testSchema = `openapi: "3.0.0"
34- info:
35- version: 1.0.0
36- title: TestServer
37- servers:
38- - url: http://deepmap.ai/
39- paths:
40- /resource:
41- get:
42- operationId: getResource
43- parameters:
44- - name: id
45- in: query
46- schema:
47- type: integer
48- minimum: 10
49- maximum: 100
50- responses:
51- '200':
52- description: success
53- content:
54- application/json:
55- schema:
56- properties:
57- name:
58- type: string
59- id:
60- type: integer
61- post:
62- operationId: createResource
63- responses:
64- '204':
65- description: No content
66- requestBody:
67- required: true
68- content:
69- application/json:
70- schema:
71- properties:
72- name:
73- type: string
74- /protected_resource:
75- get:
76- operationId: getProtectedResource
77- security:
78- - BearerAuth:
79- - someScope
80- responses:
81- '204':
82- description: no content
83- /protected_resource2:
84- get:
85- operationId: getProtectedResource
86- security:
87- - BearerAuth:
88- - otherScope
89- responses:
90- '204':
91- description: no content
92- /protected_resource_401:
93- get:
94- operationId: getProtectedResource
95- security:
96- - BearerAuth:
97- - unauthorized
98- responses:
99- '401':
100- description: no content
101- components:
102- securitySchemes:
103- BearerAuth:
104- type: http
105- scheme: bearer
106- bearerFormat: JWT
107- `
35+ //go:embed test_spec.yaml
36+ var testSchema []byte
10837
10938func doGet (t * testing.T , handler http.Handler , rawURL string ) * httptest.ResponseRecorder {
11039 u , err := url .Parse (rawURL )
@@ -127,7 +56,7 @@ func doPost(t *testing.T, handler http.Handler, rawURL string, jsonBody interfac
12756}
12857
12958func TestOapiRequestValidator (t * testing.T ) {
130- swagger , err := openapi3 .NewLoader ().LoadFromData ([] byte ( testSchema ) )
59+ swagger , err := openapi3 .NewLoader ().LoadFromData (testSchema )
13160 require .NoError (t , err , "Error initializing swagger" )
13261
13362 // Create a new echo router
0 commit comments