Skip to content
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

Uptake uri templates #1247

Merged
merged 16 commits into from
Aug 6, 2024
Merged
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
8 changes: 8 additions & 0 deletions .chronus/changes/uptake-uri-templates-2024-6-26-21-7-49.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: internal
packages:
- "@azure-tools/typespec-azure-core"
---

Call correct HTTP library API
6 changes: 6 additions & 0 deletions .chronus/changes/uptake-uri-templates-2024-7-6-9-38-18.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
changeKind: internal
packages:
- "@azure-tools/typespec-client-generator-core"
---

7 changes: 7 additions & 0 deletions .chronus/changes/uptake-uri-templates-2024-7-6-9-38-7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/typespec-autorest"
---

Add support for URI templates in routes
2 changes: 1 addition & 1 deletion core
Submodule core updated 53 files
+12 −0 .chronus/changes/uri-templates-2024-6-24-20-7-39.md
+9 −0 .chronus/changes/uri-templates-2024-6-24-21-37-52.md
+7 −0 .chronus/changes/uri-templates-2024-6-25-9-3-39-2.md
+13 −0 .chronus/changes/uri-templates-2024-6-25-9-3-39.md
+8 −0 .chronus/changes/uri-templates-2024-7-6-16-39-59.md
+20 −4 docs/libraries/http/reference/data-types.md
+30 −26 docs/libraries/http/reference/decorators.md
+1 −0 docs/libraries/http/reference/index.mdx
+13 −0 docs/standard-library/built-in-data-types.md
+11 −0 packages/compiler/lib/std/decorators.tsp
+121 −5 .../http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientOptionsProvider.cs
+44 −16 packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/ClientProvider.cs
+3 −5 packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmOutputLibrary.cs
+180 −0 ...client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/ClientOptionsProviderTests.cs
+67 −4 ...s/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/ClientProviderTests.cs
+20 −3 packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/TestHelpers/MockHelpers.cs
+0 −12 ...ages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/TestHelpers/tspCodeModel.json
+1 −1 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/LibraryVisitor.cs
+2 −0 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/OutputLibrary.cs
+3 −3 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/EnumProvider.cs
+2 −1 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ExtensibleEnumProvider.cs
+27 −3 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/FixedEnumProvider.cs
+22 −0 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Shared/StringExtensions.cs
+23 −9 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/TypeFactory.cs
+1 −1 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/InputLibraryVisitorTests.cs
+19 −0 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/EnumProviderTests.cs
+35 −0 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/TypeFactoryTests.cs
+14 −0 packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Utilities/StringExtensionsTests.cs
+7 −1 packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp
+26 −1 ...ient-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClientOptions.cs
+367 −338 packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/tspCodeModel.json
+30 −26 packages/http/README.md
+32 −14 packages/http/generated-defs/TypeSpec.Http.ts
+60 −14 packages/http/lib/decorators.tsp
+31 −30 packages/http/src/decorators.ts
+52 −7 packages/http/src/http-property.ts
+1 −1 packages/http/src/index.ts
+15 −8 packages/http/src/lib.ts
+2 −1 packages/http/src/operations.ts
+52 −10 packages/http/src/parameters.ts
+83 −39 packages/http/src/route.ts
+28 −14 packages/http/src/types.ts
+54 −0 packages/http/src/uri-template.ts
+36 −16 packages/http/test/http-decorators.test.ts
+154 −4 packages/http/test/routes.test.ts
+33 −0 packages/http/test/uri-template.test.ts
+12 −0 packages/openapi3/src/lib.ts
+63 −26 packages/openapi3/src/openapi.ts
+161 −21 packages/openapi3/test/parameters.test.ts
+3 −2 packages/rest/src/rest.ts
+1 −1 packages/rest/tsconfig.json
+1 −3 packages/samples/specs/visibility/visibility.tsp
+0 −1 packages/samples/test/output/visibility/@typespec/openapi3/openapi.yaml
35 changes: 35 additions & 0 deletions docs/libraries/azure-core/rules/no-query-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
title: "no-query-explode"
---

```text title="Full name"
@azure-tools/typespec-azure-core/no-query-explode
```

