Skip to content

Commit

Permalink
fix(cli): validate example endpoint calls when there are base-path ov…
Browse files Browse the repository at this point in the history
…errides (#4815)
  • Loading branch information
dsinghvi authored Oct 6, 2024
1 parent 98533a9 commit 20ce0ba
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 5 deletions.
7 changes: 7 additions & 0 deletions packages/cli/cli/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
- changelogEntry:
- summary: |
The Fern Definition respects endpoint level base-path overrides when validating examples.
type: fix
irVersion: 53
version: 0.44.6

- changelogEntry:
- summary: |
The Fern Definition now supports overriding `base-path` at the endpoint level.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: endpoint-level-base-path
base-path: /{version}
path-parameters:
version: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
service:
auth: false
base-path: "/servicePath"
endpoints:
get:
method: GET
base-path: "/latest"
path: /{endpointPathParam}
path-parameters:
endpointPathParam: string
examples:
- path-parameters:
endpointPathParam: hello
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
Expand Up @@ -495,4 +495,19 @@ describe("valid-example-endpoint-call", () => {

expect(violations).toEqual(expectedViolations);
});

it("endpoint-level-base-path", async () => {
const violations = await getViolationsForRule({
rule: ValidExampleEndpointCallRule,
absolutePathToWorkspace: join(
AbsoluteFilePath.of(__dirname),
RelativeFilePath.of("fixtures"),
RelativeFilePath.of("endpoint-level-base-path")
)
});

const expectedViolations: ValidationViolation[] = [];

expect(violations).toEqual(expectedViolations);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,14 @@ export const ValidExampleEndpointCallRule: Rule = {
{ relativeFilepath, contents: definitionFile }
) => {
return validateExampleEndpointCallParameters({
allDeclarations: {
...workspace.definition.rootApiFile.contents["path-parameters"],
...service["path-parameters"],
...endpoint["path-parameters"]
},
allDeclarations:
endpoint["base-path"] != null
? { ...endpoint["path-parameters"] }
: {
...workspace.definition.rootApiFile.contents["path-parameters"],
...service["path-parameters"],
...endpoint["path-parameters"]
},
examples,
parameterDisplayName: "path parameter",
typeResolver,
Expand Down

0 comments on commit 20ce0ba

Please sign in to comment.