Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo committed Sep 17, 2024
2 parents f34338d + 58b8452 commit c4fde91
Show file tree
Hide file tree
Showing 4,953 changed files with 248,612 additions and 6,251 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
71 changes: 70 additions & 1 deletion .github/workflows/seed.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: seed

on:
push:
branches:
- main
pull_request:
branches:
- main
Expand All @@ -24,6 +27,7 @@ jobs:
typescript: ${{ steps.filter.outputs.typescript }}
go: ${{ steps.filter.outputs.go }}
csharp: ${{ steps.filter.outputs.csharp }}
php: ${{ steps.filter.outputs.php }}
steps:
- uses: actions/checkout@v2
- uses: dorny/paths-filter@v2
Expand Down Expand Up @@ -69,7 +73,10 @@ jobs:
- 'generators/csharp/**'
- seed/csharp-sdk/seed.yml
- seed/csharp-model/seed.yml
php:
- 'generators/php/**'
- seed/php-sdk/seed.yml
- seed/php-model/seed.yml
ruby-model:
runs-on: ubuntu-latest
needs: changes
Expand Down Expand Up @@ -617,3 +624,65 @@ jobs:
- name: Ensure no changes to git-tracked files
run: git --no-pager diff --exit-code -- ":(exclude)seed/*/.mock/*"

php-model:
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.php == 'true' || needs.changes.outputs.seed == 'true' }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install
uses: ./.github/actions/install

- uses: bufbuild/[email protected]
with:
github_token: ${{ github.token }}

- uses: actions/setup-go@v5
with:
go-version: "stable"

- name: Install protoc-gen-openapi
run: go install github.com/google/gnostic/cmd/[email protected]

- name: Seed Test
env:
FORCE_COLOR: "2"
run: |
pnpm seed:local test --generator php-model --parallel 16
- name: Ensure no changes to git-tracked files
run: git --no-pager diff --exit-code -- ":(exclude)seed/*/.mock/*"

php-sdk:
runs-on: ubuntu-latest
needs: changes
if: ${{ needs.changes.outputs.php == 'true' || needs.changes.outputs.seed == 'true' }}
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Install
uses: ./.github/actions/install

- uses: bufbuild/[email protected]
with:
github_token: ${{ github.token }}

- uses: actions/setup-go@v5
with:
go-version: "stable"

- name: Install protoc-gen-openapi
run: go install github.com/google/gnostic/cmd/[email protected]

- name: Seed Test
env:
FORCE_COLOR: "2"
run: |
pnpm seed:local test --generator php-sdk --parallel 16
- name: Ensure no changes to git-tracked files
run: git --no-pager diff --exit-code -- ":(exclude)seed/*/.mock/*"
64 changes: 40 additions & 24 deletions docker/seed/Dockerfile.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
FROM node:lts-slim as base
FROM node:lts-slim

FROM base AS builder
RUN yarn add \
# jest
jest@29.7.0 \
@types/jest@29.5.5 \
# node fetch
node-fetch@2.7.0 \
@types/node-fetch@2.6.9 \
# node
@types/node@17.0.33 \
# qs
qs@6.11.2 \
@types/qs@6.9.8 \
# url join
url-join@4.0.1 \
@types/url-join@4.0.1 \
# readable stream
readable-stream@4.5.2 \
@types/readable-stream@4.0.15 \
# form data
form-data@4.0.0 \
# formdata-node
formdata-node@6.0.3 \
# jest env jsdom
jest-environment-jsdom@29.7.0 \
# js base64
"[email protected]" \
# prettier
prettier@2.7.1 \
# ts jest
ts-jest@29.1.1 \
# typescript
"[email protected]" \
# form data encoder
form-data-encoder@4.0.2 \
# webpack
ts-loader@9.3.1 \
webpack@5.94.0 \
# fetch mock jest
fetch-mock-jest@1.5.1

RUN mkdir /yarn-cache-template
RUN yarn config set cache-folder /yarn-cache-template
RUN yarn add \
@types/jest@29.5.5 \
@types/node-fetch@2.6.9 \
@types/node@17.0.33 \
@types/qs@6.9.8 \
@types/url-join@4.0.1 \
form-data@4.0.0 \
jest-environment-jsdom@29.7.0 \
jest@29.7.0 \
js-base64@3.7.2 \
node-fetch@2.7.0 \
prettier@2.7.1 \
qs@6.11.2 \
ts-jest@29.1.1 \
typescript@4.6.4 \
url-join@4.0.1

