@@ -30,13 +30,40 @@ public class OpenApiXml : IOpenApiSerializable, IOpenApiExtensible
3030 /// Declares whether the property definition translates to an attribute instead of an element.
3131 /// Default value is false.
3232 /// </summary>
33- public bool Attribute { get ; set ; }
33+ [ Obsolete ( "Use NodeType property instead. This property will be removed in a future version." ) ]
34+ internal bool Attribute
35+ {
36+ get
37+ {
38+ return NodeType == OpenApiXmlNodeType . Attribute ;
39+ }
40+ set
41+ {
42+ NodeType = value ? OpenApiXmlNodeType . Attribute : OpenApiXmlNodeType . None ;
43+ }
44+ }
3445
3546 /// <summary>
3647 /// Signifies whether the array is wrapped.
3748 /// Default value is false.
3849 /// </summary>
39- public bool Wrapped { get ; set ; }
50+ [ Obsolete ( "Use NodeType property instead. This property will be removed in a future version." ) ]
51+ internal bool Wrapped
52+ {
53+ get
54+ {
55+ return NodeType == OpenApiXmlNodeType . Element ;
56+ }
57+ set
58+ {
59+ NodeType = value ? OpenApiXmlNodeType . Element : OpenApiXmlNodeType . None ;
60+ }
61+ }
62+
63+ /// <summary>
64+ /// The node type of the XML representation.
65+ /// </summary>
66+ public OpenApiXmlNodeType ? NodeType { get ; set ; }
4067
4168 /// <summary>
4269 /// Specification Extensions.
@@ -56,8 +83,7 @@ public OpenApiXml(OpenApiXml xml)
5683 Name = xml ? . Name ?? Name ;
5784 Namespace = xml ? . Namespace ?? Namespace ;
5885 Prefix = xml ? . Prefix ?? Prefix ;
59- Attribute = xml ? . Attribute ?? Attribute ;
60- Wrapped = xml ? . Wrapped ?? Wrapped ;
86+ NodeType = xml ? . NodeType ?? NodeType ;
6187 Extensions = xml ? . Extensions != null ? new Dictionary < string , IOpenApiExtension > ( xml . Extensions ) : null ;
6288 }
6389
@@ -108,11 +134,25 @@ private void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
108134 // prefix
109135 writer . WriteProperty ( OpenApiConstants . Prefix , Prefix ) ;
110136
111- // attribute
112- writer . WriteProperty ( OpenApiConstants . Attribute , Attribute , false ) ;
113-
114- // wrapped
115- writer . WriteProperty ( OpenApiConstants . Wrapped , Wrapped , false ) ;
137+ // For OpenAPI 3.2.0 and above, serialize nodeType
138+ if ( specVersion >= OpenApiSpecVersion . OpenApi3_2 )
139+ {
140+ if ( NodeType . HasValue )
141+ {
142+ writer . WriteProperty ( OpenApiConstants . NodeType , NodeType . Value . GetDisplayName ( ) ) ;
143+ }
144+ }
145+ else
146+ {
147+ // For OpenAPI 3.1.0 and below, serialize attribute and wrapped
148+ // Use backing fields if they were set via obsolete properties,
149+ // otherwise derive from NodeType if set
150+ var attribute = NodeType . HasValue && NodeType == OpenApiXmlNodeType . Attribute ;
151+ var wrapped = NodeType . HasValue && NodeType == OpenApiXmlNodeType . Element ;
152+
153+ writer . WriteProperty ( OpenApiConstants . Attribute , attribute , false ) ;
154+ writer . WriteProperty ( OpenApiConstants . Wrapped , wrapped , false ) ;
155+ }
116156
117157 // extensions
118158 writer . WriteExtensions ( Extensions , specVersion ) ;
0 commit comments