From 4db17f9af26d08d58fdb54b75d9b8003a3a7b266 Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 17 Mar 2026 11:40:14 -0400 Subject: [PATCH 1/3] Xml gaps --- .../http-specs/specs/payload/xml/main.tsp | 531 +++++++++++++----- .../http-specs/specs/payload/xml/mockapi.ts | 202 +++++++ 2 files changed, 607 insertions(+), 126 deletions(-) diff --git a/packages/http-specs/specs/payload/xml/main.tsp b/packages/http-specs/specs/payload/xml/main.tsp index d768dfb2d2d..c786bfe2c4d 100644 --- a/packages/http-specs/specs/payload/xml/main.tsp +++ b/packages/http-specs/specs/payload/xml/main.tsp @@ -6,127 +6,25 @@ 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 used across multiple scenarios + +/** §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; -} - -@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; +@nsDeclarations +enum Namespaces { + smp: "http://example.com/schema", + ns2: "http://example.com/ns2", } -@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 +50,9 @@ interface XmlOperations { put(@header("content-type") contentType: "application/xml", @body input: TModel): void; } -@doc("Operations for the SimpleModel type.") +// --- Scenarios --- + +/** §1.1 — Operations for the SimpleModel type. */ @route("/simpleModel") interface SimpleModelValue extends XmlOperations< @@ -165,7 +65,13 @@ interface SimpleModelValue """ > {} -@doc("Operations for the ModelWithSimpleArrays type.") +/** §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 +91,12 @@ interface ModelWithSimpleArraysValue """ > {} -@doc("Operations for the ModelWithArrayOfModel type.") +/** §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,7 +117,13 @@ interface ModelWithArrayOfModelValue """ > {} -@doc("Operations for the ModelWithOptionalField type.") +/** Contains an optional field. */ +model ModelWithOptionalField { + item: string; + value?: int32; +} + +/** Operations for the ModelWithOptionalField type. */ @route("/modelWithOptionalField") interface ModelWithOptionalFieldValue extends XmlOperations< @@ -218,7 +135,14 @@ interface ModelWithOptionalFieldValue """ > {} -@doc("Operations for the ModelWithAttributes type.") +/** §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,7 +154,13 @@ interface ModelWithAttributesValue """ > {} -@doc("Operations for the ModelWithUnwrappedArray 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< @@ -248,7 +178,13 @@ interface ModelWithUnwrappedArrayValue """ > {} -@doc("Operations for the ModelWithRenamedArrays type.") +/** §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< @@ -266,7 +202,14 @@ interface ModelWithRenamedArraysValue """ > {} -@doc("Operations for the ModelWithRenamedFields type.") +/** §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< @@ -285,7 +228,12 @@ interface ModelWithRenamedFieldsValue """ > {} -@doc("Operations for the ModelWithEmptyArray type.") +/** 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< @@ -297,7 +245,13 @@ interface ModelWithEmptyArrayValue """ > {} -@doc("Operations for the ModelWithText type.") +/** §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 +263,12 @@ interface ModelWithTextValue """ > {} -@doc("Operations for the ModelWithDictionary type.") +/** Contains a dictionary of key value pairs. */ +model ModelWithDictionary { + metadata: Record; +} + +/** Operations for the ModelWithDictionary type. */ @route("/modelWithDictionary") interface ModelWithDictionaryValue extends XmlOperations< @@ -325,7 +284,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 +311,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 +342,18 @@ interface ModelWithEnumValue """ > {} -@doc("Operations for the ModelWithDatetime type.") +/** Contains datetime properties with different encodings. */ +model ModelWithDatetime { + @encode(DateTimeKnownEncoding.rfc3339) + /** DateTime value with rfc3339 encoding. */ + rfc3339: utcDateTime; + + @encode(DateTimeKnownEncoding.rfc7231) + /** DateTime value with rfc7231 encoding. */ + rfc7231: utcDateTime; +} + +/** Operations for the ModelWithDatetime type. */ @route("/modelWithDatetime") interface ModelWithDatetimeValue extends XmlOperations< @@ -370,7 +366,290 @@ interface ModelWithDatetimeValue """ > {} -@doc("Operations that return an error response in XML format.") +/** §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 + + """ + > {} + +/** §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 + + + """ + > {} + +/** 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.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< + ModelWithUnwrappedModelArray, + """ + + + foo + 123 + + + bar + 456 + + + """ + > {} + +/** §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.2 — Contains a renamed XML attribute. */ +model ModelWithRenamedAttribute { + @attribute + @name("xml-id") + id: int32; + + title: string; + author: string; +} + +/** §5.2 — Operations for the ModelWithRenamedAttribute type. */ +@route("/modelWithRenamedAttribute") +interface ModelWithRenamedAttributeValue + extends XmlOperations< + ModelWithRenamedAttribute, + """ + + The Great Gatsby + F. Scott Fitzgerald + + """ + > {} + +/** §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< + ModelWithNamespace, + """ + + 123 + The Great Gatsby + + """ + > {} + +/** §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< + ModelWithNamespaceOnProperties, + """ + + 123 + The Great Gatsby + F. Scott Fitzgerald + + """ + > {} + +/** 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..1cf7762752b 100644 --- a/packages/http-specs/specs/payload/xml/mockapi.ts +++ b/packages/http-specs/specs/payload/xml/mockapi.ts @@ -146,6 +146,115 @@ const modelWithDatetimeNoMs = ` `; +export const modelWithRenamedProperty = ` + + foo + bar + +`; + +export const modelWithNestedModel = ` + + + foo + 123 + + +`; + +export const modelWithRenamedNestedModel = ` + + + foo + + +`; + +export const modelWithWrappedPrimitiveCustomItemNames = ` + + + fiction + classic + + +`; + +export const modelWithUnwrappedModelArray = ` + + + foo + 123 + + + bar + 456 + + +`; + +export const modelWithRenamedWrappedModelArray = ` + + + + foo + 123 + + + bar + 456 + + + +`; + +export const modelWithRenamedUnwrappedModelArray = ` + + + foo + 123 + + + bar + 456 + + +`; + +export const modelWithRenamedWrappedAndItemModelArray = ` + + + + The Great Gatsby + + + Les Miserables + + + +`; + +export const modelWithRenamedAttribute = ` + + The Great Gatsby + F. Scott Fitzgerald + +`; + +export const modelWithNamespace = ` + + 123 + The Great Gatsby + +`; + +export const modelWithNamespaceOnProperties = ` + + 123 + The Great Gatsby + F. Scott Fitzgerald + +`; + function createServerTests(uri: string, data?: any) { return { get: passOnSuccess({ @@ -300,6 +409,99 @@ Scenarios.Payload_Xml_ModelWithDatetimeValue_put = passOnSuccess({ kind: "MockApiDefinition", }); +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_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; + +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; + +const Payload_Xml_ModelWithUnwrappedModelArray = createServerTests( + "/payload/xml/modelWithUnwrappedModelArray", + modelWithUnwrappedModelArray, +); +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; + +const Payload_Xml_ModelWithRenamedAttribute = createServerTests( + "/payload/xml/modelWithRenamedAttribute", + modelWithRenamedAttribute, +); +Scenarios.Payload_Xml_ModelWithRenamedAttributeValue_get = + Payload_Xml_ModelWithRenamedAttribute.get; +Scenarios.Payload_Xml_ModelWithRenamedAttributeValue_put = + Payload_Xml_ModelWithRenamedAttribute.put; + +const Payload_Xml_ModelWithNamespace = createServerTests( + "/payload/xml/modelWithNamespace", + modelWithNamespace, +); +Scenarios.Payload_Xml_ModelWithNamespaceValue_get = Payload_Xml_ModelWithNamespace.get; +Scenarios.Payload_Xml_ModelWithNamespaceValue_put = Payload_Xml_ModelWithNamespace.put; + +const Payload_Xml_ModelWithNamespaceOnProperties = createServerTests( + "/payload/xml/modelWithNamespaceOnProperties", + modelWithNamespaceOnProperties, +); +Scenarios.Payload_Xml_ModelWithNamespaceOnPropertiesValue_get = + Payload_Xml_ModelWithNamespaceOnProperties.get; +Scenarios.Payload_Xml_ModelWithNamespaceOnPropertiesValue_put = + Payload_Xml_ModelWithNamespaceOnProperties.put; + export const xmlError = ` Something went wrong From 94d48500881fcb73f4c28d95c5f0498ea31540ef Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 17 Mar 2026 11:54:39 -0400 Subject: [PATCH 2/3] fix ordering --- .../http-specs/specs/payload/xml/main.tsp | 620 +++++++++--------- .../http-specs/specs/payload/xml/mockapi.ts | 538 ++++++++------- 2 files changed, 621 insertions(+), 537 deletions(-) diff --git a/packages/http-specs/specs/payload/xml/main.tsp b/packages/http-specs/specs/payload/xml/main.tsp index c786bfe2c4d..9b77a97bede 100644 --- a/packages/http-specs/specs/payload/xml/main.tsp +++ b/packages/http-specs/specs/payload/xml/main.tsp @@ -10,7 +10,9 @@ using TypeSpec.Xml; @scenarioService("/payload/xml") namespace Payload.Xml; -// Shared types used across multiple scenarios +// ──────────────────────────────────────────────────────────────────────────── +// Shared types +// ──────────────────────────────────────────────────────────────────────────── /** §1.1 — Contains fields of primitive types. */ model SimpleModel { @@ -50,7 +52,9 @@ interface XmlOperations { put(@header("content-type") contentType: "application/xml", @body input: TModel): void; } -// --- Scenarios --- +// ──────────────────────────────────────────────────────────────────────────── +// §1 — Primitive properties +// ──────────────────────────────────────────────────────────────────────────── /** §1.1 — Operations for the SimpleModel type. */ @route("/simpleModel") @@ -65,140 +69,24 @@ interface SimpleModelValue """ > {} -/** §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< - ModelWithSimpleArrays, - """ - - - red - green - blue - - - 1 - 2 - - - """ - > {} - -/** §4.1 — Contains an array of models. */ -model ModelWithArrayOfModel { - items: SimpleModel[]; -} - -/** §4.1 — Operations for the ModelWithArrayOfModel type. */ -@route("/modelWithArrayOfModel") -interface ModelWithArrayOfModelValue - extends XmlOperations< - ModelWithArrayOfModel, - """ - - - - foo - 123 - - - bar - 456 - - - - """ - > {} - -/** Contains an optional field. */ -model ModelWithOptionalField { - item: string; - value?: int32; -} - -/** Operations for the ModelWithOptionalField type. */ -@route("/modelWithOptionalField") -interface ModelWithOptionalFieldValue - extends XmlOperations< - ModelWithOptionalField, - """ - - widget - - """ - > {} - -/** §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< - ModelWithAttributes, - """ - - true - - """ - > {} - -/** §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 - - - """ - > {} +/** §1.2 — Contains a scalar property with a custom XML name. */ +model ModelWithRenamedProperty { + @name("renamedTitle") + title: string; -/** §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[]; + author: string; } -/** §3.3, §3.4 — Operations for the ModelWithRenamedArrays type. */ -@route("/modelWithRenamedArrays") -interface ModelWithRenamedArraysValue +/** §1.2 — Operations for the ModelWithRenamedProperty type. */ +@route("/modelWithRenamedProperty") +interface ModelWithRenamedPropertyValue extends XmlOperations< - ModelWithRenamedArrays, + ModelWithRenamedProperty, """ - - red - green - blue - - 1 - 2 - - + + foo + bar + """ > {} @@ -228,207 +116,130 @@ interface ModelWithRenamedFieldsValue """ > {} -/** 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, - """ - - - - """ - > {} - -/** §8.1 — Contains an attribute and text. */ -model ModelWithText { - @attribute language: string; - @unwrapped content: string; -} +// ──────────────────────────────────────────────────────────────────────────── +// §2 — Nested models +// ──────────────────────────────────────────────────────────────────────────── -/** §8.1 — Operations for the ModelWithText type. */ -@route("/modelWithText") -interface ModelWithTextValue - extends XmlOperations< - ModelWithText, - """ - - This is some text. - - """ - > {} - -/** Contains a dictionary of key value pairs. */ -model ModelWithDictionary { - metadata: Record; -} - -/** Operations for the ModelWithDictionary type. */ -@route("/modelWithDictionary") -interface ModelWithDictionaryValue - extends XmlOperations< - ModelWithDictionary, - """ - - - blue - 123 - false - - - """ - > {} - -/** 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[]; +/** §2.1 — Contains a property that references another model. */ +model ModelWithNestedModel { + nested: SimpleModel; } -/** Operations for the ModelWithEncodedNames type. */ -@route("/modelWithEncodedNames") -interface ModelWithEncodedNamesValue +/** §2.1 — Operations for the ModelWithNestedModel type. */ +@route("/modelWithNestedModel") +interface ModelWithNestedModelValue extends XmlOperations< - ModelWithEncodedNames, + ModelWithNestedModel, """ - - + + foo 123 - - - red - green - blue - - + + """ > {} -/** 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; +/** Author model with a custom XML name. */ +@name("XmlAuthor") +model Author { + name: string; } -/** Operations for the ModelWithEnum type. */ -@route("/modelWithEnum") -interface ModelWithEnumValue - extends XmlOperations< - ModelWithEnum, - """ - - success - - """ - > {} - -/** Contains datetime properties with different encodings. */ -model ModelWithDatetime { - @encode(DateTimeKnownEncoding.rfc3339) - /** DateTime value with rfc3339 encoding. */ - rfc3339: utcDateTime; - - @encode(DateTimeKnownEncoding.rfc7231) - /** DateTime value with rfc7231 encoding. */ - rfc7231: utcDateTime; +/** §2.2 — Contains a property whose type has @Xml.name. The property name takes precedence. */ +model ModelWithRenamedNestedModel { + author: Author; } -/** Operations for the ModelWithDatetime type. */ -@route("/modelWithDatetime") -interface ModelWithDatetimeValue +/** §2.2 — Operations for the ModelWithRenamedNestedModel type. */ +@route("/modelWithRenamedNestedModel") +interface ModelWithRenamedNestedModelValue extends XmlOperations< - ModelWithDatetime, + ModelWithRenamedNestedModel, """ - - 2022-08-26T18:38:00.000Z - Fri, 26 Aug 2022 14:38:00 GMT - + + + foo + + """ > {} -/** §1.2 — Contains a scalar property with a custom XML name. */ -model ModelWithRenamedProperty { - @name("renamedTitle") - title: string; +// ──────────────────────────────────────────────────────────────────────────── +// §3 — Array of primitive types +// ──────────────────────────────────────────────────────────────────────────── - author: string; +/** §3.1 — Contains fields of arrays of primitive types. */ +model ModelWithSimpleArrays { + colors: string[]; + counts: int32[]; } -/** §1.2 — Operations for the ModelWithRenamedProperty type. */ -@route("/modelWithRenamedProperty") -interface ModelWithRenamedPropertyValue +/** §3.1 — Operations for the ModelWithSimpleArrays type. */ +@route("/modelWithSimpleArrays") +interface ModelWithSimpleArraysValue extends XmlOperations< - ModelWithRenamedProperty, + ModelWithSimpleArrays, """ - - foo - bar - + + + red + green + blue + + + 1 + 2 + + """ > {} -/** §2.1 — Contains a property that references another model. */ -model ModelWithNestedModel { - nested: SimpleModel; +/** §3.2 — Contains fields of wrapped and unwrapped arrays of primitive types. */ +model ModelWithUnwrappedArray { + @unwrapped colors: string[]; + counts: int32[]; } -/** §2.1 — Operations for the ModelWithNestedModel type. */ -@route("/modelWithNestedModel") -interface ModelWithNestedModelValue +/** §3.2 — Operations for the ModelWithUnwrappedArray type. */ +@route("/modelWithUnwrappedArray") +interface ModelWithUnwrappedArrayValue extends XmlOperations< - ModelWithNestedModel, + ModelWithUnwrappedArray, """ - - - foo - 123 - - + + red + green + blue + + 1 + 2 + + """ > {} -/** 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; +/** §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[]; } -/** §2.2 — Operations for the ModelWithRenamedNestedModel type. */ -@route("/modelWithRenamedNestedModel") -interface ModelWithRenamedNestedModelValue +/** §3.3, §3.4 — Operations for the ModelWithRenamedArrays type. */ +@route("/modelWithRenamedArrays") +interface ModelWithRenamedArraysValue extends XmlOperations< - ModelWithRenamedNestedModel, + ModelWithRenamedArrays, """ - - - foo - - + + red + green + blue + + 1 + 2 + + """ > {} @@ -457,6 +268,36 @@ interface ModelWithWrappedPrimitiveCustomItemNamesValue """ > {} +// ──────────────────────────────────────────────────────────────────────────── +// §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< + ModelWithArrayOfModel, + """ + + + + foo + 123 + + + bar + 456 + + + + """ + > {} + /** §4.2 — Contains an unwrapped array of models. */ model ModelWithUnwrappedModelArray { @unwrapped @@ -566,6 +407,29 @@ interface ModelWithRenamedWrappedAndItemModelArrayValue """ > {} +// ──────────────────────────────────────────────────────────────────────────── +// §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< + ModelWithAttributes, + """ + + true + + """ + > {} + /** §5.2 — Contains a renamed XML attribute. */ model ModelWithRenamedAttribute { @attribute @@ -589,6 +453,10 @@ interface ModelWithRenamedAttributeValue """ > {} +// ──────────────────────────────────────────────────────────────────────────── +// §6/§7 — Namespace and prefix +// ──────────────────────────────────────────────────────────────────────────── + /** §6.1, §7.1 — Contains fields with XML namespace on the model. */ @ns(Namespaces.smp) model ModelWithNamespace { @@ -635,6 +503,170 @@ interface ModelWithNamespaceOnPropertiesValue """ > {} +// ──────────────────────────────────────────────────────────────────────────── +// §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< + ModelWithText, + """ + + This is some text. + + """ + > {} + +// ──────────────────────────────────────────────────────────────────────────── +// 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< + ModelWithDictionary, + """ + + + blue + 123 + false + + + """ + > {} + +/** 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< + ModelWithEncodedNames, + """ + + + foo + 123 + + + red + green + blue + + + """ + > {} + +/** 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< + ModelWithEnum, + """ + + success + + """ + > {} + +/** Contains datetime properties with different encodings. */ +model ModelWithDatetime { + @encode(DateTimeKnownEncoding.rfc3339) + /** DateTime value with rfc3339 encoding. */ + rfc3339: utcDateTime; + + @encode(DateTimeKnownEncoding.rfc7231) + /** DateTime value with rfc7231 encoding. */ + rfc7231: utcDateTime; +} + +/** Operations for the ModelWithDatetime type. */ +@route("/modelWithDatetime") +interface ModelWithDatetimeValue + extends XmlOperations< + ModelWithDatetime, + """ + + 2022-08-26T18:38:00.000Z + Fri, 26 Aug 2022 14:38:00 GMT + + """ + > {} + /** An error response body in XML format. */ @error model XmlError { diff --git a/packages/http-specs/specs/payload/xml/mockapi.ts b/packages/http-specs/specs/payload/xml/mockapi.ts index 1cf7762752b..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,102 +96,6 @@ export const modelWithRenamedArrays = ` `; -export const modelWithRenamedFields = ` - - - foo - 123 - - - bar - 456 - - -`; - -export const modelWithEmptyArray = ` - - - -`; - -export const modelWithText = ` - - This is some text. - -`; - -export const modelWithDictionary = ` - - - blue - 123 - false - - -`; - -export const modelWithEncodedNames = ` - - - foo - 123 - - - red - green - blue - - -`; - -export const modelWithEnum = ` - - success - -`; - -export const modelWithDatetime = ` - - 2022-08-26T18:38:00.000Z - Fri, 26 Aug 2022 14:38:00 GMT - -`; - -// Some clients serialize UTC datetimes without trailing zero milliseconds. Both -// "2022-08-26T18:38:00.000Z" and "2022-08-26T18:38:00Z" are valid RFC3339 representations -// of the same instant; accept either form. -const modelWithDatetimeNoMs = ` - - 2022-08-26T18:38:00Z - Fri, 26 Aug 2022 14:38:00 GMT - -`; - -export const modelWithRenamedProperty = ` - - foo - bar - -`; - -export const modelWithNestedModel = ` - - - foo - 123 - - -`; - -export const modelWithRenamedNestedModel = ` - - - foo - - -`; - export const modelWithWrappedPrimitiveCustomItemNames = ` @@ -179,6 +105,25 @@ export const modelWithWrappedPrimitiveCustomItemNames = ` `; +// ──────────────────────────────────────────────────────────────────────────── +// §4 — Array of complex types +// ──────────────────────────────────────────────────────────────────────────── + +export const modelWithArrayOfModel = ` + + + + foo + 123 + + + bar + 456 + + + +`; + export const modelWithUnwrappedModelArray = ` @@ -233,6 +178,16 @@ export const modelWithRenamedWrappedAndItemModelArray = ` `; +// ──────────────────────────────────────────────────────────────────────────── +// §5 — Attributes +// ──────────────────────────────────────────────────────────────────────────── + +export const modelWithAttributes = ` + + true + +`; + export const modelWithRenamedAttribute = ` The Great Gatsby @@ -240,6 +195,10 @@ export const modelWithRenamedAttribute = ` `; +// ──────────────────────────────────────────────────────────────────────────── +// §6/§7 — Namespace and prefix +// ──────────────────────────────────────────────────────────────────────────── + export const modelWithNamespace = ` 123 @@ -255,6 +214,90 @@ export const modelWithNamespaceOnProperties = ` `; +// ──────────────────────────────────────────────────────────────────────────── +// §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 = ` + + + blue + 123 + false + + +`; + +export const modelWithEncodedNames = ` + + + foo + 123 + + + red + green + blue + + +`; + +export const modelWithEnum = ` + + success + +`; + +export const modelWithDatetime = ` + + 2022-08-26T18:38:00.000Z + Fri, 26 Aug 2022 14:38:00 GMT + +`; + +// Some clients serialize UTC datetimes without trailing zero milliseconds. Both +// "2022-08-26T18:38:00.000Z" and "2022-08-26T18:38:00Z" are valid RFC3339 representations +// of the same instant; accept either form. +const modelWithDatetimeNoMs = ` + + 2022-08-26T18:38:00Z + Fri, 26 Aug 2022 14:38:00 GMT + +`; + +export const xmlError = ` + + Something went wrong + 400 + +`; + +// ──────────────────────────────────────────────────────────────────────────── +// Scenario registrations +// ──────────────────────────────────────────────────────────────────────────── + function createServerTests(uri: string, data?: any) { return { get: passOnSuccess({ @@ -288,51 +331,18 @@ 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_ModelWithSimpleArrays = createServerTests( - "/payload/xml/modelWithSimpleArrays", - modelWithSimpleArrays, -); -Scenarios.Payload_Xml_ModelWithSimpleArraysValue_get = Payload_Xml_ModelWithSimpleArrays.get; -Scenarios.Payload_Xml_ModelWithSimpleArraysValue_put = Payload_Xml_ModelWithSimpleArrays.put; - -const Payload_Xml_ModelWithArrayOfModel = createServerTests( - "/payload/xml/modelWithArrayOfModel", - modelWithArrayOfModel, -); -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, -); -Scenarios.Payload_Xml_ModelWithOptionalFieldValue_get = Payload_Xml_ModelWithOptionalField.get; -Scenarios.Payload_Xml_ModelWithOptionalFieldValue_put = Payload_Xml_ModelWithOptionalField.put; - -const Payload_Xml_ModelWithAttributes = createServerTests( - "/payload/xml/modelWithAttributes", - modelWithAttributes, -); -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, -); -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, +const Payload_Xml_ModelWithRenamedProperty = createServerTests( + "/payload/xml/modelWithRenamedProperty", + modelWithRenamedProperty, ); -Scenarios.Payload_Xml_ModelWithRenamedArraysValue_get = Payload_Xml_ModelWithRenamedArrays.get; -Scenarios.Payload_Xml_ModelWithRenamedArraysValue_put = Payload_Xml_ModelWithRenamedArrays.put; +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", @@ -341,80 +351,7 @@ const Payload_Xml_ModelWithRenamedFields = createServerTests( Scenarios.Payload_Xml_ModelWithRenamedFieldsValue_get = Payload_Xml_ModelWithRenamedFields.get; Scenarios.Payload_Xml_ModelWithRenamedFieldsValue_put = Payload_Xml_ModelWithRenamedFields.put; -const Payload_Xml_ModelWithEmptyArray = createServerTests( - "/payload/xml/modelWithEmptyArray", - modelWithEmptyArray, -); -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, -); -Scenarios.Payload_Xml_ModelWithDictionaryValue_get = Payload_Xml_ModelWithDictionary.get; -Scenarios.Payload_Xml_ModelWithDictionaryValue_put = Payload_Xml_ModelWithDictionary.put; - -const Payload_Xml_ModelWithEncodedNames = createServerTests( - "/payload/xml/modelWithEncodedNames", - modelWithEncodedNames, -); -Scenarios.Payload_Xml_ModelWithEncodedNamesValue_get = Payload_Xml_ModelWithEncodedNames.get; -Scenarios.Payload_Xml_ModelWithEncodedNamesValue_put = Payload_Xml_ModelWithEncodedNames.put; - -const Payload_Xml_ModelWithEnum = createServerTests("/payload/xml/modelWithEnum", modelWithEnum); -Scenarios.Payload_Xml_ModelWithEnumValue_get = Payload_Xml_ModelWithEnum.get; -Scenarios.Payload_Xml_ModelWithEnumValue_put = Payload_Xml_ModelWithEnum.put; - -Scenarios.Payload_Xml_ModelWithDatetimeValue_get = passOnSuccess({ - uri: "/payload/xml/modelWithDatetime", - method: "get", - request: {}, - response: { - status: 200, - body: xml(modelWithDatetime), - }, - kind: "MockApiDefinition", -}); - -Scenarios.Payload_Xml_ModelWithDatetimeValue_put = passOnSuccess({ - uri: "/payload/xml/modelWithDatetime", - method: "put", - request: { - body: xml(modelWithDatetime), - }, - handler: (req: MockRequest) => { - req.expect.containsHeader("content-type", "application/xml"); - // Accept both "2022-08-26T18:38:00.000Z" and "2022-08-26T18:38:00Z" as equivalent UTC datetimes. - let firstError: unknown; - try { - req.expect.xmlBodyEquals(modelWithDatetime); - } catch (e) { - firstError = e; - } - if (firstError !== undefined) { - req.expect.xmlBodyEquals(modelWithDatetimeNoMs); - } - return { - status: 204, - }; - }, - response: { - status: 204, - }, - kind: "MockApiDefinition", -}); - -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; +// §2 — Nested models const Payload_Xml_ModelWithNestedModel = createServerTests( "/payload/xml/modelWithNestedModel", @@ -432,6 +369,29 @@ Scenarios.Payload_Xml_ModelWithRenamedNestedModelValue_get = Scenarios.Payload_Xml_ModelWithRenamedNestedModelValue_put = Payload_Xml_ModelWithRenamedNestedModel.put; +// §3 — Array of primitive types + +const Payload_Xml_ModelWithSimpleArrays = createServerTests( + "/payload/xml/modelWithSimpleArrays", + modelWithSimpleArrays, +); +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, @@ -441,6 +401,15 @@ Scenarios.Payload_Xml_ModelWithWrappedPrimitiveCustomItemNamesValue_get = Scenarios.Payload_Xml_ModelWithWrappedPrimitiveCustomItemNamesValue_put = Payload_Xml_ModelWithWrappedPrimitiveCustomItemNames.put; +// §4 — Array of complex types + +const Payload_Xml_ModelWithArrayOfModel = createServerTests( + "/payload/xml/modelWithArrayOfModel", + modelWithArrayOfModel, +); +Scenarios.Payload_Xml_ModelWithArrayOfModelValue_get = Payload_Xml_ModelWithArrayOfModel.get; +Scenarios.Payload_Xml_ModelWithArrayOfModelValue_put = Payload_Xml_ModelWithArrayOfModel.put; + const Payload_Xml_ModelWithUnwrappedModelArray = createServerTests( "/payload/xml/modelWithUnwrappedModelArray", modelWithUnwrappedModelArray, @@ -477,6 +446,15 @@ Scenarios.Payload_Xml_ModelWithRenamedWrappedAndItemModelArrayValue_get = Scenarios.Payload_Xml_ModelWithRenamedWrappedAndItemModelArrayValue_put = Payload_Xml_ModelWithRenamedWrappedAndItemModelArray.put; +// §5 — Attributes + +const Payload_Xml_ModelWithAttributes = createServerTests( + "/payload/xml/modelWithAttributes", + modelWithAttributes, +); +Scenarios.Payload_Xml_ModelWithAttributesValue_get = Payload_Xml_ModelWithAttributes.get; +Scenarios.Payload_Xml_ModelWithAttributesValue_put = Payload_Xml_ModelWithAttributes.put; + const Payload_Xml_ModelWithRenamedAttribute = createServerTests( "/payload/xml/modelWithRenamedAttribute", modelWithRenamedAttribute, @@ -486,6 +464,8 @@ Scenarios.Payload_Xml_ModelWithRenamedAttributeValue_get = Scenarios.Payload_Xml_ModelWithRenamedAttributeValue_put = Payload_Xml_ModelWithRenamedAttribute.put; +// §6/§7 — Namespace and prefix + const Payload_Xml_ModelWithNamespace = createServerTests( "/payload/xml/modelWithNamespace", modelWithNamespace, @@ -502,12 +482,84 @@ Scenarios.Payload_Xml_ModelWithNamespaceOnPropertiesValue_get = Scenarios.Payload_Xml_ModelWithNamespaceOnPropertiesValue_put = Payload_Xml_ModelWithNamespaceOnProperties.put; -export const xmlError = ` - - Something went wrong - 400 - -`; +// §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", + modelWithEmptyArray, +); +Scenarios.Payload_Xml_ModelWithEmptyArrayValue_get = Payload_Xml_ModelWithEmptyArray.get; +Scenarios.Payload_Xml_ModelWithEmptyArrayValue_put = Payload_Xml_ModelWithEmptyArray.put; + +const Payload_Xml_ModelWithDictionary = createServerTests( + "/payload/xml/modelWithDictionary", + modelWithDictionary, +); +Scenarios.Payload_Xml_ModelWithDictionaryValue_get = Payload_Xml_ModelWithDictionary.get; +Scenarios.Payload_Xml_ModelWithDictionaryValue_put = Payload_Xml_ModelWithDictionary.put; + +const Payload_Xml_ModelWithEncodedNames = createServerTests( + "/payload/xml/modelWithEncodedNames", + modelWithEncodedNames, +); +Scenarios.Payload_Xml_ModelWithEncodedNamesValue_get = Payload_Xml_ModelWithEncodedNames.get; +Scenarios.Payload_Xml_ModelWithEncodedNamesValue_put = Payload_Xml_ModelWithEncodedNames.put; + +const Payload_Xml_ModelWithEnum = createServerTests("/payload/xml/modelWithEnum", modelWithEnum); +Scenarios.Payload_Xml_ModelWithEnumValue_get = Payload_Xml_ModelWithEnum.get; +Scenarios.Payload_Xml_ModelWithEnumValue_put = Payload_Xml_ModelWithEnum.put; + +Scenarios.Payload_Xml_ModelWithDatetimeValue_get = passOnSuccess({ + uri: "/payload/xml/modelWithDatetime", + method: "get", + request: {}, + response: { + status: 200, + body: xml(modelWithDatetime), + }, + kind: "MockApiDefinition", +}); + +Scenarios.Payload_Xml_ModelWithDatetimeValue_put = passOnSuccess({ + uri: "/payload/xml/modelWithDatetime", + method: "put", + request: { + body: xml(modelWithDatetime), + }, + handler: (req: MockRequest) => { + req.expect.containsHeader("content-type", "application/xml"); + // Accept both "2022-08-26T18:38:00.000Z" and "2022-08-26T18:38:00Z" as equivalent UTC datetimes. + let firstError: unknown; + try { + req.expect.xmlBodyEquals(modelWithDatetime); + } catch (e) { + firstError = e; + } + if (firstError !== undefined) { + req.expect.xmlBodyEquals(modelWithDatetimeNoMs); + } + return { + status: 204, + }; + }, + response: { + status: 204, + }, + kind: "MockApiDefinition", +}); Scenarios.Payload_Xml_XmlErrorValue_get = passOnCode(400, { uri: "/payload/xml/error", From 37df2ec7d9d077641957472870f510107fd70ddb Mon Sep 17 00:00:00 2001 From: Timothee Guerin Date: Tue, 17 Mar 2026 12:19:16 -0400 Subject: [PATCH 3/3] format --- packages/http-specs/spec-summary.md | 350 ++++++++++++++++++ .../http-specs/specs/payload/xml/main.tsp | 4 +- 2 files changed, 352 insertions(+), 2 deletions(-) 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 9b77a97bede..57a620adc8a 100644 --- a/packages/http-specs/specs/payload/xml/main.tsp +++ b/packages/http-specs/specs/payload/xml/main.tsp @@ -645,12 +645,12 @@ interface ModelWithEnumValue /** Contains datetime properties with different encodings. */ model ModelWithDatetime { - @encode(DateTimeKnownEncoding.rfc3339) /** DateTime value with rfc3339 encoding. */ + @encode(DateTimeKnownEncoding.rfc3339) rfc3339: utcDateTime; - @encode(DateTimeKnownEncoding.rfc7231) /** DateTime value with rfc7231 encoding. */ + @encode(DateTimeKnownEncoding.rfc7231) rfc7231: utcDateTime; }