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

azure-http-specs, add clientNamespace #1929

Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: feature
packages:
- "@azure-tools/azure-http-specs"
---

Add test scenario for clientNamespace
17 changes: 17 additions & 0 deletions packages/azure-http-specs/spec-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -1381,6 +1381,23 @@ Expected response body:
}
```

### Client_ClientNamespace

- Endpoints:
- `get /client/client-namespace/second`
- `get /client/client-namespace/first`

Expected client namespace for clients:

- ClientNamespaceFirstClient: Client.ClientNamespace
- ClientNamespaceSecondClient: Client.ClientNamespace.Second

Expected client namespace for models:

- FirstClientResult: Client.ClientNamespace.First
- SecondClientResult: Client.ClientNamespace.Second
- SecondClientEnumType: Client.ClientNamespace.Second.Sub

### Client_Naming_Header_request

- Endpoint: `post /client/naming/header`
Expand Down
31 changes: 31 additions & 0 deletions packages/azure-http-specs/specs/client/namespace/client.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import "./main.tsp";
import "@azure-tools/typespec-client-generator-core";

using TypeSpec.Http;
using Spector;
using Azure.ClientGenerator.Core;
using Client.ClientNamespace;

@route("/client/client-namespace")
namespace ClientNameSpaceClient;

@client({
name: "ClientNamespaceFirstClient",
service: Client.ClientNamespace,
})
@clientNamespace("client.clientnamespace", "java")
tadelesh marked this conversation as resolved.
Show resolved Hide resolved
interface ClientNamespaceFirstClient {
getFirst is First.getFirst;
}
@@clientNamespace(FirstModel, "client.clientnamespace.first", "java");

@client({
name: "ClientNamespaceSecondClient",
service: Client.ClientNamespace,
})
@clientNamespace("client.clientnamespace.second", "java")
namespace ClientNamespaceSecondClient {
op getSecond is Second.getSecond;
}
@@clientNamespace(Second.Model, "client.clientnamespace.second", "java");
@@clientNamespace(Second.Model.SecondClientEnumType, "client.clientnamespace.second.sub", "java");
51 changes: 51 additions & 0 deletions packages/azure-http-specs/specs/client/namespace/main.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import "@typespec/http";
import "@typespec/spector";

using TypeSpec.Http;
using Spector;

/** Illustrates the clientNamespace cases. */
@scenarioService("/client/client-namespace")
@scenario
@scenarioDoc("""
Expected client namespace for clients:
- ClientNamespaceFirstClient: Client.ClientNamespace
- ClientNamespaceSecondClient: Client.ClientNamespace.Second

Expected client namespace for models:
- FirstClientResult: Client.ClientNamespace.First
- SecondClientResult: Client.ClientNamespace.Second
- SecondClientEnumType: Client.ClientNamespace.Second.Sub
""")
namespace Client.ClientNamespace;

interface First {
#suppress "@azure-tools/cadl-ranch-expect/missing-scenario" "scenario defined in client.tsp"
@route("/first")
@get
getFirst(): FirstModel.FirstClientResult;
}

namespace FirstModel {
model FirstClientResult {
name: string;
}
}

namespace Second {
#suppress "@azure-tools/cadl-ranch-expect/missing-scenario" "scenario defined in client.tsp"
@route("/second")
@get
op getSecond(): Model.SecondClientResult;

namespace Model {
model SecondClientResult {
type: SecondClientEnumType;
}

union SecondClientEnumType {
string,
Second: "second",
}
}
}
30 changes: 30 additions & 0 deletions packages/azure-http-specs/specs/client/namespace/mockapi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

export const Scenarios: Record<string, ScenarioMockApi> = {};

Scenarios.Client_ClientNamespace = passOnSuccess([
{
uri: "/client/client-namespace/first",
method: "get",
request: {
body: {},
},
response: {
status: 200,
body: json({ name: "first" }),
},
kind: "MockApiDefinition",
},
{
uri: "/client/client-namespace/second",
method: "get",
request: {
body: {},
},
response: {
status: 200,
body: json({ type: "second" }),
},
kind: "MockApiDefinition",
},
]);
Loading