@typespec/http-specs 0.1.0-alpha.9 → 0.1.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/CHANGELOG.md +260 -3
  2. package/README.md +11 -3
  3. package/dist/specs/authentication/noauth/union/mockapi.d.ts +3 -0
  4. package/dist/specs/authentication/noauth/union/mockapi.d.ts.map +1 -0
  5. package/dist/specs/authentication/noauth/union/mockapi.js +25 -0
  6. package/dist/specs/authentication/noauth/union/mockapi.js.map +1 -0
  7. package/dist/specs/documentation/mockapi.d.ts +3 -0
  8. package/dist/specs/documentation/mockapi.d.ts.map +1 -0
  9. package/dist/specs/documentation/mockapi.js +40 -0
  10. package/dist/specs/documentation/mockapi.js.map +1 -0
  11. package/dist/specs/encode/array/mockapi.d.ts +3 -0
  12. package/dist/specs/encode/array/mockapi.d.ts.map +1 -0
  13. package/dist/specs/encode/array/mockapi.js +33 -0
  14. package/dist/specs/encode/array/mockapi.js.map +1 -0
  15. package/dist/specs/encode/bytes/mockapi.js +16 -24
  16. package/dist/specs/encode/bytes/mockapi.js.map +1 -1
  17. package/dist/specs/encode/datetime/mockapi.js +2 -2
  18. package/dist/specs/encode/datetime/mockapi.js.map +1 -1
  19. package/dist/specs/encode/duration/mockapi.d.ts.map +1 -1
  20. package/dist/specs/encode/duration/mockapi.js +115 -3
  21. package/dist/specs/encode/duration/mockapi.js.map +1 -1
  22. package/dist/specs/encode/numeric/mockapi.js +2 -2
  23. package/dist/specs/encode/numeric/mockapi.js.map +1 -1
  24. package/dist/specs/helper.d.ts +2 -2
  25. package/dist/specs/helper.d.ts.map +1 -1
  26. package/dist/specs/parameters/basic/mockapi.d.ts.map +1 -1
  27. package/dist/specs/parameters/basic/mockapi.js +3 -3
  28. package/dist/specs/parameters/basic/mockapi.js.map +1 -1
  29. package/dist/specs/parameters/body-optionality/mockapi.d.ts.map +1 -1
  30. package/dist/specs/parameters/body-optionality/mockapi.js +14 -4
  31. package/dist/specs/parameters/body-optionality/mockapi.js.map +1 -1
  32. package/dist/specs/parameters/collection-format/mockapi.js +4 -15
  33. package/dist/specs/parameters/collection-format/mockapi.js.map +1 -1
  34. package/dist/specs/parameters/path/mockapi.d.ts +3 -0
  35. package/dist/specs/parameters/path/mockapi.d.ts.map +1 -0
  36. package/dist/specs/parameters/path/mockapi.js +29 -0
  37. package/dist/specs/parameters/path/mockapi.js.map +1 -0
  38. package/dist/specs/parameters/query/mockapi.d.ts +3 -0
  39. package/dist/specs/parameters/query/mockapi.d.ts.map +1 -0
  40. package/dist/specs/parameters/query/mockapi.js +14 -0
  41. package/dist/specs/parameters/query/mockapi.js.map +1 -0
  42. package/dist/specs/parameters/spread/mockapi.d.ts.map +1 -1
  43. package/dist/specs/parameters/spread/mockapi.js +19 -19
  44. package/dist/specs/parameters/spread/mockapi.js.map +1 -1
  45. package/dist/specs/payload/json-merge-patch/mockapi.js +4 -4
  46. package/dist/specs/payload/json-merge-patch/mockapi.js.map +1 -1
  47. package/dist/specs/payload/media-type/mockapi.js +2 -2
  48. package/dist/specs/payload/media-type/mockapi.js.map +1 -1
  49. package/dist/specs/payload/multipart/mockapi.d.ts.map +1 -1
  50. package/dist/specs/payload/multipart/mockapi.js +196 -60
  51. package/dist/specs/payload/multipart/mockapi.js.map +1 -1
  52. package/dist/specs/payload/pageable/mockapi.d.ts.map +1 -1
  53. package/dist/specs/payload/pageable/mockapi.js +626 -14
  54. package/dist/specs/payload/pageable/mockapi.js.map +1 -1
  55. package/dist/specs/payload/xml/mockapi.d.ts +19 -5
  56. package/dist/specs/payload/xml/mockapi.d.ts.map +1 -1
  57. package/dist/specs/payload/xml/mockapi.js +311 -55
  58. package/dist/specs/payload/xml/mockapi.js.map +1 -1
  59. package/dist/specs/response/status-code-range/mockapi.d.ts.map +1 -1
  60. package/dist/specs/response/status-code-range/mockapi.js +5 -9
  61. package/dist/specs/response/status-code-range/mockapi.js.map +1 -1
  62. package/dist/specs/routes/mockapi.js +16 -16
  63. package/dist/specs/routes/mockapi.js.map +1 -1
  64. package/dist/specs/serialization/encoded-name/json/mockapi.js +1 -1
  65. package/dist/specs/serialization/encoded-name/json/mockapi.js.map +1 -1
  66. package/dist/specs/server/versions/not-versioned/mockapi.js +1 -1
  67. package/dist/specs/server/versions/not-versioned/mockapi.js.map +1 -1
  68. package/dist/specs/server/versions/versioned/mockapi.js +8 -12
  69. package/dist/specs/server/versions/versioned/mockapi.js.map +1 -1
  70. package/dist/specs/special-words/mockapi.d.ts.map +1 -1
  71. package/dist/specs/special-words/mockapi.js +59 -6
  72. package/dist/specs/special-words/mockapi.js.map +1 -1
  73. package/dist/specs/streaming/jsonl/mockapi.d.ts +3 -0
  74. package/dist/specs/streaming/jsonl/mockapi.d.ts.map +1 -0
  75. package/dist/specs/streaming/jsonl/mockapi.js +30 -0
  76. package/dist/specs/streaming/jsonl/mockapi.js.map +1 -0
  77. package/dist/specs/type/array/mockapi.js +1 -1
  78. package/dist/specs/type/array/mockapi.js.map +1 -1
  79. package/dist/specs/type/dictionary/mockapi.js +1 -1
  80. package/dist/specs/type/dictionary/mockapi.js.map +1 -1
  81. package/dist/specs/type/enum/extensible/mockapi.js +1 -1
  82. package/dist/specs/type/enum/extensible/mockapi.js.map +1 -1
  83. package/dist/specs/type/enum/fixed/mockapi.js +2 -2
  84. package/dist/specs/type/enum/fixed/mockapi.js.map +1 -1
  85. package/dist/specs/type/file/mockapi.d.ts +3 -0
  86. package/dist/specs/type/file/mockapi.d.ts.map +1 -0
  87. package/dist/specs/type/file/mockapi.js +187 -0
  88. package/dist/specs/type/file/mockapi.js.map +1 -0
  89. package/dist/specs/type/model/empty/mockapi.js +2 -2
  90. package/dist/specs/type/model/empty/mockapi.js.map +1 -1
  91. package/dist/specs/type/model/inheritance/enum-discriminator/mockapi.js +1 -1
  92. package/dist/specs/type/model/inheritance/enum-discriminator/mockapi.js.map +1 -1
  93. package/dist/specs/type/model/inheritance/nested-discriminator/mockapi.js +2 -2
  94. package/dist/specs/type/model/inheritance/nested-discriminator/mockapi.js.map +1 -1
  95. package/dist/specs/type/model/inheritance/not-discriminated/mockapi.js +2 -2
  96. package/dist/specs/type/model/inheritance/not-discriminated/mockapi.js.map +1 -1
  97. package/dist/specs/type/model/inheritance/recursive/mockapi.js +1 -1
  98. package/dist/specs/type/model/inheritance/recursive/mockapi.js.map +1 -1
  99. package/dist/specs/type/model/inheritance/single-discriminator/mockapi.js +2 -2
  100. package/dist/specs/type/model/inheritance/single-discriminator/mockapi.js.map +1 -1
  101. package/dist/specs/type/model/usage/mockapi.js +4 -4
  102. package/dist/specs/type/model/usage/mockapi.js.map +1 -1
  103. package/dist/specs/type/model/visibility/mockapi.js +9 -10
  104. package/dist/specs/type/model/visibility/mockapi.js.map +1 -1
  105. package/dist/specs/type/property/additional-properties/mockapi.js +9 -6
  106. package/dist/specs/type/property/additional-properties/mockapi.js.map +1 -1
  107. package/dist/specs/type/property/nullable/mockapi.js +2 -6
  108. package/dist/specs/type/property/nullable/mockapi.js.map +1 -1
  109. package/dist/specs/type/property/optionality/mockapi.js +1 -1
  110. package/dist/specs/type/property/optionality/mockapi.js.map +1 -1
  111. package/dist/specs/type/property/value-types/mockapi.js +3 -3
  112. package/dist/specs/type/property/value-types/mockapi.js.map +1 -1
  113. package/dist/specs/type/scalar/mockapi.js +9 -9
  114. package/dist/specs/type/scalar/mockapi.js.map +1 -1
  115. package/dist/specs/type/union/discriminated/mockapi.d.ts +3 -0
  116. package/dist/specs/type/union/discriminated/mockapi.d.ts.map +1 -0
  117. package/dist/specs/type/union/discriminated/mockapi.js +212 -0
  118. package/dist/specs/type/union/discriminated/mockapi.js.map +1 -0
  119. package/dist/specs/type/union/mockapi.js +2 -2
  120. package/dist/specs/type/union/mockapi.js.map +1 -1
  121. package/dist/specs/versioning/added/mockapi.js +6 -6
  122. package/dist/specs/versioning/added/mockapi.js.map +1 -1
  123. package/dist/specs/versioning/madeOptional/mockapi.js +2 -2
  124. package/dist/specs/versioning/madeOptional/mockapi.js.map +1 -1
  125. package/dist/specs/versioning/removed/mockapi.js +11 -11
  126. package/dist/specs/versioning/removed/mockapi.js.map +1 -1
  127. package/dist/specs/versioning/renamedFrom/mockapi.js +5 -5
  128. package/dist/specs/versioning/renamedFrom/mockapi.js.map +1 -1
  129. package/dist/specs/versioning/returnTypeChangedFrom/mockapi.js +1 -1
  130. package/dist/specs/versioning/returnTypeChangedFrom/mockapi.js.map +1 -1
  131. package/dist/specs/versioning/typeChangedFrom/mockapi.js +3 -3
  132. package/dist/specs/versioning/typeChangedFrom/mockapi.js.map +1 -1
  133. package/manifest.json +11545 -0
  134. package/package.json +31 -20
  135. package/smoke/petstore/main.tsp +96 -0
  136. package/smoke/todoapp/main.tsp +293 -0
  137. package/spec-summary.md +2137 -121
  138. package/specs/authentication/noauth/union/main.tsp +30 -0
  139. package/specs/authentication/noauth/union/mockapi.ts +27 -0
  140. package/specs/documentation/main.tsp +158 -0
  141. package/specs/documentation/mockapi.ts +59 -0
  142. package/specs/encode/array/main.tsp +339 -0
  143. package/specs/encode/array/mockapi.ts +83 -0
  144. package/specs/encode/bytes/main.tsp +29 -20
  145. package/specs/encode/bytes/mockapi.ts +13 -31
  146. package/specs/encode/datetime/main.tsp +2 -7
  147. package/specs/encode/datetime/mockapi.ts +2 -2
  148. package/specs/encode/duration/main.tsp +420 -7
  149. package/specs/encode/duration/mockapi.ts +221 -2
  150. package/specs/encode/numeric/mockapi.ts +2 -2
  151. package/specs/parameters/basic/mockapi.ts +3 -3
  152. package/specs/parameters/body-optionality/main.tsp +2 -0
  153. package/specs/parameters/body-optionality/mockapi.ts +24 -4
  154. package/specs/parameters/collection-format/main.tsp +5 -25
  155. package/specs/parameters/collection-format/mockapi.ts +4 -16
  156. package/specs/parameters/path/main.tsp +48 -0
  157. package/specs/parameters/path/mockapi.ts +34 -0
  158. package/specs/parameters/query/main.tsp +22 -0
  159. package/specs/parameters/query/mockapi.ts +15 -0
  160. package/specs/parameters/spread/mockapi.ts +19 -19
  161. package/specs/payload/json-merge-patch/main.tsp +2 -2
  162. package/specs/payload/json-merge-patch/mockapi.ts +4 -4
  163. package/specs/payload/media-type/mockapi.ts +2 -2
  164. package/specs/payload/multipart/main.tsp +230 -32
  165. package/specs/payload/multipart/mockapi.ts +207 -59
  166. package/specs/payload/pageable/main.tsp +648 -0
  167. package/specs/payload/pageable/mockapi.ts +691 -14
  168. package/specs/payload/xml/main.tsp +532 -132
  169. package/specs/payload/xml/mockapi.ts +402 -67
  170. package/specs/response/status-code-range/main.tsp +2 -2
  171. package/specs/response/status-code-range/mockapi.ts +5 -9
  172. package/specs/routes/main.tsp +29 -29
  173. package/specs/routes/mockapi.ts +16 -16
  174. package/specs/serialization/encoded-name/json/main.tsp +1 -1
  175. package/specs/serialization/encoded-name/json/mockapi.ts +1 -1
  176. package/specs/server/endpoint/not-defined/main.tsp +1 -3
  177. package/specs/server/path/multiple/main.tsp +3 -5
  178. package/specs/server/versions/not-versioned/mockapi.ts +1 -1
  179. package/specs/server/versions/versioned/main.tsp +1 -1
  180. package/specs/server/versions/versioned/mockapi.ts +6 -12
  181. package/specs/special-headers/conditional-request/main.tsp +1 -1
  182. package/specs/special-headers/repeatability/main.tsp +2 -2
  183. package/specs/special-words/main.tsp +124 -6
  184. package/specs/special-words/mockapi.ts +62 -6
  185. package/specs/streaming/jsonl/main.tsp +33 -0
  186. package/specs/streaming/jsonl/mockapi.ts +32 -0
  187. package/specs/type/array/mockapi.ts +1 -1
  188. package/specs/type/dictionary/mockapi.ts +1 -1
  189. package/specs/type/enum/extensible/main.tsp +18 -2
  190. package/specs/type/enum/extensible/mockapi.ts +1 -1
  191. package/specs/type/enum/fixed/main.tsp +15 -3
  192. package/specs/type/enum/fixed/mockapi.ts +2 -2
  193. package/specs/type/file/main.tsp +109 -0
  194. package/specs/type/file/mockapi.ts +200 -0
  195. package/specs/type/model/empty/mockapi.ts +2 -2
  196. package/specs/type/model/inheritance/enum-discriminator/mockapi.ts +1 -1
  197. package/specs/type/model/inheritance/nested-discriminator/mockapi.ts +2 -2
  198. package/specs/type/model/inheritance/not-discriminated/mockapi.ts +2 -2
  199. package/specs/type/model/inheritance/recursive/mockapi.ts +1 -1
  200. package/specs/type/model/inheritance/single-discriminator/mockapi.ts +2 -2
  201. package/specs/type/model/usage/mockapi.ts +4 -4
  202. package/specs/type/model/visibility/main.tsp +9 -17
  203. package/specs/type/model/visibility/mockapi.ts +9 -10
  204. package/specs/type/property/additional-properties/main.tsp +17 -17
  205. package/specs/type/property/additional-properties/mockapi.ts +10 -10
  206. package/specs/type/property/nullable/mockapi.ts +7 -8
  207. package/specs/type/property/optionality/mockapi.ts +1 -1
  208. package/specs/type/property/value-types/mockapi.ts +3 -3
  209. package/specs/type/scalar/main.tsp +58 -9
  210. package/specs/type/scalar/mockapi.ts +9 -9
  211. package/specs/type/union/discriminated/main.tsp +251 -0
  212. package/specs/type/union/discriminated/mockapi.ts +230 -0
  213. package/specs/type/union/mockapi.ts +2 -2
  214. package/specs/versioning/added/mockapi.ts +6 -6
  215. package/specs/versioning/madeOptional/mockapi.ts +2 -2
  216. package/specs/versioning/removed/main.tsp +5 -5
  217. package/specs/versioning/removed/mockapi.ts +11 -11
  218. package/specs/versioning/renamedFrom/mockapi.ts +5 -5
  219. package/specs/versioning/returnTypeChangedFrom/main.tsp +17 -2
  220. package/specs/versioning/returnTypeChangedFrom/mockapi.ts +1 -1
  221. package/specs/versioning/typeChangedFrom/mockapi.ts +3 -3
  222. package/temp/.tsbuildinfo +1 -1
  223. package/tsconfig.build.json +0 -4
  224. package/tspconfig.yaml +0 -2