FROM base AS runner

COPY --from=builder /yarn-cache-template /yarn-cache-template
# Installs tsc
RUN npm install -g typescript

Expand Down
2 changes: 1 addition & 1 deletion fern/pages/fern-docs/config/sdk-snippets.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ groups:
</Callout>

### Add the package name to your docs configuration
Add the package name for the corresponding SDK to your `docs.yml` file. For Go, use the exact URL where the SDK repository is located.

<CodeBlock title="docs.yml">
```yaml
Expand All @@ -65,7 +66,6 @@ navigation:
snippets:
python: your-package-name # <--- needs to match the naming in generators.yml
typescript: your-package-name
ruby: your-package-name
go: https://github.com/your-organization/your-repository # <--- needs the https://github.com/ prefix
```
</CodeBlock>
Expand Down
20 changes: 20 additions & 0 deletions generators/commons/src/ast/Argument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AbstractAstNode } from "./AbstractAstNode";

export type Argument = NamedArgument | UnnamedArgument;

export type Arguments = NamedArgument[] | UnnamedArgument[];

export interface NamedArgument {
name: string;
assignment: AbstractAstNode;
}

export type UnnamedArgument = AbstractAstNode;

export function isNamedArgument(argument: NamedArgument | UnnamedArgument): argument is NamedArgument {
return (argument as NamedArgument)?.name != null;
}

export function hasNamedArgument(arguments_: Arguments): boolean {
return arguments_.length > 0 && arguments_[0] != null && isNamedArgument(arguments_[0]);
}
8 changes: 8 additions & 0 deletions generators/commons/src/ast/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export { AbstractAstNode } from "./AbstractAstNode";
export { AbstractWriter } from "./AbstractWriter";
export { CodeBlock } from "./CodeBlock";
export {
type Argument,
type Arguments,
type NamedArgument,
type UnnamedArgument,
hasNamedArgument,
isNamedArgument
} from "./Argument";
1 change: 1 addition & 0 deletions generators/commons/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { getPackageName } from "./getPackageName";
export { getSdkVersion } from "./getSdkVersion";
export { parseGeneratorConfig } from "./parseGeneratorConfig";
export { parseIR } from "./parseIR";
4 changes: 2 additions & 2 deletions generators/commons/src/utils/parseGeneratorConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { readFile } from "fs/promises";
export async function parseGeneratorConfig(pathToConfig: string): Promise<FernGeneratorExec.GeneratorConfig> {
const configStr = await readFile(pathToConfig);
// eslint-disable-next-line no-console
console.log(`Read ${pathToConfig}`);
console.log(`Parsed ${pathToConfig}`);
const rawConfig = JSON.parse(configStr.toString());
const parsedConfig = await GeneratorExecParsing.GeneratorConfig.parse(rawConfig, {
unrecognizedObjectKeys: "passthrough"
});

if (!parsedConfig.ok) {
// eslint-disable-next-line no-console
console.log(`Failed to read ${pathToConfig}`);
console.log(`Failed to parse ${pathToConfig}`);
throw new Error("Failed to parse the generator configuration");
}

Expand Down
82 changes: 82 additions & 0 deletions generators/commons/src/utils/parseIR.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { AbsoluteFilePath, streamObjectFromFile } from "@fern-api/fs-utils";

export declare namespace parseIR {
export interface Args<IntermediateRepresentation> {
absolutePathToIR: AbsoluteFilePath;
parse: (raw: unknown, opts?: SchemaOptions) => MaybePromise<MaybeValid<IntermediateRepresentation>>;
}

/* Copy some types across the IR SDKs */
export type MaybePromise<T> = T | Promise<T>;

export type MaybeValid<T> = Valid<T> | Invalid;

export interface Valid<T> {
ok: true;
value: T;
}

export interface Invalid {
ok: false;
errors: unknown[];
}

interface SchemaOptions {
/**
* how to handle unrecognized keys in objects
*
* @default "fail"
*/
unrecognizedObjectKeys?: "fail" | "passthrough" | "strip";
/**
* whether to fail when an unrecognized discriminant value is
* encountered in a union
*
* @default false
*/
allowUnrecognizedUnionMembers?: boolean;
/**
* whether to fail when an unrecognized enum value is encountered
*
* @default false
*/
allowUnrecognizedEnumValues?: boolean;
/**
* whether to allow data that doesn't conform to the schema.
* invalid data is passed through without transformation.
*
* when this is enabled, .parse() and .json() will always
* return `ok: true`. `.parseOrThrow()` and `.jsonOrThrow()`
* will never fail.
*
* @default false
*/
skipValidation?: boolean;
/**
* each validation failure contains a "path" property, which is
* the breadcrumbs to the offending node in the JSON. you can supply
* a prefix that is prepended to all the errors' paths. this can be
* helpful for zurg's internal debug logging.
*/
breadcrumbsPrefix?: string[];
}
}

export async function parseIR<IR>({ absolutePathToIR, parse }: parseIR.Args<IR>): Promise<IR> {
const irJson = await streamObjectFromFile(absolutePathToIR);
// eslint-disable-next-line no-console
console.log(`Parsed ${absolutePathToIR}`);
const parsedIR = await parse(irJson, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedEnumValues: true,
allowUnrecognizedUnionMembers: true
});

if (!parsedIR.ok) {
// eslint-disable-next-line no-console
console.log(`Failed to parse ${absolutePathToIR}`);
throw new Error(`Failed to parse IR: ${parsedIR.errors}`);
}

return parsedIR.value;
}
16 changes: 0 additions & 16 deletions generators/csharp/codegen/src/ast/Argument.ts

