Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import "@typespec/http";
import "@typespec/spector";
import "@azure-tools/typespec-client-generator-core";

using Http;
using Azure.ClientGenerator.Core;
using Spector;

@doc("Test for convenientAPI and protocolAPI decorators.")
@scenarioService("/azure/client-generator-core/convenient-api")
namespace _Specs_.Azure.ClientGenerator.Core.ConvenientApi;

@route("/convenientNamespace")
@operationGroup
@scenario
@scenarioDoc("""
Test @convenientAPI decorator applied at namespace level.
All operations in this namespace should not generate convenient methods.
Expected query parameter: name="sample"
Expected response body:
```json
{
"name": "sample"
}
```
""")
@convenientAPI(false)
namespace ConvenientNamespace {
model TestModel {
name: string;
}

@route("/operation1")
@get
op operation1(@query name: string): TestModel;

@route("/operation2")
@post
op operation2(@query name: string): TestModel;
}

@route("/protocolNamespace")
@operationGroup
@scenario
@scenarioDoc("""
Test @protocolAPI decorator applied at namespace level.
All operations in this namespace should not generate protocol methods.
Expected query parameter: name="sample"
Expected response body:
```json
{
"name": "sample"
}
```
""")
@protocolAPI(false)
namespace ProtocolNamespace {
model TestModel {
name: string;
}

@route("/operation1")
@get
op operation1(@query name: string): TestModel;

@route("/operation2")
@post
op operation2(@query name: string): TestModel;
}

@route("/convenientInterface")
@operationGroup
@scenario
@scenarioDoc("""
Test @convenientAPI decorator applied at interface level.
All operations in this interface should not generate convenient methods.
Expected query parameter: name="sample"
Expected response body:
```json
{
"name": "sample"
}
```
""")
namespace ConvenientInterfaceNs {
model TestModel {
name: string;
}

@convenientAPI(false)
interface ConvenientInterface {
@route("/operation1")
@get
op operation1(@query name: string): TestModel;

@route("/operation2")
@post
op operation2(@query name: string): TestModel;
}
}

@route("/protocolInterface")
@operationGroup
@scenario
@scenarioDoc("""
Test @protocolAPI decorator applied at interface level.
All operations in this interface should not generate protocol methods.
Expected query parameter: name="sample"
Expected response body:
```json
{
"name": "sample"
}
```
""")
namespace ProtocolInterfaceNs {
model TestModel {
name: string;
}

@protocolAPI(false)
interface ProtocolInterface {
@route("/operation1")
@get
op operation1(@query name: string): TestModel;

@route("/operation2")
@post
op operation2(@query name: string): TestModel;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { json, MockApiDefinition, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api";

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

function createMockApiDefinition(route: string, method: "get" | "post"): MockApiDefinition {
return {
uri: `/azure/client-generator-core/convenient-api/${route}`,
method: method,
request: {
query: {
name: "sample",
},
},
response: {
status: 200,
body: json({ name: "sample" }),
},
kind: "MockApiDefinition",
};
}

Scenarios.Azure_ClientGenerator_Core_ConvenientApi_ConvenientNamespace = passOnSuccess([
createMockApiDefinition("convenientNamespace/operation1", "get"),
createMockApiDefinition("convenientNamespace/operation2", "post"),
]);

Scenarios.Azure_ClientGenerator_Core_ConvenientApi_ProtocolNamespace = passOnSuccess([
createMockApiDefinition("protocolNamespace/operation1", "get"),
createMockApiDefinition("protocolNamespace/operation2", "post"),
]);

Scenarios.Azure_ClientGenerator_Core_ConvenientApi_ConvenientInterfaceNs = passOnSuccess([
createMockApiDefinition("convenientInterface/operation1", "get"),
createMockApiDefinition("convenientInterface/operation2", "post"),
]);

Scenarios.Azure_ClientGenerator_Core_ConvenientApi_ProtocolInterfaceNs = passOnSuccess([
createMockApiDefinition("protocolInterface/operation1", "get"),
createMockApiDefinition("protocolInterface/operation2", "post"),
]);
Loading