Skip to content

Commit

Permalink
(feature, typescript): Generarte API version scheme (#4071)
Browse files Browse the repository at this point in the history
  • Loading branch information
amckinney authored Jul 17, 2024
1 parent f6de375 commit 56797ee
Show file tree
Hide file tree
Showing 276 changed files with 6,652 additions and 239 deletions.
72 changes: 36 additions & 36 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 4 additions & 0 deletions generators/typescript/express/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ 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.17.2] - 2024-07-16

- Internal: Upgrade to IRv48.

## [0.17.1] - 2024-07-10

- Fix: This fixes a bug introduced in `0.17.0-rc0` that prevented the SDK from serializing types
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.17.1
0.17.2
2 changes: 1 addition & 1 deletion generators/typescript/express/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"devDependencies": {
"@fern-fern/generator-exec-sdk": "^0.0.898",
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -27,7 +27,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -190,6 +190,9 @@ export class GeneratedExpressEndpointTypeSchemasImpl implements GeneratedExpress
if (this.endpoint.response.body?.type === "streaming") {
throw new Error("Streaming response is not supported");
}
if (this.endpoint.response.body?.type === "streamParameter") {
throw new Error("Streaming response is not supported");
}
if (this.endpoint.response.body?.type === "text") {
throw new Error("Text response is not supported");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -27,7 +27,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -930,6 +930,9 @@ export class GeneratedExpressServiceImpl implements GeneratedExpressService {
streaming: () => {
throw new Error("Streaming is not supported");
},
streamParameter: () => {
throw new Error("Streaming is not supported");
},
fileDownload: () => {
throw new Error("File download is not supported");
},
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 @@ -28,7 +28,7 @@
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-api/fs-utils": "workspace:*",
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/express-endpoint-type-schemas-generator": "workspace:*",
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 @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -27,7 +27,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -27,7 +27,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.0",
"@fern-typescript/abstract-schema-generator": "workspace:*",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
Expand Down
45 changes: 44 additions & 1 deletion generators/typescript/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,50 @@ 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.33.0] - 2024-07-15
## [0.34.0] - 2024-07-16

- Internal: Upgrade to IRv50.
- Feature: Add support for generating an API version scheme in `version.ts`.
Consider the following `api.yml` configuration:

```yaml
version:
header: X-API-Version
default: "1.0.0"
values:
- "1.0.0-alpha"
- "1.0.0-beta"
- "1.0.0"
```
The following `version.ts` file is generated:

```typescript
/**
* This file was auto-generated by Fern from our API Definition.
*/
/** The version of the API, sent as the X-API-Version header. */
export type AcmeVersion = "1.0.0" | "2.0.0" | "latest";
```

If a default value is specified, it is set on every request but can be overridden
in either the client-level `Options` or call-specific `RequestOptions`. If a default
value is _not_ specified, the value of the header is required on the generated `Options`.

An example call is shown below:

```typescript
import { AcmeClient } from "acme";
const client = new AcmeClient({ apiKey: "YOUR_API_KEY", xApiVersion: "2.0.0" });
await client.users.create({
firstName: "john",
lastName: "doe"
});
```

## [0.33.0] - 2024-07-16

- Fix: This release comes with numerous improvements to multipart uploads:

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.33.0
0.34.0
2 changes: 1 addition & 1 deletion generators/typescript/sdk/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"devDependencies": {
"@fern-api/fs-utils": "workspace:*",
"@fern-api/generator-commons": "workspace:*",
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -27,7 +27,7 @@
},
"dependencies": {
"@fern-api/core-utils": "workspace:*",
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.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 @@ -269,6 +269,23 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
retainOriginalCasing: this.retainOriginalCasing,
omitUndefined: this.omitUndefined
}),
streamParameter: (streamParameter) =>
// TODO(amckinney): For now we just generate the stream variant of the endpoint.
// We need to implement both the non-streaming and streaming variants.
new GeneratedStreamingEndpointImplementation({
packageId,
endpoint,
generatedSdkClientClass: this,
includeCredentialsOnCrossOriginRequests,
response: getGeneratedEndpointResponse({
response: HttpResponseBody.streaming(streamParameter.streamResponse)
}),
defaultTimeoutInSeconds,
request: getGeneratedEndpointRequest(),
includeSerdeLayer,
retainOriginalCasing: this.retainOriginalCasing,
omitUndefined: this.omitUndefined
}),
text: (textResponse) => {
return getDefaultEndpointImplementation({
response: HttpResponseBody.text(textResponse)
Expand Down Expand Up @@ -797,6 +814,57 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
);
}

const generatedVersion = context.version.getGeneratedVersion();
if (generatedVersion != null) {
const header = generatedVersion.getHeader();
const headerName = this.getOptionKeyForHeader(header);
const defaultVersion = generatedVersion.getDefaultVersion();

let value: ts.Expression;
if (defaultVersion != null) {
value = ts.factory.createBinaryExpression(
ts.factory.createPropertyAccessChain(
ts.factory.createIdentifier(REQUEST_OPTIONS_PARAMETER_NAME),
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
ts.factory.createIdentifier(headerName)
),
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
ts.factory.createBinaryExpression(
ts.factory.createPropertyAccessChain(
ts.factory.createPropertyAccessExpression(
ts.factory.createThis(),
GeneratedSdkClientClassImpl.OPTIONS_PRIVATE_MEMBER
),
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
ts.factory.createIdentifier(headerName)
),
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
ts.factory.createStringLiteral(defaultVersion)
)
);
} else {
value = ts.factory.createBinaryExpression(
ts.factory.createPropertyAccessChain(
ts.factory.createIdentifier(REQUEST_OPTIONS_PARAMETER_NAME),
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
ts.factory.createIdentifier(headerName)
),
ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken),
ts.factory.createPropertyAccessExpression(
ts.factory.createPropertyAccessExpression(
ts.factory.createThis(),
GeneratedSdkClientClassImpl.OPTIONS_PRIVATE_MEMBER
),
ts.factory.createIdentifier(headerName)
)
);
}
headers.push({
header: header.name.wireValue,
value
});
}

headers.push(
{
header: "X-Fern-Runtime",
Expand All @@ -822,7 +890,7 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
}

private generateRequestOptionsInterface(context: SdkContext): OptionalKind<InterfaceDeclarationStructure> {
return {
const requestOptions = {
name: GeneratedSdkClientClassImpl.REQUEST_OPTIONS_INTERFACE_NAME,
properties: [
{
Expand Down Expand Up @@ -853,6 +921,18 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
})
]
};

const generatedVersion = context.version.getGeneratedVersion();
if (generatedVersion != null) {
const header = generatedVersion.getHeader();
requestOptions.properties.push({
name: this.getOptionKeyForHeader(header),
type: generatedVersion.getEnumValueUnion(),
hasQuestionToken: true,
docs: [`Override the ${header.name.wireValue} header`]
});
}
return requestOptions;
}

/******************************
Expand Down Expand Up @@ -964,6 +1044,17 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
}
}

const generatedVersion = context.version.getGeneratedVersion();
if (generatedVersion != null && !generatedVersion.hasDefaultVersion()) {
const header = generatedVersion.getHeader();
properties.push(
ts.factory.createPropertyAssignment(
this.getOptionKeyForHeader(header),
ts.factory.createStringLiteral(generatedVersion.getFirstEnumValue())
)
);
}

return properties;
}

Expand Down Expand Up @@ -1144,6 +1235,17 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass {
}
}

const generatedVersion = context.version.getGeneratedVersion();
if (generatedVersion != null) {
const header = generatedVersion.getHeader();
properties.push({
name: this.getOptionKeyForHeader(header),
type: generatedVersion.getEnumValueUnion(),
hasQuestionToken: generatedVersion.hasDefaultVersion(),
docs: [`Override the ${header.name.wireValue} header`]
});
}

if (this.allowCustomFetcher) {
properties.push({
name: GeneratedSdkClientClassImpl.CUSTOM_FETCHER_PROPERTY_NAME,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"depcheck": "depcheck"
},
"dependencies": {
"@fern-fern/ir-sdk": "48.1.0",
"@fern-fern/ir-sdk": "50.2.0",
"@fern-typescript/commons": "workspace:*",
"@fern-typescript/contexts": "workspace:*",
"@fern-typescript/resolvers": "workspace:*",
Expand Down
Loading

0 comments on commit 56797ee

Please sign in to comment.