Skip to content

Commit

Permalink
(feature): Add allowExtraFields configuration to TypeScript generators (
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Apr 15, 2024
1 parent 4879ae3 commit fcdb463
Show file tree
Hide file tree
Showing 702 changed files with 127,840 additions and 62 deletions.
Binary file not shown.
Binary file not shown.
12 changes: 12 additions & 0 deletions generators/typescript/express/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.11.0-rc0] - 2024-04-12

- Feature: Add `allowExtraFields` option to permit extra fields in the returned response.

```yaml
- name: fernapi/fern-typscript-express
version: 0.11.0-rc0
...
config:
allowExtraFields: true
```
## [0.10.0] - 2024-04-09
- Support V37 of the IR.
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/express/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.0
0.11.0-rc0
6 changes: 4 additions & 2 deletions generators/typescript/express/cli/src/ExpressGeneratorCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class ExpressGeneratorCli extends AbstractGeneratorCli<ExpressCustomConfi
noSerdeLayer,
outputEsm: parsed?.outputEsm ?? false,
outputSourceFiles: parsed?.outputSourceFiles ?? false,
retainOriginalCasing: parsed?.retainOriginalCasing ?? false
retainOriginalCasing: parsed?.retainOriginalCasing ?? false,
allowExtraFields: parsed?.allowExtraFields ?? false
};
}

