MCPcopy Index your code
hub / github.com/oapi-codegen/oapi-codegen / TestUsedAndUndeclaredVariables

Function TestUsedAndUndeclaredVariables

pkg/codegen/server_urls_test.go:40–62  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

38}
39
40func TestUsedAndUndeclaredVariables(t *testing.T) {
41 srv := ServerObjectDefinition{
42 GoName: "ServerUrlExample",
43 OAPISchema: &openapi3.Server{
44 URL: "https://{host}.example.com:{port}/{path}",
45 Variables: map[string]*openapi3.ServerVariable{
46 "host": {Default: "demo"},
47 "port": {Default: "443", Enum: []string{"443", "8443"}},
48 "unused": {Default: "x"}, // declared, but not referenced in URL
49 // "path" is referenced in URL but not declared
50 },
51 },
52 }
53
54 used := srv.UsedVariables()
55 assert.Len(t, used, 2)
56 assert.Contains(t, used, "host")
57 assert.Contains(t, used, "port")
58 assert.NotContains(t, used, "unused", "declared-but-unused must be filtered (#2004)")
59
60 undeclared := srv.UndeclaredPlaceholders()
61 assert.Equal(t, []string{"path"}, undeclared, "URL placeholder not in variables must be reported (#2005)")
62}
63
64// renderServerURLs parses the embedded templates and renders the
65// server-urls template for spec, mirroring the setup in Generate.

Callers

nothing calls this directly

Calls 3

UsedVariablesMethod · 0.95
LenMethod · 0.45

Tested by

no test coverage detected