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

Enums are not extensible by default anymore #473

Merged
merged 20 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
532271d
Enums are not extensible by default anymore
timotheeguerin Mar 21, 2024
cf4441d
Merge branch 'main' into enum-model-as-string-false
timotheeguerin Mar 21, 2024
e7eb947
Create enum-model-as-string-false-2024-2-21-19-56-37.md
timotheeguerin Mar 21, 2024
75c6858
Fix tests
timotheeguerin Mar 21, 2024
6f600bf
Merge branch 'main' into enum-model-as-string-false
timotheeguerin Mar 22, 2024
b0d60a8
Merge branch 'main' into enum-model-as-string-false
timotheeguerin Mar 25, 2024
28b6604
Merge branch 'main' into enum-model-as-string-false
timotheeguerin Mar 25, 2024
e7091ae
Merge branch 'main' into enum-model-as-string-false
timotheeguerin Mar 25, 2024
08491ca
Regen for core
timotheeguerin Mar 25, 2024
20bdaa2
Merge branch 'main' into enum-model-as-string-false
timotheeguerin Apr 15, 2024
3d2c5a2
Merge branch 'main' into enum-model-as-string-false
timotheeguerin Apr 18, 2024
f06ddb2
Merge branch 'main' of https://github.com/Azure/typespec-azure into e…
timotheeguerin Apr 19, 2024
c3cd165
Regen samples
timotheeguerin Apr 19, 2024
20d8eeb
Merge branch 'main' into enum-model-as-string-false
timotheeguerin Apr 19, 2024
ed4c87d
Merge branch 'main' into enum-model-as-string-false
timotheeguerin May 6, 2024
9d7c5c3
Merge branch 'main' into enum-model-as-string-false
timotheeguerin May 16, 2024
20856f0
Merge branch 'main' into enum-model-as-string-false
timotheeguerin May 22, 2024
f7eea20
Merge branch 'main' into enum-model-as-string-false
timotheeguerin May 24, 2024
8acb2ac
regen
timotheeguerin May 24, 2024
104c2b2
remove dup tests
timotheeguerin May 24, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: breaking
packages:
- "@azure-tools/typespec-autorest"
---

Enums are not extensible by default anymore. Update to an extensible union `union Foo {a: "a", b: "b", string}`
5 changes: 2 additions & 3 deletions packages/typespec-autorest/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
getLroMetadata,
getPagedResult,
getUnionAsEnum,
isFixed,
} from "@azure-tools/typespec-azure-core";
import {
getArmCommonTypeOpenAPIRef,
Expand Down Expand Up @@ -1925,7 +1924,7 @@ export async function getOpenAPIForService(
if (type.node && type.node.parent && type.node.parent.kind === SyntaxKind.ModelStatement) {
schema["x-ms-enum"] = {
name: type.node.parent.id.sv,
modelAsString: true,
modelAsString: false,
};
} else if (type.kind === "String") {
schema["x-ms-enum"] = {
Expand All @@ -1934,7 +1933,7 @@ export async function getOpenAPIForService(
} else if (type.kind === "Enum") {
schema["x-ms-enum"] = {
name: type.name,
modelAsString: isFixed(program, type) ? false : true,
modelAsString: false,
};

const values = [];
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-autorest/test/host.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe("typespec-autorest: host/x-ms-parameterized-host", () => {
required: true,
type: "string",
enum: ["westus", "eastus"],
"x-ms-enum": { modelAsString: true, name: "Region" },
"x-ms-enum": { modelAsString: false, name: "Region" },
},
],
});
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-autorest/test/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ describe("typespec-autorest: model definitions", () => {
enum: ["a-value", "b"],
"x-ms-enum": {
name: "MyEnum",
modelAsString: true,
modelAsString: false,
values: [
{ name: "a", value: "a-value" },
{ name: "b", value: "b" },
Expand Down Expand Up @@ -709,7 +709,7 @@ describe("typespec-autorest: model definitions", () => {
type: "string",
enum: ["dog", "cat"],
"x-ms-enum": {
modelAsString: true,
modelAsString: false,
name: "PetKind",
},
});
Expand Down
34 changes: 9 additions & 25 deletions packages/typespec-autorest/test/openapi-output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,41 +617,25 @@ describe("typespec-autorest: enums", () => {
type: "string",
enum: ["foo", "bar"],
});

it("create basic enum without values", async () => {
const res = await oapiForModel(
"Foo",
`
enum Foo {foo, bar}
`
);
const res = await oapiForModel("Foo", `enum Foo {foo, bar}`);

const schema = res.defs.Foo;
deepStrictEqual(schema, {
...enumBase,
"x-ms-enum": {
modelAsString: true,
modelAsString: false,
name: "Foo",
},
});
});

it("create fixed enum", async () => {
const res = await oapiForModel(
"Foo",
`
@fixed
enum Foo {foo, bar}
`
);
it("enums are marked with modelAsString false by default", async () => {
const res = await oapiForModel("Foo", `enum Foo {foo, bar}`);

const schema = res.defs.Foo;
deepStrictEqual(schema, {
...enumBase,
"x-ms-enum": {
modelAsString: false,
name: "Foo",
},
});
deepStrictEqual(schema["x-ms-enum"].modelAsString, false);
});

it("create enum with doc on a member", async () => {
Expand All @@ -670,7 +654,7 @@ describe("typespec-autorest: enums", () => {
deepStrictEqual(schema, {
...enumBase,
"x-ms-enum": {
modelAsString: true,
modelAsString: false,
name: "Foo",
values: [
{
Expand Down Expand Up @@ -702,7 +686,7 @@ describe("typespec-autorest: enums", () => {
deepStrictEqual(schema, {
...enumBase,
"x-ms-enum": {
modelAsString: true,
modelAsString: false,
name: "Foo",
values: [
{
Expand Down Expand Up @@ -734,7 +718,7 @@ describe("typespec-autorest: enums", () => {
type: "number",
enum: [0, 1],
"x-ms-enum": {
modelAsString: true,
modelAsString: false,
name: "Test",
values: [
{
Expand Down
4 changes: 2 additions & 2 deletions packages/typespec-autorest/test/parameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ describe("typespec-autorest: parameters", () => {
required: true,
type: "string",
enum: ["one", "two"],
"x-ms-enum": { modelAsString: true, name: "Foo" },
"x-ms-enum": { modelAsString: false, name: "Foo" },
});
});

Expand All @@ -364,7 +364,7 @@ describe("typespec-autorest: parameters", () => {
items: {
type: "string",
enum: ["one", "two"],
"x-ms-enum": { modelAsString: true, name: "Foo" },
"x-ms-enum": { modelAsString: false, name: "Foo" },
},
});
});
Expand Down
Loading