Azure services favor serializing query parameter of array type using the simple style(Where each values is joined by a `,`)
Using the `*` uri template modifier or `explode: true` property specify that each individual value of the array should be sent as a separate query parameter.

#### ❌ Incorrect

```tsp
op list(
@query(#{ explode: true })
select: string[],
): Pet[];
```

#### ✅ Correct

```tsp
op list(
@query
select: string[],
): Pet[];
```

```tsp
op list(
@query(#{ explode: false })
select: string[],
): Pet[];
```
4 changes: 1 addition & 3 deletions docs/release-notes/release-2023-04-11.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ op list(@collectionFormat("multi") @query select: string[]): Pet[];

// Now
op list(
@query({
format: "multi",
})
@query(#{ explode: true })
select: string[],
): Pet[];
```
2 changes: 1 addition & 1 deletion packages/e2e-tests/cadl-ranch-specs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@azure-tools/typespec-e2e-cadl-ranch-specs",
"dependencies": {
"@azure-tools/cadl-ranch-specs": "0.34.10"
"@azure-tools/cadl-ranch-specs": "0.35.0"
},
"type": "module",
"private": true
Expand Down
12 changes: 3 additions & 9 deletions packages/samples/specs/misc/appconfig/keyvalues.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ namespace KeyValuesResource {
After: plainDate,

@doc("Used to select what fields are present in the returned resource(s).")
@query({
format: "multi",
})
@query(#{ explode: true })
$Select?: KeyField[],
): {
...Response<200>;
Expand All @@ -70,9 +68,7 @@ namespace KeyValuesResource {
After: plainDate,

@doc("Used to select what fields are present in the returned resource(s).")
@query({
format: "multi",
})
@query(#{ explode: true })
$Select?: KeyField[],
): {
...Response<200>;
Expand All @@ -88,9 +84,7 @@ namespace KeyValuesResource {
...KeyWithFilters,

@doc("Used to select what fields are present in the returned resource(s).")
@query({
format: "multi",
})
@query(#{ explode: true })
$Select?: KeyField[],
): {
...Response<200>;
Expand Down
4 changes: 1 addition & 3 deletions packages/samples/specs/misc/appconfig/labels.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ namespace LabelsResource {
@query name?: string,
@query after?: string,

@query({
format: "multi",
})
@query(#{ explode: true })
$Select?: LabelField[],
): {
...Response<200>;
Expand Down
4 changes: 1 addition & 3 deletions packages/samples/specs/misc/appconfig/revisions.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ namespace RevisionsResource {
...AcceptDatetimeHeader,

@doc("Used to select what fields are present in the returned resource(s).")
@query({
format: "multi",
})
@query(#{ explode: true })
$Select?: KeyField[],

@doc("A filter used to match labels")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,6 @@ components:
type: array
items:
type: string
style: form
explode: true
Azure.Core.SkipQueryParameter:
name: skip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ components:
type: array
items:
type: string
style: form
explode: true
Azure.Core.SkipQueryParameter:
name: skip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ components:
type: array
items:
type: string
style: form
explode: true
Azure.Core.SkipQueryParameter:
name: skip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,6 @@ components:
type: array
items:
type: string
style: form
explode: true
Azure.Core.SkipQueryParameter:
name: skip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,6 @@ components:
type: array
items:
type: string
style: form
explode: true
Azure.Core.SkipQueryParameter:
name: skip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ paths:
type: array
items:
$ref: '#/components/schemas/KeyField'
style: form
explode: true
responses:
'200':
Expand Down Expand Up @@ -147,7 +146,6 @@ paths:
type: array
items:
$ref: '#/components/schemas/KeyField'
style: form
explode: true
responses:
'200':
Expand Down Expand Up @@ -182,7 +180,6 @@ paths:
type: array
items:
$ref: '#/components/schemas/KeyField'
style: form
explode: true
responses:
'200':
Expand Down Expand Up @@ -464,7 +461,6 @@ paths:
type: array
items:
$ref: '#/components/schemas/LabelField'
style: form
explode: true
responses:
'200':
Expand Down Expand Up @@ -570,7 +566,6 @@ paths:
type: array
items:
$ref: '#/components/schemas/KeyField'
style: form
explode: true
- name: label
in: query
Expand Down
Loading
Loading