@@ -195,7 +195,7 @@ func TestFilterSchemasByName(t *testing.T) {
195195 require .NoError (t , err )
196196
197197 matcher := NewContentTypeMatcher (DefaultContentTypes ())
198- schemas , err := GatherSchemas (doc , matcher )
198+ schemas , err := GatherSchemas (doc , matcher , OutputOptions {} )
199199 require .NoError (t , err )
200200
201201 // Count component schemas
@@ -228,7 +228,7 @@ func TestFilterSchemasByName_Empty(t *testing.T) {
228228 require .NoError (t , err )
229229
230230 matcher := NewContentTypeMatcher (DefaultContentTypes ())
231- schemas , err := GatherSchemas (doc , matcher )
231+ schemas , err := GatherSchemas (doc , matcher , OutputOptions {} )
232232 require .NoError (t , err )
233233
234234 filtered := FilterSchemasByName (schemas , nil )
@@ -300,6 +300,74 @@ func TestFilterIntegration_GenerateWithExcludeSchemas(t *testing.T) {
300300 assert .NotContains (t , code , "type Pet struct" )
301301}
302302
303+ // TestFilterIntegration_IncludeTagsFiltersSchemas verifies that when include-tags is used,
304+ // only schemas referenced by the included operations are generated.
305+ // This is the behavioral test for https://github.com/oapi-codegen/oapi-codegen-exp/issues/3
306+ func TestFilterIntegration_IncludeTagsFiltersSchemas (t * testing.T ) {
307+ doc , err := libopenapi .NewDocument ([]byte (filterTestSpec ))
308+ require .NoError (t , err )
309+
310+ cfg := Configuration {
311+ PackageName : "testpkg" ,
312+ Generation : GenerationOptions {
313+ Client : true ,
314+ },
315+ OutputOptions : OutputOptions {
316+ IncludeTags : []string {"users" },
317+ PruneUnreferencedSchemas : true ,
318+ },
319+ }
320+
321+ code , err := Generate (doc , []byte (filterTestSpec ), cfg )
322+ require .NoError (t , err )
323+
324+ t .Logf ("Generated code:\n %s" , code )
325+
326+ // Operations: only ListUsers should be included
327+ assert .Contains (t , code , "ListUsers(ctx context.Context" )
328+ assert .NotContains (t , code , "ListPets(ctx context.Context" )
329+ assert .NotContains (t , code , "GetSettings(ctx context.Context" )
330+
331+ // Schemas: only User (used by listUsers) should be generated.
332+ // Pet and Settings are only used by excluded operations and should NOT be generated.
333+ assert .Contains (t , code , "type User struct" )
334+ assert .NotContains (t , code , "type Pet struct" , "Pet schema should not be generated when only 'users' tag is included" )
335+ assert .NotContains (t , code , "type Settings struct" , "Settings schema should not be generated when only 'users' tag is included" )
336+ }
337+
338+ // TestFilterIntegration_ExcludeTagsFiltersSchemas verifies that when exclude-tags is used,
339+ // schemas only referenced by excluded operations are not generated.
340+ func TestFilterIntegration_ExcludeTagsFiltersSchemas (t * testing.T ) {
341+ doc , err := libopenapi .NewDocument ([]byte (filterTestSpec ))
342+ require .NoError (t , err )
343+
344+ cfg := Configuration {
345+ PackageName : "testpkg" ,
346+ Generation : GenerationOptions {
347+ Client : true ,
348+ },
349+ OutputOptions : OutputOptions {
350+ ExcludeTags : []string {"admin" },
351+ PruneUnreferencedSchemas : true ,
352+ },
353+ }
354+
355+ code , err := Generate (doc , []byte (filterTestSpec ), cfg )
356+ require .NoError (t , err )
357+
358+ t .Logf ("Generated code:\n %s" , code )
359+
360+ // Operations: users and pets should be included, admin should not
361+ assert .Contains (t , code , "ListUsers(ctx context.Context" )
362+ assert .Contains (t , code , "ListPets(ctx context.Context" )
363+ assert .NotContains (t , code , "GetSettings(ctx context.Context" )
364+
365+ // Schemas: User and Pet should be generated, Settings (admin-only) should not
366+ assert .Contains (t , code , "type User struct" )
367+ assert .Contains (t , code , "type Pet struct" )
368+ assert .NotContains (t , code , "type Settings struct" , "Settings schema should not be generated when 'admin' tag is excluded" )
369+ }
370+
303371func TestFilterIntegration_ServerWithIncludeTags (t * testing.T ) {
304372 doc , err := libopenapi .NewDocument ([]byte (filterTestSpec ))
305373 require .NoError (t , err )
0 commit comments