Skip to content

Commit

Permalink
Merge branch 'main' into ab/no-fdr-id
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo authored Sep 26, 2024
2 parents 67bb19d + d95bbc6 commit 8929fb5
Show file tree
Hide file tree
Showing 373 changed files with 10,007 additions and 1,381 deletions.
5 changes: 5 additions & 0 deletions fern/pages/changelogs/fastapi/2024-09-26.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 1.5.0-rc5
**`(fix):`** Pydantic utilities now correctly handles cases where you have a Pydantic model, with a list of pydantic models as a field, where those models have literals.
Effectively, `deep_union_pydantic_objects` now handles lists of objects and merges them appropriately.


5 changes: 5 additions & 0 deletions fern/pages/changelogs/pydantic/2024-09-26.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 1.4.7-rc1
**`(fix):`** Pydantic utilities now correctly handles cases where you have a Pydantic model, with a list of pydantic models as a field, where those models have literals.
Effectively, `deep_union_pydantic_objects` now handles lists of objects and merges them appropriately.


5 changes: 5 additions & 0 deletions fern/pages/changelogs/python-sdk/2024-09-26.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## 4.2.7-rc2
**`(fix):`** Pydantic utilities now correctly handles cases where you have a Pydantic model, with a list of pydantic models as a field, where those models have literals.
Effectively, `deep_union_pydantic_objects` now handles lists of objects and merges them appropriately.


2 changes: 1 addition & 1 deletion generators/openapi/src/customConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { GeneratorConfig } from "@fern-api/generator-commons";
export interface FernOpenapiCustomConfig {
format: "yaml" | "json";
customOverrides: Record<string, unknown>;
filename: string;
filename?: string;
}

const DEFAULT_FERN_OPENAPI_CUSTOM_CONFIG: FernOpenapiCustomConfig = {
Expand Down
29 changes: 18 additions & 11 deletions generators/openapi/src/writeOpenApi.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { IntermediateRepresentation } from "@fern-fern/ir-sdk/api";
import * as IrSerialization from "@fern-fern/ir-sdk/serialization";
import { readFile, writeFile } from "fs/promises";
import { writeFile } from "fs/promises";
import yaml from "js-yaml";
import merge from "lodash-es/merge";
import path from "path";
import { convertToOpenApi } from "./convertToOpenApi";
import { getCustomConfig } from "./customConfig";
import {
GeneratorNotificationService,
GeneratorExecParsing,
GeneratorUpdate,
ExitStatusUpdate,
parseGeneratorConfig,
Expand Down Expand Up @@ -41,28 +39,37 @@ export async function writeOpenApi(mode: Mode, pathToConfig: string): Promise<vo
ir,
mode
});
// eslint-disable-next-line no-console
console.log(`openapi before override ${JSON.stringify(openapi)}`);

if (customConfig.customOverrides != null) {
openapi = await mergeWithOverrides({
data: openapi,
overrides: customConfig.customOverrides
});
// eslint-disable-next-line no-console
console.log(`openapi after override ${JSON.stringify(openapi)}`);
}

