Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/complex-array-tests-2026-2-12-18-44-14.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@typespec/http-specs"
---

Add tests for complex xml array definitions
54 changes: 54 additions & 0 deletions packages/http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2995,6 +2995,60 @@ Expected response body:
</PetListResult>
```

### Payload_Xml_ComplexArrayNoItemsValue_get

- Endpoint: `get /payload/xml/complexArrayModelNoItems`

Expected response body:

```xml
<ComplexArrayModel />
```

### Payload_Xml_ComplexArrayNoItemsValue_put

- Endpoint: `put /payload/xml/complexArrayModelNoItems`

Expected request body:

```xml
<ComplexArrayModel />
```

### Payload_Xml_ComplexArrayValue_get

- Endpoint: `get /payload/xml/complexArrayModel`

Expected response body:

```xml
<ComplexArrayModel>
<ComplexModel>
<Id>123abc</Id>
</ComplexModel>
<ComplexModel>
<Id>123abc</Id>
</ComplexModel>
</ComplexArrayModel>
```

### Payload_Xml_ComplexArrayValue_put

- Endpoint: `put /payload/xml/complexArrayModel`

Expected request body:

```xml
<ComplexArrayModel>
<ComplexModel>
<Id>123abc</Id>
</ComplexModel>
<ComplexModel>
<Id>123abc</Id>
</ComplexModel>
</ComplexArrayModel>
```

### Payload_Xml_ModelWithArrayOfModelValue_get

- Endpoint: `get /payload/xml/modelWithArrayOfModel`
Expand Down
43 changes: 43 additions & 0 deletions packages/http-specs/specs/payload/xml/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ model XmlErrorBody {
code: int32;
}

@doc("The complex model.")
@name("ComplexModel")
model ComplexModel {
@doc("The unique ID for the complex model.")
@name("Id")
id: string;
}

@doc("Contains an array of complex models with XML unwrapped representation.")
model UnwrappedArrayModel {
@doc("The array of complex models.")
@unwrapped
@name("MyModel")
items: Array<ComplexModel>;
}

@doc("Template for XML operations")
interface XmlOperations<TModel, TDoc extends valueof string> {
@scenario
Expand Down Expand Up @@ -389,3 +405,30 @@ interface XmlErrorValue {
@body body: SimpleModel;
} | XmlError;
}

@doc("Operations for the UnwrappedArrayModel type.")
@route("/unwrappedArrayModel")
interface UnwrappedArrayValue
extends XmlOperations<
UnwrappedArrayModel,
"""
<UnwrappedArrayModel>
<MyModel>
<Id>123abc</Id>
</MyModel>
<MyModel>
<Id>123abc</Id>
</MyModel>
</UnwrappedArrayModel>
"""
> {}

@doc("Operations for the UnwrappedArrayModel type with no items (empty array).")
@route("/unwrappedArrayModelNoItems")
interface UnwrappedArrayNoItemsValue
extends XmlOperations<
UnwrappedArrayModel,
"""
<UnwrappedArrayModel />
"""
> {}
27 changes: 27 additions & 0 deletions packages/http-specs/specs/payload/xml/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ export const modelWithDatetime = `
</ModelWithDatetime>
`;

export const unwrappedArrayModel = `
<UnwrappedArrayModel>
<MyModel>
<Id>123abc</Id>
</MyModel>
<MyModel>
<Id>123abc</Id>
</MyModel>
</UnwrappedArrayModel>
`;

export const unwrappedArrayOfModelNoItems = `<UnwrappedArrayModel />`;

// 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.
Expand Down Expand Up @@ -317,3 +330,17 @@ Scenarios.Payload_Xml_XmlErrorValue_get = passOnCode(400, {
},
kind: "MockApiDefinition",
});

const Payload_Xml_UnwrappedArrayModel = createServerTests(
"/payload/xml/unwrappedArrayModel",
unwrappedArrayModel,
);
Scenarios.Payload_Xml_UnwrappedArrayValue_get = Payload_Xml_UnwrappedArrayModel.get;
Scenarios.Payload_Xml_UnwrappedArrayValue_put = Payload_Xml_UnwrappedArrayModel.put;

const Payload_Xml_UnwrappedArrayOfModelNoItems = createServerTests(
"/payload/xml/unwrappedArrayOfModelNoItems",
unwrappedArrayOfModelNoItems,
);
Scenarios.Payload_Xml_UnwrappedArrayNoItemsValue_get = Payload_Xml_UnwrappedArrayOfModelNoItems.get;
Scenarios.Payload_Xml_UnwrappedArrayNoItemsValue_put = Payload_Xml_UnwrappedArrayOfModelNoItems.put;
Loading