Commit 5c6d6b3
Add commaDelimited and newlineDelimited to ArrayEncoding enum (#9002)
## Adding commaDelimited and newlineDelimited to ArrayEncoding enum ✅
**Implementation complete!**
- [x] Explore repository structure and build system
- [x] Understand ArrayEncoding enum location and current values
- [x] Add `commaDelimited` and `newlineDelimited` enum members to
`ArrayEncoding` in decorators.tsp
- [x] Update documentation for existing enum members (`pipeDelimited`
and `spaceDelimited`)
- [x] Add tests for the new enum values in compiler tests
- [x] Update openapi3 encoding logic to recognize new enum values
- [x] Update openapi3 examples.ts to handle new delimiters
- [x] Add comprehensive tests in openapi3 for the new delimiters
- [x] Create changelog entry for the changes
- [x] Run tests and ensure everything passes
- [x] Run linting and format checks
- [x] Manual verification with TypeSpec compiler
- [x] Regenerate JS documentation for compiler
- [x] Fix cspell violations
- [x] Update tests to use new Tester pattern
- [x] Final verification
## Summary
This PR successfully adds `commaDelimited` and `newlineDelimited` values
to the `ArrayEncoding` enum as per the approved design. The
implementation includes:
### Core Changes:
1. **decorators.tsp** - Added two new enum members with comprehensive
documentation explaining how they work in different protocols (JSON vs
HTTP)
2. **Updated existing documentation** - Enhanced docs for
`pipeDelimited` and `spaceDelimited` to match the new format
### OpenAPI3 Integration:
3. **encoding.ts** - Updated to recognize the new encoding values
4. **parameters.ts** - Extended parameter style handling to support
comma and newline delimiters
5. **examples.ts** - Added support for generating examples with the new
delimiters
### Testing:
6. **Compiler tests** - Added 4 new tests verifying each ArrayEncoding
enum value can be used (updated to use new Tester pattern)
7. **OpenAPI3 examples tests** - Added 12 comprehensive tests covering
all scenarios (undefined, string, array, object) × (explode true/false)
for both new delimiters
8. **OpenAPI3 parameters tests** - Added 2 tests verifying parameter
style mapping
### Documentation:
9. **Changelog** - Created proper change entry documenting the feature
addition
10. **Built-in data types documentation** - Regenerated to include the
new enum values with full descriptions
11. **cspell exceptions** - Added URL-encoded color names (Ablack,
Cblack, Cbrown) from test strings to exceptions list
### Test Results:
- ✅ All 208 compiler tests pass
- ✅ All 2,326 openapi3 tests pass (262 in examples.test.ts, 172 in
parameters.test.ts)
- ✅ Linting passes
- ✅ Code formatting verified
- ✅ Manual verification with TypeSpec compiler successful
- ✅ Documentation regenerated successfully
- ✅ Cspell violations fixed
- ✅ Tests updated to use new Tester pattern
The implementation follows TypeSpec conventions and properly integrates
with the existing ArrayEncoding infrastructure.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>Add support for list with encode of string</issue_title>
> <issue_description>### Clear and concise description of the problem
>
> Short version:
> ```typespec
> model MyModel {
> @encode(string, ",")
> terms: string[];
> }
> ```
>
> would match this JSON:
> ```json
> {
> "synomyms": "a,b,c"
> }
> ```
>
> and produce SDK like:
> ```python
> class Data:
> synonyms: List[str]
> ```
>
> Which will tell the serializer deserializer to use csv, for instance
`a,b,c`. Delimiter is the second parameter. We may decide to accept it
only on list of strings for now (refuse `int[]`)
>
> Kwown separator: `\n`, `|` and `,`
>
> ### Checklist
>
> - [x] Follow our [Code of
Conduct](https://github.com/microsoft/typespec/blob/main/CODE_OF_CONDUCT.md)
> - [x] Read the [docs](https://typespec.io/docs/).
> - [x] Check that there isn't already an issue that request the same
feature to avoid creating a duplicate.</issue_description>
>
> <agent_instructions>Per the approved design, add new elements for
commaDelimited and newlineDelimited lists to the array encoding enum,
including documentation, changelog entry, and tests for the new
values.</agent_instructions>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> <comment_new><author>@bterlson</author><body>
> My feeling on this:
>
> We have `ArrayEncoding.spaceDelimited` and
`ArrayEncoding.commaDelimited` which today only work in query strings.
It's not clear how these should even work outside of that context
because the escaping rules are not specified. This seems like a related
problem to solve.
>
> One proposal I like is to add `ArrayEncoding.CSV` with a configurable
delimiter and make the existing encoding formats aliases for CSV
encoding with the proper delimiter (e.g. `ArrayEncoding.spaceDelimited`
would mean the same thing as `ArrayEncoding.CSV, #{ delimiter: " " }`).
We can follow the CSV RFC for this. For example:
>
> ```tsp
> model Foo {
> @encode(ArrayEncoding.CSV)
> list: string[];
> matrix: string[][];
> }
> ```
> might look like this on the wire:
>
> ```ts
> {
> list: "\"A,B\", C",
> matrix: "r1c1,r1c2\nr2c1,r2c2"
> }
> ```
>
> One concern with this approach is that it would require a standards
compliant CSV parser for HTTP clients/servers, which may not in fact be
needed. E.g. we know of a service which takes CSV but does not allow
commas in the elements which means you can safely split/join. We might
consider something like a `noEscape` option for this
scenario.</body></comment_new>
> <comment_new><author>@timotheeguerin</author><body>
> Add commaDelimited, newlineDelimited to ArrayEncoding in core and
update `pipeDelimited` and `spaceDelimited` to have similar doc around
containing the delimiter
>
> ```tsp
> enum ArrayEncoding {
> /**
> * Values can only contain , if underlying protocol supports encoding
those
> * - json -> error
> * - http -> %2C
> */
> commaDelimited,
>
> /**
> * Values can only contain \n if underlying protocol supports encoding
those
> * - json -> error
> * - http -> %0A
> */
> newlineDelimited,
> }
> ```
>
>
> ## Appendix : Encoding with options
>
> Just for reference, do not implement
>
> A POC of what we could do without new language syntax
> ```tsp
> namespace Encoding {
> scalar custom;
>
> scalar `array` extends custom {
> /**
> * Values can only contain the delimiter if underlying protocol
supports encoding those
> * Example delimiter: ,
> * - json -> error
> * - http -> %2c
> */
> init join(delimiter: valueof string);
> }
> }
> model Test {
> @encode(CustomCSVEncoding("-"))
> @encode(#{encoding: ArrayEncoding2.CSV, sep: "-"})
> foo: string[]
> }
>
> ```</body></comment_new>
> </comments>
>
</details>
- Fixes #8874
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 We'd love your input! Share your thoughts on Copilot coding agent in
our [2 minute survey](https://gh.io/copilot-coding-agent-survey).
---------
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: markcowl <[email protected]>
Co-authored-by: timotheeguerin <[email protected]>
Co-authored-by: Timothee Guerin <[email protected]>1 parent 190b9c2 commit 5c6d6b3
File tree
10 files changed
+181
-7
lines changed- .chronus/changes
- packages
- compiler
- lib/std
- test/decorators
- openapi3
- src
- test
- website/src/content/docs/docs/standard-library
10 files changed
+181
-7
lines changedLines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
| 40 | + | |
38 | 41 | | |
39 | 42 | | |
40 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
531 | 531 | | |
532 | 532 | | |
533 | 533 | | |
534 | | - | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
535 | 540 | | |
536 | 541 | | |
537 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
538 | 548 | | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
539 | 565 | | |
540 | 566 | | |
541 | 567 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
795 | 797 | | |
796 | 798 | | |
797 | 799 | | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
798 | 846 | | |
799 | 847 | | |
800 | 848 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
11 | 16 | | |
12 | 17 | | |
13 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
376 | 380 | | |
377 | 381 | | |
378 | 382 | | |
| |||
518 | 522 | | |
519 | 523 | | |
520 | 524 | | |
521 | | - | |
| 525 | + | |
522 | 526 | | |
523 | 527 | | |
524 | 528 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
439 | 439 | | |
440 | 440 | | |
441 | 441 | | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
442 | 514 | | |
443 | 515 | | |
444 | 516 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
Lines changed: 4 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
490 | 490 | | |
491 | 491 | | |
492 | 492 | | |
493 | | - | |
494 | | - | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
495 | 497 | | |
496 | 498 | | |
497 | 499 | | |
| |||
0 commit comments