Expand Down Expand Up @@ -55,7 +56,8 @@ export class ExpressGeneratorCli extends AbstractGeneratorCli<ExpressCustomConfi
treatUnknownAsAny: customConfig.treatUnknownAsAny,
includeSerdeLayer: !customConfig.noSerdeLayer,
outputEsm: customConfig.outputEsm,
retainOriginalCasing: customConfig.retainOriginalCasing
retainOriginalCasing: customConfig.retainOriginalCasing,
allowExtraFields: customConfig.allowExtraFields
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ export interface ExpressCustomConfig {
outputEsm: boolean;
outputSourceFiles: boolean;
retainOriginalCasing: boolean;
allowExtraFields: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const ExpressCustomConfigSchema = z.strictObject({
outputSourceFiles: z.optional(z.boolean()),
includeUtilsOnUnionMembers: z.optional(z.boolean()),
includeOtherInUnionTypes: z.optional(z.boolean()),
retainOriginalCasing: z.optional(z.boolean())
retainOriginalCasing: z.optional(z.boolean()),
allowExtraFields: z.optional(z.boolean())
});

export type ExpressCustomConfigSchema = z.infer<typeof ExpressCustomConfigSchema>;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GeneratedExpressEndpointTypeSchemasImpl } from "./GeneratedExpressEndpo
export declare namespace ExpressEndpointTypeSchemasGenerator {
export interface Init {
includeSerdeLayer: boolean;
allowExtraFields: boolean;
}

export namespace generateEndpointTypeSchemas {
Expand All @@ -19,9 +20,11 @@ export declare namespace ExpressEndpointTypeSchemasGenerator {

export class ExpressEndpointTypeSchemasGenerator {
private includeSerdeLayer: boolean;
private allowExtraFields: boolean;

constructor({ includeSerdeLayer }: ExpressEndpointTypeSchemasGenerator.Init) {
constructor({ includeSerdeLayer, allowExtraFields }: ExpressEndpointTypeSchemasGenerator.Init) {
this.includeSerdeLayer = includeSerdeLayer;
this.allowExtraFields = allowExtraFields;
}

public generateEndpointTypeSchemas({
Expand All @@ -33,7 +36,8 @@ export class ExpressEndpointTypeSchemasGenerator {
packageId,
service,
endpoint,
includeSerdeLayer: this.includeSerdeLayer
includeSerdeLayer: this.includeSerdeLayer,
allowExtraFields: this.allowExtraFields
});
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertNever } from "@fern-api/core-utils";
import { HttpEndpoint, HttpService } from "@fern-fern/ir-sdk/api";
import { PackageId } from "@fern-typescript/commons";
import { getSchemaOptions, PackageId } from "@fern-typescript/commons";
import { ExpressContext, GeneratedExpressEndpointTypeSchemas } from "@fern-typescript/contexts";
import { ts } from "ts-morph";
import { GeneratedEndpointTypeSchema } from "./GeneratedEndpointTypeSchema";
Expand All @@ -12,6 +12,7 @@ export declare namespace GeneratedExpressEndpointTypeSchemasImpl {
service: HttpService;
endpoint: HttpEndpoint;
includeSerdeLayer: boolean;
allowExtraFields: boolean;
}
}

Expand All @@ -23,10 +24,18 @@ export class GeneratedExpressEndpointTypeSchemasImpl implements GeneratedExpress
private generatedRequestSchema: GeneratedEndpointTypeSchema | undefined;
private generatedResponseSchema: GeneratedEndpointTypeSchemaImpl | undefined;
private includeSerdeLayer: boolean;

constructor({ packageId, service, endpoint, includeSerdeLayer }: GeneratedExpressEndpointTypeSchemasImpl.Init) {
private allowExtraFields: boolean;

constructor({
packageId,
service,
endpoint,
includeSerdeLayer,
allowExtraFields
}: GeneratedExpressEndpointTypeSchemasImpl.Init) {
this.endpoint = endpoint;
this.includeSerdeLayer = includeSerdeLayer;
this.allowExtraFields = allowExtraFields;

if (includeSerdeLayer) {
// only generate request schemas for referenced request bodies. inlined
Expand Down Expand Up @@ -162,11 +171,9 @@ export class GeneratedExpressEndpointTypeSchemasImpl implements GeneratedExpress
return context.typeSchema
.getSchemaOfNamedType(this.endpoint.response.value.responseBodyType, { isGeneratingSchema: false })
.jsonOrThrow(referenceToParsedResponse, {
unrecognizedObjectKeys: "strip",
allowUnrecognizedEnumValues: false,
allowUnrecognizedUnionMembers: false,
skipValidation: false,
breadcrumbsPrefix: []
...getSchemaOptions({
allowExtraFields: this.allowExtraFields
})
});
case "primitive":
case "container":
Expand All @@ -176,11 +183,9 @@ export class GeneratedExpressEndpointTypeSchemasImpl implements GeneratedExpress
return this.generatedResponseSchema
.getReferenceToZurgSchema(context)
.jsonOrThrow(referenceToParsedResponse, {
unrecognizedObjectKeys: "strip",
allowUnrecognizedEnumValues: false,
allowUnrecognizedUnionMembers: false,
skipValidation: false,
breadcrumbsPrefix: []
...getSchemaOptions({
allowExtraFields: this.allowExtraFields
})
});
default:
assertNever(this.endpoint.response.value.responseBodyType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GeneratedExpressErrorSchemaImpl } from "./GeneratedExpressErrorSchemaIm
export declare namespace ExpressErrorSchemaGenerator {
export interface Init {
includeSerdeLayer: boolean;
allowExtraFields: boolean;
}

export namespace generateError {
Expand All @@ -17,9 +18,11 @@ export declare namespace ExpressErrorSchemaGenerator {

export class ExpressErrorSchemaGenerator {
private includeSerdeLayer: boolean;
private allowExtraFields: boolean;

constructor({ includeSerdeLayer }: ExpressErrorSchemaGenerator.Init) {
constructor({ includeSerdeLayer, allowExtraFields }: ExpressErrorSchemaGenerator.Init) {
this.includeSerdeLayer = includeSerdeLayer;
this.allowExtraFields = allowExtraFields;
}

public generateExpressErrorSchema({
Expand All @@ -33,7 +36,8 @@ export class ExpressErrorSchemaGenerator {
errorDeclaration,
type: errorDeclaration.type,
errorName,
includeSerdeLayer: this.includeSerdeLayer
includeSerdeLayer: this.includeSerdeLayer,
allowExtraFields: this.allowExtraFields
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertNever } from "@fern-api/core-utils";
import { ErrorDeclaration, TypeReference } from "@fern-fern/ir-sdk/api";
import { AbstractGeneratedSchema } from "@fern-typescript/abstract-schema-generator";
import { getTextOfTsNode, Reference, Zurg } from "@fern-typescript/commons";
import { getSchemaOptions, getTextOfTsNode, Reference, Zurg } from "@fern-typescript/commons";
import { ExpressContext, GeneratedExpressErrorSchema } from "@fern-typescript/contexts";
import { ModuleDeclaration, ts } from "ts-morph";

Expand All @@ -11,6 +11,7 @@ export declare namespace GeneratedExpressErrorSchemaImpl {
errorDeclaration: ErrorDeclaration;
type: TypeReference;
includeSerdeLayer: boolean;
allowExtraFields: boolean;
}
}

Expand All @@ -21,12 +22,20 @@ export class GeneratedExpressErrorSchemaImpl
private errorDeclaration: ErrorDeclaration;
private type: TypeReference;
private includeSerdeLayer: boolean;
private allowExtraFields: boolean;

constructor({ errorName, errorDeclaration, type, includeSerdeLayer }: GeneratedExpressErrorSchemaImpl.Init) {
constructor({
errorName,
errorDeclaration,
type,
includeSerdeLayer,
allowExtraFields
}: GeneratedExpressErrorSchemaImpl.Init) {
super({ typeName: errorName });
this.errorDeclaration = errorDeclaration;
this.type = type;
this.includeSerdeLayer = includeSerdeLayer;
this.allowExtraFields = allowExtraFields;
}

public writeToFile(context: ExpressContext): void {
Expand Down Expand Up @@ -62,22 +71,18 @@ export class GeneratedExpressErrorSchemaImpl
return context.typeSchema
.getSchemaOfNamedType(this.type, { isGeneratingSchema: false })
.jsonOrThrow(referenceToBody, {
allowUnrecognizedEnumValues: false,
allowUnrecognizedUnionMembers: false,
unrecognizedObjectKeys: "strip",
skipValidation: false,
breadcrumbsPrefix: []
...getSchemaOptions({
allowExtraFields: this.allowExtraFields
})
});
case "unknown":
return referenceToBody;
case "primitive":
case "container":
return this.getReferenceToZurgSchema(context).jsonOrThrow(referenceToBody, {
allowUnrecognizedEnumValues: false,
allowUnrecognizedUnionMembers: false,
unrecognizedObjectKeys: "strip",
skipValidation: false,
breadcrumbsPrefix: []
...getSchemaOptions({
allowExtraFields: this.allowExtraFields
})
});
default:
assertNever(this.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export declare namespace ExpressGenerator {
includeSerdeLayer: boolean;
outputEsm: boolean;
retainOriginalCasing: boolean;
allowExtraFields: boolean;
}
}

Expand Down Expand Up @@ -194,7 +195,8 @@ export class ExpressGenerator {
includeSerdeLayer: config.includeSerdeLayer
});
this.expressEndpointTypeSchemasGenerator = new ExpressEndpointTypeSchemasGenerator({
includeSerdeLayer: config.includeSerdeLayer
includeSerdeLayer: config.includeSerdeLayer,
allowExtraFields: config.allowExtraFields
});
this.expressServiceGenerator = new ExpressServiceGenerator({
packageResolver: this.packageResolver,
Expand All @@ -210,7 +212,8 @@ export class ExpressGenerator {
this.genericApiExpressErrorGenerator = new GenericAPIExpressErrorGenerator();
this.expressErrorGenerator = new ExpressErrorGenerator();
this.expressErrorSchemaGenerator = new ExpressErrorSchemaGenerator({
includeSerdeLayer: config.includeSerdeLayer
includeSerdeLayer: config.includeSerdeLayer,
allowExtraFields: config.allowExtraFields
});
}

Expand Down
12 changes: 12 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.14.0-rc0] - 2024-04-12

- Feature: Add `allowExtraFields` option to permit extra fields in the serialized request.

```yaml
- name: fernapi/fern-typscript-node-sdk
version: 0.14.0-rc0
...
config:
allowExtraFields: true
```
## [0.13.0] - 2024-04-09
- Support V37 of the IR.
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.0
0.14.0-rc0
6 changes: 4 additions & 2 deletions generators/typescript/sdk/cli/src/SdkGeneratorCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export class SdkGeneratorCli extends AbstractGeneratorCli<SdkCustomConfig> {
noOptionalProperties: parsed?.noOptionalProperties ?? false,
includeApiReference: parsed?.includeApiReference ?? false,
tolerateRepublish: parsed?.tolerateRepublish ?? false,
retainOriginalCasing: parsed?.retainOriginalCasing ?? false
retainOriginalCasing: parsed?.retainOriginalCasing ?? false,
allowExtraFields: parsed?.allowExtraFields ?? false
};
}

Expand Down Expand Up @@ -103,7 +104,8 @@ export class SdkGeneratorCli extends AbstractGeneratorCli<SdkCustomConfig> {
retainOriginalCasing: customConfig.retainOriginalCasing ?? false,
noOptionalProperties: customConfig.noOptionalProperties,
includeApiReference: customConfig.includeApiReference ?? false,
tolerateRepublish: customConfig.tolerateRepublish
tolerateRepublish: customConfig.tolerateRepublish,
allowExtraFields: customConfig.allowExtraFields ?? false
}
});
const typescriptProject = await sdkGenerator.generate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ export interface SdkCustomConfig {
includeApiReference: boolean | undefined;
tolerateRepublish: boolean;
retainOriginalCasing: boolean | undefined;
allowExtraFields: boolean | undefined;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const SdkCustomConfigSchema = z.strictObject({
includeOtherInUnionTypes: z.optional(z.boolean()),
includeApiReference: z.optional(z.boolean()),
retainOriginalCasing: z.optional(z.boolean()),
allowExtraFields: z.optional(z.boolean()),

// deprecated
timeoutInSeconds: z.optional(z.union([z.literal("infinity"), z.number()]))
Expand Down
7 changes: 5 additions & 2 deletions generators/typescript/sdk/generator/src/SdkGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export declare namespace SdkGenerator {
includeApiReference: boolean;
tolerateRepublish: boolean;
retainOriginalCasing: boolean;
allowExtraFields: boolean;
}
}

Expand Down Expand Up @@ -271,7 +272,8 @@ export class SdkGenerator {
intermediateRepresentation,
shouldGenerateErrors: config.neverThrowErrors,
skipResponseValidation: config.skipResponseValidation,
includeSerdeLayer: config.includeSerdeLayer
includeSerdeLayer: config.includeSerdeLayer,
allowExtraFields: config.allowExtraFields
});
this.requestWrapperGenerator = new RequestWrapperGenerator();
this.environmentsGenerator = new EnvironmentsGenerator();
Expand All @@ -293,7 +295,8 @@ export class SdkGenerator {
this.genericAPISdkErrorGenerator = new GenericAPISdkErrorGenerator();
this.timeoutSdkErrorGenerator = new TimeoutSdkErrorGenerator();
this.sdkInlinedRequestBodySchemaGenerator = new SdkInlinedRequestBodySchemaGenerator({
includeSerdeLayer: config.includeSerdeLayer
includeSerdeLayer: config.includeSerdeLayer,
allowExtraFields: config.allowExtraFields
});
this.jestTestGenerator = new JestTestGenerator(
intermediateRepresentation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const Mocks = {
includeApiReference: false,
tolerateRepublish: false,
retainOriginalCasing: false,
allowExtraFields: false,
...partialConfig
};
}
Expand Down
Loading

0 comments on commit fcdb463

Please sign in to comment.