Skip to content

Commit

Permalink
(fix): fern add with a new --group works (#3602)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored May 13, 2024
1 parent f9c734e commit b25ceb6
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ export async function updateGeneratorGroup({
return context.failAndThrow("No group specified.");
}
const groups = (generatorsConfiguration.groups ??= {});
for (const groupName of Object.keys(groups)) {

const group = groups[groupName];
if (group == null) {
const draftGroup = (groups[groupName] ??= { generators: [] });
await update(draftGroup, groupName);
} else {
await update(group, groupName);
}

return generatorsConfiguration;
}
117 changes: 117 additions & 0 deletions packages/cli/ete-tests/src/tests/add/__snapshots__/add.test.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`fern add fern add <generator> --group sdk 1`] = `
[
{
"contents": [
{
"contents": [
{
"contents": "name: api
error-discrimination:
strategy: status-code
",
"name": "api.yml",
"type": "file",
},
{
"contents": "# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
service:
auth: false
base-path: /movies
endpoints:
createMovie:
docs: Add a movie to the database
method: POST
path: /create-movie
request: CreateMovieRequest
response: MovieId
getMovie:
docs: Retrieve a movie from the database based on the ID
method: GET
path: /{id}
path-parameters:
id: MovieId
response: Movie
errors:
- MovieDoesNotExistError
examples:
# Success response
- path-parameters:
id: tt0111161
response:
body:
id: tt0111161
title: The Shawshank Redemption
rating: 9.3
# Error response
- path-parameters:
id: tt1234
response:
error: MovieDoesNotExistError
body: tt1234
types:
MovieId:
type: string
docs: The unique identifier for a Movie in the database
Movie:
properties:
id: MovieId
title: string
rating:
type: double
docs: The rating scale out of ten stars
CreateMovieRequest:
properties:
title: string
rating: double
errors:
MovieDoesNotExistError:
status-code: 404
type: MovieId
",
"name": "imdb.yml",
"type": "file",
},
],
"name": "definition",
"type": "directory",
},
{
"contents": "{
"organization": "fern",
"version": "0.0.0"
}",
"name": "fern.config.json",
"type": "file",
},
{
"contents": "default-group: local
groups:
local:
generators:
- name: fernapi/fern-typescript-node-sdk
version: 0.9.5
output:
location: local-file-system
path: ../sdks/typescript
typescript:
generators:
- name: fernapi/fern-typescript
version: 0.7.2
",
"name": "generators.yml",
"type": "file",
},
],
"name": "fern",
"type": "directory",
},
]
`;
14 changes: 14 additions & 0 deletions packages/cli/ete-tests/src/tests/add/add.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@ describe("fern add", () => {

expect(await getDirectoryContents(pathOfDirectory)).not.toBeNull();
}, 60_000);

it("fern add <generator> --group sdk", async () => {
const pathOfDirectory = await init();

const add = async (generator: string, groupName: string) => {
await runFernCli(["add", generator, "--group", groupName], {
cwd: pathOfDirectory
});
};

await add("fern-typescript", "typescript");

expect(await getDirectoryContents(pathOfDirectory)).toMatchSnapshot();
}, 60_000);
});

0 comments on commit b25ceb6

Please sign in to comment.