Skip to content
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3304d59
migrate eam for hlc
kazrael2119 Mar 24, 2025
dad95a9
merge main
kazrael2119 Mar 24, 2025
cce6d5b
update
kazrael2119 Mar 24, 2025
62b995b
update
kazrael2119 Mar 24, 2025
b6719e2
Merge branch 'main' into migrate-esm
kazrael2119 Mar 31, 2025
f07c16d
Merge branch 'main' into migrate-esm
kazrael2119 Apr 7, 2025
2d2c636
Update typescriptGenerator.ts
kazrael2119 Apr 7, 2025
b1aac0f
Merge branch 'migrate-esm' of https://github.com/kazrael2119/autorest…
kazrael2119 Apr 7, 2025
1198d02
update
kazrael2119 Apr 8, 2025
480255c
generate-swaggers
kazrael2119 Apr 8, 2025
2ea1f5f
Update case-hlcReadme.md
kazrael2119 Apr 8, 2025
e646cf2
update
kazrael2119 Apr 8, 2025
0a98ef3
revert moduleKind changes
kazrael2119 Apr 9, 2025
a37bfa1
update
kazrael2119 Apr 9, 2025
a715b58
update
kazrael2119 Apr 10, 2025
72f6902
update
kazrael2119 Apr 10, 2025
d908e73
update
kazrael2119 Apr 10, 2025
23b8bb0
separate changes
kazrael2119 Apr 14, 2025
9d2eaef
revert import type change
kazrael2119 Apr 14, 2025
f4b30b7
update
kazrael2119 Apr 15, 2025
66a0619
Update operationGenerator.ts
kazrael2119 Apr 15, 2025
5cf44d8
update
kazrael2119 Apr 15, 2025
caba4d9
Update smoke-test.ts
kazrael2119 Apr 15, 2025
26bc77c
update
kazrael2119 Apr 15, 2025
9c60f0c
update
kazrael2119 Apr 15, 2025
fd8fbbf
update
kazrael2119 Apr 15, 2025
36a0646
Update operationGenerator.ts
kazrael2119 Apr 15, 2025
a1404cb
Merge branch 'main' into migrate-esm
MaryGao Apr 15, 2025
7249c93
update
kazrael2119 Apr 15, 2025
df2e8d3
Update nameConstructors.spec.ts
kazrael2119 Apr 15, 2025
d2ff62c
update
kazrael2119 Apr 15, 2025
f80261a
Merge branch 'main' into migrate-esm
MaryGao Apr 15, 2025
844c48f
Update nameConstructors.spec.ts
kazrael2119 Apr 16, 2025
4e21c54
Update nameConstructors.ts
kazrael2119 Apr 16, 2025
d892269
Update nameConstructors.ts
kazrael2119 Apr 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 1 addition & 3 deletions packages/autorest.typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ In addition to the [list of Autorest flags](https://github.com/Azure/autorest/bl
| `--generate-metadata` | Generates meta files such as readme, license, package.json, etc. Typically, you need to specify this flag in your first generation only |
| `--tracing-info` | Controls specification of meta info attached to requests for tracing purposes |
| `--disable-async-iterators` | Does not generate async iterators needed for paging operations |
| `--allow-insecure-connection` | Allow generated clients to make requests to HTTP endpoints |
| `--module-kind` | Allows controlling between CommonJS and ESM style imports and exports. Accepted values: `esm`, `cjs`. Defaults to `cjs` for backwards compatibility. ESM style imports and exports will include the file extension and avoid directory imports. |
Comment thread
MaryGao marked this conversation as resolved.

| `--allow-insecure-connection` | Allow generated clients to make requests to HTTP endpoints |
## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a
Expand Down
1 change: 0 additions & 1 deletion packages/autorest.typescript/src/autorestSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ export interface AutorestOptions {
lenientModelDeduplication?: boolean;
useLegacyLro?: boolean;
flavor?: PackageFlavor;
moduleKind?: "cjs" | "esm";
}

let host: AutorestExtensionHost;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
packageDetails,
coreHttpCompatMode,
useLegacyLro,
moduleKind
isTestPackage
} = getAutorestOptions();
const { addCredentials } = getSecurityInfoFromModel(clientDetails.security);
const hasMappers = !!clientDetails.mappers.length;
Expand Down Expand Up @@ -144,7 +144,7 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
});
clientFile.addImportDeclaration({
namedImports: ["createLroSpec"],
moduleSpecifier: getImportModuleName(`./lroImpl`, moduleKind)
moduleSpecifier: getImportModuleName(`./lroImpl`, isTestPackage)
Comment thread
MaryGao marked this conversation as resolved.
});
}