let filename: string = customConfig.filename ?? "openapi.yml";
if (customConfig.format === "json") {
await writeFile(
path.join(config.output.path, replaceExtension(customConfig.filename, "json")),
JSON.stringify(openapi, undefined, 2)
);
filename = path.join(config.output.path, replaceExtension(filename, "json"));
await writeFile(filename, JSON.stringify(openapi, undefined, 2));
} else {
const filename =
customConfig.filename.endsWith("yml") || customConfig.filename.endsWith("yaml")
? customConfig.filename
: replaceExtension(customConfig.filename, "yml");
filename =
filename.endsWith("yml") || filename.endsWith("yaml")
? filename
: replaceExtension(filename, "yml");
await writeFile(path.join(config.output.path, filename), yaml.dump(openapi));
}
await generatorLoggingClient.sendUpdate(GeneratorUpdate.exitStatusUpdate(ExitStatusUpdate.successful({})));
} catch (e) {
if (e instanceof Error) {
// eslint-disable-next-line no-console
console.log((e as Error)?.message);
// eslint-disable-next-line no-console
console.log((e as Error)?.stack);
}
await generatorLoggingClient.sendUpdate(
GeneratorUpdate.exitStatusUpdate(
ExitStatusUpdate.error({
Expand Down
9 changes: 9 additions & 0 deletions generators/openapi/versions.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
- version: 0.1.4
createdAt: '2024-09-25'
changelogEntry:
- type: fix
summary: |
The generator now handles `config.filename` being null so that the
configuration for the generator can continue to be backwards compatible.
irVersion: 53

- version: 0.1.3
createdAt: '2024-09-25'
changelogEntry:
Expand Down
22 changes: 21 additions & 1 deletion generators/python/core_utilities/shared/pydantic_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,33 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
return convert_and_respect_annotation_metadata(object_=dict_dump, annotation=self.__class__, direction="write")


def _union_list_of_pydantic_dicts(
source: typing.List[typing.Any], destination: typing.List[typing.Any]
) -> typing.List[typing.Any]:
converted_list: typing.List[typing.Any] = []
for i, item in enumerate(source):
destination_value = destination[i] # type: ignore
if isinstance(item, dict):
converted_list.append(deep_union_pydantic_dicts(item, destination_value))
elif isinstance(item, list):
converted_list.append(_union_list_of_pydantic_dicts(item, destination_value))
else:
converted_list.append(item)
return converted_list


def deep_union_pydantic_dicts(
source: typing.Dict[str, typing.Any], destination: typing.Dict[str, typing.Any]
) -> typing.Dict[str, typing.Any]:
for key, value in source.items():
node = destination.setdefault(key, {})
if isinstance(value, dict):
node = destination.setdefault(key, {})
deep_union_pydantic_dicts(value, node)
# Note: we do not do this same processing for sets given we do not have sets of models
# and given the sets are unordered, the processing of the set and matching objects would
# be non-trivial.
elif isinstance(value, list):
destination[key] = _union_list_of_pydantic_dicts(value, node)
else:
destination[key] = value

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,33 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
return super().dict(**kwargs_with_defaults_exclude_unset_include_fields)


def _union_list_of_pydantic_dicts(
source: typing.List[typing.Any], destination: typing.List[typing.Any]
) -> typing.List[typing.Any]:
converted_list: typing.List[typing.Any] = []
for i, item in enumerate(source):
destination_value = destination[i] # type: ignore
if isinstance(item, dict):
converted_list.append(deep_union_pydantic_dicts(item, destination_value))
elif isinstance(item, list):
converted_list.append(_union_list_of_pydantic_dicts(item, destination_value))
else:
converted_list.append(item)
return converted_list


def deep_union_pydantic_dicts(
source: typing.Dict[str, typing.Any], destination: typing.Dict[str, typing.Any]
) -> typing.Dict[str, typing.Any]:
for key, value in source.items():
node = destination.setdefault(key, {})
if isinstance(value, dict):
node = destination.setdefault(key, {})
deep_union_pydantic_dicts(value, node)
# Note: we do not do this same processing for sets given we do not have sets of models
# and given the sets are unordered, the processing of the set and matching objects would
# be non-trivial.
elif isinstance(value, list):
destination[key] = _union_list_of_pydantic_dicts(value, node)
else:
destination[key] = value

Expand Down
10 changes: 9 additions & 1 deletion generators/python/fastapi/versions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# For unreleased changes, use unreleased.yml
# For unreleased changes, use unreleased.yml
- version: 1.5.0-rc5
irVersion: 53
changelogEntry:
- type: fix
summary: |
Pydantic utilities now correctly handles cases where you have a Pydantic model, with a list of pydantic models as a field, where those models have literals.
Effectively, `deep_union_pydantic_objects` now handles lists of objects and merges them appropriately.
- version: 1.5.0-rc4
irVersion: 53
changelogEntry:
Expand Down
8 changes: 8 additions & 0 deletions generators/python/pydantic/versions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# For unreleased changes, use unreleased.yml
- version: 1.4.7-rc1
irVersion: 53
changelogEntry:
- type: fix
summary: |
Pydantic utilities now correctly handles cases where you have a Pydantic model, with a list of pydantic models as a field, where those models have literals.
Effectively, `deep_union_pydantic_objects` now handles lists of objects and merges them appropriately.
- version: 1.4.7-rc0
irVersion: 53
changelogEntry:
Expand Down
10 changes: 9 additions & 1 deletion generators/python/sdk/versions.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# For unreleased changes, use unreleased.yml
- version: 4.2.7-rc2
- version: 4.2.7-rc3
irVersion: 53
changelogEntry:
- type: fix
summary: |
When sending Snippet Templates back to Fern, the generator will not try to coerce a potentially missing ID into the `api_definition_id` field.
This, had been a cause of the error log `Failed to upload snippet templates to FDR, this is ok: one of the hex, bytes, bytes_le, fields, or int arguments must be given`.
- version: 4.2.7-rc2
irVersion: 53
changelogEntry:
- type: fix
summary: |
Pydantic utilities now correctly handles cases where you have a Pydantic model, with a list of pydantic models as a field, where those models have literals.
Effectively, `deep_union_pydantic_objects` now handles lists of objects and merges them appropriately.
- version: 4.2.7-rc1
irVersion: 53
changelogEntry:
Expand Down
Loading

0 comments on commit 8929fb5

Please sign in to comment.