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

Add modular coverage cases for models-empty in cadl-ranch #2117

Merged
merged 4 commits into from
Jan 18, 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
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ function buildBodyParameter(

if (bodyParameter && bodyParts.length > 0) {
return `\nbody: {${bodyParts.join(",\n")}},`;
} else if (bodyParameter && bodyParts.length === 0) {
return `\nbody: ${bodyParameter.clientName},`;
}
} else if (
bodyParameter.type.type === "model" &&
Expand Down
4 changes: 4 additions & 0 deletions packages/typespec-ts/test/commands/cadl-ranch-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ export const modularTsps: TypeSpecRanchConfig[] = [
{
outputPath: "azure/core-traits",
inputPath: "azure/core/traits"
},
{
outputPath: "models/empty",
inputPath: "type/model/empty"
}
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Pipeline } from "@azure/core-rest-pipeline";
import { EmptyInput, EmptyOutput, EmptyInputOutput } from "./models/models.js";
import {
PutEmptyOptions,
GetEmptyOptions,
PostRoundTripEmptyOptions,
} from "./models/options.js";
import {
createEmpty,
EmptyClientOptions,
EmptyContext,
putEmpty,
getEmpty,
postRoundTripEmpty,
} from "./api/index.js";

export { EmptyClientOptions } from "./api/EmptyContext.js";

export class EmptyClient {
private _client: EmptyContext;
/** The pipeline used by this client to make requests */
public readonly pipeline: Pipeline;

/** Illustrates usage of empty model used in operation's parameters and responses. */
constructor(options: EmptyClientOptions = {}) {
this._client = createEmpty(options);
this.pipeline = this._client.pipeline;
}

putEmpty(
input: EmptyInput,
options: PutEmptyOptions = { requestOptions: {} },
): Promise<void> {
return putEmpty(this._client, input, options);
}

getEmpty(
options: GetEmptyOptions = { requestOptions: {} },
): Promise<EmptyOutput> {
return getEmpty(this._client, options);
}

postRoundTripEmpty(
body: EmptyInputOutput,
options: PostRoundTripEmptyOptions = { requestOptions: {} },
): Promise<EmptyInputOutput> {
return postRoundTripEmpty(this._client, body, options);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { ClientOptions } from "@azure-rest/core-client";
import { EmptyContext } from "../rest/index.js";
import getClient from "../rest/index.js";

export interface EmptyClientOptions extends ClientOptions {}

export { EmptyContext } from "../rest/index.js";

/** Illustrates usage of empty model used in operation's parameters and responses. */
export function createEmpty(options: EmptyClientOptions = {}): EmptyContext {
const clientContext = getClient(options);
return clientContext;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export {
createEmpty,
EmptyClientOptions,
EmptyContext,
} from "./EmptyContext.js";
export { putEmpty, getEmpty, postRoundTripEmpty } from "./operations.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { EmptyInput, EmptyOutput, EmptyInputOutput } from "../models/models.js";
import {
EmptyContext as Client,
GetEmpty200Response,
PostRoundTripEmpty200Response,
PutEmpty204Response,
} from "../rest/index.js";
import {
StreamableMethod,
operationOptionsToRequestParameters,
createRestError,
} from "@azure-rest/core-client";
import {
PutEmptyOptions,
GetEmptyOptions,
PostRoundTripEmptyOptions,
} from "../models/options.js";

export function _putEmptySend(
context: Client,
input: EmptyInput,
options: PutEmptyOptions = { requestOptions: {} },
): StreamableMethod<PutEmpty204Response> {
return context
.path("/type/model/empty/alone")
.put({ ...operationOptionsToRequestParameters(options), body: input });
}

export async function _putEmptyDeserialize(
result: PutEmpty204Response,
): Promise<void> {
if (result.status !== "204") {
throw createRestError(result);
}

return;
}

export async function putEmpty(
context: Client,
input: EmptyInput,
options: PutEmptyOptions = { requestOptions: {} },
): Promise<void> {
const result = await _putEmptySend(context, input, options);
return _putEmptyDeserialize(result);
}

export function _getEmptySend(
context: Client,
options: GetEmptyOptions = { requestOptions: {} },
): StreamableMethod<GetEmpty200Response> {
return context
.path("/type/model/empty/alone")
.get({ ...operationOptionsToRequestParameters(options) });
}

export async function _getEmptyDeserialize(
result: GetEmpty200Response,
): Promise<EmptyOutput> {
if (result.status !== "200") {
throw createRestError(result);
}

return result.body;
}

export async function getEmpty(
context: Client,
options: GetEmptyOptions = { requestOptions: {} },
): Promise<EmptyOutput> {
const result = await _getEmptySend(context, options);
return _getEmptyDeserialize(result);
}

export function _postRoundTripEmptySend(
context: Client,
body: EmptyInputOutput,
options: PostRoundTripEmptyOptions = { requestOptions: {} },
): StreamableMethod<PostRoundTripEmpty200Response> {
return context
.path("/type/model/empty/round-trip")
.post({ ...operationOptionsToRequestParameters(options), body: body });
}

export async function _postRoundTripEmptyDeserialize(
result: PostRoundTripEmpty200Response,
): Promise<EmptyInputOutput> {
if (result.status !== "200") {
throw createRestError(result);
}

return result.body;
}

export async function postRoundTripEmpty(
context: Client,
body: EmptyInputOutput,
options: PostRoundTripEmptyOptions = { requestOptions: {} },
): Promise<EmptyInputOutput> {
const result = await _postRoundTripEmptySend(context, body, options);
return _postRoundTripEmptyDeserialize(result);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export { EmptyClient, EmptyClientOptions } from "./EmptyClient.js";
export {
EmptyInput,
EmptyOutput,
EmptyInputOutput,
PutEmptyOptions,
GetEmptyOptions,
PostRoundTripEmptyOptions,
} from "./models/index.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { createClientLogger } from "@azure/logger";
export const logger = createClientLogger("modular-model-empty");
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

export { EmptyInput, EmptyOutput, EmptyInputOutput } from "./models.js";
export {
PutEmptyOptions,
GetEmptyOptions,
PostRoundTripEmptyOptions,
} from "./options.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/** Empty model used in operation parameters */
export interface EmptyInput {}

/** Empty model used in operation return type */
export interface EmptyOutput {}

/** Empty model used in both parameter and return type */
export interface EmptyInputOutput {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { OperationOptions } from "@azure-rest/core-client";

export interface PutEmptyOptions extends OperationOptions {}

export interface GetEmptyOptions extends OperationOptions {}

export interface PostRoundTripEmptyOptions extends OperationOptions {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import {
PutEmptyParameters,
GetEmptyParameters,
PostRoundTripEmptyParameters,
} from "./parameters.js";
import {
PutEmpty204Response,
GetEmpty200Response,
PostRoundTripEmpty200Response,
} from "./responses.js";
import { Client, StreamableMethod } from "@azure-rest/core-client";

export interface PutEmpty {
put(options: PutEmptyParameters): StreamableMethod<PutEmpty204Response>;
get(options?: GetEmptyParameters): StreamableMethod<GetEmpty200Response>;
}

export interface PostRoundTripEmpty {
post(
options: PostRoundTripEmptyParameters,
): StreamableMethod<PostRoundTripEmpty200Response>;
}

export interface Routes {
/** Resource for '/type/model/empty/alone' has methods for the following verbs: put, get */
(path: "/type/model/empty/alone"): PutEmpty;
/** Resource for '/type/model/empty/round-trip' has methods for the following verbs: post */
(path: "/type/model/empty/round-trip"): PostRoundTripEmpty;
}

export type EmptyContext = Client & {
path: Routes;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { getClient, ClientOptions } from "@azure-rest/core-client";
import { logger } from "../logger.js";
import { EmptyContext } from "./clientDefinitions.js";

/**
* Initialize a new instance of `EmptyContext`
* @param options - the parameter for all optional parameters
*/
export default function createClient(
options: ClientOptions = {},
): EmptyContext {
const baseUrl = options.baseUrl ?? `http://localhost:3000`;
const userAgentInfo = `azsdk-js-modular-model-empty-rest/1.0.0-beta.1`;
const userAgentPrefix =
options.userAgentOptions && options.userAgentOptions.userAgentPrefix
? `${options.userAgentOptions.userAgentPrefix} ${userAgentInfo}`
: `${userAgentInfo}`;
options = {
...options,
userAgentOptions: {
userAgentPrefix,
},
loggingOptions: {
logger: options.loggingOptions?.logger ?? logger.info,
},
};

const client = getClient(baseUrl, options) as EmptyContext;

client.pipeline.removePolicy({ name: "ApiVersionPolicy" });
return client;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import EmptyClient from "./emptyClient.js";

export * from "./emptyClient.js";
export * from "./parameters.js";
export * from "./responses.js";
export * from "./clientDefinitions.js";
export * from "./models.js";
export * from "./outputModels.js";

export default EmptyClient;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/** Empty model used in operation parameters */
export interface EmptyInput {}

/** Empty model used in both parameter and return type */
export interface EmptyInputOutput {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

/** Empty model used in operation return type */
export interface EmptyOutputOutput {}

/** Empty model used in both parameter and return type */
export interface EmptyInputOutputOutput {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { RequestParameters } from "@azure-rest/core-client";
import { EmptyInput, EmptyInputOutput } from "./models.js";

export interface PutEmptyBodyParam {
body: EmptyInput;
}

export type PutEmptyParameters = PutEmptyBodyParam & RequestParameters;
export type GetEmptyParameters = RequestParameters;

export interface PostRoundTripEmptyBodyParam {
body: EmptyInputOutput;
}

export type PostRoundTripEmptyParameters = PostRoundTripEmptyBodyParam &
RequestParameters;
Loading
Loading