@@ -39,3 +39,95 @@ x-test: some-value
3939 require .True (t , ok )
4040 require .Equal (t , "some-value" , ext .Value )
4141}
42+
43+ func TestTag_Unmarshal_WithNewFields_Success (t * testing.T ) {
44+ t .Parallel ()
45+
46+ yml := `
47+ name: products
48+ summary: Products
49+ description: All product-related operations
50+ parent: catalog
51+ kind: nav
52+ externalDocs:
53+ description: Product API documentation
54+ url: https://example.com/products
55+ x-custom: custom-value
56+ `
57+
58+ var tag openapi.Tag
59+
60+ validationErrs , err := marshaller .Unmarshal (t .Context (), bytes .NewBufferString (yml ), & tag )
61+ require .NoError (t , err )
62+ require .Empty (t , validationErrs )
63+
64+ require .Equal (t , "products" , tag .GetName ())
65+ require .Equal (t , "Products" , tag .GetSummary ())
66+ require .Equal (t , "All product-related operations" , tag .GetDescription ())
67+ require .Equal (t , "catalog" , tag .GetParent ())
68+ require .Equal (t , "nav" , tag .GetKind ())
69+
70+ extDocs := tag .GetExternalDocs ()
71+ require .NotNil (t , extDocs )
72+ require .Equal (t , "Product API documentation" , extDocs .GetDescription ())
73+ require .Equal (t , "https://example.com/products" , extDocs .GetURL ())
74+
75+ ext , ok := tag .GetExtensions ().Get ("x-custom" )
76+ require .True (t , ok )
77+ require .Equal (t , "custom-value" , ext .Value )
78+ }
79+
80+ func TestTag_Unmarshal_MinimalNewFields_Success (t * testing.T ) {
81+ t .Parallel ()
82+
83+ yml := `
84+ name: minimal
85+ summary: Minimal Tag
86+ `
87+
88+ var tag openapi.Tag
89+
90+ validationErrs , err := marshaller .Unmarshal (t .Context (), bytes .NewBufferString (yml ), & tag )
91+ require .NoError (t , err )
92+ require .Empty (t , validationErrs )
93+
94+ require .Equal (t , "minimal" , tag .GetName ())
95+ require .Equal (t , "Minimal Tag" , tag .GetSummary ())
96+ require .Equal (t , "" , tag .GetDescription ())
97+ require .Equal (t , "" , tag .GetParent ())
98+ require .Equal (t , "" , tag .GetKind ())
99+ }
100+
101+ func TestTag_Unmarshal_KindValues_Success (t * testing.T ) {
102+ t .Parallel ()
103+
104+ tests := []struct {
105+ name string
106+ kind string
107+ expected string
108+ }{
109+ {"nav kind" , "nav" , "nav" },
110+ {"badge kind" , "badge" , "badge" },
111+ {"audience kind" , "audience" , "audience" },
112+ {"custom kind" , "custom-value" , "custom-value" },
113+ }
114+
115+ for _ , tt := range tests {
116+ t .Run (tt .name , func (t * testing.T ) {
117+ t .Parallel ()
118+
119+ yml := `
120+ name: test
121+ kind: ` + tt .kind
122+
123+ var tag openapi.Tag
124+
125+ validationErrs , err := marshaller .Unmarshal (t .Context (), bytes .NewBufferString (yml ), & tag )
126+ require .NoError (t , err )
127+ require .Empty (t , validationErrs )
128+
129+ require .Equal (t , "test" , tag .GetName ())
130+ require .Equal (t , tt .expected , tag .GetKind ())
131+ })
132+ }
133+ }
0 commit comments