-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rohin/support-nulls-openapi
- Loading branch information
Showing
194 changed files
with
4,362 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
## 0.5.0 | ||
**`(feat):`** Add the `__toString()` magic method to all generated class types. | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 61 additions & 12 deletions
73
generators/browser-compatible-base/src/dynamic-snippets/AbstractDynamicSnippetsGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,70 @@ | ||
import { FernIr } from "@fern-api/dynamic-ir-sdk"; | ||
|
||
import { AbstractDynamicSnippetsGeneratorContext } from "./AbstractDynamicSnippetsGeneratorContext"; | ||
import { AbstractEndpointSnippetGenerator } from "./AbstractEndpointSnippetGenerator"; | ||
import { Result } from "./Result"; | ||
|
||
export abstract class AbstractDynamicSnippetsGenerator< | ||
Context extends AbstractDynamicSnippetsGeneratorContext, | ||
EndpointSnippetRequest, | ||
EndpointSnippetResponse | ||
EndpointSnippetGenerator extends AbstractEndpointSnippetGenerator<Context> | ||
> { | ||
public constructor(public readonly context: Context) {} | ||
|
||
/** | ||
* Generates code for the specified request. | ||
* @param request | ||
*/ | ||
public abstract generate(request: EndpointSnippetRequest): Promise<EndpointSnippetResponse>; | ||
protected abstract createSnippetGenerator(context: Context): EndpointSnippetGenerator; | ||
|
||
public async generate( | ||
request: FernIr.dynamic.EndpointSnippetRequest | ||
): Promise<FernIr.dynamic.EndpointSnippetResponse> { | ||
const endpoints = this.context.resolveEndpointLocationOrThrow(request.endpoint); | ||
if (endpoints.length === 0) { | ||
throw new Error(`No endpoints found that match "${request.endpoint.method} ${request.endpoint.path}"`); | ||
} | ||
const result = new Result(); | ||
for (const endpoint of endpoints) { | ||
const context = this.context.clone() as Context; | ||
const snippetGenerator = this.createSnippetGenerator(context); | ||
try { | ||
const snippet = await snippetGenerator.generateSnippet({ endpoint, request }); | ||
if (context.errors.empty()) { | ||
return { | ||
snippet, | ||
errors: undefined | ||
}; | ||
} | ||
result.update({ context, snippet }); | ||
} catch (error) { | ||
if (result.err == null) { | ||
result.err = error as Error; | ||
} | ||
} | ||
} | ||
return result.getResponseOrThrow({ endpoint: request.endpoint }); | ||
} | ||
|
||
/** | ||
* Generates code for the specified request. | ||
* @param request | ||
*/ | ||
public abstract generateSync(request: EndpointSnippetRequest): EndpointSnippetResponse; | ||
public generateSync(request: FernIr.dynamic.EndpointSnippetRequest): FernIr.dynamic.EndpointSnippetResponse { | ||
const endpoints = this.context.resolveEndpointLocationOrThrow(request.endpoint); | ||
if (endpoints.length === 0) { | ||
throw new Error(`No endpoints found that match "${request.endpoint.method} ${request.endpoint.path}"`); | ||
} | ||
const result = new Result(); | ||
for (const endpoint of endpoints) { | ||
const context = this.context.clone() as Context; | ||
const snippetGenerator = this.createSnippetGenerator(context); | ||
try { | ||
const snippet = snippetGenerator.generateSnippetSync({ endpoint, request }); | ||
if (context.errors.empty()) { | ||
return { | ||
snippet, | ||
errors: undefined | ||
}; | ||
} | ||
result.update({ context, snippet }); | ||
} catch (error) { | ||
if (result.err == null) { | ||
result.err = error as Error; | ||
} | ||
} | ||
} | ||
return result.getResponseOrThrow({ endpoint: request.endpoint }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
generators/browser-compatible-base/src/dynamic-snippets/AbstractEndpointSnippetGenerator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { FernIr } from "@fern-api/dynamic-ir-sdk"; | ||
|
||
import { AbstractDynamicSnippetsGeneratorContext } from "./AbstractDynamicSnippetsGeneratorContext"; | ||
|
||
export abstract class AbstractEndpointSnippetGenerator<Context extends AbstractDynamicSnippetsGeneratorContext> { | ||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
public constructor({ context }: { context: Context }) { | ||
// eslint-disable-line @typescript-eslint/no-useless-constructor | ||
} | ||
|
||
public abstract generateSnippet({ | ||
endpoint, | ||
request | ||
}: { | ||
endpoint: FernIr.dynamic.Endpoint; | ||
request: FernIr.dynamic.EndpointSnippetRequest; | ||
}): Promise<string>; | ||
|
||
public abstract generateSnippetSync({ | ||
endpoint, | ||
request | ||
}: { | ||
endpoint: FernIr.dynamic.Endpoint; | ||
request: FernIr.dynamic.EndpointSnippetRequest; | ||
}): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.