Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
282 changes: 175 additions & 107 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions packages/typespec-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"type": "module",
"dependencies": {
"@azure-tools/typespec-ts": "workspace:^0.23.0",
"@typespec/openapi": ">=0.53.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.39.0 <1.0.0",
"@typespec/openapi3": ">=0.53.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.39.1 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.40.0-dev.17",
"@typespec/compiler": ">=0.53.1 <1.0.0",
"@typespec/http": ">=0.53.0 <1.0.0",
"@typespec/rest": ">=0.53.0 <1.0.0",
"@typespec/versioning": ">=0.53.0 <1.0.0",
"@typespec/openapi": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-autorest": ">=0.40.0 <1.0.0",
"@typespec/openapi3": ">=0.54.0 <1.0.0",
"@azure-tools/typespec-azure-core": ">=0.40.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.40.0",
"@typespec/compiler": ">=0.54.0 <1.0.0",
"@typespec/http": ">=0.54.0 <1.0.0",
"@typespec/rest": ">=0.54.0 <1.0.0",
"@typespec/versioning": ">=0.54.0 <1.0.0",
"prettier": "^3.1.0"
},
"devDependencies": {
Expand Down
24 changes: 12 additions & 12 deletions packages/typespec-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@
"@azure/core-util": "^1.4.0",
"eslint-plugin-require-extensions": "0.1.3",
"@typespec/ts-http-runtime": "1.0.0-alpha.20240226.9",
"@azure-tools/typespec-azure-core": ">=0.39.1 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.40.0-dev.17",
"@typespec/compiler": ">=0.53.1 <1.0.0",
"@typespec/http": ">=0.53.0 <1.0.0",
"@typespec/rest": ">=0.53.0 <1.0.0",
"@typespec/versioning": ">=0.53.0 <1.0.0"
"@azure-tools/typespec-azure-core": ">=0.40.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.40.0",
"@typespec/compiler": ">=0.54.0 <1.0.0",
"@typespec/http": ">=0.54.0 <1.0.0",
"@typespec/rest": ">=0.54.0 <1.0.0",
"@typespec/versioning": ">=0.54.0 <1.0.0"
},
"peerDependencies": {
"@azure-tools/typespec-azure-core": ">=0.39.1 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.40.0-dev.17",
"@typespec/compiler": ">=0.53.1 <1.0.0",
"@typespec/http": ">=0.53.0 <1.0.0",
"@typespec/rest": ">=0.53.0 <1.0.0",
"@typespec/versioning": ">=0.53.0 <1.0.0"
"@azure-tools/typespec-azure-core": ">=0.40.0 <1.0.0",
"@azure-tools/typespec-client-generator-core": "0.40.0",
"@typespec/compiler": ">=0.54.0 <1.0.0",
"@typespec/http": ">=0.54.0 <1.0.0",
"@typespec/rest": ">=0.54.0 <1.0.0",
"@typespec/versioning": ">=0.54.0 <1.0.0"
},
"dependencies": {
"prettier": "^3.1.0",
Expand Down
8 changes: 6 additions & 2 deletions packages/typespec-ts/src/modular/buildCodeModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,9 @@ function emitEnum(context: SdkContext, type: Enum): Record<string, any> {

return {
type: "enum",
name: getLibraryName(context, type),
name: getLibraryName(context, type)
? getLibraryName(context, type)
: type.name,
description: getDocStr(program, type),
valueType: { type: enumMemberType(type.members.values().next().value) },
values: enumValues,
Expand Down Expand Up @@ -1421,7 +1423,9 @@ function emitUnion(
};
} else if (sdkType.kind === "enum") {
return {
name: sdkType.name,
name: getLibraryName(context, type)
? getLibraryName(context, type)
: type.name,
nullable: sdkType.nullable,
description: sdkType.description || `Type of ${sdkType.name}`,
internal: true,
Expand Down
18 changes: 12 additions & 6 deletions packages/typespec-ts/src/modular/helpers/typeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,18 @@ function handleConstantType(type: Type): TypeMetadata {
* Handles the conversion of enum types to TypeScript representation metadata.
*/
function handleEnumType(type: Type): TypeMetadata {
if (
!type.name &&
(!type?.valueType?.type ||
!["string", "number"].includes(type?.valueType?.type))
) {
throw new Error("Unable to process enum without name");
if (!type.name) {
const valueType = !type.isFixed
? ((type.values?.[0] as Type).valueType?.type ?? "string") + " | "
: "";
return {
name: `${valueType}${type.values
?.map((e) => {
return getType(e as Type).name;
})
.join(" | ")}`,
nullable: type.nullable
};
}
const name = handleNullableTypeName({
name: type.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ export interface UserActionResponse {
userActionResult: string;
}

/** Alias for RepeatabilityResult */
/** Repeatability Result header options */
/** */
export type RepeatabilityResult = "accepted" | "rejected";
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export {
ListItemInputBody,
UserListResults,
PagedUser,
ListItemInputExtensibleEnum,
PagedFirstItem,
FirstItem,
PagedSecondItem,
SecondItem,
ListItemInputExtensibleEnum,
CreateOrUpdateOptions,
CreateOrReplaceOptions,
GetOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ export {
ListItemInputBody,
UserListResults,
PagedUser,
ListItemInputExtensibleEnum,
PagedFirstItem,
FirstItem,
PagedSecondItem,
SecondItem,
ListItemInputExtensibleEnum,
} from "./models.js";
export {
CreateOrUpdateOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,27 @@ export interface PagedUser {
/** The User items on this page */
value: User[];
/** The link to the next page of items */
nextLink?: string;
readonly nextLink?: string;
}

/** Paged collection of User items */
export interface PagedUser {
/** The User items on this page */
value: User[];
/** The link to the next page of items */
nextLink?: string;
readonly nextLink?: string;
}

/** An extensible enum input parameter. */
/** "First", "Second" */
export type ListItemInputExtensibleEnum = string;

/** Paged collection of FirstItem items */
export interface PagedFirstItem {
/** The FirstItem items on this page */
value: FirstItem[];
/** The link to the next page of items */
nextLink?: string;
readonly nextLink?: string;
}

/** First item. */
Expand All @@ -71,14 +75,11 @@ export interface PagedSecondItem {
/** The SecondItem items on this page */
value: SecondItem[];
/** The link to the next page of items */
nextLink?: string;
readonly nextLink?: string;
}

/** Second item. */
export interface SecondItem {
/** The name of the item. */
readonly name: string;
}

/** Alias for ListItemInputExtensibleEnum */
export type ListItemInputExtensibleEnum = string | "First" | "Second";
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
// Licensed under the MIT license.

import { Pipeline } from "@azure/core-rest-pipeline";
import { ImmediateSuccessOptions } from "./models/options.js";
import {
immediateSuccess,
createRepeatability,
RepeatabilityClientOptions,
RepeatabilityContext,
} from "./api/index.js";
import { ImmediateSuccessOptions } from "./models/options.js";

export { RepeatabilityClientOptions } from "./api/RepeatabilityContext.js";

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

export * from "./models.js";
Comment thread
MaryGao marked this conversation as resolved.
Outdated
export { ImmediateSuccessOptions } from "./options.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export {
export {
Dog,
Golden,
DogKind,
Snake,
Cobra,
SnakeKind,
DogUnion,
DogKind,
SnakeUnion,
GetExtensibleModelOptions,
PutExtensibleModelOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
export {
Dog,
Golden,
DogKind,
Snake,
Cobra,
SnakeKind,
DogUnion,
DogKind,
SnakeUnion,
} from "./models.js";
export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface Golden extends Dog {
kind: "golden";
}

/** extensible enum type for discriminator */
/** "golden" */
export type DogKind = string;

/** Test fixed enum type for discriminator */
export interface Snake {
/** the discriminator possible values: cobra */
Expand All @@ -34,7 +38,5 @@ export interface Cobra extends Snake {
export type SnakeKind = "cobra";
/** Alias for DogUnion */
export type DogUnion = Golden | Dog;
/** Alias for DogKind */
export type DogKind = string | "golden";
/** Alias for SnakeUnion */
export type SnakeUnion = Cobra | Snake;
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export {
CollectionsStringProperty,
ModelProperty,
ExtensibleEnumProperty,
InnerEnum,
EnumProperty,
FixedInnerEnum,
DurationProperty,
Expand All @@ -36,7 +37,6 @@ export {
BytesProperty,
StringProperty,
BooleanProperty,
InnerEnum,
BooleanGetOptions,
BooleanPutOptions,
StringGetOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {
CollectionsStringProperty,
ModelProperty,
ExtensibleEnumProperty,
InnerEnum,
EnumProperty,
FixedInnerEnum,
DurationProperty,
Expand All @@ -32,7 +33,6 @@ export {
BytesProperty,
StringProperty,
BooleanProperty,
InnerEnum,
} from "./models.js";
export {
BooleanGetOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ export interface ExtensibleEnumProperty {
property: InnerEnum;
}

/** Enum that will be used as a property for model EnumProperty. Extensible. */
/** "ValueOne", "ValueTwo" */
export type InnerEnum = string;

/** Model with enum properties */
export interface EnumProperty {
/** Property */
Expand Down Expand Up @@ -175,6 +179,3 @@ export interface BooleanProperty {
/** Property */
property: boolean;
}

/** Alias for InnerEnum */
export type InnerEnum = string | "ValueOne" | "ValueTwo";
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface PagedUser {
/** The User items on this page */
value: User[];
/** The link to the next page of items */
nextLink?: string;
readonly nextLink?: string;
}

/** User model */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export {
MixedLiteralsCases,
StringAndArrayCases,
EnumsOnlyCases,
LR,
UD,
Dog,
StringExtensibleNamedUnion,
StringsOnlyGetOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ export {
MixedLiteralsCases,
StringAndArrayCases,
EnumsOnlyCases,
LR,
UD,
Dog,
StringExtensibleNamedUnion,
} from "./models.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@ export interface StringAndArrayCases {

export interface EnumsOnlyCases {
/** This should be receive/send the left variant */
lr: LR | UD;
lr: "left" | "right" | "up" | "down";
/** This should be receive/send the up variant */
ud: UD | UD;
ud: "up" | "down";
}

/** "left", "right" */
export type LR = string;
/** "up", "down" */
export type UD = string;

export interface Dog {
bark: string;
}

/** Alias for StringExtensibleNamedUnion */
export type StringExtensibleNamedUnion = string | "b" | "c";
/** Type of StringExtensibleNamedUnion */
/** "b", "c" */
export type StringExtensibleNamedUnion = string;