Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge autorest 0.39.1 hotfix back into main #240

Merged
merged 3 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .changeset/chatty-bobcats-love.md

This file was deleted.

1 change: 1 addition & 0 deletions eng/pipelines/pr-tryit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: PR Tools
trigger: none
pr:
- main
- release/*

variables:
- template: templates/variables/globals.yml
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build": ""
},
"devDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"typescript": "~5.3.3",
"dotenv": "~16.3.1"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
],
"dependencies": {
"@typespec/versioning": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/openapi": "workspace:~0.53.0",
"@typespec/openapi3": "workspace:~0.53.0",
"@typespec/openapi3": "workspace:~0.53.1",
"@typespec/http": "workspace:~0.53.0",
"@typespec/rest": "workspace:~0.53.0",
"@azure-tools/typespec-azure-core": "workspace:~0.39.0",
"@azure-tools/typespec-autorest": "workspace:~0.39.0",
"@azure-tools/typespec-autorest": "workspace:~0.39.1",
"@azure-tools/typespec-azure-resource-manager": "workspace:~0.39.0",
"@azure-tools/typespec-client-generator-core": "workspace:~0.39.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ components:
enum:
- accepted
- rejected
description: Repeatability Result header options
Versions:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ components:
enum:
- accepted
- rejected
description: Repeatability Result header options
Versions:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,7 @@ components:
enum:
- accepted
- rejected
description: Repeatability Result header options
Versions:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,7 @@ components:
enum:
- accepted
- rejected
description: Repeatability Result header options
Versions:
type: string
enum:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ components:
enum:
- accepted
- rejected
description: Repeatability Result header options
Versions:
type: string
enum:
Expand Down
7 changes: 7 additions & 0 deletions packages/typespec-autorest/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log - @azure-tools/typespec-autorest

## 0.39.1

### Patch Changes

- b5fa501: Support default value for union properties
- b5fa501: Fix: Description being ignored on unions

## 0.39.0

### Minor Changes
Expand Down
8 changes: 4 additions & 4 deletions packages/typespec-autorest/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-autorest",
"version": "0.39.0",
"version": "0.39.1",
"author": "Microsoft Corporation",
"description": "TypeSpec library for emitting openapi from the TypeSpec REST protocol binding",
"homepage": "https://azure.github.io/typespec-azure",
Expand Down Expand Up @@ -54,7 +54,7 @@
"!dist/test/**"
],
"peerDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@azure-tools/typespec-azure-core": "workspace:~0.39.0",
"@azure-tools/typespec-client-generator-core": "workspace:~0.39.0",
"@typespec/http": "workspace:~0.53.0",
Expand All @@ -63,8 +63,8 @@
"@typespec/versioning": "workspace:~0.53.0"
},
"devDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/json-schema": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/json-schema": "workspace:~0.53.1",
"@azure-tools/typespec-azure-core": "workspace:~0.39.0",
"@azure-tools/typespec-client-generator-core": "workspace:~0.39.0",
"@typespec/http": "workspace:~0.53.0",
Expand Down
34 changes: 25 additions & 9 deletions packages/typespec-autorest/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ function createOAPIEmitter(
if (e.nullable) {
schema["x-nullable"] = true;
}
return schema;
return applyIntrinsicDecorators(union, schema);
}

function getSchemaForUnion(union: Union, visibility: Visibility): OpenAPI2Schema {
Expand Down Expand Up @@ -1607,6 +1607,8 @@ function createOAPIEmitter(
format: { type: type.kind },
target: type,
});
case "UnionVariant":
return getDefaultValue(type.type);
default:
reportDiagnostic(program, {
code: "invalid-default",
Expand Down Expand Up @@ -1793,10 +1795,20 @@ function createOAPIEmitter(
}

function resolveProperty(prop: ModelProperty, visibility: Visibility): OpenAPI2SchemaProperty {
const propSchema =
prop.type.kind === "Enum" && prop.default
? getSchemaForEnum(prop.type)
: getSchemaOrRef(prop.type, visibility);
let propSchema;
if (prop.type.kind === "Enum" && prop.default) {
propSchema = getSchemaForEnum(prop.type);
} else if (prop.type.kind === "Union" && prop.default) {
const [asEnum, _] = getUnionAsEnum(prop.type);
if (asEnum) {
propSchema = getSchemaForUnionEnum(prop.type, asEnum);
} else {
propSchema = getSchemaOrRef(prop.type, visibility);
}
} else {
propSchema = getSchemaOrRef(prop.type, visibility);
}

return applyIntrinsicDecorators(prop, propSchema);
}

Expand Down Expand Up @@ -1830,15 +1842,17 @@ function createOAPIEmitter(
}

function applyIntrinsicDecorators(
typespecType: Model | Scalar | ModelProperty,
typespecType: Model | Scalar | ModelProperty | Union,
target: OpenAPI2Schema
): OpenAPI2Schema {
const newTarget = { ...target };
const docStr = getDoc(program, typespecType);
const isString =
typespecType.kind !== "Model" && isStringType(program, getPropertyType(typespecType));
(typespecType.kind === "Scalar" || typespecType.kind === "ModelProperty") &&
isStringType(program, getPropertyType(typespecType));
const isNumeric =
typespecType.kind !== "Model" && isNumericType(program, getPropertyType(typespecType));
(typespecType.kind === "Scalar" || typespecType.kind === "ModelProperty") &&
isNumericType(program, getPropertyType(typespecType));

if (docStr) {
newTarget.description = docStr;
Expand Down Expand Up @@ -1927,7 +1941,9 @@ function createOAPIEmitter(

attachExtensions(typespecType, newTarget);

return typespecType.kind === "Model" ? newTarget : applyEncoding(typespecType, newTarget);
return typespecType.kind === "Scalar" || typespecType.kind === "ModelProperty"
? applyEncoding(typespecType, newTarget)
: newTarget;
}

function applyEncoding(
Expand Down
35 changes: 35 additions & 0 deletions packages/typespec-autorest/test/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,41 @@ describe("typespec-autorest: model definitions", () => {
});
});

it("specify default value on union with variant", async () => {
const res = await oapiForModel(
"Foo",
`
model Foo {
optionalUnion?: MyUnion = MyUnion.a;
};

union MyUnion {
a: "a-value",
b: "b-value",
}
`
);

deepStrictEqual(res.defs.Foo, {
type: "object",
properties: {
optionalUnion: {
type: "string",
enum: ["a-value", "b-value"],
"x-ms-enum": {
values: [
{ name: "a", value: "a-value" },
{ name: "b", value: "b-value" },
],
modelAsString: false,
name: "MyUnion",
},
default: "a-value",
},
},
});
});

it("errors on empty enum", async () => {
const diagnostics = await diagnoseOpenApiFor(
`
Expand Down
16 changes: 15 additions & 1 deletion packages/typespec-autorest/test/union-schema.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expectDiagnostics } from "@typespec/compiler/testing";
import { deepStrictEqual } from "assert";
import { deepStrictEqual, strictEqual } from "assert";
import { describe, it } from "vitest";
import { diagnoseOpenApiFor, openApiFor } from "./test-host.js";

Expand Down Expand Up @@ -138,5 +138,19 @@ describe("typespec-autorest: union schema", () => {
},
});
});

it("supports description on unions that reduce to enums", async () => {
const res = await openApiFor(
`
@doc("FooUnion")
union Foo {
"a";
"b";
}

`
);
strictEqual(res.definitions.Foo.description, "FooUnion");
});
});
});
4 changes: 2 additions & 2 deletions packages/typespec-azure-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"!dist/test/**"
],
"peerDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/http": "workspace:~0.53.0",
"@typespec/rest": "workspace:~0.53.0"
},
"devDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/http": "workspace:~0.53.0",
"@typespec/rest": "workspace:~0.53.0",
"@typespec/eslint-config-typespec": "workspace:~0.53.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/typespec-azure-playground-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@
],
"dependencies": {
"@typespec/versioning": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/rest": "workspace:~0.53.0",
"@typespec/http": "workspace:~0.53.0",
"@typespec/openapi": "workspace:~0.53.0",
"@typespec/openapi3": "workspace:~0.53.0",
"@azure-tools/typespec-autorest": "workspace:~0.39.0",
"@typespec/openapi3": "workspace:~0.53.1",
"@azure-tools/typespec-autorest": "workspace:~0.39.1",
"@azure-tools/typespec-azure-core": "workspace:~0.39.0",
"@azure-tools/typespec-azure-resource-manager": "workspace:~0.39.0",
"@azure-tools/typespec-client-generator-core": "workspace:~0.39.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/typespec-azure-portal-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"test-official": "vitest run --coverage --reporter=junit --reporter=default --no-file-parallelism",
"lint": "eslint . --ext .ts --max-warnings=0",
"lint:fix": "eslint . --fix --ext .ts",
"regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/libraries/typespec-azure-portal-core/reference"
"regen-docs": "tspd doc . --enable-experimental --output-dir ../../docs/libraries/azure-portal-core/reference"
},
"keywords": [
"Azure",
Expand All @@ -29,15 +29,15 @@
"tspMain": "lib/main.tsp",
"peerDependencies": {
"@azure-tools/typespec-azure-resource-manager": "workspace:~0.39.0",
"@typespec/compiler": "workspace:~0.53.0"
"@typespec/compiler": "workspace:~0.53.1"
},
"devDependencies": {
"@azure-tools/typespec-autorest": "workspace:~0.39.0",
"@azure-tools/typespec-autorest": "workspace:~0.39.1",
"@azure-tools/typespec-azure-core": "workspace:~0.39.0",
"@azure-tools/typespec-azure-resource-manager": "workspace:~0.39.0",
"@azure-tools/typespec-client-generator-core": "workspace:~0.39.0",
"@types/node": "~18.11.9",
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/eslint-config-typespec": "workspace:~0.53.0",
"@typespec/eslint-plugin": "workspace:~0.53.0",
"@typespec/http": "workspace:~0.53.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/typespec-azure-resource-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@
"!dist/test/**"
],
"peerDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@azure-tools/typespec-azure-core": "~0.39.0",
"@azure-tools/typespec-autorest": "~0.39.0",
"@azure-tools/typespec-autorest": "~0.39.1",
"@typespec/openapi": "workspace:~0.53.0",
"@typespec/rest": "workspace:~0.53.0",
"@typespec/http": "workspace:~0.53.0",
"@typespec/versioning": "workspace:~0.53.0"
},
"devDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/openapi": "workspace:~0.53.0",
"@azure-tools/typespec-azure-core": "workspace:~0.39.0",
"@azure-tools/typespec-autorest": "workspace:~0.39.0",
"@azure-tools/typespec-autorest": "workspace:~0.39.1",
"@typespec/rest": "workspace:~0.53.0",
"@typespec/http": "workspace:~0.53.0",
"@typespec/versioning": "workspace:~0.53.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-client-generator-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@
"change-case": "~5.3.0"
},
"peerDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/http": "workspace:~0.53.0",
"@typespec/rest": "workspace:~0.53.0",
"@typespec/versioning": "workspace:~0.53.0"
},
"devDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/http": "workspace:~0.53.0",
"@typespec/rest": "workspace:~0.53.0",
"@typespec/eslint-config-typespec": "workspace:~0.53.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/typespec-service-csharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@
"!dist/test/**"
],
"peerDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@typespec/compiler": "workspace:~0.53.1",
"@typespec/rest": "workspace:~0.53.0",
"@typespec/http": "workspace:~0.53.0",
"@typespec/versioning": "workspace:~0.53.0",
"@azure-tools/typespec-autorest": "~0.39.0",
"@azure-tools/typespec-autorest": "~0.39.1",
"@azure-tools/typespec-azure-core": "~0.39.0"
},
"dependencies": {
"change-case": "~5.3.0"
},
"devDependencies": {
"@typespec/compiler": "workspace:~0.53.0",
"@azure-tools/typespec-autorest": "workspace:~0.39.0",
"@typespec/compiler": "workspace:~0.53.1",
"@azure-tools/typespec-autorest": "workspace:~0.39.1",
"@typespec/openapi": "workspace:~0.53.0",
"@typespec/rest": "workspace:~0.53.0",
"@typespec/http": "workspace:~0.53.0",
Expand Down
1 change: 1 addition & 0 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@azure-tools/typespec-azure-resource-manager": "workspace:~0.39.0",
"@azure-tools/typespec-client-generator-core": "workspace:~0.39.0",
"@azure-tools/typespec-service-csharp": "workspace:~0.32.0",
"@azure-tools/typespec-azure-portal-core": "workspace:~0.39.0",
"@docusaurus/module-type-aliases": "^3.0.0",
"@docusaurus/tsconfig": "^3.0.0",
"@docusaurus/types": "^3.0.0",
Expand Down
Loading
Loading