Skip to content

Commit c931cc8

Browse files
committed
fixup! feat: Add code generation and fix double-slash URL path bug(#804)
Signed-off-by: Sean Chittenden <sean.chittenden@crowdstrike.com>
1 parent eedccfc commit c931cc8

5 files changed

Lines changed: 25 additions & 20 deletions

File tree

cmd/osgen/emit/format_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package emit_test
88

99
import (
10+
"net/http"
1011
"testing"
1112

1213
"github.com/stretchr/testify/require"
@@ -85,7 +86,7 @@ func TestMethodComment(t *testing.T) {
8586
MethodName: "GetRole",
8687
Group: "security.get_role",
8788
Description: "Retrieves one role.",
88-
HTTPMethods: []string{"GET"},
89+
HTTPMethods: []string{http.MethodGet},
8990
PrimaryPath: "/_plugins/_security/api/roles/{role}",
9091
VersionAdded: "1.0.0",
9192
ExcludedDistros: []string{"amazon-managed", "amazon-serverless"},
@@ -104,7 +105,7 @@ func TestMethodComment(t *testing.T) {
104105
data: emit.MethodDocData{
105106
MethodName: "Health",
106107
Group: "security.health",
107-
HTTPMethods: []string{"GET"},
108+
HTTPMethods: []string{http.MethodGet},
108109
PrimaryPath: "/_plugins/_security/health",
109110
},
110111
checks: []string{
@@ -118,7 +119,7 @@ func TestMethodComment(t *testing.T) {
118119
MethodName: "Search",
119120
Group: "search",
120121
Description: "Returns results matching a query.",
121-
HTTPMethods: []string{"GET", "POST"},
122+
HTTPMethods: []string{http.MethodGet, http.MethodPost},
122123
PrimaryPath: "/{index}/_search",
123124
},
124125
checks: []string{
@@ -133,7 +134,7 @@ func TestMethodComment(t *testing.T) {
133134
MethodName: "OldGet",
134135
Group: "old.get",
135136
Description: "Fetches a resource.",
136-
HTTPMethods: []string{"GET"},
137+
HTTPMethods: []string{http.MethodGet},
137138
PrimaryPath: "/old/{id}",
138139
VersionAdded: "1.0",
139140
VersionDeprecated: "2.0",
@@ -162,7 +163,7 @@ func TestMethodComment(t *testing.T) {
162163
Group: "create",
163164
Description: "Creates a new document in the index.\n\n" +
164165
"Returns a 409 response when a document with a same ID already exists in the index.",
165-
HTTPMethods: []string{"PUT"},
166+
HTTPMethods: []string{http.MethodPut},
166167
PrimaryPath: "/{index}/_create/{id}",
167168
VersionAdded: "1.0",
168169
},

cmd/osgen/emit/frag_req_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package emit_test
88

99
import (
10+
"net/http"
1011
"strings"
1112
"testing"
1213

@@ -23,7 +24,7 @@ func TestReqFragment_SimpleOp(t *testing.T) {
2324
Group: "cluster.health",
2425
TypePrefix: "ClusterHealth",
2526
Description: "Returns cluster health.",
26-
HTTPMethods: []string{"GET"},
27+
HTTPMethods: []string{http.MethodGet},
2728
PrimaryPath: "/_cluster/health",
2829
PathBuilder: ir.PathBuilder{StructName: "ClusterHealthPath"},
2930
}
@@ -47,7 +48,7 @@ func TestReqFragment_WithBodyAndPathFields(t *testing.T) {
4748
Group: "index",
4849
TypePrefix: "Index",
4950
Description: "Indexes a document.",
50-
HTTPMethods: []string{"PUT", "POST"},
51+
HTTPMethods: []string{http.MethodPut, http.MethodPost},
5152
PrimaryPath: "/{index}/_doc/{id}",
5253
HasBody: true,
5354
PathFields: []ir.PathField{
@@ -79,7 +80,7 @@ func TestReqFragment_WithTypedBody(t *testing.T) {
7980
Group: "ml.register_model",
8081
TypePrefix: "MlRegisterModel",
8182
Description: "Registers a model.",
82-
HTTPMethods: []string{"POST"},
83+
HTTPMethods: []string{http.MethodPost},
8384
PrimaryPath: "/_plugins/_ml/models/_register",
8485
HasBody: true,
8586
HasTypedBody: true,
@@ -200,7 +201,7 @@ func TestFileAssembly_ReqAndParams(t *testing.T) {
200201
Group: "cluster.health",
201202
TypePrefix: "ClusterHealth",
202203
Description: "Returns cluster health.",
203-
HTTPMethods: []string{"GET"},
204+
HTTPMethods: []string{http.MethodGet},
204205
PrimaryPath: "/_cluster/health",
205206
PathBuilder: ir.PathBuilder{StructName: "ClusterHealthPath"},
206207
QueryParams: []ir.QueryParam{

cmd/osgen/emit/frag_resp_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package emit_test
88

99
import (
10+
"net/http"
1011
"testing"
1112

1213
"github.com/stretchr/testify/require"
@@ -120,7 +121,7 @@ func TestDispatchFragment(t *testing.T) {
120121
IsPointerReq: true,
121122
HasBody: true,
122123
HasTypedBody: true,
123-
HTTPMethods: []string{"GET", "POST"},
124+
HTTPMethods: []string{http.MethodGet, http.MethodPost},
124125
DispatchRoutes: []ir.DispatchRoute{
125126
{ReceiverType: "Client", MethodName: "Search", TopLevel: true},
126127
},
@@ -144,7 +145,7 @@ func TestDispatchFragment(t *testing.T) {
144145
IsPointerReq: false,
145146
HasBody: true,
146147
HasTypedBody: true,
147-
HTTPMethods: []string{"POST"},
148+
HTTPMethods: []string{http.MethodPost},
148149
DispatchRoutes: []ir.DispatchRoute{
149150
{ReceiverType: "Client", MethodName: "Bulk", TopLevel: true},
150151
},

cmd/osgen/emit/frag_tests_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package emit_test
88

99
import (
10+
"net/http"
1011
"testing"
1112

1213
"github.com/stretchr/testify/require"
@@ -90,7 +91,7 @@ func TestReqTestFragment_Body(t *testing.T) {
9091
ImportPath: ir.DefaultCoreImportPath,
9192
TypePrefix: "ClusterHealth",
9293
Cases: []emit.ReqTestCase{
93-
{Name: "empty request", WantMethod: "GET", WantPath: "/_cluster/health", WantErr: "false"},
94+
{Name: "empty request", WantMethod: http.MethodGet, WantPath: "/_cluster/health", WantErr: "false"},
9495
},
9596
}
9697

@@ -183,7 +184,7 @@ func TestReqTestFile_BlackBox(t *testing.T) {
183184
PkgName: ir.DefaultCorePkgName,
184185
ImportPath: ir.DefaultCoreImportPath,
185186
TypePrefix: "ClusterHealth",
186-
Cases: []emit.ReqTestCase{{Name: "empty", WantMethod: "GET", WantPath: "/", WantErr: "false"}},
187+
Cases: []emit.ReqTestCase{{Name: "empty", WantMethod: http.MethodGet, WantPath: "/", WantErr: "false"}},
187188
}
188189

189190
target := &emit.File{

cmd/osgen/paths_group_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package main
88

99
import (
10+
"net/http"
1011
"testing"
1112

1213
"github.com/getkin/kin-openapi/openapi3"
@@ -298,7 +299,7 @@ func TestExpandUnionPaths(t *testing.T) {
298299
return pathVariant{
299300
path: path,
300301
pathParams: append([]string(nil), params...),
301-
methods: map[string]struct{}{"GET": {}},
302+
methods: map[string]struct{}{http.MethodGet: {}},
302303
arrayParams: map[string]bool{},
303304
}
304305
}
@@ -429,18 +430,18 @@ func TestExpandUnionPaths_DeepCopiesMaps(t *testing.T) {
429430
original := pathVariant{
430431
path: "/_nodes/{node_id_or_metric}",
431432
pathParams: []string{"node_id_or_metric"},
432-
methods: map[string]struct{}{"GET": {}},
433+
methods: map[string]struct{}{http.MethodGet: {}},
433434
arrayParams: map[string]bool{"node_id_or_metric": true},
434435
}
435436
g := opGroup{
436437
name: "nodes.info",
437438
pathSpecs: []pathVariant{
438-
{path: "/_nodes", methods: map[string]struct{}{"GET": {}}},
439+
{path: "/_nodes", methods: map[string]struct{}{http.MethodGet: {}}},
439440
original,
440441
{
441442
path: "/_nodes/{node_id}/{metric}",
442443
pathParams: []string{"node_id", "metric"},
443-
methods: map[string]struct{}{"GET": {}},
444+
methods: map[string]struct{}{http.MethodGet: {}},
444445
arrayParams: map[string]bool{},
445446
},
446447
},
@@ -465,7 +466,7 @@ func TestExpandUnionPaths_DeepCopiesMaps(t *testing.T) {
465466
require.NotNil(t, syn1, "expected /_nodes/{node_id} synthetic variant")
466467
require.NotNil(t, syn2, "expected /_nodes/{metric} synthetic variant")
467468

468-
syn1.methods["POST"] = struct{}{}
469-
require.NotContains(t, syn2.methods, "POST", "synthetic variants share no method map")
470-
require.NotContains(t, original.methods, "POST", "synthetic mutation leaked into original")
469+
syn1.methods[http.MethodPost] = struct{}{}
470+
require.NotContains(t, syn2.methods, http.MethodPost, "synthetic variants share no method map")
471+
require.NotContains(t, original.methods, http.MethodPost, "synthetic mutation leaked into original")
471472
}

0 commit comments

Comments
 (0)