@@ -11,6 +11,10 @@ namespace Microsoft.OpenApi
1111 /// </summary>
1212 public class OpenApiXml : IOpenApiSerializable , IOpenApiExtensible
1313 {
14+ private OpenApiXmlNodeType ? _nodeType ;
15+ private bool _attribute ;
16+ private bool _wrapped ;
17+
1418 /// <summary>
1519 /// Replaces the name of the element/attribute used for the described schema property.
1620 /// </summary>
@@ -30,13 +34,56 @@ public class OpenApiXml : IOpenApiSerializable, IOpenApiExtensible
3034 /// Declares whether the property definition translates to an attribute instead of an element.
3135 /// Default value is false.
3236 /// </summary>
33- public bool Attribute { get ; set ; }
37+ [ Obsolete ( "Use NodeType property instead. This property will be removed in a future version." ) ]
38+ public bool Attribute
39+ {
40+ get
41+ {
42+ // If NodeType is explicitly set, use it; otherwise use the backing field
43+ if ( _nodeType . HasValue )
44+ {
45+ return _nodeType == OpenApiXmlNodeType . Attribute ;
46+ }
47+ return _attribute ;
48+ }
49+ set
50+ {
51+ _attribute = value ;
52+ _nodeType = value ? OpenApiXmlNodeType . Attribute : OpenApiXmlNodeType . None ;
53+ }
54+ }
3455
3556 /// <summary>
3657 /// Signifies whether the array is wrapped.
3758 /// Default value is false.
3859 /// </summary>
39- public bool Wrapped { get ; set ; }
60+ [ Obsolete ( "Use NodeType property instead. This property will be removed in a future version." ) ]
61+ public bool Wrapped
62+ {
63+ get
64+ {
65+ // If NodeType is explicitly set, use it; otherwise use the backing field
66+ if ( _nodeType . HasValue )
67+ {
68+ return _nodeType == OpenApiXmlNodeType . Element ;
69+ }
70+ return _wrapped ;
71+ }
72+ set
73+ {
74+ _wrapped = value ;
75+ _nodeType = value ? OpenApiXmlNodeType . Element : OpenApiXmlNodeType . None ;
76+ }
77+ }
78+
79+ /// <summary>
80+ /// The node type of the XML representation.
81+ /// </summary>
82+ public OpenApiXmlNodeType ? NodeType
83+ {
84+ get => _nodeType ;
85+ set => _nodeType = value ;
86+ }
4087
4188 /// <summary>
4289 /// Specification Extensions.
@@ -56,8 +103,9 @@ public OpenApiXml(OpenApiXml xml)
56103 Name = xml ? . Name ?? Name ;
57104 Namespace = xml ? . Namespace ?? Namespace ;
58105 Prefix = xml ? . Prefix ?? Prefix ;
59- Attribute = xml ? . Attribute ?? Attribute ;
60- Wrapped = xml ? . Wrapped ?? Wrapped ;
106+ _nodeType = xml ? . _nodeType ?? _nodeType ;
107+ _attribute = xml ? . _attribute ?? _attribute ;
108+ _wrapped = xml ? . _wrapped ?? _wrapped ;
61109 Extensions = xml ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( xml . Extensions ) : null ;
62110 }
63111
@@ -108,11 +156,32 @@ private void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
108156 // prefix
109157 writer . WriteProperty ( OpenApiConstants . Prefix , Prefix ) ;
110158
111- // attribute
112- writer . WriteProperty ( OpenApiConstants . Attribute , Attribute , false ) ;
113-
114- // wrapped
115- writer . WriteProperty ( OpenApiConstants . Wrapped , Wrapped , false ) ;
159+ // For OpenAPI 3.2.0 and above, serialize nodeType
160+ if ( specVersion >= OpenApiSpecVersion . OpenApi3_2 )
161+ {
162+ if ( _nodeType . HasValue )
163+ {
164+ writer . WriteProperty ( OpenApiConstants . NodeType , _nodeType . Value . GetDisplayName ( ) ) ;
165+ }
166+ }
167+ else
168+ {
169+ // For OpenAPI 3.1.0 and below, serialize attribute and wrapped
170+ // Use backing fields if they were set via obsolete properties,
171+ // otherwise derive from NodeType if set
172+ bool attribute = _attribute ;
173+ bool wrapped = _wrapped ;
174+
175+ if ( _nodeType . HasValue && ! _attribute && ! _wrapped )
176+ {
177+ // NodeType was set directly, not via obsolete properties
178+ attribute = _nodeType == OpenApiXmlNodeType . Attribute ;
179+ wrapped = _nodeType == OpenApiXmlNodeType . Element ;
180+ }
181+
182+ writer . WriteProperty ( OpenApiConstants . Attribute , attribute , false ) ;
183+ writer . WriteProperty ( OpenApiConstants . Wrapped , wrapped , false ) ;
184+ }
116185
117186 // extensions
118187 writer . WriteExtensions ( Extensions , specVersion ) ;
0 commit comments