Skip to content

Commit

Permalink
fix(typescript): respect noSerde layer when generating date examples (
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Aug 23, 2024
1 parent d9308ac commit 77adb52
Show file tree
Hide file tree
Showing 347 changed files with 8,886 additions and 261 deletions.
2 changes: 1 addition & 1 deletion generators/typescript/express/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"devDependencies": {
"@fern-fern/generator-exec-sdk": "^0.0.898",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-generator-cli": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-error-class-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/express/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/express-endpoint-type-schemas-generator": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class ExpressContextImpl implements ExpressContext {
public readonly externalDependencies: ExternalDependencies;
public readonly coreUtilities: CoreUtilities;
public readonly fernConstants: Constants;
public readonly includeSerdeLayer: boolean;

public readonly type: TypeContextImpl;
public readonly typeSchema: TypeSchemaContextImpl;
Expand Down Expand Up @@ -131,6 +132,7 @@ export class ExpressContextImpl implements ExpressContext {
includeSerdeLayer,
retainOriginalCasing
}: ExpressContextImpl.Init) {
this.includeSerdeLayer = includeSerdeLayer;
this.sourceFile = sourceFile;
this.externalDependencies = createExternalDependencies({
dependencyManager,
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/model/type-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/union-generator": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,15 @@ export class GeneratedTypeReferenceExampleImpl implements GeneratedTypeReference
base64: (base64Example) => ts.factory.createStringLiteral(base64Example),
boolean: (booleanExample) => (booleanExample ? ts.factory.createTrue() : ts.factory.createFalse()),
uuid: (uuidExample) => ts.factory.createStringLiteral(uuidExample),
datetime: (datetimeExample) =>
ts.factory.createNewExpression(ts.factory.createIdentifier("Date"), undefined, [
ts.factory.createStringLiteral(datetimeExample.toISOString())
]),
datetime: (datetimeExample) => {
if (context.includeSerdeLayer != null && datetimeExample.raw != null) {
return ts.factory.createStringLiteral(datetimeExample.raw);
} else {
return ts.factory.createNewExpression(ts.factory.createIdentifier("Date"), undefined, [
ts.factory.createStringLiteral(datetimeExample.datetime.toISOString())
]);
}
},
date: (dateExample) => ts.factory.createStringLiteral(dateExample),
_other: () => {
throw new Error("Unknown primitive example: " + primitiveExample.type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/model/union-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
6 changes: 6 additions & 0 deletions generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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.39.5] - 2024-08-20

- Fix: If `noSerdeLayer` is enabled, then the generated TypeScript SDK snippets and wire tests
will not use `Date` objects but instead use strings. Without this fix, the generated
wire tests would result in failures.

## [0.39.4] - 2024-08-20

- Fix: Ensure that environment files don't generate, unless there is a valid environment available.
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.39.4
0.39.5
2 changes: 1 addition & 1 deletion generators/typescript/sdk/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"devDependencies": {
"@fern-api/fs-utils": "workspace:*",
"@fern-api/generator-commons": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-generator-cli": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@fern-api/logging-execa": "workspace:*",
"@fern-fern/generator-cli-sdk": "0.0.56",
"@fern-fern/generator-exec-sdk": "^0.0.898",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-fern/snippet-sdk": "^0.0.5526",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
3 changes: 2 additions & 1 deletion generators/typescript/sdk/generator/src/SdkGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ export class SdkGenerator {
ir: intermediateRepresentation,
dependencyManager: this.dependencyManager,
rootDirectory: this.rootDirectory,
writeUnitTests: this.config.writeUnitTests
writeUnitTests: this.config.writeUnitTests,
includeSerdeLayer: config.includeSerdeLayer
});
this.generatorCli = new GeneratorCli({
logger: context.logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export declare namespace JestTestGenerator {
ir: IR.IntermediateRepresentation;
dependencyManager: DependencyManager;
rootDirectory: Directory;
includeSerdeLayer: boolean;
writeUnitTests: boolean;
}
}
Expand All @@ -27,12 +28,14 @@ export class JestTestGenerator {
private dependencyManager: DependencyManager;
private rootDirectory: Directory;
private writeUnitTests: boolean;
private includeSerdeLayer: boolean;

constructor({ ir, dependencyManager, rootDirectory, writeUnitTests }: JestTestGenerator.Args) {
constructor({ ir, dependencyManager, rootDirectory, includeSerdeLayer, writeUnitTests }: JestTestGenerator.Args) {
this.ir = ir;
this.dependencyManager = dependencyManager;
this.rootDirectory = rootDirectory;
this.writeUnitTests = writeUnitTests;
this.includeSerdeLayer = includeSerdeLayer;
}

private addJestConfig(): void {
Expand Down Expand Up @@ -321,6 +324,8 @@ describe("test", () => {
// For certain complex types, we just JSON.parse/JSON.stringify to simplify some times
let shouldJsonParseStringify = false;

const includeSerdeLayer = this.includeSerdeLayer;

const getExpectedResponse = () => {
const body = getExampleTypeReferenceForResponse(example.response);
if (!body) {
Expand All @@ -341,7 +346,11 @@ describe("test", () => {
float: (value) => literalOf(value),
base64: (value) => literalOf(value),
bigInteger: (value) => literalOf(value),
datetime: (value) => code`new Date(${literalOf(value.toISOString())})`,
datetime: (value) => {
return includeSerdeLayer
? code`new Date(${literalOf(value.datetime.toISOString())})`
: literalOf(value.raw);
},
date: (value) => literalOf(value),
uuid: (value) => literalOf(value),
_other: (value) => literalOf(value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"ts-morph": "^15.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/sdk/sdk-error-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-error-class-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@fern-api/generator-commons": "workspace:*",
"@fern-api/logger": "workspace:*",
"@fern-fern/generator-exec-sdk": "^0.0.898",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/utils/commons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@fern-api/fs-utils": "workspace:*",
"@fern-api/logger": "workspace:*",
"@fern-api/logging-execa": "workspace:*",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/fetcher": "workspace:*",
"@fern-typescript/zurg": "workspace:*",
"decompress": "^4.2.1",
Expand Down
2 changes: 1 addition & 1 deletion generators/typescript/utils/contexts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"dependencies": {
"@fern-api/logger": "workspace:*",
"@fern-fern/generator-exec-sdk": "^0.0.898",
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*",
"ts-morph": "^15.1.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import { TypeSchemaContext } from "./type-schema";
export interface ModelContext extends BaseContext {
type: TypeContext;
typeSchema: TypeSchemaContext;
includeSerdeLayer: boolean;
}
2 changes: 1 addition & 1 deletion generators/typescript/utils/resolvers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "53.5.0",
"@fern-fern/ir-sdk": "53.8.0",
"@fern-typescript/commons": "workspace:*"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 77adb52

Please sign in to comment.