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
4 changes: 2 additions & 2 deletions packages/typespec-ts/src/utils/modelUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1184,9 +1184,9 @@ function getSchemaForArrayModel(
.join(" | ");
}
}
} else if (schema.items.type.includes("|")) {
} else if (schema.items.type && schema.items.type.includes("|")) {
schema.typeName = `(${schema.items.type})[]`;
} else {
} else if (schema.items.type) {
schema.typeName = `${schema.items.type}[]`;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { assert } from "chai";
import AlternateTypeClientFactory, {
AlternateTypeClient
} from "./generated/azure/client-generator-core/alternate-type/src/index.js";

describe("AlternateType Client", () => {
let client: AlternateTypeClient;

beforeEach(() => {
client = AlternateTypeClientFactory({
allowInsecureConnection: true,
retryOptions: {
maxRetries: 0
}
});
});

const feature = {
type: "Feature",
geometry: {
type: "Point",
coordinates: [-122.25, 37.87]
},
properties: {
name: "A single point of interest",
category: "landmark",
elevation: 100
},
id: "feature-1"
};

const modelWithFeatureProperty = {
feature,
additionalProperty: "extra"
};

it("should get model in external type operation", async () => {
const result = await client
.path("/azure/client-generator-core/alternate-type/external/model")
.get();
assert.strictEqual(result.status, "200");
assert.deepEqual(result.body, feature);
});

it("should put model in external type operation", async () => {
const result = await client
.path("/azure/client-generator-core/alternate-type/external/model")
.put({ body: feature });
assert.strictEqual(result.status, "204");
});

it("should get property in external type operation", async () => {
const result = await client
.path("/azure/client-generator-core/alternate-type/external/property")
.get();
assert.strictEqual(result.status, "200");
assert.deepEqual(result.body, modelWithFeatureProperty);
});

it("should put property in external type operation", async () => {
const result = await client
.path("/azure/client-generator-core/alternate-type/external/property")
.put({ body: modelWithFeatureProperty });
assert.strictEqual(result.status, "204");
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
!/src
/src/**
!/src/index.d.ts
!/.gitignore
!/tspconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
emit:
- "@azure-tools/typespec-ts"
options:
"@azure-tools/typespec-ts":
emitter-output-dir: "{project-root}"
generate-metadata: true
generate-test: false
add-credentials: false
flavor: azure
azure-sdk-for-js: false
is-typespec-test: true
generate-sample: true
package-details:
name: "@msinternal/clientGeneratorCore-alternateType"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AlternateTypeClient from "./alternateTypeClient.js";
export * from "./alternateTypeClient.js";
export * from "./parameters.js";
export * from "./responses.js";
export * from "./clientDefinitions.js";
export * from "./models.js";
export * from "./outputModels.js";
export default AlternateTypeClient;
//# sourceMappingURL=index.d.ts.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { assert } from "chai";
import { AlternateTypeClient } from "./generated/azure/client-generator-core/alternate-type/src/index.js";

describe("AlternateType Client Modular", () => {
let client: AlternateTypeClient;

beforeEach(() => {
client = new AlternateTypeClient({
allowInsecureConnection: true,
retryOptions: {
maxRetries: 0
}
});
});

const feature = {
type: "Feature" as const,
geometry: {
type: "Point",
coordinates: [-122.25, 37.87]
},
properties: {
name: "A single point of interest",
category: "landmark",
elevation: 100
},
id: "feature-1"
};

const modelWithFeatureProperty = {
feature,
additionalProperty: "extra"
};

it("should get model in external type operation", async () => {
const result = await client.externalType.getModel();
assert.deepEqual(result, feature);
});

it("should put model in external type operation", async () => {
const result = await client.externalType.putModel(feature);
assert.strictEqual(result, undefined);
});

it("should get property in external type operation", async () => {
const result = await client.externalType.getProperty();
assert.deepEqual(result, modelWithFeatureProperty);
});

it("should put property in external type operation", async () => {
const result = await client.externalType.putProperty(modelWithFeatureProperty);
assert.strictEqual(result, undefined);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
!/src
/src/**
!/src/index.d.ts
!/.gitignore
!/tspconfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { ClientOptions } from '@azure-rest/core-client';
import { OperationOptions } from '@azure-rest/core-client';
import { Pipeline } from '@azure/core-rest-pipeline';

export declare class AlternateTypeClient {
private _client;
readonly pipeline: Pipeline;
constructor(options?: AlternateTypeClientOptionalParams);
putProperty(body: ModelWithFeatureProperty, options?: PutPropertyOptionalParams): Promise<void>;
getProperty(options?: GetPropertyOptionalParams): Promise<ModelWithFeatureProperty>;
putModel(body: Feature, options?: PutModelOptionalParams): Promise<void>;
getModel(options?: GetModelOptionalParams): Promise<Feature>;
}

export declare interface AlternateTypeClientOptionalParams extends ClientOptions {
}

export declare interface Feature {
type: "Feature";
geometry: Geometry | null;
properties: Record<string, any>;
id?: string | number;
}

export declare interface Geometry {
type: string;
coordinates: number[];
}

export declare interface GetModelOptionalParams extends OperationOptions {
}

export declare interface GetPropertyOptionalParams extends OperationOptions {
}

export declare interface ModelWithFeatureProperty {
feature: Feature;
additionalProperty: string;
}

export declare interface PutModelOptionalParams extends OperationOptions {
}

export declare interface PutPropertyOptionalParams extends OperationOptions {
}

export { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
emit:
- "@azure-tools/typespec-ts"
options:
"@azure-tools/typespec-ts":
emitter-output-dir: "{project-root}"
generate-metadata: true
generate-test: false
add-credentials: false
flavor: azure
azure-sdk-for-js: false
is-typespec-test: true
is-modular-library: true
hierarchy-client: false
package-details:
name: "@msinternal/clientGeneratorCore-alternateType"
description: "Azure clientGenerator Core alternate type Test Service"
8 changes: 8 additions & 0 deletions packages/typespec-ts/test/commands/cadl-ranch-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ export const azureRlcTsps = [
outputPath: "azure/client-generator-core/override",
inputPath: "azure/client-generator-core/override"
},
{
outputPath: "azure/client-generator-core/alternate-type",
inputPath: "azure/client-generator-core/alternate-type"
},
{
outputPath: "azure/versioning/previewVersion",
inputPath: "azure/versioning/previewVersion"
Expand Down Expand Up @@ -876,6 +880,10 @@ export const azureModularTsps = [
outputPath: "azure/client-generator-core/override",
inputPath: "azure/client-generator-core/override"
},
{
outputPath: "azure/client-generator-core/alternate-type",
inputPath: "azure/client-generator-core/alternate-type"
},
{
outputPath: "azure/versioning/previewVersion",
inputPath: "azure/versioning/previewVersion"
Expand Down
Loading