This file was deleted.

8 changes: 3 additions & 5 deletions generators/csharp/codegen/src/ast/ClassInstantiation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Arguments, isNamedArgument, NamedArgument, UnnamedArgument } from "./Argument";
import { Arguments, hasNamedArgument, isNamedArgument } from "@fern-api/generator-commons";
import { ClassReference } from "./ClassReference";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";
Expand All @@ -15,7 +15,7 @@ export declare namespace ClassInstantiation {

export class ClassInstantiation extends AstNode {
public readonly classReference: ClassReference;
public readonly arguments_: NamedArgument[] | UnnamedArgument[];
public readonly arguments_: Arguments;
private readonly forceUseConstructor: boolean;

constructor({ classReference, arguments_, forceUseConstructor }: ClassInstantiation.Args) {
Expand All @@ -33,9 +33,7 @@ export class ClassInstantiation extends AstNode {
writer.writeNode(this.classReference);
}

const hasNamedArguments =
this.arguments_.length > 0 && this.arguments_[0] != null && isNamedArgument(this.arguments_[0]);

const hasNamedArguments = hasNamedArgument(this.arguments_);
if (hasNamedArguments && !this.forceUseConstructor) {
writer.write("{ ");
} else {
Expand Down
2 changes: 1 addition & 1 deletion generators/csharp/codegen/src/ast/Dictionary.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assertNever } from "@fern-api/core-utils";
import { UnnamedArgument } from "./Argument";
import { UnnamedArgument } from "@fern-api/generator-commons";
import { AstNode } from "./core/AstNode";
import { Writer } from "./core/Writer";
import { Type } from "./Type";
Expand Down
1 change: 0 additions & 1 deletion generators/csharp/codegen/src/ast/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export { And } from "./And";
export { Annotation } from "./Annotation";
export { type Argument, type Arguments, type NamedArgument, type UnnamedArgument } from "./Argument";
export { Class } from "./Class";
export { ClassInstantiation } from "./ClassInstantiation";
export { ClassReference } from "./ClassReference";
Expand Down
10 changes: 5 additions & 5 deletions generators/csharp/codegen/src/cli/AbstractCsharpGeneratorCli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbstractGeneratorCli } from "@fern-api/generator-commons";
import { AbsoluteFilePath } from "@fern-api/fs-utils";
import { AbstractGeneratorCli, parseIR } from "@fern-api/generator-commons";
import { IntermediateRepresentation } from "@fern-fern/ir-sdk/api";
import * as IrSerialization from "@fern-fern/ir-sdk/serialization";
import { readFile } from "fs/promises";
Expand All @@ -15,10 +16,9 @@ export abstract class AbstractCsharpGeneratorCli<
* @returns
*/
protected async parseIntermediateRepresentation(irFilepath: string): Promise<IntermediateRepresentation> {
const rawIr = (await readFile(irFilepath)).toString();
const parsedIr = JSON.parse(rawIr);
return IrSerialization.IntermediateRepresentation.parseOrThrow(parsedIr, {
unrecognizedObjectKeys: "passthrough"
return await parseIR<IntermediateRepresentation>({
absolutePathToIR: AbsoluteFilePath.of(irFilepath),
parse: IrSerialization.IntermediateRepresentation.parse
});
}
}
Loading

0 comments on commit c4fde91

Please sign in to comment.