Skip to content

Commit

Permalink
Merge branch 'main' into users/pahallis/1es-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
hallipr committed May 8, 2024
2 parents c99f4ec + 33f1071 commit 15182d1
Show file tree
Hide file tree
Showing 459 changed files with 43,871 additions and 511 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@
},
"[powershell]": {
"editor.defaultFormatter": "ms-vscode.powershell"
}
},
"typespec.tsp-server.path": "./packages/extensions/openapi-to-typespec/node_modules/@typespec/compiler"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Support AnyObject",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Add command to run compilation on test projects",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Change isFullCompatible logic",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Support apiversion as path parameter",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
79 changes: 50 additions & 29 deletions common/config/rush/pnpm-lock.yaml

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/extensions/openapi-to-typespec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -68,6 +69,7 @@
"@types/fs-extra": "^9.0.13",
"chalk": "^4.1.0",
"@azure-tools/typespec-autorest": "^0.39.0",
"@azure-tools/typespec-client-generator-core": "^0.39.0",
"webpack-cli": "~5.1.4",
"webpack": "~5.89.0",
"@typescript-eslint/eslint-plugin": "^6.11.0",
Expand Down
1 change: 1 addition & 0 deletions packages/extensions/openapi-to-typespec/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ApiVersion = "ApiVersion";
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function getServiceInformation(program: TypespecProgram) {
``,
`using TypeSpec.Rest;`,
`using TypeSpec.Http;`,
`using TypeSpec.Versioning;`,
];
const content = generateServiceInformation(program);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function generateArmResourceModel(resource: TspArmResource): string {
}

if (resource.locationParent) {
definitions.push(`@parentResource("${resource.locationParent}")`);
definitions.push(`@parentResource(${resource.locationParent})`);
}

if (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ApiVersion } from "../constants";
import { TypespecProgram, EndpointParameter, Auth } from "../interfaces";
import { getOptions } from "../options";
import { generateDocs } from "../utils/docs";
Expand Down Expand Up @@ -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("}");
Expand All @@ -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("}");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
isResourceSchema,
} from "../utils/resource-discovery";
import { isResponseSchema } from "../utils/schemas";
import { transformObjectProperty } from "./transform-object";
import { getTypespecType, transformObjectProperty } from "./transform-object";
import { transformParameter, transformRequest } from "./transform-operations";

const generatedResourceObjects: Map<string, string> = new Map<string, string>();
Expand Down Expand Up @@ -290,7 +290,7 @@ function getCustomizations(
if (bodyParam) {
if (bodyParam.language.default.name !== templateName && isFullCompatible) {
augmentedDecorators.push(
`@@encodedName(${tspOperationGroupName}.\`${operationName}\`::parameters.${templateName}, "json", "${bodyParam.language.default.name}");`,
`@@encodedName(${tspOperationGroupName}.\`${operationName}\`::parameters.${templateName}, "application/json", "${bodyParam.language.default.name}");`,
);
augmentedDecorators.push(
`@@extension(${tspOperationGroupName}.\`${operationName}\`::parameters.${templateName}, "x-ms-client-name", "${bodyParam.language.default.name}");`,
Expand Down Expand Up @@ -536,7 +536,7 @@ function convertResourceActionOperations(
}
}

const request = bodyParam ? bodyParam.schema.language.default.name : "void";
const request = bodyParam ? getTypespecType(bodyParam.schema, getSession().model) : "void";
const baseParameters = buildOperationBaseParameters(swaggerOperation, resourceMetadata);
let kind;
if (!okResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"),
);

if (apiVersionParams.length) {
return apiVersionParams.map((c) => c.value.value);
}
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)),
);

return undefined;
return apiVersionParams.length > 0 ? apiVersionParams : undefined;
}

function getEndpointParameter(codeModel: CodeModel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
}
Loading

0 comments on commit 15182d1

Please sign in to comment.