-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: add a flag to allow python to generate discriminated uni…
…ons as undiscriminated unions (#3740)
- Loading branch information
1 parent
f08f122
commit e9d64a0
Showing
55 changed files
with
1,091 additions
and
265 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
59 changes: 10 additions & 49 deletions
59
packages/cli/cli/src/commands/generate/generateAPIWorkspace.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 |
---|---|---|
@@ -1,88 +1,49 @@ | ||
import { FernToken } from "@fern-api/auth"; | ||
import { | ||
DEFAULT_GROUP_GENERATORS_CONFIG_KEY, | ||
fernConfigJson, | ||
GENERATORS_CONFIGURATION_FILENAME | ||
} from "@fern-api/configuration"; | ||
import { AbsoluteFilePath } from "@fern-api/fs-utils"; | ||
import { fernConfigJson, generatorsYml } from "@fern-api/configuration"; | ||
import { runLocalGenerationForWorkspace } from "@fern-api/local-workspace-runner"; | ||
import { runRemoteGenerationForAPIWorkspace } from "@fern-api/remote-workspace-runner"; | ||
import { TaskContext } from "@fern-api/task-context"; | ||
import { FernWorkspace } from "@fern-api/workspace-loader"; | ||
import { GROUP_CLI_OPTION } from "../../constants"; | ||
import { validateAPIWorkspaceAndLogIssues } from "../validate/validateAPIWorkspaceAndLogIssues"; | ||
import { FernWorkspaceMetadata } from "@fern-api/workspace-loader"; | ||
|
||
export async function generateWorkspace({ | ||
organization, | ||
workspace, | ||
projectConfig, | ||
workspaceGetter, | ||
context, | ||
groupName, | ||
version, | ||
shouldLogS3Url, | ||
token, | ||
useLocalDocker, | ||
keepDocker, | ||
absolutePathToPreview | ||
keepDocker | ||
}: { | ||
organization: string; | ||
workspace: FernWorkspace; | ||
workspaceGetter: ( | ||
sdkLanguage: generatorsYml.GenerationLanguage | undefined | ||
) => Promise<FernWorkspaceMetadata | undefined>; | ||
projectConfig: fernConfigJson.ProjectConfig; | ||
context: TaskContext; | ||
version: string | undefined; | ||
groupName: string | undefined; | ||
shouldLogS3Url: boolean; | ||
token: FernToken; | ||
useLocalDocker: boolean; | ||
keepDocker: boolean; | ||
absolutePathToPreview: AbsoluteFilePath | undefined; | ||
}): Promise<void> { | ||
if (workspace.generatorsConfiguration == null) { | ||
context.logger.warn("This workspaces has no generators.yml"); | ||
return; | ||
} | ||
|
||
if (workspace.generatorsConfiguration.groups.length === 0) { | ||
context.logger.warn(`This workspaces has no groups specified in ${GENERATORS_CONFIGURATION_FILENAME}`); | ||
return; | ||
} | ||
|
||
const groupNameOrDefault = groupName ?? workspace.generatorsConfiguration.defaultGroup; | ||
if (groupNameOrDefault == null) { | ||
return context.failAndThrow( | ||
`No group specified. Use the --${GROUP_CLI_OPTION} option, or set "${DEFAULT_GROUP_GENERATORS_CONFIG_KEY}" in ${GENERATORS_CONFIGURATION_FILENAME}` | ||
); | ||
} | ||
|
||
const group = workspace.generatorsConfiguration.groups.find( | ||
(otherGroup) => otherGroup.groupName === groupNameOrDefault | ||
); | ||
if (group == null) { | ||
return context.failAndThrow(`Group '${groupNameOrDefault}' does not exist.`); | ||
} | ||
|
||
await validateAPIWorkspaceAndLogIssues({ workspace, context, logWarnings: false }); | ||
|
||
if (useLocalDocker) { | ||
await runLocalGenerationForWorkspace({ | ||
projectConfig, | ||
workspace, | ||
generatorGroup: group, | ||
workspaceGetter, | ||
keepDocker, | ||
context | ||
}); | ||
} else { | ||
await runRemoteGenerationForAPIWorkspace({ | ||
projectConfig, | ||
organization, | ||
workspace, | ||
workspaceGetter, | ||
context, | ||
generatorGroup: group, | ||
version, | ||
shouldLogS3Url, | ||
token, | ||
whitelabel: workspace.generatorsConfiguration.whitelabel, | ||
absolutePathToPreview | ||
token | ||
}); | ||
} | ||
} |
Oops, something went wrong.