Skip to content
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 @@ -944,7 +944,7 @@ function deserializeResponseValue(
type.elementType!,
"p",
runtimeImports,
required,
true,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just found typespec can't not define this way playground link

Copy link
Copy Markdown
Member

@qiaozha qiaozha Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assume elementTypes are all required, for nullable, since the current nullable logic has problem, I would prefer to have another independent pr to fix it. @MaryGao let me know if you have different thoughts.

[...typeStack, type.elementType!],
type.elementType?.format
)})`;
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 @@ -318,6 +318,10 @@ export const modularTsps: TypeSpecRanchConfig[] = [
{
outputPath: "models/empty",
inputPath: "type/model/empty"
},
{
outputPath: "arrays/items",
inputPath: "type/array"
}
];

Expand Down
154 changes: 154 additions & 0 deletions packages/typespec-ts/test/modularIntegration/arrayItemTypes.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import { assert } from "chai";
import { ArrayClient } from "./generated/arrays/items/src/index.js";

interface TypeDetail {
type: string;
defaultValue: any;
convertedToFn?: (_: any) => any;
}

const testedTypes: TypeDetail[] = [
{
type: "int32",
defaultValue: [1, 2]
},
{
type: "int64",
defaultValue: [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER]
},
{
type: "boolean",
defaultValue: [true, false]
},
{
type: "string",
defaultValue: ["hello", ""]
},
{
type: "float32",
defaultValue: [42.42]
},
{
type: "datetime",
defaultValue: [new Date("2022-08-26T18:38:00Z")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Datetime type is a Date typescript type in modular.

},
{
type: "duration",
defaultValue: ["P123DT22H14M12.011S"]
},
{
type: "unknown",
defaultValue: [1, "hello", null]
},
{
type: "model",
defaultValue: [
{ property: "hello", children: undefined },
{ property: "world", children: undefined }
Comment on lines +46 to +47
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the children: undefined are added by the current serialization and deserialization logic in modular.

]
},
{
type: "nullable-float",
defaultValue: [1.2, null, 3.0]
}
];
describe("Array Item-Types Client", () => {
let client: ArrayClient;

beforeEach(() => {
client = new ArrayClient({
allowInsecureConnection: true,
retryOptions: {
maxRetries: 0
}
});
});
for (let item of testedTypes) {
it(`should get ${item.type} value`, async () => {
try {
let result: any;
switch (item.type) {
case "int32":
result = await client.int32Value.get();
break;
case "int64":
result = await client.int64Value.get();
break;
case "boolean":
result = await client.booleanValue.get();
break;
case "string":
result = await client.stringValue.get();
break;
case "float32":
result = await client.float32Value.get();
break;
case "datetime":
result = await client.datetimeValue.get();
break;
case "duration":
result = await client.durationValue.get();
break;
case "unknown":
result = await client.unknownValue.get();
break;
case "model":
result = await client.modelValue.get();
break;
case "nullable-float":
result = await client.nullableFloatValue.get();
break;
default:
break;
}
assert.deepEqual(result, item.defaultValue);
} catch (err) {
assert.fail(err as string);
}
});
}
for (let item of testedTypes) {
it(`should put ${item.type} vaule`, async () => {
try {
let result: any;
switch (item.type) {
case "int32":
result = await client.int32Value.put(item.defaultValue);
break;
case "int64":
result = await client.int64Value.put(item.defaultValue);
break;
case "boolean":
result = await client.booleanValue.put(item.defaultValue);
break;
case "string":
result = await client.stringValue.put(item.defaultValue);
break;
case "float32":
result = await client.float32Value.put(item.defaultValue);
break;
case "datetime":
result = await client.datetimeValue.put(item.defaultValue);
break;
case "duration":
result = await client.durationValue.put(item.defaultValue);
break;
case "unknown":
result = await client.unknownValue.put(item.defaultValue);
break;
case "model":
result = await client.modelValue.put(item.defaultValue);
break;
case "nullable-float":
result = await client.nullableFloatValue.put(item.defaultValue);
break;
default:
break;
}
assert.isUndefined(result);
} catch (err) {
assert.fail(err as string);
}
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { Pipeline } from "@azure/core-rest-pipeline";
import {
getInt32ValueOperations,
Int32ValueOperations,
} from "./classic/int32Value/index.js";
import {
getInt64ValueOperations,
Int64ValueOperations,
} from "./classic/int64Value/index.js";
import {
getBooleanValueOperations,
BooleanValueOperations,
} from "./classic/booleanValue/index.js";
import {
getStringValueOperations,
StringValueOperations,
} from "./classic/stringValue/index.js";
import {
getFloat32ValueOperations,
Float32ValueOperations,
} from "./classic/float32Value/index.js";
import {
getDatetimeValueOperations,
DatetimeValueOperations,
} from "./classic/datetimeValue/index.js";
import {
getDurationValueOperations,
DurationValueOperations,
} from "./classic/durationValue/index.js";
import {
getUnknownValueOperations,
UnknownValueOperations,
} from "./classic/unknownValue/index.js";
import {
getModelValueOperations,
ModelValueOperations,
} from "./classic/modelValue/index.js";
import {
getNullableFloatValueOperations,
NullableFloatValueOperations,
} from "./classic/nullableFloatValue/index.js";
import { createArray, ArrayClientOptions, ArrayContext } from "./api/index.js";

export { ArrayClientOptions } from "./api/ArrayContext.js";

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

/** Illustrates various of dictionaries. */
constructor(options: ArrayClientOptions = {}) {
this._client = createArray(options);
this.pipeline = this._client.pipeline;
this.int32Value = getInt32ValueOperations(this._client);
this.int64Value = getInt64ValueOperations(this._client);
this.booleanValue = getBooleanValueOperations(this._client);
this.stringValue = getStringValueOperations(this._client);
this.float32Value = getFloat32ValueOperations(this._client);
this.datetimeValue = getDatetimeValueOperations(this._client);
this.durationValue = getDurationValueOperations(this._client);
this.unknownValue = getUnknownValueOperations(this._client);
this.modelValue = getModelValueOperations(this._client);
this.nullableFloatValue = getNullableFloatValueOperations(this._client);
}

/** The operation groups for Int32Value */
public readonly int32Value: Int32ValueOperations;
/** The operation groups for Int64Value */
public readonly int64Value: Int64ValueOperations;
/** The operation groups for BooleanValue */
public readonly booleanValue: BooleanValueOperations;
/** The operation groups for StringValue */
public readonly stringValue: StringValueOperations;
/** The operation groups for Float32Value */
public readonly float32Value: Float32ValueOperations;
/** The operation groups for DatetimeValue */
public readonly datetimeValue: DatetimeValueOperations;
/** The operation groups for DurationValue */
public readonly durationValue: DurationValueOperations;
/** The operation groups for UnknownValue */
public readonly unknownValue: UnknownValueOperations;
/** The operation groups for ModelValue */
public readonly modelValue: ModelValueOperations;
/** The operation groups for NullableFloatValue */
public readonly nullableFloatValue: NullableFloatValueOperations;
}
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 { ArrayContext } from "../rest/index.js";
import getClient from "../rest/index.js";

export interface ArrayClientOptions extends ClientOptions {}

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

/** Illustrates various of dictionaries. */
export function createArray(options: ArrayClientOptions = {}): ArrayContext {
const clientContext = getClient(options);
return clientContext;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import {
ArrayContext as Client,
BooleanValueGet200Response,
BooleanValuePut204Response,
} from "../../rest/index.js";
import {
StreamableMethod,
operationOptionsToRequestParameters,
createRestError,
} from "@azure-rest/core-client";
import {
BooleanValueGetOptions,
BooleanValuePutOptions,
} from "../../models/options.js";

export function _booleanValueGetSend(
context: Client,
options: BooleanValueGetOptions = { requestOptions: {} },
): StreamableMethod<BooleanValueGet200Response> {
return context
.path("/type/array/boolean")
.get({ ...operationOptionsToRequestParameters(options) });
}

export async function _booleanValueGetDeserialize(
result: BooleanValueGet200Response,
): Promise<boolean[]> {
if (result.status !== "200") {
throw createRestError(result);
}

return result.body;
}

export async function booleanValueGet(
context: Client,
options: BooleanValueGetOptions = { requestOptions: {} },
): Promise<boolean[]> {
const result = await _booleanValueGetSend(context, options);
return _booleanValueGetDeserialize(result);
}

export function _booleanValuePutSend(
context: Client,
body: boolean[],
options: BooleanValuePutOptions = { requestOptions: {} },
): StreamableMethod<BooleanValuePut204Response> {
return context
.path("/type/array/boolean")
.put({ ...operationOptionsToRequestParameters(options), body: body });
}

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

return;
}

export async function booleanValuePut(
context: Client,
body: boolean[],
options: BooleanValuePutOptions = { requestOptions: {} },
): Promise<void> {
const result = await _booleanValuePutSend(context, body, options);
return _booleanValuePutDeserialize(result);
}
Loading