Skip to content

Commit

Permalink
Add error constants to IR (#815)
Browse files Browse the repository at this point in the history
* Add error constants to IR

* string -> wire string

* Add doc
  • Loading branch information
zachkirsch authored Oct 13, 2022
1 parent ad0f881 commit 1d1a924
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 27 deletions.
16 changes: 8 additions & 8 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
2 changes: 1 addition & 1 deletion fern/fern.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"organization": "fern",
"version": "0.0.208"
"version": "0.0.211"
}
12 changes: 12 additions & 0 deletions fern/ir-types/definition/constants.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/fern-api/fern/main/fern.schema.json
imports:
commons: commons.yml
types:
Constants:
properties:
errors: ErrorConstants
ErrorConstants:
properties:
errorDiscriminant: commons.WireStringWithAllCasings
errorInstanceIdKey: commons.WireStringWithAllCasings
errorContentKey: commons.WireStringWithAllCasings
6 changes: 5 additions & 1 deletion fern/ir-types/definition/ir.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ imports:
serviceCommons: services/commons.yml
http: services/http.yml
websocket: services/websocket.yml
constants: constants.yml
types:
IntermediateRepresentation:
docs: "Complete representation of the API schema"
Expand All @@ -20,7 +21,10 @@ types:
docs: "The services exposed by this API"
type: Services
errors: list<errors.ErrorDeclaration>
constants: FernConstants
constants:
type: FernConstants
docs: this is deprecated. use constantsV2
constantsV2: constants.Constants
Services:
properties:
http: list<http.HttpService>
Expand Down
9 changes: 7 additions & 2 deletions fern/ir-types/definition/services/commons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@ types:
error: errors.DeclaredErrorName

ResponseErrorsV2:
docs: this is deprecated. use ResponseErrors. Yes, this is weird.
properties:
discriminant: commons.WireStringWithAllCasings
types: list<ResponseErrorV2>
ResponseErrorV2:
extends: commons.WithDocs
properties:
discriminantValue: commons.WireStringWithAllCasings
shape: ResponseErrorShape
discriminantValue:
type: commons.WireStringWithAllCasings
docs: this is deprecated. use the discriminant value on the error declaration.
shape:
type: ResponseErrorShape
docs: this is deprecated. if the error has a type, then use the errorBody constant.
ResponseErrorShape:
union:
singleProperty: SingleResponseErrorProperty
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@fern-api/validator": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"@fern-fern/fiddle-client": "^0.0.49",
"@fern-fern/ir-model": "0.0.237",
"@fern-fern/ir-model": "0.0.241",
"ansi-escapes": "^5.0.0",
"boxen": "^7.0.0",
"chalk": "^5.0.1",
Expand Down
28 changes: 28 additions & 0 deletions packages/cli/ete-tests/src/tests/ir/__snapshots__/ir.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,34 @@ exports[`ir simple 1`] = `
"errorDiscriminant": "_error",
"errorInstanceIdKey": "_errorInstanceId",
"unknownErrorDiscriminantValue": "_unknown"
},
"constantsV2": {
"errors": {
"errorDiscriminant": {
"originalValue": "error",
"camelCase": "error",
"snakeCase": "error",
"pascalCase": "Error",
"screamingSnakeCase": "ERROR",
"wireValue": "error"
},
"errorInstanceIdKey": {
"originalValue": "errorInstanceId",
"camelCase": "errorInstanceId",
"snakeCase": "error_instance_id",
"pascalCase": "ErrorInstanceId",
"screamingSnakeCase": "ERROR_INSTANCE_ID",
"wireValue": "errorInstanceId"
},
"errorContentKey": {
"originalValue": "content",
"camelCase": "content",
"snakeCase": "content",
"pascalCase": "Content",
"screamingSnakeCase": "CONTENT",
"wireValue": "content"
}
}
}
}"
`;
2 changes: 1 addition & 1 deletion packages/cli/generation/ir-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@fern-api/core-utils": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"@fern-api/yaml-schema": "workspace:*",
"@fern-fern/ir-model": "0.0.237",
"@fern-fern/ir-model": "0.0.241",
"lodash-es": "^4.17.21"
},
"devDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions packages/cli/generation/ir-generator/src/FernConstants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import { Constants } from "@fern-fern/ir-model/constants";
import { FernConstants } from "@fern-fern/ir-model/ir";
import { generateWireStringWithAllCasings } from "./utils/generateCasings";

export const FERN_CONSTANTS: FernConstants = {
errorDiscriminant: "_error",
errorInstanceIdKey: "_errorInstanceId",
unknownErrorDiscriminantValue: "_unknown",
};

