From 41882eece63ad34a1679325aab65f57df295f1c5 Mon Sep 17 00:00:00 2001 From: eden wang <64514273+eyw520@users.noreply.github.com> Date: Wed, 8 Jan 2025 17:35:42 -0500 Subject: [PATCH] fix(cli): Add `in-lined` test case to `no-duplicate-overrides.test.ts` (#5561) * fix(cli): Add `in-lined` test case to `no-duplicate-overrides.test.ts` * us --- .../no-duplicate-overrides.test.ts.snap | 19 ++++++- .../fixtures/in-lined/fern.config.json | 4 ++ .../__test__/fixtures/in-lined/generators.yml | 3 + .../fixtures/in-lined/openapi/openapi.yml | 55 +++++++++++++++++++ .../__test__/no-duplicate-overrides.test.ts | 27 ++++++++- 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/fern.config.json create mode 100644 packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/generators.yml create mode 100644 packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/openapi/openapi.yml diff --git a/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/__snapshots__/no-duplicate-overrides.test.ts.snap b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/__snapshots__/no-duplicate-overrides.test.ts.snap index 8ae528da3c2..0793052e9d9 100644 --- a/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/__snapshots__/no-duplicate-overrides.test.ts.snap +++ b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/__snapshots__/no-duplicate-overrides.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html -exports[`no-duplicate-overrides > complex failure > ./__snapshots__/openapi/complex.json 1`] = ` +exports[`no-duplicate-overrides > complex failure 1`] = ` [ { "message": "SDK method a.b.c.d already exists (x-fern-sdk-group-name: a.b.c, x-fern-sdk-method-name: d)", @@ -15,7 +15,22 @@ exports[`no-duplicate-overrides > complex failure > ./__snapshots__/openapi/comp ] `; -exports[`no-duplicate-overrides > simple failure > ./__snapshots__/openapi/simple.json 1`] = ` +exports[`no-duplicate-overrides > inlined failure 1`] = ` +[ + { + "message": "SDK method a.b already exists (x-fern-sdk-group-name: a, x-fern-sdk-method-name: b)", + "nodePath": [ + "paths", + "/a/b", + "get", + ], + "relativeFilepath": "openapi/openapi.yml", + "severity": "error", + }, +] +`; + +exports[`no-duplicate-overrides > simple failure 1`] = ` [ { "message": "SDK method a.b already exists (x-fern-sdk-group-name: a, x-fern-sdk-method-name: b)", diff --git a/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/fern.config.json b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/fern.config.json new file mode 100644 index 00000000000..b85cac2a9db --- /dev/null +++ b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/fern.config.json @@ -0,0 +1,4 @@ +{ + "organization": "twelvelabs", + "version": "0.44.11" +} \ No newline at end of file diff --git a/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/generators.yml b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/generators.yml new file mode 100644 index 00000000000..56703442713 --- /dev/null +++ b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/generators.yml @@ -0,0 +1,3 @@ +api: + specs: + - openapi: ./openapi/openapi.yml \ No newline at end of file diff --git a/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/openapi/openapi.yml b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/openapi/openapi.yml new file mode 100644 index 00000000000..f21104812a1 --- /dev/null +++ b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/fixtures/in-lined/openapi/openapi.yml @@ -0,0 +1,55 @@ +openapi: 3.1.0 +info: + title: Sample API + version: 1.0.0 +paths: + /a/{alpha}: + post: + x-fern-sdk-group-name: + - a + x-fern-sdk-method-name: b + summary: Test summary + description: Test description + parameters: + - name: alpha + in: path + required: true + schema: + type: string + operationId: operation-id-a + requestBody: + description: Request body containing beta + required: true + content: + application/json: + schema: + type: string + responses: + '201': + description: Resource created successfully + content: + application/json: + schema: + type: string + + /a/b: + get: + x-fern-sdk-group-name: + - a + x-fern-sdk-method-name: b + summary: Test summary + description: Test description + parameters: + - name: alpha + in: query + required: true + schema: + type: string + operationId: operation-id-b + responses: + '200': + description: Successful retrieval + content: + application/json: + schema: + type: string diff --git a/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/no-duplicate-overrides.test.ts b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/no-duplicate-overrides.test.ts index 9f067980187..5655599ab18 100644 --- a/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/no-duplicate-overrides.test.ts +++ b/packages/cli/workspace/oss-validator/src/rules/no-duplicate-overrides/__test__/no-duplicate-overrides.test.ts @@ -25,7 +25,7 @@ describe("no-duplicate-overrides", () => { } ]; - expect(violations).toMatchSnapshot("./__snapshots__/openapi/simple.json"); + expect(violations).toMatchSnapshot(); }, 10_000); it("complex failure", async () => { @@ -48,6 +48,29 @@ describe("no-duplicate-overrides", () => { } ]; - expect(violations).toMatchSnapshot("./__snapshots__/openapi/complex.json"); + expect(violations).toMatchSnapshot(); + }, 10_000); + + it("inlined failure", async () => { + const violations = await getViolationsForRule({ + rule: NoDuplicateOverridesRule, + absolutePathToWorkspace: join( + AbsoluteFilePath.of(__dirname), + RelativeFilePath.of("fixtures"), + RelativeFilePath.of("in-lined") + ), + cliVersion: "0.1.3-rc0" + }); + + const expectedViolations: ValidationViolation[] = [ + { + severity: "error", + relativeFilepath: RelativeFilePath.of("openapi/openapi.yml"), + nodePath: ["paths", "/a/b", "get"], + message: "SDK method a.b.c.d already exists (x-fern-sdk-group-name: a.b.c, x-fern-sdk-method-name: d)" + } + ]; + + expect(violations).toMatchSnapshot(); }, 10_000); });