(t *testing.T)
| 107 | } |
| 108 | |
| 109 | func TestPruningUnusedComponents(t *testing.T) { |
| 110 | // Get a spec from the test definition in this file: |
| 111 | swagger, err := openapi3.NewLoader().LoadFromData([]byte(pruneComprehensiveTestFixture)) |
| 112 | assert.NoError(t, err) |
| 113 | |
| 114 | assert.Len(t, swagger.Components.Schemas, 8) |
| 115 | assert.Len(t, swagger.Components.Parameters, 1) |
| 116 | assert.Len(t, swagger.Components.SecuritySchemes, 2) |
| 117 | assert.Len(t, swagger.Components.RequestBodies, 1) |
| 118 | assert.Len(t, swagger.Components.Responses, 2) |
| 119 | assert.Len(t, swagger.Components.Headers, 3) |
| 120 | assert.Len(t, swagger.Components.Examples, 1) |
| 121 | assert.Len(t, swagger.Components.Links, 1) |
| 122 | assert.Len(t, swagger.Components.Callbacks, 1) |
| 123 | |
| 124 | pruneUnusedComponents(swagger) |
| 125 | |
| 126 | assert.Len(t, swagger.Components.Schemas, 0) |
| 127 | assert.Len(t, swagger.Components.Parameters, 0) |
| 128 | // securitySchemes are an exception. definitions in securitySchemes |
| 129 | // are referenced directly by name. and not by $ref |
| 130 | assert.Len(t, swagger.Components.SecuritySchemes, 2) |
| 131 | assert.Len(t, swagger.Components.RequestBodies, 0) |
| 132 | assert.Len(t, swagger.Components.Responses, 0) |
| 133 | assert.Len(t, swagger.Components.Headers, 0) |
| 134 | assert.Len(t, swagger.Components.Examples, 0) |
| 135 | assert.Len(t, swagger.Components.Links, 0) |
| 136 | assert.Len(t, swagger.Components.Callbacks, 0) |
| 137 | } |
| 138 | |
| 139 | const pruneComprehensiveTestFixture = ` |
| 140 | openapi: 3.0.1 |
nothing calls this directly
no test coverage detected