export const FERN_CONSTANTS_V2: Constants = {
errors: {
errorDiscriminant: generateWireStringWithAllCasings({ wireValue: "error", name: "error" }),
errorInstanceIdKey: generateWireStringWithAllCasings({ wireValue: "errorInstanceId", name: "errorInstanceId" }),
errorContentKey: generateWireStringWithAllCasings({ wireValue: "content", name: "content" }),
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { convertErrorDeclaration } from "./converters/convertErrorDeclaration";
import { convertHttpService } from "./converters/services/convertHttpService";
import { convertWebsocketChannel } from "./converters/services/convertWebsocketChannel";
import { convertTypeDeclaration } from "./converters/type-declarations/convertTypeDeclaration";
import { FERN_CONSTANTS } from "./FernConstants";
import { FERN_CONSTANTS, FERN_CONSTANTS_V2 } from "./FernConstants";
import { constructFernFileContext, FernFileContext } from "./FernFileContext";
import { ErrorResolverImpl } from "./resolvers/ErrorResolver";
import { TypeResolverImpl } from "./resolvers/TypeResolver";
Expand All @@ -31,6 +31,7 @@ export async function generateIntermediateRepresentation(workspace: Workspace):
websocket: [],
},
constants: FERN_CONSTANTS,
constantsV2: FERN_CONSTANTS_V2,
};

const typeResolver = new TypeResolverImpl(workspace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@fern-api/generators-configuration": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"@fern-fern/generator-exec-client": "0.0.5",
"@fern-fern/ir-model": "0.0.237",
"@fern-fern/ir-model": "0.0.241",
"tmp-promise": "^3.0.3"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@fern-api/task-context": "workspace:*",
"@fern-api/workspace-loader": "workspace:*",
"@fern-fern/fiddle-client": "^0.0.49",
"@fern-fern/ir-model": "0.0.237",
"@fern-fern/ir-model": "0.0.241",
"axios": "^0.27.2",
"chalk": "^5.0.1",
"decompress": "^4.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/yaml/yaml-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-model": "0.0.237",
"@fern-fern/ir-model": "0.0.241",
"zod": "^3.14.3"
},
"devDependencies": {
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3175,7 +3175,7 @@ __metadata:
"@fern-api/validator": "workspace:*"
"@fern-api/workspace-loader": "workspace:*"
"@fern-fern/fiddle-client": ^0.0.49
"@fern-fern/ir-model": 0.0.237
"@fern-fern/ir-model": 0.0.241
"@types/boxen": ^3.0.1
"@types/inquirer": ^9.0.1
"@types/is-ci": ^3.0.0
Expand Down Expand Up @@ -3420,7 +3420,7 @@ __metadata:
"@fern-api/core-utils": "workspace:*"
"@fern-api/workspace-loader": "workspace:*"
"@fern-api/yaml-schema": "workspace:*"
"@fern-fern/ir-model": 0.0.237
"@fern-fern/ir-model": 0.0.241
"@types/jest": ^29.0.3
"@types/lodash-es": ^4.17.6
"@types/node": ^18.7.18
Expand Down Expand Up @@ -3487,7 +3487,7 @@ __metadata:
"@fern-api/generators-configuration": "workspace:*"
"@fern-api/workspace-loader": "workspace:*"
"@fern-fern/generator-exec-client": 0.0.5
"@fern-fern/ir-model": 0.0.237
"@fern-fern/ir-model": 0.0.241
"@types/jest": ^29.0.3
"@types/node": ^18.7.18
"@types/tmp": ^0.2.3
Expand Down Expand Up @@ -3677,7 +3677,7 @@ __metadata:
"@fern-api/task-context": "workspace:*"
"@fern-api/workspace-loader": "workspace:*"
"@fern-fern/fiddle-client": ^0.0.49
"@fern-fern/ir-model": 0.0.237
"@fern-fern/ir-model": 0.0.241
"@types/decompress": ^4.2.4
"@types/jest": ^29.0.3
"@types/lodash-es": ^4.17.6
Expand Down Expand Up @@ -3827,7 +3827,7 @@ __metadata:
"@babel/preset-env": ^7.19.1
"@babel/preset-typescript": ^7.18.6
"@fern-api/core-utils": "workspace:*"
"@fern-fern/ir-model": 0.0.237
"@fern-fern/ir-model": 0.0.241
"@types/jest": ^29.0.3
"@types/node": ^18.7.18
depcheck: ^1.4.3
Expand Down Expand Up @@ -3863,10 +3863,10 @@ __metadata:
languageName: node
linkType: hard

"@fern-fern/ir-model@npm:0.0.237":
version: 0.0.237
resolution: "@fern-fern/ir-model@npm:0.0.237"
checksum: 65a74f889cb87954aa9e2e6f6c3d6f5f269cd568c32b28ae4f14899b2d6fc4c7f0fd1d13f0d81845a02f7349c633094859016053fa84e6526366c8ac6c22e981
"@fern-fern/ir-model@npm:0.0.241":
version: 0.0.241
resolution: "@fern-fern/ir-model@npm:0.0.241"
checksum: 8098b61521022b535c8a44ded72bd7c072078ad75dd4dc950d7c8b332a6eec6aba5f831f0d57fe7eca3e10c53c30ad5270c70cd7bdfc4829f5caeac64381b24d
languageName: node
linkType: hard

Expand Down

0 comments on commit 1d1a924

Please sign in to comment.