rspec/rules/S3847/xml/rule.adoc
Fred Tingaud 16f6c0aecf
Inline adoc when include has no additional value (#1940)
Inline adoc files when they are included exactly once.

Also fix language tags because this inlining gives us better information
on what language the code is written in.
2023-05-25 14:18:12 +02:00

50 lines
1.4 KiB
Plaintext

== Why is this an issue?
Having a ``++nillable++`` element in a schema means that element must always be present, whether or not you have data for it. That means that the resulting XML transmissions will be larger than they need to be. On the other hand, ``++minOccurs="0"++`` communicates the same "there is no value" message, with smaller XML messages. For that reason, ``++minOccurs="0"++`` is _almost_ always preferred over ``++nillable="true"++``. The one case were ``++nillable="true"++`` is valuable is in the case of an array element, where you may have the need to set a placeholder.
This rule raises an issue when ``++nillable="true"++`` is used on an element were ``++maxOccurs++`` is 1.
=== Noncompliant code example
[source,xml]
----
<complexType name="fruitArray" nillable="true"> <!-- Noncompliant -->
<sequence>
<element name="fruit" type="xs:string" nillable="true" maxOccurs="4"/> <!-- ignored -->
</sequence>
</complexType>
----
=== Compliant solution
[source,xml]
----
<complexType name="fruitArray">
<sequence>
<element name="fruit" type="xs:string" minOccurs="0" maxOccurs="4"/>
</sequence>
</complexType>
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Use 'minOccurs="0"' here instead of 'nillable="true"'.
=== Highlighting
``++nillable="true"++``
endif::env-github,rspecator-view[]