-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement reference generation in generator-cli (#1070)
- Loading branch information
1 parent
f107b56
commit a0f252b
Showing
7 changed files
with
442 additions
and
0 deletions.
There are no files selected for viewing
184 changes: 184 additions & 0 deletions
184
clis/generator-cli/src/__test__/__snapshots__/basic-reference.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`basic-reference > basic-reference > generate reference file 1`] = ` | ||
"## Accounts | ||
This package contains all endpoints on accounts... | ||
<details><summary><code><a href="./src/accounts.py">client.accounts.get()</a></code></summary> | ||
<dl> | ||
<dd> | ||
#### 📝 Description | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
Some description specific to the endpoint about accounts, etc. etc. | ||
It can also be multi-line. | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
#### 🔌 Usage | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
\`\`\`python | ||
client.accounts.get(account_id="ID") | ||
\`\`\` | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
#### ⚙️ Parameters | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
**account_id:** \`str\` | ||
The ID of the account to retrieve. | ||
This is a multi-line description as well. | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
</details> | ||
## Users | ||
This package contains all endpoints on users... | ||
<details><summary><code><a href="./src/users.py">client.users.get()</a></code></summary> | ||
<dl> | ||
<dd> | ||
#### 📝 Description | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
Some description specific to the endpoint about users, etc. etc. | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
#### 🔌 Usage | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
\`\`\`python | ||
client.users.get(user_id="ID", account_id="ACCOUNT_ID") | ||
\`\`\` | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
#### ⚙️ Parameters | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
**user_id:** \`str\` — The ID of the user to retrieve. | ||
</dd> | ||
</dl> | ||
<dl> | ||
<dd> | ||
**account_id:** \`str\` — The ID of the account to retrieve the user from. | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
</details> | ||
<details><summary><code><a href="./src/users.py">client.users.update()</a></code></summary> | ||
<dl> | ||
<dd> | ||
#### 📝 Description | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
Some description specific to the endpoint about users, etc. etc. | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
#### 🔌 Usage | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
\`\`\`python | ||
client.users.get(update=User(id="ID") | ||
\`\`\` | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
#### ⚙️ Parameters | ||
<dl> | ||
<dd> | ||
<dl> | ||
<dd> | ||
**update:** \`<a href="./src/users.py">User</a>\` — The updated user object to send to the server. | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
</dd> | ||
</dl> | ||
</details> | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { testGenerateReference } from "./testGenerateReference"; | ||
|
||
describe("basic-reference", () => { | ||
testGenerateReference({ | ||
fixtureName: "basic-reference", | ||
referenceConfigFilename: "reference.json", | ||
}); | ||
}); |
84 changes: 84 additions & 0 deletions
84
clis/generator-cli/src/__test__/fixtures/basic-reference/reference.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
{ | ||
"sections": [ | ||
{ | ||
"title": "Accounts", | ||
"description": "This package contains all endpoints on accounts...", | ||
"endpoints": [ | ||
{ | ||
"title": { | ||
"snippetParts": [ | ||
{ | ||
"text": "client.accounts.get()", | ||
"location": { "path": "./src/accounts.py" } | ||
} | ||
] | ||
}, | ||
"description": "Some description specific to the endpoint about accounts, etc. etc.\n\nIt can also be multi-line.", | ||
"snippet": "client.accounts.get(account_id=\"ID\")", | ||
"parameters": [ | ||
{ | ||
"name": "account_id", | ||
"type": "str", | ||
"description": "The ID of the account to retrieve.\n\nThis is a multi-line description as well.", | ||
"required": true | ||
} | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"title": "Users", | ||
"description": "This package contains all endpoints on users...", | ||
"endpoints": [ | ||
{ | ||
"title": { | ||
"snippetParts": [ | ||
{ | ||
"text": "client.users.get()", | ||
"location": { "path": "./src/users.py" } | ||
} | ||
] | ||
}, | ||
"description": "Some description specific to the endpoint about users, etc. etc.", | ||
"snippet": "client.users.get(user_id=\"ID\", account_id=\"ACCOUNT_ID\")", | ||
"parameters": [ | ||
{ | ||
"name": "user_id", | ||
"type": "str", | ||
"description": "The ID of the user to retrieve.", | ||
"required": true | ||
}, | ||
{ | ||
"name": "account_id", | ||
"type": "str", | ||
"description": "The ID of the account to retrieve the user from.", | ||
"required": true | ||
} | ||
] | ||
}, | ||
{ | ||
"title": { | ||
"snippetParts": [ | ||
{ | ||
"text": "client.users.update()", | ||
"location": { "path": "./src/users.py" } | ||
} | ||
] | ||
}, | ||
"description": "Some description specific to the endpoint about users, etc. etc.", | ||
"snippet": "client.users.get(update=User(id=\"ID\")", | ||
"parameters": [ | ||
{ | ||
"name": "update", | ||
"type": "User", | ||
"location": { "path": "./src/users.py" }, | ||
"description": "The updated user object to send to the server.", | ||
"required": true | ||
} | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"language": "PYTHON" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import execa from "execa"; | ||
import path from "path"; | ||
|
||
const FIXTURES_PATH = path.join(__dirname, "fixtures"); | ||
|
||
export function testGenerateReference({ | ||
fixtureName, | ||
referenceConfigFilename, | ||
}: { | ||
fixtureName: string; | ||
referenceConfigFilename: string; | ||
}): void { | ||
// eslint-disable-next-line vitest/valid-title | ||
describe(fixtureName, () => { | ||
it("generate reference file", async () => { | ||
const absolutePathToReferenceConfig = getAbsolutePathToFixtureFile({ | ||
fixtureName, | ||
filepath: referenceConfigFilename, | ||
}); | ||
const args = [ | ||
path.join(__dirname, "../../dist/cli.cjs"), | ||
"generate-reference", | ||
"--config", | ||
absolutePathToReferenceConfig, | ||
]; | ||
|
||
const { stdout } = await execa("node", args); | ||
expect(stdout).toMatchSnapshot(); | ||
}); | ||
}); | ||
} | ||
|
||
function getAbsolutePathToFixtureFile({ fixtureName, filepath }: { fixtureName: string; filepath: string }): string { | ||
return path.join(FIXTURES_PATH, fixtureName, filepath); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
clis/generator-cli/src/configuration/loadReferenceConfig.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { AbsoluteFilePath } from "@fern-api/fs-utils"; | ||
import { readFile } from "fs/promises"; | ||
import { FernGeneratorCli } from "./generated"; | ||
|
||
export async function loadReferenceConfig({ | ||
absolutePathToConfig, | ||
}: { | ||
absolutePathToConfig: AbsoluteFilePath; | ||
}): Promise<FernGeneratorCli.ReferenceConfig> { | ||
const rawContents = await readFile(absolutePathToConfig, "utf8"); | ||
return JSON.parse(rawContents); | ||
} |
Oops, something went wrong.