@azure-tools/rlc-common
Advanced tools
Comparing version 0.34.0 to 0.35.0-alpha.20241129.2
@@ -6,16 +6,16 @@ { | ||
"packages/rlc-common/.prettierrc": "83e03202b2f3ad5b8df166a965fea698eccb0f90", | ||
"packages/rlc-common/CHANGELOG.md": "bc1e3fe8556252f0e4fe67e8c24662efb32a9b46", | ||
"packages/rlc-common/CHANGELOG.md": "92cccc5a5884b721d026eb1ff554af1cf97b8278", | ||
"packages/rlc-common/CONTRIBUTING.md": "38ef379872af08f6935263aafac67abe9ce60a1c", | ||
"packages/rlc-common/README.md": "cf3a9e48211f34b1cda27882d2f3cf07078f001e", | ||
"packages/rlc-common/package.json": "910d7df13d7c9eb1b9876c3ebbb400d3a60074c5", | ||
"packages/rlc-common/package.json": "2342ac4519f46679521a955bb10c2af81db67412", | ||
"packages/rlc-common/publishPackage.js": "3512e26d1199937b1962f3b4189aa9c506d9da1a", | ||
"packages/rlc-common/src/buildClient.ts": "615d27248dc9d8828801bbdd8b902f0207fe5ffb", | ||
"packages/rlc-common/src/buildClientDefinitions.ts": "1ca2cfcf588dac8d081e70ab159a4b2d99db38a2", | ||
"packages/rlc-common/src/buildClientDefinitions.ts": "17f0db9433f7dc72035629227b41bd3e3e867e71", | ||
"packages/rlc-common/src/buildIndexFile.ts": "0e773cba366dba88e364ca4075e47a5950a8165e", | ||
"packages/rlc-common/src/buildIsUnexpectedHelper.ts": "b8f8a13829bed28787b904ec0647412d5d9a47db", | ||
"packages/rlc-common/src/buildLogger.ts": "b6041fb5b228240487d0f009dffd25a86cc00720", | ||
"packages/rlc-common/src/buildLogger.ts": "4451f97331561c9cbc438f20b72d91103f102edb", | ||
"packages/rlc-common/src/buildMethodShortcuts.ts": "833a2b2965d7b71d5a696b358498a9f9e68d83d1", | ||
"packages/rlc-common/src/buildObjectTypes.ts": "474359c964646dfd7a8a3fef5ff9b10efc11dbc8", | ||
"packages/rlc-common/src/buildObjectTypes.ts": "bdfc591b1a3b20d9d8138611acc7666688c1839f", | ||
"packages/rlc-common/src/buildPaginateHelper.ts": "c40461534e7072349be81f90f5f78f9ece813d53", | ||
"packages/rlc-common/src/buildParameterTypes.ts": "09048ac406388b84b5d455fe9a790ecc54c7afb7", | ||
"packages/rlc-common/src/buildParameterTypes.ts": "8f07031639f12e1db788fd03f70f0e7dc95cde37", | ||
"packages/rlc-common/src/buildPollingHelper.ts": "137a2c641eb55fbfbc07f3fd05390f0fed691ea0", | ||
@@ -31,3 +31,3 @@ "packages/rlc-common/src/buildResponseTypes.ts": "7912239ce72c72edeb91838f49bcc2d553916e84", | ||
"packages/rlc-common/src/helpers/nameUtils.ts": "9a02df4ee1b3ec8c706a9010d6ecf397e9f88b8d", | ||
"packages/rlc-common/src/helpers/operationHelpers.ts": "3de0af2e566063c2c779b330138b7a02367d7e70", | ||
"packages/rlc-common/src/helpers/operationHelpers.ts": "06955b38b80b25a70f8055566e3260810af13c9f", | ||
"packages/rlc-common/src/helpers/packageUtil.ts": "1a922f02d2838b8cbbf007d6ee43ed13bd0fd620", | ||
@@ -40,3 +40,3 @@ "packages/rlc-common/src/helpers/pathUtils.ts": "d23effe48effd2e20631c76e097cd42452d0f7d3", | ||
"packages/rlc-common/src/index.ts": "8deff693b281b7f4f65acd7f6d1c4e8c08af7280", | ||
"packages/rlc-common/src/interfaces.ts": "e786765fd6e2256e19c185e011c2a78de70d1769", | ||
"packages/rlc-common/src/interfaces.ts": "374b5b93c0aff644035ceae68f1bf6e7c0cd7e39", | ||
"packages/rlc-common/src/metadata/buildApiExtractorConfig.ts": "9ac5dcfce2d31111812967e59b1f2d8fbd58f471", | ||
@@ -47,3 +47,3 @@ "packages/rlc-common/src/metadata/buildBrowserConfig.ts": "8aa97a77a03d3f3503c1959812600ab86080c75d", | ||
"packages/rlc-common/src/metadata/buildPackageFile.ts": "1409fcde8699eecb056e274d1e548ea9c4263a96", | ||
"packages/rlc-common/src/metadata/buildReadmeFile.ts": "cf1256665e32a9feabad2fb1de7eaf3d1dbc0a1c", | ||
"packages/rlc-common/src/metadata/buildReadmeFile.ts": "b198861826ff12427396efc800232dcf66575d8e", | ||
"packages/rlc-common/src/metadata/buildRollupConfig.ts": "6d05e8cdab182f7529b725cdc70d7adfdeb108f1", | ||
@@ -53,7 +53,7 @@ "packages/rlc-common/src/metadata/buildSampleEnvFile.ts": "e55ac377ede580e7a708d9f780d793e3e7ee8bbf", | ||
"packages/rlc-common/src/metadata/buildVitestConfig.ts": "711bd015fc1c581740c2de74e7dace8f8b622840", | ||
"packages/rlc-common/src/metadata/packageJson/azurePackageCommon.ts": "fdf6b49b62d132cd5a035ce20d6e4658a89e2b3f", | ||
"packages/rlc-common/src/metadata/packageJson/buildAzureMonorepoPackage.ts": "479c7e8c71bb3545a14060dbcaa70bb474e48aca", | ||
"packages/rlc-common/src/metadata/packageJson/buildAzureStandalonePackage.ts": "19d7c8e41c501acab7646e5c72183e6c8b90410f", | ||
"packages/rlc-common/src/metadata/packageJson/buildFlavorlessPackage.ts": "726153eebb7740df266b4eaf8ebe7ba20ea0c8a0", | ||
"packages/rlc-common/src/metadata/packageJson/packageCommon.ts": "51f58fc383650c76b94bbde68b79396612920958", | ||
"packages/rlc-common/src/metadata/packageJson/azurePackageCommon.ts": "3b95e0296c5ca953b4c825dabe5988b4c32717a3", | ||
"packages/rlc-common/src/metadata/packageJson/buildAzureMonorepoPackage.ts": "36e3786d6b54fc127715ee757bc0099622a1c8de", | ||
"packages/rlc-common/src/metadata/packageJson/buildAzureStandalonePackage.ts": "1e1e51d7a91e6c170dbaaa03e8c63742b0562584", | ||
"packages/rlc-common/src/metadata/packageJson/buildFlavorlessPackage.ts": "161e62c0655344bc5149f1267e825270553eb897", | ||
"packages/rlc-common/src/metadata/packageJson/packageCommon.ts": "561ad79ae6320186781c67e2f44fbcd94cdde720", | ||
"packages/rlc-common/src/static/paginateContent.ts": "7662e30b3d45a8c812a20ea9e56bd57846b50ddc", | ||
@@ -72,3 +72,3 @@ "packages/rlc-common/src/static/pollingContent.ts": "e258455ebf140e9e11bf567771ac373de9ec8f76", | ||
"packages/rlc-common/test/integration/mockHelper.ts": "a15f0920c58066a9d90792ac85b2027f4cdea491", | ||
"packages/rlc-common/test/integration/packageJson.spec.ts": "7270ac340493c441daccc82b3bd7d326eebbab66", | ||
"packages/rlc-common/test/integration/packageJson.spec.ts": "5b7f2788e8e99bb00d5e32632f99ec46c0036985", | ||
"packages/rlc-common/test/integration/static/package.json": "09d24ae57d9e1d9ff74e057c0caa90a22ffe147a", | ||
@@ -75,0 +75,0 @@ "packages/rlc-common/test/integration/vitestConfig.spec.ts": "ec157c5cdbcd50f8e3864c069c9447ab85034e1e", |
@@ -0,1 +1,15 @@ | ||
## 0.35.0 (2024-11-29) | ||
- [Feature] Upgrade eslint version to ^9.9.0. Please refer to [#2928](https://github.com/Azure/autorest.typescript/pull/2928) | ||
- [Feature] Upgrade compiler to v0.62.x and tcgc in Nov. Please refer to [#2892](https://github.com/Azure/autorest.typescript/pull/2892) | ||
- [Feature] Update azureSdkForJs default value when flavor !== azure. Please refer to [#2921](https://github.com/Azure/autorest.typescript/pull/2921) | ||
- [Feature] Remove uglify-js dep generation for autorest.typescript. Please refer to [#2920](https://github.com/Azure/autorest.typescript/pull/2920) | ||
- [Feature] Check no-emit flag. Please refer to [#2908](https://github.com/Azure/autorest.typescript/pull/2908) | ||
- [Feature] URI template support in RLC. Please refer to [#2814](https://github.com/Azure/autorest.typescript/pull/2814) | ||
- [Feature] Uprade cadl ranch version to v0.16.1. Please refer to [#2907](https://github.com/Azure/autorest.typescript/pull/2907) | ||
- [Feature] Move to use dev-tool vendored version of cross-env and uglify-js for JS repository. Please refer to [#2895](https://github.com/Azure/autorest.typescript/pull/2895) | ||
- [Bugfix] Fix tsp rlc logger.ts generation. Please refer to [#2904](https://github.com/Azure/autorest.typescript/pull/2904) | ||
- [Bugfix] Fix unix timestamps. Please refer to [#2135](https://github.com/Azure/autorest.typescript/pull/2135) | ||
- [Bugfix] Fix readme issues and duplicated licence lines issue. Please refer to [#2922](https://github.com/Azure/autorest.typescript/pull/2922) | ||
## 0.34.0 (2024-11-11) | ||
@@ -2,0 +16,0 @@ |
@@ -5,3 +5,3 @@ // Copyright (c) Microsoft Corporation. | ||
import * as path from "path"; | ||
import { buildMethodDefinitions, getPathParamDefinitions } from "./helpers/operationHelpers.js"; | ||
import { buildMethodDefinitions, getGeneratedWrapperTypes, getPathParamDefinitions } from "./helpers/operationHelpers.js"; | ||
import { generateMethodShortcuts } from "./helpers/shortcutMethods.js"; | ||
@@ -104,2 +104,3 @@ import { REST_CLIENT_RESERVED } from "./buildMethodShortcuts.js"; | ||
const pathParams = paths[key].pathParameters; | ||
getGeneratedWrapperTypes(pathParams).forEach((p) => options.importedParameters.add(p.name ?? p.type)); | ||
signatures.push({ | ||
@@ -106,0 +107,0 @@ docs: [ |
@@ -14,7 +14,9 @@ // Copyright (c) Microsoft Corporation. | ||
const project = new Project(); | ||
const { srcPath } = model; | ||
const { srcPath, rlcSourceDir } = model; | ||
const { packageDetails } = model.options; | ||
const filePath = path.join(srcPath.substring(0, srcPath.includes("generated") && !srcPath.includes("src") | ||
? srcPath.lastIndexOf("generated") + 10 | ||
: srcPath.lastIndexOf("src") + 4), `logger.ts`); | ||
const filePath = path.join(model.options.sourceFrom == "Swagger" | ||
? srcPath.substring(0, srcPath.includes("generated") && !srcPath.includes("src") | ||
? srcPath.lastIndexOf("generated") + 10 | ||
: srcPath.lastIndexOf("src") + 4) | ||
: rlcSourceDir, `logger.ts`); | ||
const loggerFile = project.createSourceFile("logger.ts", undefined, { | ||
@@ -21,0 +23,0 @@ overwrite: true |
@@ -167,3 +167,3 @@ // Copyright (c) Microsoft Corporation. | ||
*/ | ||
function getObjectInterfaceDeclaration(model, baseName, objectSchema, schemaUsage, importedModels) { | ||
export function getObjectInterfaceDeclaration(model, baseName, objectSchema, schemaUsage, importedModels) { | ||
let interfaceName = `${baseName}`; | ||
@@ -170,0 +170,0 @@ if (isPolymorphicParent(objectSchema)) { |
@@ -5,4 +5,7 @@ // Copyright (c) Microsoft Corporation. | ||
import * as path from "path"; | ||
import { SchemaContext } from "./interfaces.js"; | ||
import { getImportModuleName, getParameterBaseName, getParameterTypeName } from "./helpers/nameConstructors.js"; | ||
import { getImportSpecifier } from "./helpers/importsUtil.js"; | ||
import { getObjectInterfaceDeclaration } from "./buildObjectTypes.js"; | ||
import { getGeneratedWrapperTypes } from "./helpers/operationHelpers.js"; | ||
export function buildParameterTypes(model) { | ||
@@ -36,4 +39,4 @@ const project = new Project(); | ||
: topParamName; | ||
const queryParameterDefinitions = buildQueryParameterDefinition(parameter, baseParameterName, internalReferences, i); | ||
const pathParameterDefinitions = buildPathParameterDefinitions(parameter, baseParameterName, parametersFile, internalReferences, i); | ||
const queryParameterDefinitions = buildQueryParameterDefinition(model, parameter, baseParameterName, internalReferences, i); | ||
const pathParameterDefinitions = buildPathParameterDefinitions(model, parameter, baseParameterName, parametersFile, internalReferences, i); | ||
const headerParameterDefinitions = buildHeaderParameterDefinitions(parameter, baseParameterName, parametersFile, internalReferences, i); | ||
@@ -50,3 +53,3 @@ const contentTypeParameterDefinition = buildContentTypeParametersDefinition(parameter, baseParameterName, internalReferences, i); | ||
...(queryParameterDefinitions ?? []), | ||
...(pathParameterDefinitions ? [pathParameterDefinitions] : []), | ||
...(pathParameterDefinitions ?? []), | ||
...(headerParameterDefinitions ? [headerParameterDefinitions] : []), | ||
@@ -106,3 +109,3 @@ ...(contentTypeParameterDefinition | ||
} | ||
function buildQueryParameterDefinition(parameters, baseName, internalReferences, requestIndex) { | ||
function buildQueryParameterDefinition(model, parameters, baseName, internalReferences, requestIndex) { | ||
const queryParameters = (parameters?.parameters || []).filter((p) => p.type === "query"); | ||
@@ -117,2 +120,6 @@ if (!queryParameters.length) { | ||
const propertiesDefinition = queryParameters.map((qp) => getPropertyFromSchema(qp.param)); | ||
// Get wrapper types for query parameters | ||
const wrapperTypesDefinition = getGeneratedWrapperTypes(queryParameters).map((wrapObj) => { | ||
return getObjectInterfaceDeclaration(model, wrapObj.name, wrapObj, [SchemaContext.Input], new Set()); | ||
}); | ||
const hasRequiredParameters = propertiesDefinition.some((p) => !p.hasQuestionToken); | ||
@@ -140,3 +147,3 @@ const propertiesInterface = { | ||
internalReferences.add(queryParameterInterfaceName); | ||
return [propertiesInterface, parameterInterface]; | ||
return [...wrapperTypesDefinition, propertiesInterface, parameterInterface]; | ||
} | ||
@@ -153,3 +160,3 @@ function getPropertyFromSchema(schema) { | ||
} | ||
function buildPathParameterDefinitions(parameters, baseName, parametersFile, internalReferences, requestIndex) { | ||
function buildPathParameterDefinitions(model, parameters, baseName, parametersFile, internalReferences, requestIndex) { | ||
const pathParameters = (parameters.parameters || []).filter((p) => p.type === "path"); | ||
@@ -159,21 +166,44 @@ if (!pathParameters.length) { | ||
} | ||
const nameSuffix = requestIndex > 0 ? `${requestIndex}` : ""; | ||
const pathParameterInterfaceName = `${baseName}PathParam${nameSuffix}`; | ||
const pathInterface = getPathInterfaceDefinition(pathParameters, baseName); | ||
if (pathInterface) { | ||
parametersFile.addInterface(pathInterface); | ||
const allDefinitions = []; | ||
buildClientPathParameters(); | ||
buildMethodWrapParameters(); | ||
return allDefinitions; | ||
function buildClientPathParameters() { | ||
// we only have client-level path parameters if the source is from swagger | ||
if (model.options?.sourceFrom === "TypeSpec") { | ||
return; | ||
} | ||
const clientPathParams = pathParameters.length > 0 ? pathParameters : []; | ||
const nameSuffix = requestIndex > 0 ? `${requestIndex}` : ""; | ||
const pathParameterInterfaceName = `${baseName}PathParam${nameSuffix}`; | ||
const pathInterface = getPathInterfaceDefinition(clientPathParams, baseName); | ||
if (pathInterface) { | ||
parametersFile.addInterface(pathInterface); | ||
} | ||
internalReferences.add(pathParameterInterfaceName); | ||
allDefinitions.push({ | ||
isExported: true, | ||
kind: StructureKind.Interface, | ||
name: pathParameterInterfaceName, | ||
properties: [ | ||
{ | ||
name: "pathParameters", | ||
type: `${baseName}PathParameters`, | ||
kind: StructureKind.PropertySignature | ||
} | ||
] | ||
}); | ||
} | ||
internalReferences.add(pathParameterInterfaceName); | ||
return { | ||
isExported: true, | ||
kind: StructureKind.Interface, | ||
name: pathParameterInterfaceName, | ||
properties: [ | ||
{ | ||
name: "pathParameters", | ||
type: `${baseName}PathParameters`, | ||
kind: StructureKind.PropertySignature | ||
} | ||
] | ||
}; | ||
function buildMethodWrapParameters() { | ||
if (model.options?.sourceFrom === "Swagger") { | ||
return; | ||
} | ||
// we only have method-level path parameters if the source is from typespec | ||
const methodPathParams = pathParameters.length > 0 ? pathParameters : []; | ||
// we only need to build the wrapper types if the path parameters are objects | ||
const wrapperTypesDefinition = getGeneratedWrapperTypes(methodPathParams).map((wrap) => { | ||
return getObjectInterfaceDeclaration(model, wrap.name, wrap, [SchemaContext.Input], new Set()); | ||
}); | ||
allDefinitions.push(...wrapperTypesDefinition); | ||
} | ||
} | ||
@@ -180,0 +210,0 @@ function getPathInterfaceDefinition(pathParameters, baseName) { |
@@ -87,2 +87,16 @@ // Copyright (c) Microsoft Corporation. | ||
} | ||
export function getGeneratedWrapperTypes(params) { | ||
const wrapperTypes = params | ||
.map((qp) => isParameterMetadata(qp) ? qp.param.wrapperType : qp.wrapperType) | ||
.filter((v) => v !== undefined); | ||
const wrapperFromObjects = wrapperTypes.filter((wrap) => wrap.type === "object"); | ||
const wrapperFromUnions = wrapperTypes | ||
.filter((wrap) => wrap.type === "union") | ||
.flatMap((wrapperType) => wrapperType?.enum ?? []) | ||
.filter((v) => v.type === "object"); | ||
return [...wrapperFromUnions, ...wrapperFromObjects]; | ||
} | ||
function isParameterMetadata(param) { | ||
return param.param !== undefined; | ||
} | ||
//# sourceMappingURL=operationHelpers.js.map |
@@ -68,5 +68,2 @@ // Copyright (c) Microsoft Corporation. | ||
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: | ||
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET | ||
## Troubleshooting | ||
@@ -148,3 +145,2 @@ | ||
You will also need to **register a new AAD application and grant access to {{ serviceName}}** by assigning the suitable role to your service principal (note: roles such as \`"Owner"\` will not grant the necessary permissions). | ||
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: \`AZURE_CLIENT_ID\`, \`AZURE_TENANT_ID\`, \`AZURE_CLIENT_SECRET\`. | ||
@@ -151,0 +147,0 @@ For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). |
@@ -71,3 +71,2 @@ // Copyright (c) Microsoft Corporation. | ||
"@types/mocha": "^10.0.0", | ||
"cross-env": "^7.0.2", | ||
"@types/chai": "^4.2.8", | ||
@@ -78,3 +77,3 @@ chai: "^4.2.0", | ||
"karma-env-preprocessor": "^0.1.1", | ||
"karma-firefox-launcher": "^2.1.2", | ||
"karma-firefox-launcher": "^2.1.3", | ||
"karma-junit-reporter": "^2.0.1", | ||
@@ -81,0 +80,0 @@ "karma-mocha-reporter": "^2.2.5", |
@@ -23,2 +23,4 @@ // Copyright (c) Microsoft Corporation. | ||
const cjsDevDependencies = getCjsDevDependencies(config); | ||
const azurePackageDevDependencies = getAzurePackageDevDependencies(config); | ||
delete azurePackageDevDependencies["tshy"]; | ||
return { | ||
@@ -29,3 +31,3 @@ dependencies: { | ||
devDependencies: { | ||
...getAzurePackageDevDependencies(config), | ||
...azurePackageDevDependencies, | ||
"@azure/dev-tool": "^1.0.0", | ||
@@ -100,3 +102,2 @@ "@azure/eslint-plugin-azure-sdk": "^3.0.0", | ||
"@types/mocha": "^10.0.0", | ||
"cross-env": "^7.0.2", | ||
"@types/chai": "^4.2.8", | ||
@@ -107,3 +108,3 @@ chai: "^4.2.0", | ||
"karma-env-preprocessor": "^0.1.1", | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-firefox-launcher": "^2.1.3", | ||
"karma-junit-reporter": "^2.0.1", | ||
@@ -178,3 +179,3 @@ "karma-mocha-reporter": "^2.2.5", | ||
build: "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run vendored mkdirp ./review && dev-tool run extract-api", | ||
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", | ||
"build:node": "tsc -p . && dev-tool run vendored cross-env ONLY_NODE=true rollup -c 2>&1", | ||
"build:test": "tsc -p . && dev-tool run bundle", | ||
@@ -181,0 +182,0 @@ "build:debug": "tsc -p . && dev-tool run bundle && dev-tool run extract-api", |
@@ -30,2 +30,3 @@ // Copyright (c) Microsoft Corporation. | ||
...getStandaloneDevDependencies(config), | ||
"@microsoft/api-extractor": "^7.40.3", | ||
rimraf: "^5.0.5", | ||
@@ -51,2 +52,4 @@ mkdirp: "^3.0.1" | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
...(config.moduleKind === "cjs" && | ||
config.withTests && { "cross-env": "^7.0.2" }), | ||
rollup: "^2.66.1", | ||
@@ -53,0 +56,0 @@ "rollup-plugin-sourcemaps": "^0.6.3", |
@@ -13,2 +13,3 @@ // Copyright (c) Microsoft Corporation. | ||
...getCommonPackageDevDependencies(config), | ||
"@microsoft/api-extractor": "^7.40.3", | ||
rimraf: "^5.0.5", | ||
@@ -15,0 +16,0 @@ mkdirp: "^3.0.1" |
@@ -27,3 +27,3 @@ // Copyright (c) Microsoft Corporation. | ||
"@types/node": "^18.0.0", | ||
eslint: "^8.55.0", | ||
eslint: "^9.9.0", | ||
typescript: "~5.6.2", | ||
@@ -30,0 +30,0 @@ ...getEsmDevDependencies(config) |
@@ -1,1 +0,1 @@ | ||
{"name":"@azure-tools/rlc-common","version":"0.34.0","description":"","type":"module","main":"dist/index.js","module":"dist-esm/index.js","exports":{".":{"types":"./types/index.d.ts","require":"./dist/index.js","import":"./dist-esm/index.js"}},"types":"./types/index.d.ts","scripts":{"lint":"eslint src --ext .ts --max-warnings=0","lint:fix":"eslint src --fix --ext .ts","format":"npm run -s prettier -- --write","check-format":"npm run prettier -- --check","prettier":"prettier --config ./.prettierrc \"src/**/*.ts\"","build":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js","build:cjs":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js","build:esm":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js","test":"npm run unit-test","unit-test":"cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --loader=ts-node/esm --experimental-specifier-resolution=node test/**/*.spec.ts"},"keywords":[],"author":"","license":"ISC","dependencies":{"ts-morph":"^23.0.0","lodash":"^4.17.21","handlebars":"^4.7.7"},"devDependencies":{"@types/node":"^18.0.0","eslint":"^8.9.0","prettier":"^3.1.0","typescript":"~5.6.2","rimraf":"^5.0.0","@types/lodash":"^4.14.182","fs-extra":"^10.0.0","@types/fs-extra":"^8.1.0","ts-node":"^10.7.0","mocha":"^10.2.0","chai":"^4.3.7","@types/chai":"^4.3.4","@types/mocha":"^10.0.1","@typescript-eslint/eslint-plugin":"^6.8.0","@typescript-eslint/parser":"^6.8.0","eslint-plugin-require-extensions":"0.1.3","cross-env":"7.0.3"},"bugs":{"url":"https://github.com/Azure/autorest.typescript/issues"},"homepage":"https://github.com/Azure/autorest.typescript/tree/main/packages/rlc-common/"} | ||
{"name":"@azure-tools/rlc-common","version":"0.35.0","description":"","type":"module","main":"dist/index.js","module":"dist-esm/index.js","exports":{".":{"types":"./types/index.d.ts","require":"./dist/index.js","import":"./dist-esm/index.js"}},"types":"./types/index.d.ts","scripts":{"lint":"eslint src --ext .ts --max-warnings=0","lint:fix":"eslint src --fix --ext .ts","format":"npm run -s prettier -- --write","check-format":"npm run prettier -- --check","prettier":"prettier --config ./.prettierrc \"src/**/*.ts\"","build":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js","build:cjs":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js","build:esm":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js","test":"npm run unit-test","unit-test":"cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --loader=ts-node/esm --experimental-specifier-resolution=node test/**/*.spec.ts"},"keywords":[],"author":"","license":"ISC","dependencies":{"ts-morph":"^23.0.0","lodash":"^4.17.21","handlebars":"^4.7.7"},"devDependencies":{"@types/node":"^18.0.0","eslint":"^8.9.0","prettier":"^3.1.0","typescript":"~5.6.2","rimraf":"^5.0.0","@types/lodash":"^4.14.182","fs-extra":"^10.0.0","@types/fs-extra":"^8.1.0","ts-node":"^10.7.0","mocha":"^10.2.0","chai":"^4.3.7","@types/chai":"^4.3.4","@types/mocha":"^10.0.1","@typescript-eslint/eslint-plugin":"^6.8.0","@typescript-eslint/parser":"^6.8.0","eslint-plugin-require-extensions":"0.1.3","cross-env":"7.0.3"},"bugs":{"url":"https://github.com/Azure/autorest.typescript/issues"},"homepage":"https://github.com/Azure/autorest.typescript/tree/main/packages/rlc-common/"} |
@@ -106,2 +106,3 @@ "use strict"; | ||
const pathParams = paths[key].pathParameters; | ||
(0, operationHelpers_js_1.getGeneratedWrapperTypes)(pathParams).forEach((p) => { var _a; return options.importedParameters.add((_a = p.name) !== null && _a !== void 0 ? _a : p.type); }); | ||
signatures.push({ | ||
@@ -108,0 +109,0 @@ docs: [ |
@@ -18,7 +18,9 @@ "use strict"; | ||
const project = new ts_morph_1.Project(); | ||
const { srcPath } = model; | ||
const { srcPath, rlcSourceDir } = model; | ||
const { packageDetails } = model.options; | ||
const filePath = path.join(srcPath.substring(0, srcPath.includes("generated") && !srcPath.includes("src") | ||
? srcPath.lastIndexOf("generated") + 10 | ||
: srcPath.lastIndexOf("src") + 4), `logger.ts`); | ||
const filePath = path.join(model.options.sourceFrom == "Swagger" | ||
? srcPath.substring(0, srcPath.includes("generated") && !srcPath.includes("src") | ||
? srcPath.lastIndexOf("generated") + 10 | ||
: srcPath.lastIndexOf("src") + 4) | ||
: rlcSourceDir, `logger.ts`); | ||
const loggerFile = project.createSourceFile("logger.ts", undefined, { | ||
@@ -25,0 +27,0 @@ overwrite: true |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.buildPolymorphicAliases = buildPolymorphicAliases; | ||
exports.getObjectInterfaceDeclaration = getObjectInterfaceDeclaration; | ||
exports.getImmediateParentsNames = getImmediateParentsNames; | ||
@@ -10,0 +11,0 @@ exports.getPropertySignature = getPropertySignature; |
@@ -9,4 +9,7 @@ "use strict"; | ||
const path = require("path"); | ||
const interfaces_js_1 = require("./interfaces.js"); | ||
const nameConstructors_js_1 = require("./helpers/nameConstructors.js"); | ||
const importsUtil_js_1 = require("./helpers/importsUtil.js"); | ||
const buildObjectTypes_js_1 = require("./buildObjectTypes.js"); | ||
const operationHelpers_js_1 = require("./helpers/operationHelpers.js"); | ||
function buildParameterTypes(model) { | ||
@@ -41,4 +44,4 @@ var _a, _b, _c, _d, _e, _f; | ||
: topParamName; | ||
const queryParameterDefinitions = buildQueryParameterDefinition(parameter, baseParameterName, internalReferences, i); | ||
const pathParameterDefinitions = buildPathParameterDefinitions(parameter, baseParameterName, parametersFile, internalReferences, i); | ||
const queryParameterDefinitions = buildQueryParameterDefinition(model, parameter, baseParameterName, internalReferences, i); | ||
const pathParameterDefinitions = buildPathParameterDefinitions(model, parameter, baseParameterName, parametersFile, internalReferences, i); | ||
const headerParameterDefinitions = buildHeaderParameterDefinitions(parameter, baseParameterName, parametersFile, internalReferences, i); | ||
@@ -55,3 +58,3 @@ const contentTypeParameterDefinition = buildContentTypeParametersDefinition(parameter, baseParameterName, internalReferences, i); | ||
...(queryParameterDefinitions !== null && queryParameterDefinitions !== void 0 ? queryParameterDefinitions : []), | ||
...(pathParameterDefinitions ? [pathParameterDefinitions] : []), | ||
...(pathParameterDefinitions !== null && pathParameterDefinitions !== void 0 ? pathParameterDefinitions : []), | ||
...(headerParameterDefinitions ? [headerParameterDefinitions] : []), | ||
@@ -111,3 +114,3 @@ ...(contentTypeParameterDefinition | ||
} | ||
function buildQueryParameterDefinition(parameters, baseName, internalReferences, requestIndex) { | ||
function buildQueryParameterDefinition(model, parameters, baseName, internalReferences, requestIndex) { | ||
const queryParameters = ((parameters === null || parameters === void 0 ? void 0 : parameters.parameters) || []).filter((p) => p.type === "query"); | ||
@@ -122,2 +125,6 @@ if (!queryParameters.length) { | ||
const propertiesDefinition = queryParameters.map((qp) => getPropertyFromSchema(qp.param)); | ||
// Get wrapper types for query parameters | ||
const wrapperTypesDefinition = (0, operationHelpers_js_1.getGeneratedWrapperTypes)(queryParameters).map((wrapObj) => { | ||
return (0, buildObjectTypes_js_1.getObjectInterfaceDeclaration)(model, wrapObj.name, wrapObj, [interfaces_js_1.SchemaContext.Input], new Set()); | ||
}); | ||
const hasRequiredParameters = propertiesDefinition.some((p) => !p.hasQuestionToken); | ||
@@ -145,3 +152,3 @@ const propertiesInterface = { | ||
internalReferences.add(queryParameterInterfaceName); | ||
return [propertiesInterface, parameterInterface]; | ||
return [...wrapperTypesDefinition, propertiesInterface, parameterInterface]; | ||
} | ||
@@ -158,3 +165,3 @@ function getPropertyFromSchema(schema) { | ||
} | ||
function buildPathParameterDefinitions(parameters, baseName, parametersFile, internalReferences, requestIndex) { | ||
function buildPathParameterDefinitions(model, parameters, baseName, parametersFile, internalReferences, requestIndex) { | ||
const pathParameters = (parameters.parameters || []).filter((p) => p.type === "path"); | ||
@@ -164,21 +171,46 @@ if (!pathParameters.length) { | ||
} | ||
const nameSuffix = requestIndex > 0 ? `${requestIndex}` : ""; | ||
const pathParameterInterfaceName = `${baseName}PathParam${nameSuffix}`; | ||
const pathInterface = getPathInterfaceDefinition(pathParameters, baseName); | ||
if (pathInterface) { | ||
parametersFile.addInterface(pathInterface); | ||
const allDefinitions = []; | ||
buildClientPathParameters(); | ||
buildMethodWrapParameters(); | ||
return allDefinitions; | ||
function buildClientPathParameters() { | ||
var _a; | ||
// we only have client-level path parameters if the source is from swagger | ||
if (((_a = model.options) === null || _a === void 0 ? void 0 : _a.sourceFrom) === "TypeSpec") { | ||
return; | ||
} | ||
const clientPathParams = pathParameters.length > 0 ? pathParameters : []; | ||
const nameSuffix = requestIndex > 0 ? `${requestIndex}` : ""; | ||
const pathParameterInterfaceName = `${baseName}PathParam${nameSuffix}`; | ||
const pathInterface = getPathInterfaceDefinition(clientPathParams, baseName); | ||
if (pathInterface) { | ||
parametersFile.addInterface(pathInterface); | ||
} | ||
internalReferences.add(pathParameterInterfaceName); | ||
allDefinitions.push({ | ||
isExported: true, | ||
kind: ts_morph_1.StructureKind.Interface, | ||
name: pathParameterInterfaceName, | ||
properties: [ | ||
{ | ||
name: "pathParameters", | ||
type: `${baseName}PathParameters`, | ||
kind: ts_morph_1.StructureKind.PropertySignature | ||
} | ||
] | ||
}); | ||
} | ||
internalReferences.add(pathParameterInterfaceName); | ||
return { | ||
isExported: true, | ||
kind: ts_morph_1.StructureKind.Interface, | ||
name: pathParameterInterfaceName, | ||
properties: [ | ||
{ | ||
name: "pathParameters", | ||
type: `${baseName}PathParameters`, | ||
kind: ts_morph_1.StructureKind.PropertySignature | ||
} | ||
] | ||
}; | ||
function buildMethodWrapParameters() { | ||
var _a; | ||
if (((_a = model.options) === null || _a === void 0 ? void 0 : _a.sourceFrom) === "Swagger") { | ||
return; | ||
} | ||
// we only have method-level path parameters if the source is from typespec | ||
const methodPathParams = pathParameters.length > 0 ? pathParameters : []; | ||
// we only need to build the wrapper types if the path parameters are objects | ||
const wrapperTypesDefinition = (0, operationHelpers_js_1.getGeneratedWrapperTypes)(methodPathParams).map((wrap) => { | ||
return (0, buildObjectTypes_js_1.getObjectInterfaceDeclaration)(model, wrap.name, wrap, [interfaces_js_1.SchemaContext.Input], new Set()); | ||
}); | ||
allDefinitions.push(...wrapperTypesDefinition); | ||
} | ||
} | ||
@@ -185,0 +217,0 @@ function getPathInterfaceDefinition(pathParameters, baseName) { |
@@ -17,2 +17,3 @@ "use strict"; | ||
exports.hasOutputModels = hasOutputModels; | ||
exports.getGeneratedWrapperTypes = getGeneratedWrapperTypes; | ||
const interfaces_js_1 = require("../interfaces.js"); | ||
@@ -113,2 +114,16 @@ const nameUtils_js_1 = require("./nameUtils.js"); | ||
} | ||
function getGeneratedWrapperTypes(params) { | ||
const wrapperTypes = params | ||
.map((qp) => isParameterMetadata(qp) ? qp.param.wrapperType : qp.wrapperType) | ||
.filter((v) => v !== undefined); | ||
const wrapperFromObjects = wrapperTypes.filter((wrap) => wrap.type === "object"); | ||
const wrapperFromUnions = wrapperTypes | ||
.filter((wrap) => wrap.type === "union") | ||
.flatMap((wrapperType) => { var _a; return (_a = wrapperType === null || wrapperType === void 0 ? void 0 : wrapperType.enum) !== null && _a !== void 0 ? _a : []; }) | ||
.filter((v) => v.type === "object"); | ||
return [...wrapperFromUnions, ...wrapperFromObjects]; | ||
} | ||
function isParameterMetadata(param) { | ||
return param.param !== undefined; | ||
} | ||
//# sourceMappingURL=operationHelpers.js.map |
@@ -71,5 +71,2 @@ "use strict"; | ||
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: | ||
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET | ||
## Troubleshooting | ||
@@ -151,3 +148,2 @@ | ||
You will also need to **register a new AAD application and grant access to {{ serviceName}}** by assigning the suitable role to your service principal (note: roles such as \`"Owner"\` will not grant the necessary permissions). | ||
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: \`AZURE_CLIENT_ID\`, \`AZURE_TENANT_ID\`, \`AZURE_CLIENT_SECRET\`. | ||
@@ -154,0 +150,0 @@ For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). |
@@ -76,3 +76,2 @@ "use strict"; | ||
"@types/mocha": "^10.0.0", | ||
"cross-env": "^7.0.2", | ||
"@types/chai": "^4.2.8", | ||
@@ -83,3 +82,3 @@ chai: "^4.2.0", | ||
"karma-env-preprocessor": "^0.1.1", | ||
"karma-firefox-launcher": "^2.1.2", | ||
"karma-firefox-launcher": "^2.1.3", | ||
"karma-junit-reporter": "^2.0.1", | ||
@@ -86,0 +85,0 @@ "karma-mocha-reporter": "^2.2.5", |
@@ -28,2 +28,4 @@ "use strict"; | ||
const cjsDevDependencies = getCjsDevDependencies(config); | ||
const azurePackageDevDependencies = (0, azurePackageCommon_js_1.getAzurePackageDevDependencies)(config); | ||
delete azurePackageDevDependencies["tshy"]; | ||
return { | ||
@@ -34,3 +36,3 @@ dependencies: { | ||
devDependencies: { | ||
...(0, azurePackageCommon_js_1.getAzurePackageDevDependencies)(config), | ||
...azurePackageDevDependencies, | ||
"@azure/dev-tool": "^1.0.0", | ||
@@ -105,3 +107,2 @@ "@azure/eslint-plugin-azure-sdk": "^3.0.0", | ||
"@types/mocha": "^10.0.0", | ||
"cross-env": "^7.0.2", | ||
"@types/chai": "^4.2.8", | ||
@@ -112,3 +113,3 @@ chai: "^4.2.0", | ||
"karma-env-preprocessor": "^0.1.1", | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-firefox-launcher": "^2.1.3", | ||
"karma-junit-reporter": "^2.0.1", | ||
@@ -183,3 +184,3 @@ "karma-mocha-reporter": "^2.2.5", | ||
build: "npm run clean && tsc -p . && dev-tool run bundle && dev-tool run vendored mkdirp ./review && dev-tool run extract-api", | ||
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", | ||
"build:node": "tsc -p . && dev-tool run vendored cross-env ONLY_NODE=true rollup -c 2>&1", | ||
"build:test": "tsc -p . && dev-tool run bundle", | ||
@@ -186,0 +187,0 @@ "build:debug": "tsc -p . && dev-tool run bundle && dev-tool run extract-api", |
@@ -33,2 +33,3 @@ "use strict"; | ||
...getStandaloneDevDependencies(config), | ||
"@microsoft/api-extractor": "^7.40.3", | ||
rimraf: "^5.0.5", | ||
@@ -54,2 +55,4 @@ mkdirp: "^3.0.1" | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
...(config.moduleKind === "cjs" && | ||
config.withTests && { "cross-env": "^7.0.2" }), | ||
rollup: "^2.66.1", | ||
@@ -56,0 +59,0 @@ "rollup-plugin-sourcemaps": "^0.6.3", |
@@ -16,2 +16,3 @@ "use strict"; | ||
...(0, packageCommon_js_1.getCommonPackageDevDependencies)(config), | ||
"@microsoft/api-extractor": "^7.40.3", | ||
rimraf: "^5.0.5", | ||
@@ -18,0 +19,0 @@ mkdirp: "^3.0.1" |
@@ -34,3 +34,3 @@ "use strict"; | ||
"@types/node": "^18.0.0", | ||
eslint: "^8.55.0", | ||
eslint: "^9.9.0", | ||
typescript: "~5.6.2", | ||
@@ -37,0 +37,0 @@ ...getEsmDevDependencies(config) |
@@ -1,1 +0,1 @@ | ||
{"name":"@azure-tools/rlc-common","version":"0.34.0","description":"","type":"commonjs","main":"dist/index.js","module":"dist-esm/index.js","exports":{".":{"types":"./types/index.d.ts","require":"./dist/index.js","import":"./dist-esm/index.js"}},"types":"./types/index.d.ts","scripts":{"lint":"eslint src --ext .ts --max-warnings=0","lint:fix":"eslint src --fix --ext .ts","format":"npm run -s prettier -- --write","check-format":"npm run prettier -- --check","prettier":"prettier --config ./.prettierrc \"src/**/*.ts\"","build":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js","build:cjs":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js","build:esm":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js","test":"npm run unit-test","unit-test":"cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --loader=ts-node/esm --experimental-specifier-resolution=node test/**/*.spec.ts"},"keywords":[],"author":"","license":"ISC","dependencies":{"ts-morph":"^23.0.0","lodash":"^4.17.21","handlebars":"^4.7.7"},"devDependencies":{"@types/node":"^18.0.0","eslint":"^8.9.0","prettier":"^3.1.0","typescript":"~5.6.2","rimraf":"^5.0.0","@types/lodash":"^4.14.182","fs-extra":"^10.0.0","@types/fs-extra":"^8.1.0","ts-node":"^10.7.0","mocha":"^10.2.0","chai":"^4.3.7","@types/chai":"^4.3.4","@types/mocha":"^10.0.1","@typescript-eslint/eslint-plugin":"^6.8.0","@typescript-eslint/parser":"^6.8.0","eslint-plugin-require-extensions":"0.1.3","cross-env":"7.0.3"},"bugs":{"url":"https://github.com/Azure/autorest.typescript/issues"},"homepage":"https://github.com/Azure/autorest.typescript/tree/main/packages/rlc-common/"} | ||
{"name":"@azure-tools/rlc-common","version":"0.35.0","description":"","type":"commonjs","main":"dist/index.js","module":"dist-esm/index.js","exports":{".":{"types":"./types/index.d.ts","require":"./dist/index.js","import":"./dist-esm/index.js"}},"types":"./types/index.d.ts","scripts":{"lint":"eslint src --ext .ts --max-warnings=0","lint:fix":"eslint src --fix --ext .ts","format":"npm run -s prettier -- --write","check-format":"npm run prettier -- --check","prettier":"prettier --config ./.prettierrc \"src/**/*.ts\"","build":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && node publishPackage.js","build:cjs":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig-cjs.json && node publishPackage.js","build:esm":"rimraf --glob dist/* dist-esm/* types/* && tsc -p tsconfig.json && node publishPackage.js","test":"npm run unit-test","unit-test":"cross-env TS_NODE_PROJECT=tsconfig.json mocha -r ts-node/register --loader=ts-node/esm --experimental-specifier-resolution=node test/**/*.spec.ts"},"keywords":[],"author":"","license":"ISC","dependencies":{"ts-morph":"^23.0.0","lodash":"^4.17.21","handlebars":"^4.7.7"},"devDependencies":{"@types/node":"^18.0.0","eslint":"^8.9.0","prettier":"^3.1.0","typescript":"~5.6.2","rimraf":"^5.0.0","@types/lodash":"^4.14.182","fs-extra":"^10.0.0","@types/fs-extra":"^8.1.0","ts-node":"^10.7.0","mocha":"^10.2.0","chai":"^4.3.7","@types/chai":"^4.3.4","@types/mocha":"^10.0.1","@typescript-eslint/eslint-plugin":"^6.8.0","@typescript-eslint/parser":"^6.8.0","eslint-plugin-require-extensions":"0.1.3","cross-env":"7.0.3"},"bugs":{"url":"https://github.com/Azure/autorest.typescript/issues"},"homepage":"https://github.com/Azure/autorest.typescript/tree/main/packages/rlc-common/"} |
{ | ||
"name": "@azure-tools/rlc-common", | ||
"version": "0.34.0", | ||
"version": "0.35.0-alpha.20241129.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -17,2 +17,3 @@ // Copyright (c) Microsoft Corporation. | ||
buildMethodDefinitions, | ||
getGeneratedWrapperTypes, | ||
getPathParamDefinitions | ||
@@ -172,2 +173,5 @@ } from "./helpers/operationHelpers.js"; | ||
const pathParams = paths[key].pathParameters; | ||
getGeneratedWrapperTypes(pathParams).forEach((p) => | ||
options.importedParameters.add(p.name ?? p.type) | ||
); | ||
signatures.push({ | ||
@@ -174,0 +178,0 @@ docs: [ |
@@ -17,11 +17,13 @@ // Copyright (c) Microsoft Corporation. | ||
const project = new Project(); | ||
const { srcPath } = model; | ||
const { srcPath, rlcSourceDir } = model; | ||
const { packageDetails } = model.options; | ||
const filePath = path.join( | ||
srcPath.substring( | ||
0, | ||
srcPath.includes("generated") && !srcPath.includes("src") | ||
? srcPath.lastIndexOf("generated") + 10 | ||
: srcPath.lastIndexOf("src") + 4 | ||
), | ||
model.options.sourceFrom == "Swagger" | ||
? srcPath.substring( | ||
0, | ||
srcPath.includes("generated") && !srcPath.includes("src") | ||
? srcPath.lastIndexOf("generated") + 10 | ||
: srcPath.lastIndexOf("src") + 4 | ||
) | ||
: rlcSourceDir!, | ||
`logger.ts` | ||
@@ -28,0 +30,0 @@ ); |
@@ -286,3 +286,3 @@ // Copyright (c) Microsoft Corporation. | ||
*/ | ||
function getObjectInterfaceDeclaration( | ||
export function getObjectInterfaceDeclaration( | ||
model: RLCModel, | ||
@@ -289,0 +289,0 @@ baseName: string, |
@@ -17,3 +17,4 @@ // Copyright (c) Microsoft Corporation. | ||
RLCModel, | ||
Schema | ||
Schema, | ||
SchemaContext | ||
} from "./interfaces.js"; | ||
@@ -26,2 +27,4 @@ import { | ||
import { getImportSpecifier } from "./helpers/importsUtil.js"; | ||
import { getObjectInterfaceDeclaration } from "./buildObjectTypes.js"; | ||
import { getGeneratedWrapperTypes } from "./helpers/operationHelpers.js"; | ||
@@ -63,2 +66,3 @@ export function buildParameterTypes(model: RLCModel) { | ||
const queryParameterDefinitions = buildQueryParameterDefinition( | ||
model, | ||
parameter, | ||
@@ -70,2 +74,3 @@ baseParameterName, | ||
const pathParameterDefinitions = buildPathParameterDefinitions( | ||
model, | ||
parameter, | ||
@@ -110,3 +115,3 @@ baseParameterName, | ||
...(queryParameterDefinitions ?? []), | ||
...(pathParameterDefinitions ? [pathParameterDefinitions] : []), | ||
...(pathParameterDefinitions ?? []), | ||
...(headerParameterDefinitions ? [headerParameterDefinitions] : []), | ||
@@ -185,2 +190,3 @@ ...(contentTypeParameterDefinition | ||
function buildQueryParameterDefinition( | ||
model: RLCModel, | ||
parameters: ParameterMetadatas, | ||
@@ -207,2 +213,14 @@ baseName: string, | ||
); | ||
// Get wrapper types for query parameters | ||
const wrapperTypesDefinition = getGeneratedWrapperTypes(queryParameters).map( | ||
(wrapObj) => { | ||
return getObjectInterfaceDeclaration( | ||
model, | ||
wrapObj.name, | ||
wrapObj, | ||
[SchemaContext.Input], | ||
new Set<string>() | ||
); | ||
} | ||
); | ||
@@ -237,3 +255,3 @@ const hasRequiredParameters = propertiesDefinition.some( | ||
return [propertiesInterface, parameterInterface]; | ||
return [...wrapperTypesDefinition, propertiesInterface, parameterInterface]; | ||
} | ||
@@ -253,2 +271,3 @@ | ||
function buildPathParameterDefinitions( | ||
model: RLCModel, | ||
parameters: ParameterMetadatas, | ||
@@ -259,3 +278,3 @@ baseName: string, | ||
requestIndex: number | ||
): InterfaceDeclarationStructure | undefined { | ||
): InterfaceDeclarationStructure[] | undefined { | ||
const pathParameters = (parameters.parameters || []).filter( | ||
@@ -267,26 +286,62 @@ (p) => p.type === "path" | ||
} | ||
const allDefinitions: InterfaceDeclarationStructure[] = []; | ||
const nameSuffix = requestIndex > 0 ? `${requestIndex}` : ""; | ||
const pathParameterInterfaceName = `${baseName}PathParam${nameSuffix}`; | ||
buildClientPathParameters(); | ||
buildMethodWrapParameters(); | ||
return allDefinitions; | ||
function buildClientPathParameters() { | ||
// we only have client-level path parameters if the source is from swagger | ||
if (model.options?.sourceFrom === "TypeSpec") { | ||
return; | ||
} | ||
const clientPathParams = pathParameters.length > 0 ? pathParameters : []; | ||
const nameSuffix = requestIndex > 0 ? `${requestIndex}` : ""; | ||
const pathParameterInterfaceName = `${baseName}PathParam${nameSuffix}`; | ||
const pathInterface = getPathInterfaceDefinition(pathParameters, baseName); | ||
const pathInterface = getPathInterfaceDefinition( | ||
clientPathParams, | ||
baseName | ||
); | ||
if (pathInterface) { | ||
parametersFile.addInterface(pathInterface); | ||
if (pathInterface) { | ||
parametersFile.addInterface(pathInterface); | ||
} | ||
internalReferences.add(pathParameterInterfaceName); | ||
allDefinitions.push({ | ||
isExported: true, | ||
kind: StructureKind.Interface, | ||
name: pathParameterInterfaceName, | ||
properties: [ | ||
{ | ||
name: "pathParameters", | ||
type: `${baseName}PathParameters`, | ||
kind: StructureKind.PropertySignature | ||
} | ||
] | ||
}); | ||
} | ||
internalReferences.add(pathParameterInterfaceName); | ||
function buildMethodWrapParameters() { | ||
if (model.options?.sourceFrom === "Swagger") { | ||
return; | ||
} | ||
// we only have method-level path parameters if the source is from typespec | ||
const methodPathParams = pathParameters.length > 0 ? pathParameters : []; | ||
return { | ||
isExported: true, | ||
kind: StructureKind.Interface, | ||
name: pathParameterInterfaceName, | ||
properties: [ | ||
{ | ||
name: "pathParameters", | ||
type: `${baseName}PathParameters`, | ||
kind: StructureKind.PropertySignature | ||
} | ||
] | ||
}; | ||
// we only need to build the wrapper types if the path parameters are objects | ||
const wrapperTypesDefinition = getGeneratedWrapperTypes( | ||
methodPathParams | ||
).map((wrap) => { | ||
return getObjectInterfaceDeclaration( | ||
model, | ||
wrap.name, | ||
wrap, | ||
[SchemaContext.Input], | ||
new Set<string>() | ||
); | ||
}); | ||
allDefinitions.push(...wrapperTypesDefinition); | ||
} | ||
} | ||
@@ -293,0 +348,0 @@ |
@@ -12,4 +12,6 @@ // Copyright (c) Microsoft Corporation. | ||
ObjectSchema, | ||
ParameterMetadata, | ||
PathParameter, | ||
RLCModel, | ||
Schema, | ||
SchemaContext | ||
@@ -125,1 +127,25 @@ } from "../interfaces.js"; | ||
} | ||
export function getGeneratedWrapperTypes( | ||
params: ParameterMetadata[] | PathParameter[] | ||
): Schema[] { | ||
const wrapperTypes = params | ||
.map((qp) => | ||
isParameterMetadata(qp) ? qp.param.wrapperType : qp.wrapperType | ||
) | ||
.filter((v) => v !== undefined); | ||
const wrapperFromObjects = wrapperTypes.filter( | ||
(wrap) => wrap.type === "object" | ||
); | ||
const wrapperFromUnions = wrapperTypes | ||
.filter((wrap) => wrap.type === "union") | ||
.flatMap((wrapperType) => wrapperType?.enum ?? []) | ||
.filter((v) => v.type === "object"); | ||
return [...wrapperFromUnions, ...wrapperFromObjects]; | ||
} | ||
function isParameterMetadata( | ||
param: ParameterMetadata | PathParameter | ||
): param is ParameterMetadata { | ||
return (param as any).param !== undefined; | ||
} |
@@ -17,2 +17,3 @@ // Copyright (c) Microsoft Corporation. | ||
sampleGroups?: RLCSampleGroup[]; | ||
rlcSourceDir?: string; | ||
} | ||
@@ -179,2 +180,3 @@ | ||
value?: string | number | boolean; | ||
wrapperType?: Schema; | ||
}; | ||
@@ -253,2 +255,3 @@ | ||
ignorePropertyNameNormalize?: boolean; | ||
compatibilityQueryMultiFormat?: boolean; | ||
} | ||
@@ -366,5 +369,10 @@ | ||
name: string; | ||
param: Schema; | ||
param: ParameterSchema; | ||
} | ||
export interface ParameterSchema extends Schema { | ||
// the detailed wrapper type for the parameter and codegen needs to build this type directly | ||
wrapperType?: Schema; | ||
} | ||
export interface OperationResponse { | ||
@@ -371,0 +379,0 @@ operationGroup: string; |
@@ -71,5 +71,2 @@ // Copyright (c) Microsoft Corporation. | ||
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: | ||
AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET | ||
## Troubleshooting | ||
@@ -152,3 +149,2 @@ | ||
You will also need to **register a new AAD application and grant access to {{ serviceName}}** by assigning the suitable role to your service principal (note: roles such as \`"Owner"\` will not grant the necessary permissions). | ||
Set the values of the client ID, tenant ID, and client secret of the AAD application as environment variables: \`AZURE_CLIENT_ID\`, \`AZURE_TENANT_ID\`, \`AZURE_CLIENT_SECRET\`. | ||
@@ -155,0 +151,0 @@ For more information about how to create an Azure AD Application check out [this guide](https://docs.microsoft.com/azure/active-directory/develop/howto-create-service-principal-portal). |
@@ -101,3 +101,2 @@ // Copyright (c) Microsoft Corporation. | ||
"@types/mocha": "^10.0.0", | ||
"cross-env": "^7.0.2", | ||
"@types/chai": "^4.2.8", | ||
@@ -108,3 +107,3 @@ chai: "^4.2.0", | ||
"karma-env-preprocessor": "^0.1.1", | ||
"karma-firefox-launcher": "^2.1.2", | ||
"karma-firefox-launcher": "^2.1.3", | ||
"karma-junit-reporter": "^2.0.1", | ||
@@ -111,0 +110,0 @@ "karma-mocha-reporter": "^2.2.5", |
@@ -41,2 +41,4 @@ // Copyright (c) Microsoft Corporation. | ||
const cjsDevDependencies = getCjsDevDependencies(config); | ||
const azurePackageDevDependencies = getAzurePackageDevDependencies(config); | ||
delete azurePackageDevDependencies["tshy"]; | ||
return { | ||
@@ -47,3 +49,3 @@ dependencies: { | ||
devDependencies: { | ||
...getAzurePackageDevDependencies(config), | ||
...azurePackageDevDependencies, | ||
"@azure/dev-tool": "^1.0.0", | ||
@@ -137,3 +139,2 @@ "@azure/eslint-plugin-azure-sdk": "^3.0.0", | ||
"@types/mocha": "^10.0.0", | ||
"cross-env": "^7.0.2", | ||
"@types/chai": "^4.2.8", | ||
@@ -144,3 +145,3 @@ chai: "^4.2.0", | ||
"karma-env-preprocessor": "^0.1.1", | ||
"karma-firefox-launcher": "^1.1.0", | ||
"karma-firefox-launcher": "^2.1.3", | ||
"karma-junit-reporter": "^2.0.1", | ||
@@ -240,3 +241,4 @@ "karma-mocha-reporter": "^2.2.5", | ||
"npm run clean && tsc -p . && dev-tool run bundle && dev-tool run vendored mkdirp ./review && dev-tool run extract-api", | ||
"build:node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1", | ||
"build:node": | ||
"tsc -p . && dev-tool run vendored cross-env ONLY_NODE=true rollup -c 2>&1", | ||
"build:test": "tsc -p . && dev-tool run bundle", | ||
@@ -243,0 +245,0 @@ "build:debug": |
@@ -48,2 +48,3 @@ // Copyright (c) Microsoft Corporation. | ||
...getStandaloneDevDependencies(config), | ||
"@microsoft/api-extractor": "^7.40.3", | ||
rimraf: "^5.0.5", | ||
@@ -72,2 +73,4 @@ mkdirp: "^3.0.1" | ||
"@rollup/plugin-node-resolve": "^13.1.3", | ||
...(config.moduleKind === "cjs" && | ||
config.withTests && { "cross-env": "^7.0.2" }), | ||
rollup: "^2.66.1", | ||
@@ -74,0 +77,0 @@ "rollup-plugin-sourcemaps": "^0.6.3", |
@@ -21,2 +21,3 @@ // Copyright (c) Microsoft Corporation. | ||
...getCommonPackageDevDependencies(config), | ||
"@microsoft/api-extractor": "^7.40.3", | ||
rimraf: "^5.0.5", | ||
@@ -23,0 +24,0 @@ mkdirp: "^3.0.1" |
@@ -47,3 +47,3 @@ // Copyright (c) Microsoft Corporation. | ||
"@types/node": "^18.0.0", | ||
eslint: "^8.55.0", | ||
eslint: "^9.9.0", | ||
typescript: "~5.6.2", | ||
@@ -50,0 +50,0 @@ ...getEsmDevDependencies(config) |
@@ -355,3 +355,3 @@ // Copyright (c) Microsoft Corporation. | ||
expect(packageFile.devDependencies).to.have.property("@types/mocha"); | ||
expect(packageFile.devDependencies).to.have.property("cross-env"); | ||
expect(packageFile.devDependencies).to.not.have.property("cross-env"); | ||
expect(packageFile.devDependencies).to.have.property("@types/chai"); | ||
@@ -402,3 +402,3 @@ expect(packageFile.devDependencies).to.have.property("chai"); | ||
"build:node", | ||
"tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1" | ||
"tsc -p . && dev-tool run vendored cross-env ONLY_NODE=true rollup -c 2>&1" | ||
); | ||
@@ -405,0 +405,0 @@ expect(packageFile.scripts).to.have.property( |
@@ -10,2 +10,7 @@ import { InterfaceDeclarationStructure, PropertySignatureStructure, TypeAliasDeclarationStructure } from "ts-morph"; | ||
/** | ||
* Builds the interface for the current object schema. If it is a polymorphic | ||
* root node it will suffix it with Base. | ||
*/ | ||
export declare function getObjectInterfaceDeclaration(model: RLCModel, baseName: string, objectSchema: ObjectSchema, schemaUsage: SchemaContext[], importedModels: Set<string>): InterfaceDeclarationStructure; | ||
/** | ||
* Gets a list of types a given object may extend from | ||
@@ -12,0 +17,0 @@ */ |
import { MethodSignatureStructure, OptionalKind, ParameterDeclarationStructure } from "ts-morph"; | ||
import { Methods, PathParameter, RLCModel } from "../interfaces.js"; | ||
import { Methods, ParameterMetadata, PathParameter, RLCModel, Schema } from "../interfaces.js"; | ||
export declare function buildMethodDefinitions(methods: Methods, pathParams?: PathParameter[]): OptionalKind<MethodSignatureStructure>[]; | ||
@@ -15,1 +15,2 @@ export declare function getPathParamDefinitions(pathParams: PathParameter[]): OptionalKind<ParameterDeclarationStructure>[]; | ||
export declare function hasOutputModels(model: RLCModel): boolean; | ||
export declare function getGeneratedWrapperTypes(params: ParameterMetadata[] | PathParameter[]): Schema[]; |
@@ -15,2 +15,3 @@ export interface RLCModel { | ||
sampleGroups?: RLCSampleGroup[]; | ||
rlcSourceDir?: string; | ||
} | ||
@@ -137,2 +138,3 @@ export interface ImportInfo { | ||
value?: string | number | boolean; | ||
wrapperType?: Schema; | ||
}; | ||
@@ -206,2 +208,3 @@ export interface OperationHelperDetail { | ||
ignorePropertyNameNormalize?: boolean; | ||
compatibilityQueryMultiFormat?: boolean; | ||
} | ||
@@ -307,4 +310,7 @@ export interface ServiceInfo { | ||
name: string; | ||
param: Schema; | ||
param: ParameterSchema; | ||
} | ||
export interface ParameterSchema extends Schema { | ||
wrapperType?: Schema; | ||
} | ||
export interface OperationResponse { | ||
@@ -311,0 +317,0 @@ operationGroup: string; |
@@ -60,6 +60,6 @@ import { PackageCommonInfoConfig } from "./packageCommon.js"; | ||
devDependencies: { | ||
"@microsoft/api-extractor": string; | ||
rimraf: string; | ||
mkdirp: string; | ||
tshy?: undefined; | ||
"@microsoft/api-extractor": string; | ||
"@types/node": string; | ||
@@ -69,6 +69,6 @@ eslint: string; | ||
} | { | ||
"@microsoft/api-extractor": string; | ||
rimraf: string; | ||
mkdirp: string; | ||
tshy: string; | ||
"@microsoft/api-extractor": string; | ||
"@types/node": string; | ||
@@ -75,0 +75,0 @@ eslint: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1252153
22535