-
Notifications
You must be signed in to change notification settings - Fork 338
Add commaDelimited and newlineDelimited to ArrayEncoding enum #9002
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ae3eff6
6ae6c72
ed42d14
fbaaabd
bac10d0
ef14dc5
20f3be2
33f4e02
68c385d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/compiler" | ||
| - "@typespec/openapi3" | ||
| --- | ||
|
|
||
| Add `commaDelimited` and `newlineDelimited` values to `ArrayEncoding` enum for serializing arrays with comma and newline delimiters |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ import { | |
| createTestRunner, | ||
| expectDiagnosticEmpty, | ||
| expectDiagnostics, | ||
| t, | ||
| } from "../../src/testing/index.js"; | ||
| import { Tester } from "../tester.js"; | ||
|
|
||
| describe("compiler: built-in decorators", () => { | ||
| let runner: BasicTestRunner; | ||
|
|
@@ -795,6 +797,52 @@ describe("compiler: built-in decorators", () => { | |
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("ArrayEncoding enum", () => { | ||
| it("can use ArrayEncoding.pipeDelimited", async () => { | ||
| const { prop, program } = await Tester.compile(t.code` | ||
| model Foo { | ||
| @encode(ArrayEncoding.pipeDelimited) | ||
| ${t.modelProperty("prop")}: string[]; | ||
| } | ||
| `); | ||
|
|
||
| strictEqual(getEncode(program, prop)?.encoding, "ArrayEncoding.pipeDelimited"); | ||
| }); | ||
|
|
||
| it("can use ArrayEncoding.spaceDelimited", async () => { | ||
| const { prop, program } = await Tester.compile(t.code` | ||
| model Foo { | ||
| @encode(ArrayEncoding.spaceDelimited) | ||
| ${t.modelProperty("prop")}: string[]; | ||
| } | ||
| `); | ||
|
|
||
| strictEqual(getEncode(program, prop)?.encoding, "ArrayEncoding.spaceDelimited"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Array encoding's usage is different from bytes/datetime/duration. It uses the TypeSpec enum value name instead a defined type in ts lib.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes this is expected, same as xml libraries. Using the fqn allows it to make sure it doesn't conflict with anything else. We couldn'tchange the other one for back compat |
||
| }); | ||
|
|
||
| it("can use ArrayEncoding.commaDelimited", async () => { | ||
| const { prop, program } = await Tester.compile(t.code` | ||
| model Foo { | ||
| @encode(ArrayEncoding.commaDelimited) | ||
| ${t.modelProperty("prop")}: string[]; | ||
| } | ||
| `); | ||
|
|
||
| strictEqual(getEncode(program, prop)?.encoding, "ArrayEncoding.commaDelimited"); | ||
| }); | ||
|
|
||
| it("can use ArrayEncoding.newlineDelimited", async () => { | ||
| const { prop, program } = await Tester.compile(t.code` | ||
| model Foo { | ||
| @encode(ArrayEncoding.newlineDelimited) | ||
| ${t.modelProperty("prop")}: string[]; | ||
| } | ||
| `); | ||
|
|
||
| strictEqual(getEncode(program, prop)?.encoding, "ArrayEncoding.newlineDelimited"); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe("@withoutOmittedProperties", () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ArrayEncodingis not used in theencodedecorator behavior code. Should we add lint to only allow it to be set on array type? @timotheeguerinThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hhm yeah could do that, can you file an issue