зеркало из https://github.com/Azure/autorest.git
Support api version as path parameter (#4952)
Fix #4951 #4949 #4950 And fix some compile error for version name
This commit is contained in:
Родитель
a76da06009
Коммит
6018eb2b79
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "@autorest/openapi-to-typespec",
|
||||
"comment": "Support apiversion as path parameter",
|
||||
"type": "patch"
|
||||
}
|
||||
],
|
||||
"packageName": "@autorest/openapi-to-typespec"
|
||||
}
|
|
@ -6,8 +6,9 @@
|
|||
"typings": "dist/main.d.ts",
|
||||
"scripts": {
|
||||
"generate": "ts-node ./test/utils/generate-typespec.ts generate",
|
||||
"generate:validate": "ts-node ./test/utils/generate-typespec.ts generate swagger",
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"test:ci": "npm run generate && node ./test/utils/check-clean-tree.js",
|
||||
"test:ci": "npm run generate:validate && node ./test/utils/check-clean-tree.js",
|
||||
"clean": "rimraf ./dist ./temp",
|
||||
"start": "node --max_old_space_size=4096 ./dist/main.js",
|
||||
"debug": "node --max_old_space_size=4096 --inspect-brk=localhost:9229 ./dist/main.js",
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
export const ApiVersion = "ApiVersion";
|
|
@ -20,6 +20,7 @@ function getServiceInformation(program: TypespecProgram) {
|
|||
``,
|
||||
`using TypeSpec.Rest;`,
|
||||
`using TypeSpec.Http;`,
|
||||
`using TypeSpec.Versioning;`,
|
||||
];
|
||||
const content = generateServiceInformation(program);
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { ApiVersion } from "../constants";
|
||||
import { TypespecProgram, EndpointParameter, Auth } from "../interfaces";
|
||||
import { getOptions } from "../options";
|
||||
import { generateDocs } from "../utils/docs";
|
||||
|
@ -53,7 +54,7 @@ export function generateServiceInformation(program: TypespecProgram) {
|
|||
for (const param of allParams ?? []) {
|
||||
const doc = generateDocs(param);
|
||||
doc && definitions.push(doc);
|
||||
definitions.push(`${param.name}: string `);
|
||||
definitions.push(`${param.name}: ${param.name.startsWith(ApiVersion) ? "Versions" : "string"} `);
|
||||
}
|
||||
}
|
||||
hasParameters && definitions.push("}");
|
||||
|
@ -71,10 +72,12 @@ export function generateServiceInformation(program: TypespecProgram) {
|
|||
for (const version of serviceInformation.versions) {
|
||||
if (isArm) {
|
||||
definitions.push(`@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)`);
|
||||
definitions.push(`@useDependency(Azure.Core.Versions.v1_0_Preview_1)`);
|
||||
}
|
||||
definitions.push(`@useDependency(Azure.Core.Versions.v1_0_Preview_1)`);
|
||||
definitions.push(`/**\n* The ${version} API version.\n*/`);
|
||||
definitions.push(`v${version.replaceAll("-", "_")}: "${version}",`);
|
||||
definitions.push(
|
||||
`${version.startsWith("v") ? "" : "v"}${version.replaceAll("-", "_").replaceAll(".", "_")}: "${version}",`,
|
||||
);
|
||||
}
|
||||
definitions.push("}");
|
||||
}
|
||||
|
|
|
@ -5,9 +5,9 @@ import {
|
|||
OAuth2SecurityScheme,
|
||||
ParameterLocation,
|
||||
SecurityScheme,
|
||||
codeModelSchema,
|
||||
} from "@autorest/codemodel";
|
||||
import { getArmCommonTypeVersion } from "../autorest-session";
|
||||
import { ApiVersion } from "../constants";
|
||||
import { AadOauth2AuthFlow, ApiKeyAuthentication, Auth, EndpointParameter, ServiceInformation } from "../interfaces";
|
||||
import { getOptions } from "../options";
|
||||
import { getFirstEndpoint } from "../utils/get-endpoint";
|
||||
|
@ -86,15 +86,16 @@ function getApiVersions(model: CodeModel): string[] | undefined {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const apiVersionParams = (model.schemas.constants ?? []).filter((c) =>
|
||||
c.language.default.name.startsWith("ApiVersion"),
|
||||
);
|
||||
const apiVersionParams = (model.schemas.constants ?? [])
|
||||
.filter((c) => c.language.default.name.startsWith(ApiVersion))
|
||||
.map((c) => c.value.value)
|
||||
.concat(
|
||||
(model.schemas.choices ?? [])
|
||||
.filter((c) => c.language.default.name.startsWith(ApiVersion))
|
||||
.flatMap((c) => c.choices.map((x) => x.value)),
|
||||
);
|
||||
|
||||
if (apiVersionParams.length) {
|
||||
return apiVersionParams.map((c) => c.value.value);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
return apiVersionParams.length > 0 ? apiVersionParams : undefined;
|
||||
}
|
||||
|
||||
function getEndpointParameter(codeModel: CodeModel) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* The language service API is a suite of natural language processing (NLP) skills
|
||||
* built with best-in-class Microsoft machine learning algorithms. The API can be
|
||||
|
@ -33,5 +34,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2022-05-01 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2022_05_01: "2022-05-01",
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* The Anomaly Detector API detects anomalies automatically in time series data.
|
||||
* It supports two kinds of mode, one is for stateless using, another is for
|
||||
|
@ -26,6 +27,7 @@ using TypeSpec.Http;
|
|||
@service({
|
||||
title: "Anomaly Detector Client",
|
||||
})
|
||||
@versioned(Versions)
|
||||
@server(
|
||||
"{Endpoint}/anomalydetector/{ApiVersion}",
|
||||
"The Anomaly Detector API detects anomalies automatically in time series data. It supports two kinds of mode, one is for stateless using, another is for stateful using. In stateless mode, there are three functionalities. Entire Detect is for detecting the whole series with model trained by the time series, Last Detect is detecting last point with model trained by points before. ChangePoint Detect is for detecting trend changes in time series. In stateful mode, user can store time series, the stored time series will be used for detection anomalies. Under this mode, user can still use the above three functionalities by only giving a time range without preparing time series in client side. Besides the above three functionalities, stateful model also provide group based detection and labeling service. By leveraging labeling service user can provide labels for each detection result, these labels will be used for retuning or regenerating detection models. Inconsistency detection is a kind of group based detection, this detection will find inconsistency ones in a set of time series. By using anomaly detector service, business customers can discover incidents and establish a logic flow for root cause analysis.",
|
||||
|
@ -36,7 +38,18 @@ using TypeSpec.Http;
|
|||
$host: string,
|
||||
|
||||
Endpoint: string,
|
||||
ApiVersion: string,
|
||||
ApiVersion: Versions,
|
||||
}
|
||||
)
|
||||
namespace AnomalyDetectorClient;
|
||||
|
||||
/**
|
||||
* The available API versions.
|
||||
*/
|
||||
enum Versions {
|
||||
/**
|
||||
* The v1.1-preview.1 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v1_1_preview_1: "v1.1-preview.1",
|
||||
}
|
||||
|
|
|
@ -4,27 +4,36 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
@useAuth(AadOauth2Auth<["user_impersonation"]> | ApiKeyAuth<ApiKeyLocation.header, "Authorization">)
|
||||
@service({
|
||||
title: "Azure Batch Service"
|
||||
})
|
||||
@versioned(Versions)
|
||||
@server("{batchUrl}", "A client for issuing REST requests to the Azure Batch service."
|
||||
, {
|
||||
batchUrl: string
|
||||
}
|
||||
)
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* A client for issuing REST requests to the Azure Batch service.
|
||||
*/
|
||||
* A client for issuing REST requests to the Azure Batch service.
|
||||
*/
|
||||
@useAuth(
|
||||
AadOauth2Auth<["user_impersonation"]> | ApiKeyAuth<
|
||||
ApiKeyLocation.header,
|
||||
"Authorization"
|
||||
>
|
||||
)
|
||||
@service({
|
||||
title: "Azure Batch Service",
|
||||
})
|
||||
@versioned(Versions)
|
||||
@server(
|
||||
"{batchUrl}",
|
||||
"A client for issuing REST requests to the Azure Batch service.",
|
||||
{
|
||||
batchUrl: string,
|
||||
}
|
||||
)
|
||||
namespace Azure.Batch;
|
||||
|
||||
/**
|
||||
* The available API versions.
|
||||
*/
|
||||
* The available API versions.
|
||||
*/
|
||||
enum Versions {
|
||||
/**
|
||||
* The 2022-01-01.15.0 API version.
|
||||
*/
|
||||
v2022_01_01.15.0: "2022-01-01.15.0",
|
||||
}
|
||||
/**
|
||||
* The 2022-01-01.15.0 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2022_01_01_15_0: "2022-01-01.15.0",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* Test Infrastructure for AutoRest
|
||||
*/
|
||||
|
@ -27,5 +28,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2016-02-29 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2016_02_29: "2016-02-29",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* Some cool documentation.
|
||||
*/
|
||||
|
@ -27,5 +28,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2014-04-01-preview API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2014_04_01_preview: "2014-04-01-preview",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* The ConfidentialLedgerClient writes and retrieves ledger entries against the
|
||||
* Confidential Ledger service.
|
||||
|
@ -28,5 +29,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2022-05-13 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2022_05_13: "2022-05-13",
|
||||
}
|
||||
|
|
|
@ -4,27 +4,31 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
@service({
|
||||
title: "Azure Keyvault Service"
|
||||
})
|
||||
@versioned(Versions)
|
||||
@server("{vaultBaseUrl}", "The key vault client performs cryptographic key operations and vault operations against the Key Vault service."
|
||||
, {
|
||||
vaultBaseUrl: string
|
||||
}
|
||||
)
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* The key vault client performs cryptographic key operations and vault operations
|
||||
* against the Key Vault service.
|
||||
*/
|
||||
* The key vault client performs cryptographic key operations and vault operations
|
||||
* against the Key Vault service.
|
||||
*/
|
||||
@service({
|
||||
title: "Azure Keyvault Service",
|
||||
})
|
||||
@versioned(Versions)
|
||||
@server(
|
||||
"{vaultBaseUrl}",
|
||||
"The key vault client performs cryptographic key operations and vault operations against the Key Vault service.",
|
||||
{
|
||||
vaultBaseUrl: string,
|
||||
}
|
||||
)
|
||||
namespace Azure.Keyvault;
|
||||
|
||||
/**
|
||||
* The available API versions.
|
||||
*/
|
||||
* The available API versions.
|
||||
*/
|
||||
enum Versions {
|
||||
/**
|
||||
* The 7.4-preview.1 API version.
|
||||
*/
|
||||
v7.4_preview.1: "7.4-preview.1",
|
||||
}
|
||||
/**
|
||||
* The 7.4-preview.1 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v7_4_preview_1: "7.4-preview.1",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* These APIs allow end users to create, view and run load tests using Azure Load
|
||||
* Test Service.
|
||||
|
@ -29,5 +30,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2022-11-01 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2022_11_01: "2022-11-01",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* The Notification Hubs client performs operations to register and query devices,
|
||||
* and send notifications
|
||||
|
@ -28,5 +29,36 @@ enum Versions {
|
|||
/**
|
||||
* The 2020-06-01 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2020_06_01: "2020-06-01",
|
||||
|
||||
/**
|
||||
* The 2015-01 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2015_01: "2015-01",
|
||||
|
||||
/**
|
||||
* The 2015-04 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2015_04: "2015-04",
|
||||
|
||||
/**
|
||||
* The 2015-08 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2015_08: "2015-08",
|
||||
|
||||
/**
|
||||
* The 2016-07 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2016_07: "2016-07",
|
||||
|
||||
/**
|
||||
* The 2020-06 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2020_06: "2020-06",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* Azure OpenAI APIs for completions and search
|
||||
*/
|
||||
|
@ -30,5 +31,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2022-06-01-preview API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2022_06_01_preview: "2022-06-01-preview",
|
||||
}
|
||||
|
|
|
@ -4,26 +4,30 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
@service({
|
||||
title: "AutoRest Paging Test Service"
|
||||
})
|
||||
@versioned(Versions)
|
||||
@server("{$host}", "Long-running Operation for AutoRest"
|
||||
, {
|
||||
$host: string
|
||||
}
|
||||
)
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* Long-running Operation for AutoRest
|
||||
*/
|
||||
* Long-running Operation for AutoRest
|
||||
*/
|
||||
@service({
|
||||
title: "AutoRest Paging Test Service",
|
||||
})
|
||||
@versioned(Versions)
|
||||
@server(
|
||||
"{$host}",
|
||||
"Long-running Operation for AutoRest",
|
||||
{
|
||||
$host: string,
|
||||
}
|
||||
)
|
||||
namespace AutoRestPagingTestService;
|
||||
|
||||
/**
|
||||
* The available API versions.
|
||||
*/
|
||||
* The available API versions.
|
||||
*/
|
||||
enum Versions {
|
||||
/**
|
||||
* The 1.0.0 API version.
|
||||
*/
|
||||
v1.0.0: "1.0.0",
|
||||
}
|
||||
/**
|
||||
* The 1.0.0 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v1_0_0: "1.0.0",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* The language service API is a suite of natural language processing (NLP) skills
|
||||
* built with best-in-class Microsoft machine learning algorithms. The API can be
|
||||
|
@ -38,5 +39,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2022-07-01-preview API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2022_07_01_preview: "2022-07-01-preview",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* The language service API is a suite of natural language processing (NLP) skills
|
||||
* built with best-in-class Microsoft machine learning algorithms. The API can be
|
||||
|
@ -38,5 +39,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2023-04-01 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2023_04_01: "2023-04-01",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* An API for QnAMaker runtime
|
||||
*/
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* Azure Schema Registry is as a central schema repository, with support for
|
||||
* versioning, management, compatibility checking, and RBAC.
|
||||
|
@ -28,5 +29,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2021-10 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2021_10: "2021-10",
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* Test Infrastructure for AutoRest
|
||||
*/
|
||||
|
|
|
@ -24,10 +24,18 @@ export async function generateTypespec(repoRoot: string, folder: string, debug =
|
|||
generate(repoRoot, swaggerPath, debug, isFullCompatible);
|
||||
}
|
||||
|
||||
// A list containing all the projects we could compile. After we enable all the projects, we will delete this list.
|
||||
const whiteList = ["anomalyDetector"];
|
||||
|
||||
export async function generateSwagger(folder: string) {
|
||||
if (!whiteList.includes(folder)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { path: root } = await resolveProject(__dirname);
|
||||
const path = join(root, "test", folder, "tsp-output");
|
||||
const command = "tsp compile . --emit=@azure-tools/typespec-autorest";
|
||||
const command =
|
||||
"tsp compile . --emit=@azure-tools/typespec-autorest --option @azure-tools/typespec-autorest.output-file=./swagger-output/swagger.json";
|
||||
execSync(command, { cwd: path, stdio: "inherit" });
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import "./routes.tsp";
|
|||
|
||||
using TypeSpec.Rest;
|
||||
using TypeSpec.Http;
|
||||
using TypeSpec.Versioning;
|
||||
/**
|
||||
* // FIXME: (missing-service-description) Add service description
|
||||
*/
|
||||
|
@ -27,5 +28,6 @@ enum Versions {
|
|||
/**
|
||||
* The 2023-07-01 API version.
|
||||
*/
|
||||
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
|
||||
v2023_07_01: "2023-07-01",
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче