Skip to content
Open
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
42 changes: 42 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,21 @@ 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 ComplexArrayModel {
@doc("The array of complex models.")
@unwrapped
items: Array<ComplexModel>;
}

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

@doc("Operations for the ComplexArrayModel type with a single item.")
@route("/complexArrayModel")
interface ComplexArrayValue
extends XmlOperations<
ComplexArrayModel,
"""
<ComplexArrayModel>
<ComplexModel>
<Id>123abc</Id>
</ComplexModel>
<ComplexModel>
<Id>123abc</Id>
</ComplexModel>
</ComplexArrayModel>
"""
> {}

@doc("Operations for the ComplexArrayModel type with no items (empty array).")
@route("/complexArrayModelNoItems")
interface ComplexArrayNoItemsValue
extends XmlOperations<
ComplexArrayModel,
"""
<ComplexArrayModel />
"""
> {}
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 complexArrayModel = `
<ComplexArrayModel>
<ComplexModel>
<Id>123abc</Id>
</ComplexModel>
<ComplexModel>
<Id>123abc</Id>
</ComplexModel>
</ComplexArrayModel>
`;

export const complexArrayModelNoItems = `<ComplexArrayModel />`;

// 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_ComplexArrayModel = createServerTests(
"/payload/xml/complexArrayModel",
complexArrayModel,
);
Scenarios.Payload_Xml_ComplexArrayValue_get = Payload_Xml_ComplexArrayModel.get;
Scenarios.Payload_Xml_ComplexArrayValue_put = Payload_Xml_ComplexArrayModel.put;

const Payload_Xml_ComplexArrayModelNoItems = createServerTests(
"/payload/xml/complexArrayModelNoItems",
complexArrayModelNoItems,
);
Scenarios.Payload_Xml_ComplexArrayNoItemsValue_get = Payload_Xml_ComplexArrayModelNoItems.get;
Scenarios.Payload_Xml_ComplexArrayNoItemsValue_put = Payload_Xml_ComplexArrayModelNoItems.put;
Loading