Skip to content
This repository has been archived by the owner on Jan 21, 2025. It is now read-only.

test for @clientName of TCGC and @encodedName of compiler #511

Merged
merged 13 commits into from
Feb 21, 2024
5 changes: 5 additions & 0 deletions .changeset/early-panthers-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

add test case for `@clientName` and `@encodedName`
5 changes: 2 additions & 3 deletions packages/cadl-ranch-api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ export type KeyedMockRequestHandler<T extends string = string> = (

export type HttpMethod = "get" | "post" | "put" | "patch" | "delete" | "head" | "options";

export type MockApiForHandler<Handler extends MockRequestHandler> = Handler extends KeyedMockRequestHandler<infer K>
? KeyedMockApi<K>
: MockApi;
export type MockApiForHandler<Handler extends MockRequestHandler> =
Handler extends KeyedMockRequestHandler<infer K> ? KeyedMockApi<K> : MockApi;
qiaozha marked this conversation as resolved.
Show resolved Hide resolved

export interface MockApi {
method: HttpMethod;
Expand Down
4 changes: 2 additions & 2 deletions packages/cadl-ranch-expect/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ function getRouteSegments(program: Program, target: Operation | Interface | Name
return target.interface
? [...getRouteSegments(program, target.interface), ...seg]
: target.namespace
? [...getRouteSegments(program, target.namespace), ...seg]
: seg;
? [...getRouteSegments(program, target.namespace), ...seg]
: seg;
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
106 changes: 106 additions & 0 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2023,6 +2023,112 @@ maxpagesize=3
}
```

### Projection_ClientNameAndEncodedName_header

- Endpoint: `post /projection/client-name-and-encoded-name/header`

Testing that we can project a header name.
Your generated SDK should generate an operation header `parameter` with a single parameter called `clientName`.

Expected header parameter: `default-name="true"`
Expected response header: `default-name="true"`

### Projection_ClientNameAndEncodedName_Model_client

- Endpoint: `post /projection/client-name-and-encoded-name/model/client`

Testing that we can project the client name in our generated SDKs.
Your generated SDK should generate the model with name `ClientModel`.

Expected request body:

```json
{ "defaultName": true }
```

### Projection_ClientNameAndEncodedName_Model_language

- Endpoint: `post /projection/client-name-and-encoded-name/model/language`

Testing that we can project the language specific name in our generated SDKs.
Your generated SDK should generate the model with your language specific model name.

Expected request body:

```json
{ "defaultName": true }
```

### Projection_ClientNameAndEncodedName_operation

- Endpoint: `post /projection/client-name-and-encoded-name/operation`

Testing that we can project the operation name.
Your generated SDK should generate an operation called `clientName`.

Expected status code: 204

### Projection_ClientNameAndEncodedName_parameter

- Endpoint: `post /projection/client-name-and-encoded-name/parameter`

Testing that we can project a parameter name.
Your generated SDK should generate an operation `parameter` with a single parameter called `clientName`.

Expected query parameter: `defaultName="true"`

### Projection_ClientNameAndEncodedName_Property_client

- Endpoint: `post /projection/client-name-and-encoded-name/property/client`

Testing that we can project the client name in our generated SDKs.
Your generated SDK should generate ClientNameModel with one property `clientName` with wire name `defaultName`.

Expected request body:

```json
{ "defaultName": true }
```

### Projection_ClientNameAndEncodedName_Property_json

- Endpoint: `post /projection/client-name-and-encoded-name/property/json`

Testing that we can project the JSON name on the wire from defaultName -> wireName.
Your generated SDK should generate JsonEncodedNameModel with one property `defaultName` with wire name `wireName`.

Expected request body:

```json
{ "wireName": true }
```

### Projection_ClientNameAndEncodedName_Property_jsonAndClient

- Endpoint: `post /projection/client-name-and-encoded-name/property/json-and-client`

Testing that we can project the client name and the wire name.
Your generated SDK should generate ClientNameAndJsonEncodedNameModel with one property with client name `clientName` and wire name `wireName`.

Expected request body:

```json
{ "wireName": true }
```

### Projection_ClientNameAndEncodedName_Property_language

- Endpoint: `post /projection/client-name-and-encoded-name/property/language`

Testing that we can project the language specific name in our generated SDKs.
Your generated SDK should generate LanguageClientNameModel with one property with your language specific property name and wire name `defaultName`.

Expected request body:

```json
{ "defaultName": true }
```

### Projection_ProjectedName_Model_client

- Endpoint: `post /projection/projected-name/model/client`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import "@typespec/http";
import "@azure-tools/cadl-ranch-expect";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using Azure.ClientGenerator.Core;

@doc("Projection")
@supportedBy("dpg")
@scenarioService("/projection/client-name-and-encoded-name")
namespace Projection.ClientNameAndEncodedName;

@route("/property")
@operationGroup
namespace Property {
model LanguageClientNameModel {
@doc("Pass in true")
@clientName("CSName", "csharp")
@clientName("GoName", "go")
@clientName("JavaName", "java")
@clientName("TSName", "javascript")
@clientName("python_name", "python")
defaultName: boolean;
}

model JsonEncodedNameModel {
@doc("Pass in true")
@encodedName("application/json", "wireName")
defaultName: boolean;
}

model ClientNameModel {
@doc("Pass in true")
@clientName("clientName")
defaultName: boolean;
}

model ClientNameAndJsonEncodedNameModel {
@doc("Pass in true")
@clientName("clientName")
@encodedName("application/json", "wireName")
defaultName: boolean;
}

@scenario
@scenarioDoc("""
Testing that we can project the JSON name on the wire from defaultName -> wireName.
Your generated SDK should generate JsonEncodedNameModel with one property `defaultName` with wire name `wireName`.

Expected request body:
```json
{"wireName": true}
```
""")
@route("/json")
@post
op json(...JsonEncodedNameModel): NoContentResponse;

@scenario
@scenarioDoc("""
Testing that we can project the client name in our generated SDKs.
Your generated SDK should generate ClientNameModel with one property `clientName` with wire name `defaultName`.

Expected request body:
```json
{"defaultName": true}
weidongxu-microsoft marked this conversation as resolved.
Show resolved Hide resolved
```
""")
@route("/client")
@post
op client(...ClientNameModel): NoContentResponse;

@scenario
@scenarioDoc("""
Testing that we can project the language specific name in our generated SDKs.
Your generated SDK should generate LanguageClientNameModel with one property with your language specific property name and wire name `defaultName`.

Expected request body:
```json
{"defaultName": true}
```
""")
@route("/language")
@post
op language(...LanguageClientNameModel): NoContentResponse;

@scenario
@scenarioDoc("""
Testing that we can project the client name and the wire name.
Your generated SDK should generate ClientNameAndJsonEncodedNameModel with one property with client name `clientName` and wire name `wireName`.

Expected request body:
```json
{"wireName": true}
```
""")
@route("/json-and-client")
@post
op jsonAndClient(...ClientNameAndJsonEncodedNameModel): NoContentResponse;
}

@scenario
@scenarioDoc("""
Testing that we can project the operation name.
Your generated SDK should generate an operation called `clientName`.

Expected status code: 204
""")
@route("/operation")
@clientName("clientName")
@post
op operation(): NoContentResponse;

@scenario
@scenarioDoc("""
Testing that we can project a parameter name.
Your generated SDK should generate an operation `parameter` with a single parameter called `clientName`.

Expected query parameter: `defaultName="true"`

""")
@route("/parameter")
@post
op parameter(
@clientName("clientName")
@query
defaultName: string,
): NoContentResponse;

@scenario
@scenarioDoc("""
Testing that we can project a header name.
Your generated SDK should generate an operation header `parameter` with a single parameter called `clientName`.

Expected header parameter: `default-name="true"`
Expected response header: `default-name="true"`
""")
@route("/header")
@post
op header(
qiaozha marked this conversation as resolved.
Show resolved Hide resolved
@clientName("clientName")
@header
`default-name`: string,
): {
@clientName("clientName")
@header
`default-name`: string;
};

@route("/model")
@operationGroup
@clientName("ClientModel")
namespace Model {
@clientName("CSModel", "csharp")
@clientName("GoModel", "go")
@clientName("JavaModel", "java")
@clientName("TSModel", "javascript")
@clientName("PythonModel", "python")
model ModelWithLanguageClientName {
@doc("Pass in true")
defaultName: boolean;
}

@clientName("ClientModel")
model ModelWithClientClientName {
@doc("Pass in true")
defaultName: boolean;
}

@scenario
@scenarioDoc("""
Testing that we can project the client name in our generated SDKs.
Your generated SDK should generate the model with name `ClientModel`.

Expected request body:
```json
{"defaultName": true}
```
""")
@route("/client")
@post
op client(...ModelWithClientClientName): NoContentResponse;

@scenario
@scenarioDoc("""
Testing that we can project the language specific name in our generated SDKs.
Your generated SDK should generate the model with your language specific model name.

Expected request body:
```json
{"defaultName": true}
```
""")
@route("/language")
@post
op language(...ModelWithLanguageClientName): NoContentResponse;
}
Loading
Loading