Expand All @@ -158,7 +158,7 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
true /* shouldGuard */
)}Impl`
),
moduleSpecifier: getImportModuleName({ cjsName: "./operations", esModulesName: "./operations/index.js" }, moduleKind)
moduleSpecifier: getImportModuleName({ cjsName: "./operations", esModulesName: "./operations/index.js" }, isTestPackage)
});

clientFile.addImportDeclaration({
Expand All @@ -170,23 +170,23 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
true /* shouldGuard */
)}`
),
moduleSpecifier: getImportModuleName({ cjsName: "./operationsInterfaces", esModulesName: "./operationsInterfaces/index.js" }, moduleKind)
moduleSpecifier: getImportModuleName({ cjsName: "./operationsInterfaces", esModulesName: "./operationsInterfaces/index.js" }, isTestPackage)
});
}

if (hasInlineOperations && shouldImportParameters(clientDetails)) {
addTracingOperationImports(clientFile, ".");
clientFile.addImportDeclaration({
namespaceImport: "Parameters",
moduleSpecifier: getImportModuleName("./models/parameters", moduleKind)
moduleSpecifier: getImportModuleName("./models/parameters", isTestPackage)
});
}

// Only import mappers if there are any
if (hasInlineOperations && hasMappers) {
clientFile.addImportDeclaration({
namespaceImport: "Mappers",
moduleSpecifier: getImportModuleName("./models/mappers", moduleKind)
moduleSpecifier: getImportModuleName("./models/mappers", isTestPackage)
});
}