@@ -6,83 +6,27 @@ using Http;
6
6
  using Spector;
7
7
  using TypeSpec.Xml;
8
8
 
9
- @doc("Sends and receives bodies in XML format.")
9
+ /** Sends and receives bodies in XML format. */
10
10
  @scenarioService("/payload/xml")
11
11
  namespace Payload.Xml;
12
12
 
13
- @doc("Contains fields of primitive types.")
13
+ // ────────────────────────────────────────────────────────────────────────────
14
+ // Shared types
15
+ // ────────────────────────────────────────────────────────────────────────────
16
+
17
+ /** §1.1 — Contains fields of primitive types. */
14
18
  model SimpleModel {
15
19
  name: string;
16
20
  age: int32;
17
21
  }
18
22
 
19
- @doc("Contains fields of arrays of primitive types.")
20
- model ModelWithSimpleArrays {
21
- colors: string[];
22
- counts: int32[];
23
- }
24
-
25
- @doc("Contains an array of models.")
26
- model ModelWithArrayOfModel {
27
- items: SimpleModel[];
28
- }
29
-
30
- @doc("Contains an optional field.")
31
- model ModelWithOptionalField {
32
- item: string;
33
- value?: int32;
34
- }
35
-
36
- @doc("Contains fields that are XML attributes.")
37
- model ModelWithAttributes {
38
- @attribute id1: int32;
39
- @attribute id2: string;
40
- enabled: boolean;
41
- }
42
-
43
- @doc("Contains fields of wrapped and unwrapped arrays of primitive types.")
44
- model ModelWithUnwrappedArray {
45
- @unwrapped colors: string[];
46
- counts: int32[];
23
+ @nsDeclarations
24
+ enum Namespaces {
25
+ smp: "http://example.com/schema",
26
+ ns2: "http://example.com/ns2",
47
27
  }
48
28
 
49
- @doc("Contains fields of wrapped and unwrapped arrays of primitive types that have different XML representations.")
50
- model ModelWithRenamedArrays {
51
- @name("Colors") @unwrapped colors: string[];
52
- @name("Counts") counts: int32[];
53
- }
54
-
55
- @doc("Contains fields of the same type that have different XML representation.")
56
- @name("ModelWithRenamedFieldsSrc")
57
- model ModelWithRenamedFields {
58
- @name("InputData") inputData: SimpleModel;
59
- @name("OutputData") outputData: SimpleModel;
60
- }
61
-
62
- @doc("Contains an array of models that's supposed to be sent/received as an empty XML element.")
63
- model ModelWithEmptyArray {
64
- items: SimpleModel[];
65
- }
66
-
67
- @doc("Contains an attribute and text.")
68
- model ModelWithText {
69
- @attribute language: string;
70
- @unwrapped content: string;
71
- }
72
-
73
- @doc("Contains a dictionary of key value pairs.")
74
- model ModelWithDictionary {
75
- metadata: Record<string>;
76
- }
77
-
78
- @doc("Uses encodedName instead of Xml.Name which is functionally equivalent.")
79
- @encodedName("application/xml", "ModelWithEncodedNamesSrc")
80
- model ModelWithEncodedNames {
81
- @encodedName("application/xml", "SimpleModelData") modelData: SimpleModel;
82
- @encodedName("application/xml", "PossibleColors") colors: string[];
83
- }
84
-
85
- @doc("Template for XML operations")
29
+ /** Template for XML operations */
86
30
  interface XmlOperations<TModel, TDoc extends valueof string> {
87
31
  @scenario
88
32
  @scenarioDoc("""
@@ -108,7 +52,11 @@ interface XmlOperations<TModel, TDoc extends valueof string> {
108
52
  put(@header("content-type") contentType: "application/xml", @body input: TModel): void;
109
53
  }
110
54
 
111
- @doc("Operations for the SimpleModel type.")
55
+ // ────────────────────────────────────────────────────────────────────────────
56
+ // §1 — Primitive properties
57
+ // ────────────────────────────────────────────────────────────────────────────
58
+
59
+ /** §1.1 — Operations for the SimpleModel type. */
112
60
  @route("/simpleModel")
113
61
  interface SimpleModelValue
114
62
  extends XmlOperations<
@@ -121,7 +69,113 @@ interface SimpleModelValue
121
69
  """
122
70
  > {}
123
71
 
124
- @doc("Operations for the ModelWithSimpleArrays type.")
72
+ /** §1.2 Contains a scalar property with a custom XML name. */
73
+ model ModelWithRenamedProperty {
74
+ @name("renamedTitle")
75
+ title: string;
76
+
77
+ author: string;
78
+ }
79
+
80
+ /** §1.2 — Operations for the ModelWithRenamedProperty type. */
81
+ @route("/modelWithRenamedProperty")
82
+ interface ModelWithRenamedPropertyValue
83
+ extends XmlOperations<
84
+ ModelWithRenamedProperty,
85
+ """
86
+ <ModelWithRenamedProperty>
87
+ <renamedTitle>foo</renamedTitle>
88
+ <author>bar</author>
89
+ </ModelWithRenamedProperty>
90
+ """
91
+ > {}
92
+
93
+ /** §1.3, §2.3 — Contains fields of the same type that have different XML representation. */
94
+ @name("ModelWithRenamedFieldsSrc")
95
+ model ModelWithRenamedFields {
96
+ @name("InputData") inputData: SimpleModel;
97
+ @name("OutputData") outputData: SimpleModel;
98
+ }
99
+
100
+ /** §1.3, §2.3 — Operations for the ModelWithRenamedFields type. */
101
+ @route("/modelWithRenamedFields")
102
+ interface ModelWithRenamedFieldsValue
103
+ extends XmlOperations<
104
+ ModelWithRenamedFields,
105
+ """
106
+ <ModelWithRenamedFieldsSrc>
107
+ <InputData>
108
+ <name>foo</name>
109
+ <age>123</age>
110
+ </InputData>
111
+ <OutputData>
112
+ <name>bar</name>
113
+ <age>456</age>
114
+ </OutputData>
115
+ </ModelWithRenamedFieldsSrc>
116
+ """
117
+ > {}
118
+
119
+ // ────────────────────────────────────────────────────────────────────────────
120
+ // §2 — Nested models
121
+ // ────────────────────────────────────────────────────────────────────────────
122
+
123
+ /** §2.1 — Contains a property that references another model. */
124
+ model ModelWithNestedModel {
125
+ nested: SimpleModel;
126
+ }
127
+
128
+ /** §2.1 — Operations for the ModelWithNestedModel type. */
129
+ @route("/modelWithNestedModel")
130
+ interface ModelWithNestedModelValue
131
+ extends XmlOperations<
132
+ ModelWithNestedModel,
133
+ """
134
+ <ModelWithNestedModel>
135
+ <nested>
136
+ <name>foo</name>
137
+ <age>123</age>
138
+ </nested>
139
+ </ModelWithNestedModel>
140
+ """
141
+ > {}
142
+
143
+ /** Author model with a custom XML name. */
144
+ @name("XmlAuthor")
145
+ model Author {
146
+ name: string;
147
+ }
148
+
149
+ /** §2.2 — Contains a property whose type has @Xml.name. The property name takes precedence. */
150
+ model ModelWithRenamedNestedModel {
151
+ author: Author;
152
+ }
153
+
154
+ /** §2.2 — Operations for the ModelWithRenamedNestedModel type. */
155
+ @route("/modelWithRenamedNestedModel")
156
+ interface ModelWithRenamedNestedModelValue
157
+ extends XmlOperations<
158
+ ModelWithRenamedNestedModel,
159
+ """
160
+ <ModelWithRenamedNestedModel>
161
+ <author>
162
+ <name>foo</name>
163
+ </author>
164
+ </ModelWithRenamedNestedModel>
165
+ """
166
+ > {}
167
+
168
+ // ────────────────────────────────────────────────────────────────────────────
169
+ // §3 — Array of primitive types
170
+ // ────────────────────────────────────────────────────────────────────────────
171
+
172
+ /** §3.1 — Contains fields of arrays of primitive types. */
173
+ model ModelWithSimpleArrays {
174
+ colors: string[];
175
+ counts: int32[];
176
+ }
177
+
178
+ /** §3.1 — Operations for the ModelWithSimpleArrays type. */
125
179
  @route("/modelWithSimpleArrays")
126
180
  interface ModelWithSimpleArraysValue
127
181
  extends XmlOperations<
@@ -141,7 +195,89 @@ interface ModelWithSimpleArraysValue
141
195
  """
142
196
  > {}
143
197
 
144
- @doc("Operations for the ModelWithArrayOfModel type.")
198
+ /** §3.2 Contains fields of wrapped and unwrapped arrays of primitive types. */
199
+ model ModelWithUnwrappedArray {
200
+ @unwrapped colors: string[];
201
+ counts: int32[];
202
+ }
203
+
204
+ /** §3.2 — Operations for the ModelWithUnwrappedArray type. */
205
+ @route("/modelWithUnwrappedArray")
206
+ interface ModelWithUnwrappedArrayValue
207
+ extends XmlOperations<
208
+ ModelWithUnwrappedArray,
209
+ """
210
+ <ModelWithUnwrappedArray>
211
+ <colors>red</colors>
212
+ <colors>green</colors>
213
+ <colors>blue</colors>
214
+ <counts>
215
+ <int32>1</int32>
216
+ <int32>2</int32>
217
+ </counts>
218
+ </ModelWithUnwrappedArray>
219
+ """
220
+ > {}
221
+
222
+ /** §3.3, §3.4 — Contains fields of wrapped and unwrapped arrays of primitive types that have different XML representations. */
223
+ model ModelWithRenamedArrays {
224
+ @name("Colors") @unwrapped colors: string[];
225
+ @name("Counts") counts: int32[];
226
+ }
227
+
228
+ /** §3.3, §3.4 — Operations for the ModelWithRenamedArrays type. */
229
+ @route("/modelWithRenamedArrays")
230
+ interface ModelWithRenamedArraysValue
231
+ extends XmlOperations<
232
+ ModelWithRenamedArrays,
233
+ """
234
+ <ModelWithRenamedArrays>
235
+ <Colors>red</Colors>
236
+ <Colors>green</Colors>
237
+ <Colors>blue</Colors>
238
+ <Counts>
239
+ <int32>1</int32>
240
+ <int32>2</int32>
241
+ </Counts>
242
+ </ModelWithRenamedArrays>
243
+ """
244
+ > {}
245
+
246
+ /** Custom scalar with a custom XML item name. */
247
+ @name("ItemName")
248
+ scalar tag extends string;
249
+
250
+ /** §3.5 — Contains a wrapped primitive array with custom wrapper and item names. */
251
+ model ModelWithWrappedPrimitiveCustomItemNames {
252
+ @name("ItemsTags")
253
+ tags: tag[];
254
+ }
255
+
256
+ /** §3.5 — Operations for the ModelWithWrappedPrimitiveCustomItemNames type. */
257
+ @route("/modelWithWrappedPrimitiveCustomItemNames")
258
+ interface ModelWithWrappedPrimitiveCustomItemNamesValue
259
+ extends XmlOperations<
260
+ ModelWithWrappedPrimitiveCustomItemNames,
261
+ """
262
+ <ModelWithWrappedPrimitiveCustomItemNames>
263
+ <ItemsTags>
264
+ <ItemName>fiction</ItemName>
265
+ <ItemName>classic</ItemName>
266
+ </ItemsTags>
267
+ </ModelWithWrappedPrimitiveCustomItemNames>
268
+ """
269
+ > {}
270
+
271
+ // ────────────────────────────────────────────────────────────────────────────
272
+ // §4 — Array of complex types
273
+ // ────────────────────────────────────────────────────────────────────────────
274
+
275
+ /** §4.1 — Contains an array of models. */
276
+ model ModelWithArrayOfModel {
277
+ items: SimpleModel[];
278
+ }
279
+
280
+ /** §4.1 — Operations for the ModelWithArrayOfModel type. */
145
281
  @route("/modelWithArrayOfModel")
146
282
  interface ModelWithArrayOfModelValue
147
283
  extends XmlOperations<
@@ -162,19 +298,127 @@ interface ModelWithArrayOfModelValue
162
298
  """
163
299
  > {}
164
300
 
165
- @doc("Operations for the ModelWithOptionalField type.")
166
- @route("/modelWithOptionalField")
167
- interface ModelWithOptionalFieldValue
301
+ /** §4.2 Contains an unwrapped array of models. */
302
+ model ModelWithUnwrappedModelArray {
303
+ @unwrapped
304
+ items: SimpleModel[];
305
+ }
306
+
307
+ /** §4.2 — Operations for the ModelWithUnwrappedModelArray type. */
308
+ @route("/modelWithUnwrappedModelArray")
309
+ interface ModelWithUnwrappedModelArrayValue
168
310
  extends XmlOperations<
169
- ModelWithOptionalField,
311
+ ModelWithUnwrappedModelArray,
170
312
  """
171
- <ModelWithOptionalField>
172
- <item>widget</item>
173
- </ModelWithOptionalField>
313
+ <ModelWithUnwrappedModelArray>
314
+ <items>
315
+ <name>foo</name>
316
+ <age>123</age>
317
+ </items>
318
+ <items>
319
+ <name>bar</name>
320
+ <age>456</age>
321
+ </items>
322
+ </ModelWithUnwrappedModelArray>
323
+ """
324
+ > {}
325
+
326
+ /** §4.3 — Contains a wrapped array of models with a custom wrapper name. */
327
+ model ModelWithRenamedWrappedModelArray {
328
+ @name("AllItems")
329
+ items: SimpleModel[];
330
+ }
331
+
332
+ /** §4.3 — Operations for the ModelWithRenamedWrappedModelArray type. */
333
+ @route("/modelWithRenamedWrappedModelArray")
334
+ interface ModelWithRenamedWrappedModelArrayValue
335
+ extends XmlOperations<
336
+ ModelWithRenamedWrappedModelArray,
337
+ """
338
+ <ModelWithRenamedWrappedModelArray>
339
+ <AllItems>
340
+ <SimpleModel>
341
+ <name>foo</name>
342
+ <age>123</age>
343
+ </SimpleModel>
344
+ <SimpleModel>
345
+ <name>bar</name>
346
+ <age>456</age>
347
+ </SimpleModel>
348
+ </AllItems>
349
+ </ModelWithRenamedWrappedModelArray>
174
350
  """
175
351
  > {}
176
352
 
177
- @doc("Operations for the ModelWithAttributes type.")
353
+ /** §4.4 Contains an unwrapped array of models with a custom item name. */
354
+ model ModelWithRenamedUnwrappedModelArray {
355
+ @name("ModelItem")
356
+ @unwrapped
357
+ items: SimpleModel[];
358
+ }
359
+
360
+ /** §4.4 — Operations for the ModelWithRenamedUnwrappedModelArray type. */
361
+ @route("/modelWithRenamedUnwrappedModelArray")
362
+ interface ModelWithRenamedUnwrappedModelArrayValue
363
+ extends XmlOperations<
364
+ ModelWithRenamedUnwrappedModelArray,
365
+ """
366
+ <ModelWithRenamedUnwrappedModelArray>
367
+ <ModelItem>
368
+ <name>foo</name>
369
+ <age>123</age>
370
+ </ModelItem>
371
+ <ModelItem>
372
+ <name>bar</name>
373
+ <age>456</age>
374
+ </ModelItem>
375
+ </ModelWithRenamedUnwrappedModelArray>
376
+ """
377
+ > {}
378
+
379
+ /** Book model with a custom XML name. */
380
+ @name("XmlBook")
381
+ model Book {
382
+ title: string;
383
+ }
384
+
385
+ /** §4.5 — Contains a wrapped array of models with custom wrapper and item names. */
386
+ model ModelWithRenamedWrappedAndItemModelArray {
387
+ @name("AllBooks")
388
+ books: Book[];
389
+ }
390
+
391
+ /** §4.5 — Operations for the ModelWithRenamedWrappedAndItemModelArray type. */
392
+ @route("/modelWithRenamedWrappedAndItemModelArray")
393
+ interface ModelWithRenamedWrappedAndItemModelArrayValue
394
+ extends XmlOperations<
395
+ ModelWithRenamedWrappedAndItemModelArray,
396
+ """
397
+ <ModelWithRenamedWrappedAndItemModelArray>
398
+ <AllBooks>
399
+ <XmlBook>
400
+ <title>The Great Gatsby</title>
401
+ </XmlBook>
402
+ <XmlBook>
403
+ <title>Les Miserables</title>
404
+ </XmlBook>
405
+ </AllBooks>
406
+ </ModelWithRenamedWrappedAndItemModelArray>
407
+ """
408
+ > {}
409
+
410
+ // ────────────────────────────────────────────────────────────────────────────
411
+ // §5 — Attributes
412
+ // ────────────────────────────────────────────────────────────────────────────
413
+
414
+ /** §5.1 — Contains fields that are XML attributes. */
415
+ model ModelWithAttributes {
416
+ @attribute id1: int32;
417
+ @attribute id2: string;
418
+ enabled: boolean;
419
+ }
420
+
421
+ /** §5.1 — Operations for the ModelWithAttributes type. */
178
422
  @route("/modelWithAttributes")
179
423
  interface ModelWithAttributesValue
180
424
  extends XmlOperations<
@@ -186,74 +430,90 @@ interface ModelWithAttributesValue
186
430
  """
187
431
  > {}
188
432
 
189
- @doc("Operations for the ModelWithUnwrappedArray type.")
190
- @route("/modelWithUnwrappedArray")
191
- interface ModelWithUnwrappedArrayValue
192
- extends XmlOperations<
193
- ModelWithUnwrappedArray,
194
- """
195
- <ModelWithUnwrappedArray>
196
- <colors>red</colors>
197
- <colors>green</colors>
198
- <colors>blue</colors>
199
- <counts>
200
- <int32>1</int32>
201
- <int32>2</int32>
202
- </counts>
203
- </ModelWithUnwrappedArray>
204
- """
205
- > {}
433
+ /** §5.2 Contains a renamed XML attribute. */
434
+ model ModelWithRenamedAttribute {
435
+ @attribute
436
+ @name("xml-id")
437
+ id: int32;
206
438
 
207
- @doc("Operations for the ModelWithRenamedArrays type.")
208
- @route("/modelWithRenamedArrays")
209
- interface ModelWithRenamedArraysValue
439
+ title: string;
440
+ author: string;
441
+ }
442
+
443
+ /** §5.2 — Operations for the ModelWithRenamedAttribute type. */
444
+ @route("/modelWithRenamedAttribute")
445
+ interface ModelWithRenamedAttributeValue
210
446
  extends XmlOperations<
211
- ModelWithRenamedArrays,
447
+ ModelWithRenamedAttribute,
212
448
  """
213
- <ModelWithRenamedArrays>
214
- <Colors>red</Colors>
215
- <Colors>green</Colors>
216
- <Colors>blue</Colors>
217
- <Counts>
218
- <int32>1</int32>
219
- <int32>2</int32>
220
- </Counts>
221
- </ModelWithRenamedArrays>
449
+ <ModelWithRenamedAttribute xml-id="123">
450
+ <title>The Great Gatsby</title>
451
+ <author>F. Scott Fitzgerald</author>
452
+ </ModelWithRenamedAttribute>
222
453
  """
223
454
  > {}
224
455
 
225
- @doc("Operations for the ModelWithRenamedFields type.")
226
- @route("/modelWithRenamedFields")
227
- interface ModelWithRenamedFieldsValue
456
+ // ────────────────────────────────────────────────────────────────────────────
457
+ // §6/§7 — Namespace and prefix
458
+ // ────────────────────────────────────────────────────────────────────────────
459
+
460
+ /** §6.1, §7.1 — Contains fields with XML namespace on the model. */
461
+ @ns(Namespaces.smp)
462
+ model ModelWithNamespace {
463
+ id: int32;
464
+ title: string;
465
+ }
466
+
467
+ /** §6.1, §7.1 — Operations for the ModelWithNamespace type. */
468
+ @route("/modelWithNamespace")
469
+ interface ModelWithNamespaceValue
228
470
  extends XmlOperations<
229
- ModelWithRenamedFields,
471
+ ModelWithNamespace,
230
472
  """
231
- <ModelWithRenamedFieldsSrc>
232
- <InputData>
233
- <name>foo</name>
234
- <age>123</age>
235
- </InputData>
236
- <OutputData>
237
- <name>bar</name>
238
- <age>456</age>
239
- </OutputData>
240
- </ModelWithRenamedFieldsSrc>
473
+ <smp:ModelWithNamespace xmlns:smp="http://example.com/schema">
474
+ <id>123</id>
475
+ <title>The Great Gatsby</title>
476
+ </smp:ModelWithNamespace>
241
477
  """
242
478
  > {}
243
479
 
244
- @doc("Operations for the ModelWithEmptyArray type.")
245
- @route("/modelWithEmptyArray")
246
- interface ModelWithEmptyArrayValue
480
+ /** §6.2, §7.2 Contains fields with different XML namespaces on individual properties. */
481
+ @ns(Namespaces.smp)
482
+ model ModelWithNamespaceOnProperties {
483
+ id: int32;
484
+
485
+ @ns(Namespaces.smp)
486
+ title: string;
487
+
488
+ @ns(Namespaces.ns2)
489
+ author: string;
490
+ }
491
+
492
+ /** §6.2, §7.2 — Operations for the ModelWithNamespaceOnProperties type. */
493
+ @route("/modelWithNamespaceOnProperties")
494
+ interface ModelWithNamespaceOnPropertiesValue
247
495
  extends XmlOperations<
248
- ModelWithEmptyArray,
496
+ ModelWithNamespaceOnProperties,
249
497
  """
250
- <ModelWithEmptyArray>
251
- <items />
252
- </ModelWithEmptyArray>
498
+ <smp:ModelWithNamespaceOnProperties xmlns:smp="http://example.com/schema" xmlns:ns2="http://example.com/ns2">
499
+ <id>123</id>
500
+ <smp:title>The Great Gatsby</smp:title>
501
+ <ns2:author>F. Scott Fitzgerald</ns2:author>
502
+ </smp:ModelWithNamespaceOnProperties>
253
503
  """
254
504
  > {}
255
505
 
256
- @doc("Operations for the ModelWithText type.")
506
+ // ────────────────────────────────────────────────────────────────────────────
507
+ // §8 — Text content
508
+ // ────────────────────────────────────────────────────────────────────────────
509
+
510
+ /** §8.1 — Contains an attribute and text. */
511
+ model ModelWithText {
512
+ @attribute language: string;
513
+ @unwrapped content: string;
514
+ }
515
+
516
+ /** §8.1 — Operations for the ModelWithText type. */
257
517
  @route("/modelWithText")
258
518
  interface ModelWithTextValue
259
519
  extends XmlOperations<
@@ -265,7 +525,51 @@ interface ModelWithTextValue
265
525
  """
266
526
  > {}
267
527
 
268
- @doc("Operations for the ModelWithDictionary type.")
528
+ // ────────────────────────────────────────────────────────────────────────────
529
+ // Additional scenarios (not in the guide)
530
+ // ────────────────────────────────────────────────────────────────────────────
531
+
532
+ /** Contains an optional field. */
533
+ model ModelWithOptionalField {
534
+ item: string;
535
+ value?: int32;
536
+ }
537
+
538
+ /** Operations for the ModelWithOptionalField type. */
539
+ @route("/modelWithOptionalField")
540
+ interface ModelWithOptionalFieldValue
541
+ extends XmlOperations<
542
+ ModelWithOptionalField,
543
+ """
544
+ <ModelWithOptionalField>
545
+ <item>widget</item>
546
+ </ModelWithOptionalField>
547
+ """
548
+ > {}
549
+
550
+ /** Contains an array of models that's supposed to be sent/received as an empty XML element. */
551
+ model ModelWithEmptyArray {
552
+ items: SimpleModel[];
553
+ }
554
+
555
+ /** Operations for the ModelWithEmptyArray type. */
556
+ @route("/modelWithEmptyArray")
557
+ interface ModelWithEmptyArrayValue
558
+ extends XmlOperations<
559
+ ModelWithEmptyArray,
560
+ """
561
+ <ModelWithEmptyArray>
562
+ <items />
563
+ </ModelWithEmptyArray>
564
+ """
565
+ > {}
566
+
567
+ /** Contains a dictionary of key value pairs. */
568
+ model ModelWithDictionary {
569
+ metadata: Record<string>;
570
+ }
571
+
572
+ /** Operations for the ModelWithDictionary type. */
269
573
  @route("/modelWithDictionary")
270
574
  interface ModelWithDictionaryValue
271
575
  extends XmlOperations<
@@ -281,7 +585,14 @@ interface ModelWithDictionaryValue
281
585
  """
282
586
  > {}
283
587
 
284
- @doc("Operations for the ModelWithEncodedNames type.")
588
+ /** Uses encodedName instead of Xml.Name which is functionally equivalent. */
589
+ @encodedName("application/xml", "ModelWithEncodedNamesSrc")
590
+ model ModelWithEncodedNames {
591
+ @encodedName("application/xml", "SimpleModelData") modelData: SimpleModel;
592
+ @encodedName("application/xml", "PossibleColors") colors: string[];
593
+ }
594
+
595
+ /** Operations for the ModelWithEncodedNames type. */
285
596
  @route("/modelWithEncodedNames")
286
597
  interface ModelWithEncodedNamesValue
287
598
  extends XmlOperations<
@@ -300,3 +611,92 @@ interface ModelWithEncodedNamesValue
300
611
  </ModelWithEncodedNamesSrc>
301
612
  """
302
613
  > {}
614
+
615
+ /** Status values for the model with enum. */
616
+ union Status {
617
+ string,
618
+
619
+ /** Pending status. */
620
+ pending: "pending",
621
+
622
+ /** Success status. */
623
+ success: "success",
624
+
625
+ /** Error status. */
626
+ error: "error",
627
+ }
628
+
629
+ /** Contains a single property with an enum value. */
630
+ model ModelWithEnum {
631
+ status: Status;
632
+ }
633
+
634
+ /** Operations for the ModelWithEnum type. */
635
+ @route("/modelWithEnum")
636
+ interface ModelWithEnumValue
637
+ extends XmlOperations<
638
+ ModelWithEnum,
639
+ """
640
+ <ModelWithEnum>
641
+ <status>success</status>
642
+ </ModelWithEnum>
643
+ """
644
+ > {}
645
+
646
+ /** Contains datetime properties with different encodings. */
647
+ model ModelWithDatetime {
648
+ /** DateTime value with rfc3339 encoding. */
649
+ @encode(DateTimeKnownEncoding.rfc3339)
650
+ rfc3339: utcDateTime;
651
+
652
+ /** DateTime value with rfc7231 encoding. */
653
+ @encode(DateTimeKnownEncoding.rfc7231)
654
+ rfc7231: utcDateTime;
655
+ }
656
+
657
+ /** Operations for the ModelWithDatetime type. */
658
+ @route("/modelWithDatetime")
659
+ interface ModelWithDatetimeValue
660
+ extends XmlOperations<
661
+ ModelWithDatetime,
662
+ """
663
+ <ModelWithDatetime>
664
+ <rfc3339>2022-08-26T18:38:00.000Z</rfc3339>
665
+ <rfc7231>Fri, 26 Aug 2022 14:38:00 GMT</rfc7231>
666
+ </ModelWithDatetime>
667
+ """
668
+ > {}
669
+
670
+ /** An error response body in XML format. */
671
+ @error
672
+ model XmlError {
673
+ @statusCode _: 400;
674
+ @header("content-type") contentType: "application/xml";
675
+ @body body: XmlErrorBody;
676
+ }
677
+
678
+ /** The body of an XML error response. */
679
+ model XmlErrorBody {
680
+ message: string;
681
+ code: int32;
682
+ }
683
+
684
+ /** Operations that return an error response in XML format. */
685
+ @route("/error")
686
+ interface XmlErrorValue {
687
+ @scenario
688
+ @scenarioDoc("""
689
+ Expected error response body:
690
+ ```xml
691
+ <XmlErrorBody>
692
+ <message>Something went wrong</message>
693
+ <code>400</code>
694
+ </XmlErrorBody>
695
+ ```
696
+ """)
697
+ @get
698
+ get(): {
699
+ @header("content-type") contentType: "application/xml";
700
+ @body body: SimpleModel;
701
+ } | XmlError;
702
+ }