(t *testing.T)
| 38 | } |
| 39 | |
| 40 | func 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. |
nothing calls this directly
no test coverage detected