Expand Down Expand Up @@ -243,7 +243,7 @@ export function generateClient(clientDetails: ClientDetails, project: Project) {
if (importedModels.size) {
clientFile.addImportDeclaration({
namedImports: [...importedModels],
moduleSpecifier: getImportModuleName({ cjsName: "./models", esModulesName: "./models/index.js" }, moduleKind)
moduleSpecifier: getImportModuleName({ cjsName: "./models", esModulesName: "./models/index.js" }, isTestPackage)
});
}

Expand Down
10 changes: 5 additions & 5 deletions packages/autorest.typescript/src/generators/indexGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@ export function generateIndexFile(
}

function generateHLCIndex(clientDetails: ClientDetails, file: SourceFile) {
const { disablePagingAsyncIterators, moduleKind } = getAutorestOptions();
const { disablePagingAsyncIterators, isTestPackage } = getAutorestOptions();
if (clientDetails.options.hasPaging && !disablePagingAsyncIterators) {
file.addStatements([`/// <reference lib="esnext.asynciterable" />`]);
file.addExportDeclaration({
moduleSpecifier: getImportModuleName("./pagingHelper", moduleKind),
moduleSpecifier: getImportModuleName("./pagingHelper", isTestPackage),
namedExports: ["getContinuationToken"]
});
}

file.addExportDeclarations([
{
moduleSpecifier: getImportModuleName({ cjsName: "./models", esModulesName: "./models/index.js" }, moduleKind),
moduleSpecifier: getImportModuleName({ cjsName: "./models", esModulesName: "./models/index.js" }, isTestPackage),
},
{
moduleSpecifier: getImportModuleName(`./${clientDetails.sourceFileName}`, moduleKind),
moduleSpecifier: getImportModuleName(`./${clientDetails.sourceFileName}`, isTestPackage),
namedExports: [clientDetails.className]
}
]);
Expand All @@ -48,7 +48,7 @@ function generateHLCIndex(clientDetails: ClientDetails, file: SourceFile) {
if (operationGroups.length) {
file.addExportDeclarations([
{
moduleSpecifier: getImportModuleName({ cjsName: "./operationsInterfaces", esModulesName: "./operationsInterfaces/index.js" }, moduleKind),
moduleSpecifier: getImportModuleName({ cjsName: "./operationsInterfaces", esModulesName: "./operationsInterfaces/index.js" }, isTestPackage),
}
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ function writeDiscriminatorsMapping(

type ModelPropertiesType =
| {
[propertyName: string]: Mapper;
}
[propertyName: string]: Mapper;
}
| undefined;

export function writeMapper(writer: CodeBlockWriter, mapper: Mapper) {
Expand Down
34 changes: 17 additions & 17 deletions packages/autorest.typescript/src/generators/modelsGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const writeClientModels = (
baseClass: !useCoreV2
? "coreHttp.ServiceClientOptions"
: coreHttpCompatMode
? "coreHttpCompat.ExtendedServiceClientOptions"
: "coreClient.ServiceClientOptions"
? "coreHttpCompat.ExtendedServiceClientOptions"
: "coreClient.ServiceClientOptions"
}
);
};
Expand Down Expand Up @@ -404,11 +404,11 @@ function buildResponseType(
docs: ["The underlying HTTP response."],
type: innerResponseProperties.length
? Writers.intersectionType(
"coreHttp.HttpResponse",
Writers.objectType({
properties: innerResponseProperties
})
)
"coreHttp.HttpResponse",
Writers.objectType({
properties: innerResponseProperties
})
)
: "coreHttp.HttpResponse",
leadingTrivia: writer => writer.blankLine()
}
Expand Down Expand Up @@ -448,13 +448,13 @@ function buildResponseType(
if (!useCoreV2) {
return intersectionTypes.length > 1
? // Using apply instead of calling the method directly to be able to conditionally pass
// parameters, this way we don't have to have a nested if/else tree to decide which parameters
// to pass, we will pass any intersectionTypes availabe plus the innerType. When there are no intersection types
// we just return innerType
Writers.intersectionType.apply(
Writers,
intersectionTypes as IntersectionTypeParameters
)
// parameters, this way we don't have to have a nested if/else tree to decide which parameters
// to pass, we will pass any intersectionTypes availabe plus the innerType. When there are no intersection types
// we just return innerType
Writers.intersectionType.apply(
Writers,
intersectionTypes as IntersectionTypeParameters
)
: (innerTypeWriter as WriterFunction);
} else {
if (intersectionTypes.length > 1) {
Expand Down Expand Up @@ -698,9 +698,9 @@ function writeOptionalParameters(
isExported: true,
extends: [
baseClass ||
(!useCoreV2
? "coreHttp.OperationOptions"
: "coreClient.OperationOptions")
(!useCoreV2
? "coreHttp.OperationOptions"
: "coreClient.OperationOptions")
],
properties: properties
};
Expand Down
20 changes: 10 additions & 10 deletions packages/autorest.typescript/src/generators/operationGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function generateOperations(
clientDetails: ClientDetails,
project: Project
): void {
const { srcPath, moduleKind } = getAutorestOptions();
const { srcPath, isTestPackage } = getAutorestOptions();
let fileNames: string[] = [];

// Toplevel operations are inlined in the client
Expand All @@ -89,7 +89,7 @@ export function generateOperations(
operationIndexFile.addExportDeclarations(
fileNames.map(fileName => {
return {
moduleSpecifier: getImportModuleName(`./${fileName}`, moduleKind)
moduleSpecifier: getImportModuleName(`./${fileName}`, isTestPackage)
} as ExportDeclarationStructure;
})
);
Expand Down Expand Up @@ -466,7 +466,7 @@ function addClass(
clientDetails: ClientDetails
) {
let importedModels = new Set<string>();
const { moduleKind } = getAutorestOptions();
const { isTestPackage } = getAutorestOptions();

let allModelsNames = getAllModelsNames(clientDetails);

Expand Down Expand Up @@ -528,7 +528,7 @@ function addClass(

operationGroupFile.addImportDeclaration({
namedImports,
moduleSpecifier: getImportModuleName({ cjsName: "../models", esModulesName: "../models/index.js" }, moduleKind)
moduleSpecifier: getImportModuleName({ cjsName: "../models", esModulesName: "../models/index.js" }, isTestPackage)
});
}
}
Expand Down Expand Up @@ -1237,7 +1237,7 @@ function addImports(
operationGroupFile: SourceFile,
clientDetails: ClientDetails
) {
const { useCoreV2, useLegacyLro, moduleKind } = getAutorestOptions();
const { useCoreV2, useLegacyLro, isTestPackage } = getAutorestOptions();

const { className, mappers } = clientDetails;
addPagingEsNextRef(operationGroupDetails.operations, operationGroupFile);
Expand All @@ -1252,7 +1252,7 @@ function addImports(

operationGroupFile.addImportDeclaration({
namedImports: [`${operationGroupInterfaceName}`],
moduleSpecifier: getImportModuleName({ cjsName: "../operationsInterfaces", esModulesName: "../operationsInterfaces/index.js" }, moduleKind)
moduleSpecifier: getImportModuleName({ cjsName: "../operationsInterfaces", esModulesName: "../operationsInterfaces/index.js" }, isTestPackage)
});

if (!useCoreV2) {
Expand Down Expand Up @@ -1282,14 +1282,14 @@ function addImports(
if (mappers.length) {
operationGroupFile.addImportDeclaration({
namespaceImport: "Mappers",
moduleSpecifier: getImportModuleName("../models/mappers", moduleKind)
moduleSpecifier: getImportModuleName("../models/mappers", isTestPackage)
});
}

if (shouldImportParameters(clientDetails)) {
operationGroupFile.addImportDeclaration({
namespaceImport: "Parameters",
moduleSpecifier: getImportModuleName("../models/parameters", moduleKind)
moduleSpecifier: getImportModuleName("../models/parameters", isTestPackage)
});
}

Expand All @@ -1299,7 +1299,7 @@ function addImports(

operationGroupFile.addImportDeclaration({
namedImports: [`${clientClassName}`],
moduleSpecifier: getImportModuleName(`../${clientFileName}`, moduleKind)
moduleSpecifier: getImportModuleName(`../${clientFileName}`, isTestPackage)
});

if (hasLroOperation(operationGroupDetails)) {
Expand All @@ -1309,7 +1309,7 @@ function addImports(
});
operationGroupFile.addImportDeclaration({
namedImports: ["createLroSpec"],
moduleSpecifier: getImportModuleName(`../lroImpl`, moduleKind)
moduleSpecifier: getImportModuleName(`../lroImpl`, isTestPackage)
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function generateOperationsInterfaces(
clientDetails: ClientDetails,
project: Project
): void {
const { srcPath, moduleKind } = getAutorestOptions();
const { srcPath, isTestPackage } = getAutorestOptions();
let fileNames: string[] = [];

// Toplevel operations are inlined in the client
Expand All @@ -68,7 +68,7 @@ export function generateOperationsInterfaces(
operationIndexFile.addExportDeclarations(
fileNames.map(fileName => {
return {
moduleSpecifier: getImportModuleName(`./${fileName}`, moduleKind)
moduleSpecifier: getImportModuleName(`./${fileName}`, isTestPackage)
} as ExportDeclarationStructure;
})
);
Expand Down Expand Up @@ -129,7 +129,7 @@ function addInterface(
operationGroupDetails: OperationGroupDetails,
clientDetails: ClientDetails
) {
const { moduleKind } = getAutorestOptions();
const { isTestPackage } = getAutorestOptions();

let importedModels = new Set<string>();

Expand Down Expand Up @@ -167,7 +167,7 @@ function addInterface(

operationGroupFile.addImportDeclaration({
namedImports,
moduleSpecifier: getImportModuleName({ cjsName: "../models", esModulesName: "../models/index.js" }, moduleKind)
moduleSpecifier: getImportModuleName({ cjsName: "../models", esModulesName: "../models/index.js" }, isTestPackage)
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function generateParameters(
clientDetails: ClientDetails,
project: Project
): void {
const { useCoreV2, srcPath, moduleKind } = getAutorestOptions();
const { useCoreV2, srcPath, isTestPackage } = getAutorestOptions();
if (!shouldImportParameters(clientDetails)) {
logger.verbose(
"There are no parameters to generate, skipping parameters file generation"
Expand All @@ -47,7 +47,7 @@ export function generateParameters(
if (importedMappers.length) {
parametersFile.addImportDeclaration({
namedImports: importedMappers,
moduleSpecifier: getImportModuleName("../models/mappers", moduleKind)
moduleSpecifier: getImportModuleName("../models/mappers", isTestPackage)
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Project } from "ts-morph";
import { getAutorestOptions } from "../../autorestSession";

export function generateApiExtractorConfig(project: Project) {
const { generateMetadata, packageDetails, generateTest, restLevelClient } = getAutorestOptions();
const { generateMetadata, packageDetails } = getAutorestOptions();

if (!generateMetadata) {
return;
Expand All @@ -14,7 +14,7 @@ export function generateApiExtractorConfig(project: Project) {
const config = {
$schema:
"https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
mainEntryPointFilePath: `${restLevelClient ? "./types" : "./dist-esm"}${generateTest ? "/src" : ""}/index.d.ts`,
mainEntryPointFilePath: `dist/esm/index.d.ts`,
docModel: {
enabled: true
},
Expand All @@ -25,7 +25,7 @@ export function generateApiExtractorConfig(project: Project) {
dtsRollup: {
enabled: true,
untrimmedFilePath: "",
publicTrimmedFilePath: `./types/${packageDetails.nameWithoutScope}.d.ts`
publicTrimmedFilePath: `dist/${packageDetails.nameWithoutScope}.d.ts`
},
messages: {
tsdocMessageReporting: {
Expand All @@ -44,7 +44,7 @@ export function generateApiExtractorConfig(project: Project) {
}
};

project.createSourceFile("api-extractor.json", JSON.stringify(config), {
project.createSourceFile("api-extractor.json", JSON.stringify(config, null, 2), {
overwrite: true
});
}
Loading
Loading