diff --git a/packages/http-specs/spec-summary.md b/packages/http-specs/spec-summary.md
index c68a503c558..3be967bf045 100644
--- a/packages/http-specs/spec-summary.md
+++ b/packages/http-specs/spec-summary.md
@@ -3207,6 +3207,90 @@ Expected request body:
```
+### Payload_Xml_ModelWithNamespaceOnPropertiesValue_get
+
+- Endpoint: `get /payload/xml/modelWithNamespaceOnProperties`
+
+Expected response body:
+
+```xml
+
+ 123
+ The Great Gatsby
+ F. Scott Fitzgerald
+
+```
+
+### Payload_Xml_ModelWithNamespaceOnPropertiesValue_put
+
+- Endpoint: `put /payload/xml/modelWithNamespaceOnProperties`
+
+Expected request body:
+
+```xml
+
+ 123
+ The Great Gatsby
+ F. Scott Fitzgerald
+
+```
+
+### Payload_Xml_ModelWithNamespaceValue_get
+
+- Endpoint: `get /payload/xml/modelWithNamespace`
+
+Expected response body:
+
+```xml
+
+ 123
+ The Great Gatsby
+
+```
+
+### Payload_Xml_ModelWithNamespaceValue_put
+
+- Endpoint: `put /payload/xml/modelWithNamespace`
+
+Expected request body:
+
+```xml
+
+ 123
+ The Great Gatsby
+
+```
+
+### Payload_Xml_ModelWithNestedModelValue_get
+
+- Endpoint: `get /payload/xml/modelWithNestedModel`
+
+Expected response body:
+
+```xml
+
+
+ foo
+ 123
+
+
+```
+
+### Payload_Xml_ModelWithNestedModelValue_put
+
+- Endpoint: `put /payload/xml/modelWithNestedModel`
+
+Expected request body:
+
+```xml
+
+
+ foo
+ 123
+
+
+```
+
### Payload_Xml_ModelWithOptionalFieldValue_get
- Endpoint: `get /payload/xml/modelWithOptionalField`
@@ -3267,6 +3351,32 @@ Expected request body:
```
+### Payload_Xml_ModelWithRenamedAttributeValue_get
+
+- Endpoint: `get /payload/xml/modelWithRenamedAttribute`
+
+Expected response body:
+
+```xml
+
+ The Great Gatsby
+ F. Scott Fitzgerald
+
+```
+
+### Payload_Xml_ModelWithRenamedAttributeValue_put
+
+- Endpoint: `put /payload/xml/modelWithRenamedAttribute`
+
+Expected request body:
+
+```xml
+
+ The Great Gatsby
+ F. Scott Fitzgerald
+
+```
+
### Payload_Xml_ModelWithRenamedFieldsValue_get
- Endpoint: `get /payload/xml/modelWithRenamedFields`
@@ -3305,6 +3415,178 @@ Expected request body:
```
+### Payload_Xml_ModelWithRenamedNestedModelValue_get
+
+- Endpoint: `get /payload/xml/modelWithRenamedNestedModel`
+
+Expected response body:
+
+```xml
+
+
+ foo
+
+
+```
+
+### Payload_Xml_ModelWithRenamedNestedModelValue_put
+
+- Endpoint: `put /payload/xml/modelWithRenamedNestedModel`
+
+Expected request body:
+
+```xml
+
+
+ foo
+
+
+```
+
+### Payload_Xml_ModelWithRenamedPropertyValue_get
+
+- Endpoint: `get /payload/xml/modelWithRenamedProperty`
+
+Expected response body:
+
+```xml
+
+ foo
+ bar
+
+```
+
+### Payload_Xml_ModelWithRenamedPropertyValue_put
+
+- Endpoint: `put /payload/xml/modelWithRenamedProperty`
+
+Expected request body:
+
+```xml
+
+ foo
+ bar
+
+```
+
+### Payload_Xml_ModelWithRenamedUnwrappedModelArrayValue_get
+
+- Endpoint: `get /payload/xml/modelWithRenamedUnwrappedModelArray`
+
+Expected response body:
+
+```xml
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+```
+
+### Payload_Xml_ModelWithRenamedUnwrappedModelArrayValue_put
+
+- Endpoint: `put /payload/xml/modelWithRenamedUnwrappedModelArray`
+
+Expected request body:
+
+```xml
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+```
+
+### Payload_Xml_ModelWithRenamedWrappedAndItemModelArrayValue_get
+
+- Endpoint: `get /payload/xml/modelWithRenamedWrappedAndItemModelArray`
+
+Expected response body:
+
+```xml
+
+
+
+ The Great Gatsby
+
+
+ Les Miserables
+
+
+
+```
+
+### Payload_Xml_ModelWithRenamedWrappedAndItemModelArrayValue_put
+
+- Endpoint: `put /payload/xml/modelWithRenamedWrappedAndItemModelArray`
+
+Expected request body:
+
+```xml
+
+
+
+ The Great Gatsby
+
+
+ Les Miserables
+
+
+
+```
+
+### Payload_Xml_ModelWithRenamedWrappedModelArrayValue_get
+
+- Endpoint: `get /payload/xml/modelWithRenamedWrappedModelArray`
+
+Expected response body:
+
+```xml
+
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+
+```
+
+### Payload_Xml_ModelWithRenamedWrappedModelArrayValue_put
+
+- Endpoint: `put /payload/xml/modelWithRenamedWrappedModelArray`
+
+Expected request body:
+
+```xml
+
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+
+```
+
### Payload_Xml_ModelWithSimpleArraysValue_get
- Endpoint: `get /payload/xml/modelWithSimpleArrays`
@@ -3405,6 +3687,74 @@ Expected request body:
```
+### Payload_Xml_ModelWithUnwrappedModelArrayValue_get
+
+- Endpoint: `get /payload/xml/modelWithUnwrappedModelArray`
+
+Expected response body:
+
+```xml
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+```
+
+### Payload_Xml_ModelWithUnwrappedModelArrayValue_put
+
+- Endpoint: `put /payload/xml/modelWithUnwrappedModelArray`
+
+Expected request body:
+
+```xml
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+```
+
+### Payload_Xml_ModelWithWrappedPrimitiveCustomItemNamesValue_get
+
+- Endpoint: `get /payload/xml/modelWithWrappedPrimitiveCustomItemNames`
+
+Expected response body:
+
+```xml
+
+
+ fiction
+ classic
+
+
+```
+
+### Payload_Xml_ModelWithWrappedPrimitiveCustomItemNamesValue_put
+
+- Endpoint: `put /payload/xml/modelWithWrappedPrimitiveCustomItemNames`
+
+Expected request body:
+
+```xml
+
+
+ fiction
+ classic
+
+
+```
+
### Payload_Xml_SimpleModelValue_get
- Endpoint: `get /payload/xml/simpleModel`
diff --git a/packages/http-specs/specs/payload/xml/main.tsp b/packages/http-specs/specs/payload/xml/main.tsp
index d768dfb2d2d..57a620adc8a 100644
--- a/packages/http-specs/specs/payload/xml/main.tsp
+++ b/packages/http-specs/specs/payload/xml/main.tsp
@@ -6,127 +6,27 @@ using Http;
using Spector;
using TypeSpec.Xml;
-@doc("Sends and receives bodies in XML format.")
+/** Sends and receives bodies in XML format. */
@scenarioService("/payload/xml")
namespace Payload.Xml;
-@doc("Contains fields of primitive types.")
+// ────────────────────────────────────────────────────────────────────────────
+// Shared types
+// ────────────────────────────────────────────────────────────────────────────
+
+/** §1.1 — Contains fields of primitive types. */
model SimpleModel {
name: string;
age: int32;
}
-@doc("Contains fields of arrays of primitive types.")
-model ModelWithSimpleArrays {
- colors: string[];
- counts: int32[];
-}
-
-@doc("Contains an array of models.")
-model ModelWithArrayOfModel {
- items: SimpleModel[];
-}
-
-@doc("Contains an optional field.")
-model ModelWithOptionalField {
- item: string;
- value?: int32;
-}
-
-@doc("Contains fields that are XML attributes.")
-model ModelWithAttributes {
- @attribute id1: int32;
- @attribute id2: string;
- enabled: boolean;
+@nsDeclarations
+enum Namespaces {
+ smp: "http://example.com/schema",
+ ns2: "http://example.com/ns2",
}
-@doc("Contains fields of wrapped and unwrapped arrays of primitive types.")
-model ModelWithUnwrappedArray {
- @unwrapped colors: string[];
- counts: int32[];
-}
-
-@doc("Contains fields of wrapped and unwrapped arrays of primitive types that have different XML representations.")
-model ModelWithRenamedArrays {
- @name("Colors") @unwrapped colors: string[];
- @name("Counts") counts: int32[];
-}
-
-@doc("Contains fields of the same type that have different XML representation.")
-@name("ModelWithRenamedFieldsSrc")
-model ModelWithRenamedFields {
- @name("InputData") inputData: SimpleModel;
- @name("OutputData") outputData: SimpleModel;
-}
-
-@doc("Contains an array of models that's supposed to be sent/received as an empty XML element.")
-model ModelWithEmptyArray {
- items: SimpleModel[];
-}
-
-@doc("Contains an attribute and text.")
-model ModelWithText {
- @attribute language: string;
- @unwrapped content: string;
-}
-
-@doc("Contains a dictionary of key value pairs.")
-model ModelWithDictionary {
- metadata: Record;
-}
-
-@doc("Uses encodedName instead of Xml.Name which is functionally equivalent.")
-@encodedName("application/xml", "ModelWithEncodedNamesSrc")
-model ModelWithEncodedNames {
- @encodedName("application/xml", "SimpleModelData") modelData: SimpleModel;
- @encodedName("application/xml", "PossibleColors") colors: string[];
-}
-
-@doc("Status values for the model with enum.")
-union Status {
- string,
-
- @doc("Pending status.")
- pending: "pending",
-
- @doc("Success status.")
- success: "success",
-
- @doc("Error status.")
- error: "error",
-}
-
-@doc("Contains a single property with an enum value.")
-model ModelWithEnum {
- status: Status;
-}
-
-@doc("Contains datetime properties with different encodings.")
-model ModelWithDatetime {
- @encode(DateTimeKnownEncoding.rfc3339)
- @doc("DateTime value with rfc3339 encoding.")
- rfc3339: utcDateTime;
-
- @encode(DateTimeKnownEncoding.rfc7231)
- @doc("DateTime value with rfc7231 encoding.")
- rfc7231: utcDateTime;
-}
-
-@doc("An error response body in XML format.")
-@error
-model XmlError {
- @statusCode _: 400;
- @header("content-type") contentType: "application/xml";
- @body body: XmlErrorBody;
-}
-
-@doc("The body of an XML error response.")
-model XmlErrorBody {
- message: string;
- code: int32;
-}
-
-@doc("Template for XML operations")
+/** Template for XML operations */
interface XmlOperations {
@scenario
@scenarioDoc("""
@@ -152,7 +52,11 @@ interface XmlOperations {
put(@header("content-type") contentType: "application/xml", @body input: TModel): void;
}
-@doc("Operations for the SimpleModel type.")
+// ────────────────────────────────────────────────────────────────────────────
+// §1 — Primitive properties
+// ────────────────────────────────────────────────────────────────────────────
+
+/** §1.1 — Operations for the SimpleModel type. */
@route("/simpleModel")
interface SimpleModelValue
extends XmlOperations<
@@ -165,7 +69,113 @@ interface SimpleModelValue
"""
> {}
-@doc("Operations for the ModelWithSimpleArrays type.")
+/** §1.2 — Contains a scalar property with a custom XML name. */
+model ModelWithRenamedProperty {
+ @name("renamedTitle")
+ title: string;
+
+ author: string;
+}
+
+/** §1.2 — Operations for the ModelWithRenamedProperty type. */
+@route("/modelWithRenamedProperty")
+interface ModelWithRenamedPropertyValue
+ extends XmlOperations<
+ ModelWithRenamedProperty,
+ """
+
+ foo
+ bar
+
+ """
+ > {}
+
+/** §1.3, §2.3 — Contains fields of the same type that have different XML representation. */
+@name("ModelWithRenamedFieldsSrc")
+model ModelWithRenamedFields {
+ @name("InputData") inputData: SimpleModel;
+ @name("OutputData") outputData: SimpleModel;
+}
+
+/** §1.3, §2.3 — Operations for the ModelWithRenamedFields type. */
+@route("/modelWithRenamedFields")
+interface ModelWithRenamedFieldsValue
+ extends XmlOperations<
+ ModelWithRenamedFields,
+ """
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+ """
+ > {}
+
+// ────────────────────────────────────────────────────────────────────────────
+// §2 — Nested models
+// ────────────────────────────────────────────────────────────────────────────
+
+/** §2.1 — Contains a property that references another model. */
+model ModelWithNestedModel {
+ nested: SimpleModel;
+}
+
+/** §2.1 — Operations for the ModelWithNestedModel type. */
+@route("/modelWithNestedModel")
+interface ModelWithNestedModelValue
+ extends XmlOperations<
+ ModelWithNestedModel,
+ """
+
+
+ foo
+ 123
+
+
+ """
+ > {}
+
+/** Author model with a custom XML name. */
+@name("XmlAuthor")
+model Author {
+ name: string;
+}
+
+/** §2.2 — Contains a property whose type has @Xml.name. The property name takes precedence. */
+model ModelWithRenamedNestedModel {
+ author: Author;
+}
+
+/** §2.2 — Operations for the ModelWithRenamedNestedModel type. */
+@route("/modelWithRenamedNestedModel")
+interface ModelWithRenamedNestedModelValue
+ extends XmlOperations<
+ ModelWithRenamedNestedModel,
+ """
+
+
+ foo
+
+
+ """
+ > {}
+
+// ────────────────────────────────────────────────────────────────────────────
+// §3 — Array of primitive types
+// ────────────────────────────────────────────────────────────────────────────
+
+/** §3.1 — Contains fields of arrays of primitive types. */
+model ModelWithSimpleArrays {
+ colors: string[];
+ counts: int32[];
+}
+
+/** §3.1 — Operations for the ModelWithSimpleArrays type. */
@route("/modelWithSimpleArrays")
interface ModelWithSimpleArraysValue
extends XmlOperations<
@@ -185,7 +195,89 @@ interface ModelWithSimpleArraysValue
"""
> {}
-@doc("Operations for the ModelWithArrayOfModel type.")
+/** §3.2 — Contains fields of wrapped and unwrapped arrays of primitive types. */
+model ModelWithUnwrappedArray {
+ @unwrapped colors: string[];
+ counts: int32[];
+}
+
+/** §3.2 — Operations for the ModelWithUnwrappedArray type. */
+@route("/modelWithUnwrappedArray")
+interface ModelWithUnwrappedArrayValue
+ extends XmlOperations<
+ ModelWithUnwrappedArray,
+ """
+
+ red
+ green
+ blue
+
+ 1
+ 2
+
+
+ """
+ > {}
+
+/** §3.3, §3.4 — Contains fields of wrapped and unwrapped arrays of primitive types that have different XML representations. */
+model ModelWithRenamedArrays {
+ @name("Colors") @unwrapped colors: string[];
+ @name("Counts") counts: int32[];
+}
+
+/** §3.3, §3.4 — Operations for the ModelWithRenamedArrays type. */
+@route("/modelWithRenamedArrays")
+interface ModelWithRenamedArraysValue
+ extends XmlOperations<
+ ModelWithRenamedArrays,
+ """
+
+ red
+ green
+ blue
+
+ 1
+ 2
+
+
+ """
+ > {}
+
+/** Custom scalar with a custom XML item name. */
+@name("ItemName")
+scalar tag extends string;
+
+/** §3.5 — Contains a wrapped primitive array with custom wrapper and item names. */
+model ModelWithWrappedPrimitiveCustomItemNames {
+ @name("ItemsTags")
+ tags: tag[];
+}
+
+/** §3.5 — Operations for the ModelWithWrappedPrimitiveCustomItemNames type. */
+@route("/modelWithWrappedPrimitiveCustomItemNames")
+interface ModelWithWrappedPrimitiveCustomItemNamesValue
+ extends XmlOperations<
+ ModelWithWrappedPrimitiveCustomItemNames,
+ """
+
+
+ fiction
+ classic
+
+
+ """
+ > {}
+
+// ────────────────────────────────────────────────────────────────────────────
+// §4 — Array of complex types
+// ────────────────────────────────────────────────────────────────────────────
+
+/** §4.1 — Contains an array of models. */
+model ModelWithArrayOfModel {
+ items: SimpleModel[];
+}
+
+/** §4.1 — Operations for the ModelWithArrayOfModel type. */
@route("/modelWithArrayOfModel")
interface ModelWithArrayOfModelValue
extends XmlOperations<
@@ -206,19 +298,127 @@ interface ModelWithArrayOfModelValue
"""
> {}
-@doc("Operations for the ModelWithOptionalField type.")
-@route("/modelWithOptionalField")
-interface ModelWithOptionalFieldValue
+/** §4.2 — Contains an unwrapped array of models. */
+model ModelWithUnwrappedModelArray {
+ @unwrapped
+ items: SimpleModel[];
+}
+
+/** §4.2 — Operations for the ModelWithUnwrappedModelArray type. */
+@route("/modelWithUnwrappedModelArray")
+interface ModelWithUnwrappedModelArrayValue
extends XmlOperations<
- ModelWithOptionalField,
+ ModelWithUnwrappedModelArray,
"""
-
- - widget
-
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
"""
> {}
-@doc("Operations for the ModelWithAttributes type.")
+/** §4.3 — Contains a wrapped array of models with a custom wrapper name. */
+model ModelWithRenamedWrappedModelArray {
+ @name("AllItems")
+ items: SimpleModel[];
+}
+
+/** §4.3 — Operations for the ModelWithRenamedWrappedModelArray type. */
+@route("/modelWithRenamedWrappedModelArray")
+interface ModelWithRenamedWrappedModelArrayValue
+ extends XmlOperations<
+ ModelWithRenamedWrappedModelArray,
+ """
+
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+
+ """
+ > {}
+
+/** §4.4 — Contains an unwrapped array of models with a custom item name. */
+model ModelWithRenamedUnwrappedModelArray {
+ @name("ModelItem")
+ @unwrapped
+ items: SimpleModel[];
+}
+
+/** §4.4 — Operations for the ModelWithRenamedUnwrappedModelArray type. */
+@route("/modelWithRenamedUnwrappedModelArray")
+interface ModelWithRenamedUnwrappedModelArrayValue
+ extends XmlOperations<
+ ModelWithRenamedUnwrappedModelArray,
+ """
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+ """
+ > {}
+
+/** Book model with a custom XML name. */
+@name("XmlBook")
+model Book {
+ title: string;
+}
+
+/** §4.5 — Contains a wrapped array of models with custom wrapper and item names. */
+model ModelWithRenamedWrappedAndItemModelArray {
+ @name("AllBooks")
+ books: Book[];
+}
+
+/** §4.5 — Operations for the ModelWithRenamedWrappedAndItemModelArray type. */
+@route("/modelWithRenamedWrappedAndItemModelArray")
+interface ModelWithRenamedWrappedAndItemModelArrayValue
+ extends XmlOperations<
+ ModelWithRenamedWrappedAndItemModelArray,
+ """
+
+
+
+ The Great Gatsby
+
+
+ Les Miserables
+
+
+
+ """
+ > {}
+
+// ────────────────────────────────────────────────────────────────────────────
+// §5 — Attributes
+// ────────────────────────────────────────────────────────────────────────────
+
+/** §5.1 — Contains fields that are XML attributes. */
+model ModelWithAttributes {
+ @attribute id1: int32;
+ @attribute id2: string;
+ enabled: boolean;
+}
+
+/** §5.1 — Operations for the ModelWithAttributes type. */
@route("/modelWithAttributes")
interface ModelWithAttributesValue
extends XmlOperations<
@@ -230,74 +430,90 @@ interface ModelWithAttributesValue
"""
> {}
-@doc("Operations for the ModelWithUnwrappedArray type.")
-@route("/modelWithUnwrappedArray")
-interface ModelWithUnwrappedArrayValue
- extends XmlOperations<
- ModelWithUnwrappedArray,
- """
-
- red
- green
- blue
-
- 1
- 2
-
-
- """
- > {}
+/** §5.2 — Contains a renamed XML attribute. */
+model ModelWithRenamedAttribute {
+ @attribute
+ @name("xml-id")
+ id: int32;
-@doc("Operations for the ModelWithRenamedArrays type.")
-@route("/modelWithRenamedArrays")
-interface ModelWithRenamedArraysValue
+ title: string;
+ author: string;
+}
+
+/** §5.2 — Operations for the ModelWithRenamedAttribute type. */
+@route("/modelWithRenamedAttribute")
+interface ModelWithRenamedAttributeValue
extends XmlOperations<
- ModelWithRenamedArrays,
+ ModelWithRenamedAttribute,
"""
-
- red
- green
- blue
-
- 1
- 2
-
-
+
+ The Great Gatsby
+ F. Scott Fitzgerald
+
"""
> {}
-@doc("Operations for the ModelWithRenamedFields type.")
-@route("/modelWithRenamedFields")
-interface ModelWithRenamedFieldsValue
+// ────────────────────────────────────────────────────────────────────────────
+// §6/§7 — Namespace and prefix
+// ────────────────────────────────────────────────────────────────────────────
+
+/** §6.1, §7.1 — Contains fields with XML namespace on the model. */
+@ns(Namespaces.smp)
+model ModelWithNamespace {
+ id: int32;
+ title: string;
+}
+
+/** §6.1, §7.1 — Operations for the ModelWithNamespace type. */
+@route("/modelWithNamespace")
+interface ModelWithNamespaceValue
extends XmlOperations<
- ModelWithRenamedFields,
+ ModelWithNamespace,
"""
-
-
- foo
- 123
-
-
- bar
- 456
-
-
+
+ 123
+ The Great Gatsby
+
"""
> {}
-@doc("Operations for the ModelWithEmptyArray type.")
-@route("/modelWithEmptyArray")
-interface ModelWithEmptyArrayValue
+/** §6.2, §7.2 — Contains fields with different XML namespaces on individual properties. */
+@ns(Namespaces.smp)
+model ModelWithNamespaceOnProperties {
+ id: int32;
+
+ @ns(Namespaces.smp)
+ title: string;
+
+ @ns(Namespaces.ns2)
+ author: string;
+}
+
+/** §6.2, §7.2 — Operations for the ModelWithNamespaceOnProperties type. */
+@route("/modelWithNamespaceOnProperties")
+interface ModelWithNamespaceOnPropertiesValue
extends XmlOperations<
- ModelWithEmptyArray,
+ ModelWithNamespaceOnProperties,
"""
-
-
-
+
+ 123
+ The Great Gatsby
+ F. Scott Fitzgerald
+
"""
> {}
-@doc("Operations for the ModelWithText type.")
+// ────────────────────────────────────────────────────────────────────────────
+// §8 — Text content
+// ────────────────────────────────────────────────────────────────────────────
+
+/** §8.1 — Contains an attribute and text. */
+model ModelWithText {
+ @attribute language: string;
+ @unwrapped content: string;
+}
+
+/** §8.1 — Operations for the ModelWithText type. */
@route("/modelWithText")
interface ModelWithTextValue
extends XmlOperations<
@@ -309,7 +525,51 @@ interface ModelWithTextValue
"""
> {}
-@doc("Operations for the ModelWithDictionary type.")
+// ────────────────────────────────────────────────────────────────────────────
+// Additional scenarios (not in the guide)
+// ────────────────────────────────────────────────────────────────────────────
+
+/** Contains an optional field. */
+model ModelWithOptionalField {
+ item: string;
+ value?: int32;
+}
+
+/** Operations for the ModelWithOptionalField type. */
+@route("/modelWithOptionalField")
+interface ModelWithOptionalFieldValue
+ extends XmlOperations<
+ ModelWithOptionalField,
+ """
+
+ - widget
+
+ """
+ > {}
+
+/** Contains an array of models that's supposed to be sent/received as an empty XML element. */
+model ModelWithEmptyArray {
+ items: SimpleModel[];
+}
+
+/** Operations for the ModelWithEmptyArray type. */
+@route("/modelWithEmptyArray")
+interface ModelWithEmptyArrayValue
+ extends XmlOperations<
+ ModelWithEmptyArray,
+ """
+
+
+
+ """
+ > {}
+
+/** Contains a dictionary of key value pairs. */
+model ModelWithDictionary {
+ metadata: Record;
+}
+
+/** Operations for the ModelWithDictionary type. */
@route("/modelWithDictionary")
interface ModelWithDictionaryValue
extends XmlOperations<
@@ -325,7 +585,14 @@ interface ModelWithDictionaryValue
"""
> {}
-@doc("Operations for the ModelWithEncodedNames type.")
+/** Uses encodedName instead of Xml.Name which is functionally equivalent. */
+@encodedName("application/xml", "ModelWithEncodedNamesSrc")
+model ModelWithEncodedNames {
+ @encodedName("application/xml", "SimpleModelData") modelData: SimpleModel;
+ @encodedName("application/xml", "PossibleColors") colors: string[];
+}
+
+/** Operations for the ModelWithEncodedNames type. */
@route("/modelWithEncodedNames")
interface ModelWithEncodedNamesValue
extends XmlOperations<
@@ -345,7 +612,26 @@ interface ModelWithEncodedNamesValue
"""
> {}
-@doc("Operations for the ModelWithEnum type.")
+/** Status values for the model with enum. */
+union Status {
+ string,
+
+ /** Pending status. */
+ pending: "pending",
+
+ /** Success status. */
+ success: "success",
+
+ /** Error status. */
+ error: "error",
+}
+
+/** Contains a single property with an enum value. */
+model ModelWithEnum {
+ status: Status;
+}
+
+/** Operations for the ModelWithEnum type. */
@route("/modelWithEnum")
interface ModelWithEnumValue
extends XmlOperations<
@@ -357,7 +643,18 @@ interface ModelWithEnumValue
"""
> {}
-@doc("Operations for the ModelWithDatetime type.")
+/** Contains datetime properties with different encodings. */
+model ModelWithDatetime {
+ /** DateTime value with rfc3339 encoding. */
+ @encode(DateTimeKnownEncoding.rfc3339)
+ rfc3339: utcDateTime;
+
+ /** DateTime value with rfc7231 encoding. */
+ @encode(DateTimeKnownEncoding.rfc7231)
+ rfc7231: utcDateTime;
+}
+
+/** Operations for the ModelWithDatetime type. */
@route("/modelWithDatetime")
interface ModelWithDatetimeValue
extends XmlOperations<
@@ -370,7 +667,21 @@ interface ModelWithDatetimeValue
"""
> {}
-@doc("Operations that return an error response in XML format.")
+/** An error response body in XML format. */
+@error
+model XmlError {
+ @statusCode _: 400;
+ @header("content-type") contentType: "application/xml";
+ @body body: XmlErrorBody;
+}
+
+/** The body of an XML error response. */
+model XmlErrorBody {
+ message: string;
+ code: int32;
+}
+
+/** Operations that return an error response in XML format. */
@route("/error")
interface XmlErrorValue {
@scenario
diff --git a/packages/http-specs/specs/payload/xml/mockapi.ts b/packages/http-specs/specs/payload/xml/mockapi.ts
index de2d3f85834..c14916371a7 100644
--- a/packages/http-specs/specs/payload/xml/mockapi.ts
+++ b/packages/http-specs/specs/payload/xml/mockapi.ts
@@ -2,6 +2,10 @@ import { MockRequest, passOnCode, passOnSuccess, ScenarioMockApi, xml } from "@t
export const Scenarios: Record = {};
+// ────────────────────────────────────────────────────────────────────────────
+// §1 — Primitive properties
+// ────────────────────────────────────────────────────────────────────────────
+
export const simpleModel = `
foo
@@ -9,6 +13,51 @@ export const simpleModel = `
`;
+export const modelWithRenamedProperty = `
+
+ foo
+ bar
+
+`;
+
+export const modelWithRenamedFields = `
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+`;
+
+// ────────────────────────────────────────────────────────────────────────────
+// §2 — Nested models
+// ────────────────────────────────────────────────────────────────────────────
+
+export const modelWithNestedModel = `
+
+
+ foo
+ 123
+
+
+`;
+
+export const modelWithRenamedNestedModel = `
+
+
+ foo
+
+
+`;
+
+// ────────────────────────────────────────────────────────────────────────────
+// §3 — Array of primitive types
+// ────────────────────────────────────────────────────────────────────────────
+
export const modelWithSimpleArrays = `
@@ -23,33 +72,6 @@ export const modelWithSimpleArrays = `
`;
-export const modelWithArrayOfModel = `
-
-
-
- foo
- 123
-
-
- bar
- 456
-
-
-
-`;
-
-export const modelWithOptionalField = `
-
- - widget
-
-`;
-
-export const modelWithAttributes = `
-
- true
-
-`;
-
export const modelWithUnwrappedArray = `
red
@@ -74,31 +96,150 @@ export const modelWithRenamedArrays = `
`;
-export const modelWithRenamedFields = `
-
-
+export const modelWithWrappedPrimitiveCustomItemNames = `
+
+
+ fiction
+ classic
+
+
+`;
+
+// ────────────────────────────────────────────────────────────────────────────
+// §4 — Array of complex types
+// ────────────────────────────────────────────────────────────────────────────
+
+export const modelWithArrayOfModel = `
+
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+
+`;
+
+export const modelWithUnwrappedModelArray = `
+
+
foo
123
-
-
+
+
bar
456
-
-
+
+
`;
-export const modelWithEmptyArray = `
-
-
-
+export const modelWithRenamedWrappedModelArray = `
+
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+
+`;
+
+export const modelWithRenamedUnwrappedModelArray = `
+
+
+ foo
+ 123
+
+
+ bar
+ 456
+
+
+`;
+
+export const modelWithRenamedWrappedAndItemModelArray = `
+
+
+
+ The Great Gatsby
+
+
+ Les Miserables
+
+
+
+`;
+
+// ────────────────────────────────────────────────────────────────────────────
+// §5 — Attributes
+// ────────────────────────────────────────────────────────────────────────────
+
+export const modelWithAttributes = `
+
+ true
+
+`;
+
+export const modelWithRenamedAttribute = `
+
+ The Great Gatsby
+ F. Scott Fitzgerald
+
`;
+// ────────────────────────────────────────────────────────────────────────────
+// §6/§7 — Namespace and prefix
+// ────────────────────────────────────────────────────────────────────────────
+
+export const modelWithNamespace = `
+
+ 123
+ The Great Gatsby
+
+`;
+
+export const modelWithNamespaceOnProperties = `
+
+ 123
+ The Great Gatsby
+ F. Scott Fitzgerald
+
+`;
+
+// ────────────────────────────────────────────────────────────────────────────
+// §8 — Text content
+// ────────────────────────────────────────────────────────────────────────────
+
export const modelWithText = `
This is some text.
`;
+// ────────────────────────────────────────────────────────────────────────────
+// Additional scenarios (not in the guide)
+// ────────────────────────────────────────────────────────────────────────────
+
+export const modelWithOptionalField = `
+
+ - widget
+
+`;
+
+export const modelWithEmptyArray = `
+
+
+
+`;
+
export const modelWithDictionary = `
@@ -146,6 +287,17 @@ const modelWithDatetimeNoMs = `
`;
+export const xmlError = `
+
+ Something went wrong
+ 400
+
+`;
+
+// ────────────────────────────────────────────────────────────────────────────
+// Scenario registrations
+// ────────────────────────────────────────────────────────────────────────────
+
function createServerTests(uri: string, data?: any) {
return {
get: passOnSuccess({
@@ -179,10 +331,46 @@ function createServerTests(uri: string, data?: any) {
};
}
+// §1 — Primitive properties
+
const Payload_Xml_SimpleModel = createServerTests("/payload/xml/simpleModel", simpleModel);
Scenarios.Payload_Xml_SimpleModelValue_get = Payload_Xml_SimpleModel.get;
Scenarios.Payload_Xml_SimpleModelValue_put = Payload_Xml_SimpleModel.put;
+const Payload_Xml_ModelWithRenamedProperty = createServerTests(
+ "/payload/xml/modelWithRenamedProperty",
+ modelWithRenamedProperty,
+);
+Scenarios.Payload_Xml_ModelWithRenamedPropertyValue_get = Payload_Xml_ModelWithRenamedProperty.get;
+Scenarios.Payload_Xml_ModelWithRenamedPropertyValue_put = Payload_Xml_ModelWithRenamedProperty.put;
+
+const Payload_Xml_ModelWithRenamedFields = createServerTests(
+ "/payload/xml/modelWithRenamedFields",
+ modelWithRenamedFields,
+);
+Scenarios.Payload_Xml_ModelWithRenamedFieldsValue_get = Payload_Xml_ModelWithRenamedFields.get;
+Scenarios.Payload_Xml_ModelWithRenamedFieldsValue_put = Payload_Xml_ModelWithRenamedFields.put;
+
+// §2 — Nested models
+
+const Payload_Xml_ModelWithNestedModel = createServerTests(
+ "/payload/xml/modelWithNestedModel",
+ modelWithNestedModel,
+);
+Scenarios.Payload_Xml_ModelWithNestedModelValue_get = Payload_Xml_ModelWithNestedModel.get;
+Scenarios.Payload_Xml_ModelWithNestedModelValue_put = Payload_Xml_ModelWithNestedModel.put;
+
+const Payload_Xml_ModelWithRenamedNestedModel = createServerTests(
+ "/payload/xml/modelWithRenamedNestedModel",
+ modelWithRenamedNestedModel,
+);
+Scenarios.Payload_Xml_ModelWithRenamedNestedModelValue_get =
+ Payload_Xml_ModelWithRenamedNestedModel.get;
+Scenarios.Payload_Xml_ModelWithRenamedNestedModelValue_put =
+ Payload_Xml_ModelWithRenamedNestedModel.put;
+
+// §3 — Array of primitive types
+
const Payload_Xml_ModelWithSimpleArrays = createServerTests(
"/payload/xml/modelWithSimpleArrays",
modelWithSimpleArrays,
@@ -190,6 +378,31 @@ const Payload_Xml_ModelWithSimpleArrays = createServerTests(
Scenarios.Payload_Xml_ModelWithSimpleArraysValue_get = Payload_Xml_ModelWithSimpleArrays.get;
Scenarios.Payload_Xml_ModelWithSimpleArraysValue_put = Payload_Xml_ModelWithSimpleArrays.put;
+const Payload_Xml_ModelWithUnwrappedArray = createServerTests(
+ "/payload/xml/modelWithUnwrappedArray",
+ modelWithUnwrappedArray,
+);
+Scenarios.Payload_Xml_ModelWithUnwrappedArrayValue_get = Payload_Xml_ModelWithUnwrappedArray.get;
+Scenarios.Payload_Xml_ModelWithUnwrappedArrayValue_put = Payload_Xml_ModelWithUnwrappedArray.put;
+
+const Payload_Xml_ModelWithRenamedArrays = createServerTests(
+ "/payload/xml/modelWithRenamedArrays",
+ modelWithRenamedArrays,
+);
+Scenarios.Payload_Xml_ModelWithRenamedArraysValue_get = Payload_Xml_ModelWithRenamedArrays.get;
+Scenarios.Payload_Xml_ModelWithRenamedArraysValue_put = Payload_Xml_ModelWithRenamedArrays.put;
+
+const Payload_Xml_ModelWithWrappedPrimitiveCustomItemNames = createServerTests(
+ "/payload/xml/modelWithWrappedPrimitiveCustomItemNames",
+ modelWithWrappedPrimitiveCustomItemNames,
+);
+Scenarios.Payload_Xml_ModelWithWrappedPrimitiveCustomItemNamesValue_get =
+ Payload_Xml_ModelWithWrappedPrimitiveCustomItemNames.get;
+Scenarios.Payload_Xml_ModelWithWrappedPrimitiveCustomItemNamesValue_put =
+ Payload_Xml_ModelWithWrappedPrimitiveCustomItemNames.put;
+
+// §4 — Array of complex types
+
const Payload_Xml_ModelWithArrayOfModel = createServerTests(
"/payload/xml/modelWithArrayOfModel",
modelWithArrayOfModel,
@@ -197,12 +410,43 @@ const Payload_Xml_ModelWithArrayOfModel = createServerTests(
Scenarios.Payload_Xml_ModelWithArrayOfModelValue_get = Payload_Xml_ModelWithArrayOfModel.get;
Scenarios.Payload_Xml_ModelWithArrayOfModelValue_put = Payload_Xml_ModelWithArrayOfModel.put;
-const Payload_Xml_ModelWithOptionalField = createServerTests(
- "/payload/xml/modelWithOptionalField",
- modelWithOptionalField,
+const Payload_Xml_ModelWithUnwrappedModelArray = createServerTests(
+ "/payload/xml/modelWithUnwrappedModelArray",
+ modelWithUnwrappedModelArray,
);
-Scenarios.Payload_Xml_ModelWithOptionalFieldValue_get = Payload_Xml_ModelWithOptionalField.get;
-Scenarios.Payload_Xml_ModelWithOptionalFieldValue_put = Payload_Xml_ModelWithOptionalField.put;
+Scenarios.Payload_Xml_ModelWithUnwrappedModelArrayValue_get =
+ Payload_Xml_ModelWithUnwrappedModelArray.get;
+Scenarios.Payload_Xml_ModelWithUnwrappedModelArrayValue_put =
+ Payload_Xml_ModelWithUnwrappedModelArray.put;
+
+const Payload_Xml_ModelWithRenamedWrappedModelArray = createServerTests(
+ "/payload/xml/modelWithRenamedWrappedModelArray",
+ modelWithRenamedWrappedModelArray,
+);
+Scenarios.Payload_Xml_ModelWithRenamedWrappedModelArrayValue_get =
+ Payload_Xml_ModelWithRenamedWrappedModelArray.get;
+Scenarios.Payload_Xml_ModelWithRenamedWrappedModelArrayValue_put =
+ Payload_Xml_ModelWithRenamedWrappedModelArray.put;
+
+const Payload_Xml_ModelWithRenamedUnwrappedModelArray = createServerTests(
+ "/payload/xml/modelWithRenamedUnwrappedModelArray",
+ modelWithRenamedUnwrappedModelArray,
+);
+Scenarios.Payload_Xml_ModelWithRenamedUnwrappedModelArrayValue_get =
+ Payload_Xml_ModelWithRenamedUnwrappedModelArray.get;
+Scenarios.Payload_Xml_ModelWithRenamedUnwrappedModelArrayValue_put =
+ Payload_Xml_ModelWithRenamedUnwrappedModelArray.put;
+
+const Payload_Xml_ModelWithRenamedWrappedAndItemModelArray = createServerTests(
+ "/payload/xml/modelWithRenamedWrappedAndItemModelArray",
+ modelWithRenamedWrappedAndItemModelArray,
+);
+Scenarios.Payload_Xml_ModelWithRenamedWrappedAndItemModelArrayValue_get =
+ Payload_Xml_ModelWithRenamedWrappedAndItemModelArray.get;
+Scenarios.Payload_Xml_ModelWithRenamedWrappedAndItemModelArrayValue_put =
+ Payload_Xml_ModelWithRenamedWrappedAndItemModelArray.put;
+
+// §5 — Attributes
const Payload_Xml_ModelWithAttributes = createServerTests(
"/payload/xml/modelWithAttributes",
@@ -211,26 +455,47 @@ const Payload_Xml_ModelWithAttributes = createServerTests(
Scenarios.Payload_Xml_ModelWithAttributesValue_get = Payload_Xml_ModelWithAttributes.get;
Scenarios.Payload_Xml_ModelWithAttributesValue_put = Payload_Xml_ModelWithAttributes.put;
-const Payload_Xml_ModelWithUnwrappedArray = createServerTests(
- "/payload/xml/modelWithUnwrappedArray",
- modelWithUnwrappedArray,
+const Payload_Xml_ModelWithRenamedAttribute = createServerTests(
+ "/payload/xml/modelWithRenamedAttribute",
+ modelWithRenamedAttribute,
);
-Scenarios.Payload_Xml_ModelWithUnwrappedArrayValue_get = Payload_Xml_ModelWithUnwrappedArray.get;
-Scenarios.Payload_Xml_ModelWithUnwrappedArrayValue_put = Payload_Xml_ModelWithUnwrappedArray.put;
+Scenarios.Payload_Xml_ModelWithRenamedAttributeValue_get =
+ Payload_Xml_ModelWithRenamedAttribute.get;
+Scenarios.Payload_Xml_ModelWithRenamedAttributeValue_put =
+ Payload_Xml_ModelWithRenamedAttribute.put;
-const Payload_Xml_ModelWithRenamedArrays = createServerTests(
- "/payload/xml/modelWithRenamedArrays",
- modelWithRenamedArrays,
+// §6/§7 — Namespace and prefix
+
+const Payload_Xml_ModelWithNamespace = createServerTests(
+ "/payload/xml/modelWithNamespace",
+ modelWithNamespace,
);
-Scenarios.Payload_Xml_ModelWithRenamedArraysValue_get = Payload_Xml_ModelWithRenamedArrays.get;
-Scenarios.Payload_Xml_ModelWithRenamedArraysValue_put = Payload_Xml_ModelWithRenamedArrays.put;
+Scenarios.Payload_Xml_ModelWithNamespaceValue_get = Payload_Xml_ModelWithNamespace.get;
+Scenarios.Payload_Xml_ModelWithNamespaceValue_put = Payload_Xml_ModelWithNamespace.put;
-const Payload_Xml_ModelWithRenamedFields = createServerTests(
- "/payload/xml/modelWithRenamedFields",
- modelWithRenamedFields,
+const Payload_Xml_ModelWithNamespaceOnProperties = createServerTests(
+ "/payload/xml/modelWithNamespaceOnProperties",
+ modelWithNamespaceOnProperties,
);
-Scenarios.Payload_Xml_ModelWithRenamedFieldsValue_get = Payload_Xml_ModelWithRenamedFields.get;
-Scenarios.Payload_Xml_ModelWithRenamedFieldsValue_put = Payload_Xml_ModelWithRenamedFields.put;
+Scenarios.Payload_Xml_ModelWithNamespaceOnPropertiesValue_get =
+ Payload_Xml_ModelWithNamespaceOnProperties.get;
+Scenarios.Payload_Xml_ModelWithNamespaceOnPropertiesValue_put =
+ Payload_Xml_ModelWithNamespaceOnProperties.put;
+
+// §8 — Text content
+
+const Payload_Xml_ModelWithText = createServerTests("/payload/xml/modelWithText", modelWithText);
+Scenarios.Payload_Xml_ModelWithTextValue_get = Payload_Xml_ModelWithText.get;
+Scenarios.Payload_Xml_ModelWithTextValue_put = Payload_Xml_ModelWithText.put;
+
+// Additional scenarios
+
+const Payload_Xml_ModelWithOptionalField = createServerTests(
+ "/payload/xml/modelWithOptionalField",
+ modelWithOptionalField,
+);
+Scenarios.Payload_Xml_ModelWithOptionalFieldValue_get = Payload_Xml_ModelWithOptionalField.get;
+Scenarios.Payload_Xml_ModelWithOptionalFieldValue_put = Payload_Xml_ModelWithOptionalField.put;
const Payload_Xml_ModelWithEmptyArray = createServerTests(
"/payload/xml/modelWithEmptyArray",
@@ -239,10 +504,6 @@ const Payload_Xml_ModelWithEmptyArray = createServerTests(
Scenarios.Payload_Xml_ModelWithEmptyArrayValue_get = Payload_Xml_ModelWithEmptyArray.get;
Scenarios.Payload_Xml_ModelWithEmptyArrayValue_put = Payload_Xml_ModelWithEmptyArray.put;
-const Payload_Xml_ModelWithText = createServerTests("/payload/xml/modelWithText", modelWithText);
-Scenarios.Payload_Xml_ModelWithTextValue_get = Payload_Xml_ModelWithText.get;
-Scenarios.Payload_Xml_ModelWithTextValue_put = Payload_Xml_ModelWithText.put;
-
const Payload_Xml_ModelWithDictionary = createServerTests(
"/payload/xml/modelWithDictionary",
modelWithDictionary,
@@ -300,13 +561,6 @@ Scenarios.Payload_Xml_ModelWithDatetimeValue_put = passOnSuccess({
kind: "MockApiDefinition",
});
-export const xmlError = `
-
- Something went wrong
- 400
-
-`;
-
Scenarios.Payload_Xml_XmlErrorValue_get = passOnCode(400, {
uri: "/payload/xml/error",
method: "get",