Skip to content

Commit

Permalink
Merge branch 'main' into eden/validation-schema-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
eyw520 authored Nov 15, 2024
2 parents a984f8f + 61bdcb0 commit bcb5176
Show file tree
Hide file tree
Showing 840 changed files with 46,960 additions and 18,232 deletions.
Binary file added .package.json.swp
Binary file not shown.
3 changes: 2 additions & 1 deletion fern/pages/changelogs/cli/2024-11-14.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 0.45.0-rc44
**`(fix):`** Minor typo fix & support piping query parameter validation into fern definition generation
**`(fix):`** Update the IR's `ServiceTypeReferenceInfo` to include all transitive types
referenced by a service.


3 changes: 3 additions & 0 deletions fern/pages/changelogs/csharp-sdk/2024-11-14.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.9.8
**`(feat):`** Add support for [idempotency headers](https://buildwithfern.com/learn/sdks/features/idempotency-headers).

4 changes: 4 additions & 0 deletions fern/pages/changelogs/go-sdk/2024-11-14.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.31.0
**`(feat):`** Improves type file layout with zero impact on backwards compatibility.
Shared types are now more accurately placed in the `types.go` file, whereas types referenced by a single service are now placed in a file that matches the service's filename (e.g. user.go).

4 changes: 4 additions & 0 deletions fern/pages/changelogs/go-sdk/2024-11-15.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 0.31.1
**`(internal):`** Adds additional tests to confirm the behavior of the `core.Retrier`.
No functional, user-facing changes are included.

4 changes: 4 additions & 0 deletions fern/pages/changelogs/python-sdk/2024-11-14.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 4.3.5
**`(fix):`** Update README.md snippet builder to omit invalid snippets during readme config generation.


4 changes: 4 additions & 0 deletions fern/pages/changelogs/python-sdk/2024-11-15.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 4.3.6
**`(fix):`** Fix README.md and reference.md generation.


8 changes: 7 additions & 1 deletion generators/csharp/codegen/src/asIs/RawClient.Template.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public record BaseApiRequest

public Headers Headers { get; init; } = new();

public RequestOptions? Options { get; init; }
public IRequestOptions? Options { get; init; }
}

/// <summary>
Expand Down Expand Up @@ -145,6 +145,12 @@ private HttpRequestMessage BuildHttpRequest(BaseApiRequest request)
SetHeaders(httpRequest, Options.Headers);
SetHeaders(httpRequest, request.Headers);
SetHeaders(httpRequest, request.Options?.Headers ?? new Headers());
<% if (idempotencyHeaders) { %>
if (request.Options is IIdempotentRequestOptions idempotentRequest)
{
SetHeaders(httpRequest, idempotentRequest.GetIdempotencyHeaders());
}
<% } %>
return httpRequest;
}

Expand Down
16 changes: 14 additions & 2 deletions generators/csharp/codegen/src/ast/Class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ export class Class extends AstNode {
this.fields.push(field);
}

public addFields(fields: Field[]): void {
fields.forEach((field) => this.fields.push(field));
}

public addConstructor(constructor: Class.Constructor): void {
this.constructors.push(constructor);
}
Expand Down Expand Up @@ -283,6 +287,10 @@ export class Class extends AstNode {
this.writeFields({ writer, fields: this.getFieldsByAccess(Access.Internal) });
writer.dedent();

writer.indent();
this.writeFields({ writer, fields: this.getFieldsByAccess(undefined) });
writer.dedent();

writer.indent();
this.nestedClasses.forEach((nestedClass, index) => {
nestedClass.write(writer);
Expand Down Expand Up @@ -317,6 +325,10 @@ export class Class extends AstNode {
this.writeMethods({ writer, methods: this.getMethodsByAccess(Access.Private) });
writer.dedent();

writer.indent();
this.writeMethods({ writer, methods: this.getMethodsByAccess(undefined) });
writer.dedent();

writer.indent();
this.operators.forEach((operator) => {
this.writeOperator({ writer, operator });
Expand Down Expand Up @@ -358,7 +370,7 @@ export class Class extends AstNode {
});
}

private getMethodsByAccess(access: Access): Method[] {
private getMethodsByAccess(access: Access | undefined): Method[] {
return this.methods.filter((method) => method.access === access);
}

Expand All @@ -373,7 +385,7 @@ export class Class extends AstNode {
});
}

private getFieldsByAccess(access: Access): Field[] {
private getFieldsByAccess(access: Access | undefined): Field[] {
return this.fields.filter((field) => field.access === access);
}

Expand Down
21 changes: 16 additions & 5 deletions generators/csharp/codegen/src/ast/Field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export declare namespace Field {
/* The type of the field */
type: Type;
/* The access level of the method */
access: Access;
access?: Access;
/* Whether the the field is a constant value */
const_?: boolean;
/* Whether the the field should use the new keyword */
Expand Down Expand Up @@ -54,12 +54,14 @@ export declare namespace Field {
useRequired?: boolean;
/* If true, the default initializer (if any) is not included. */
skipDefaultInitializer?: boolean;
/* If specified, use the interface name in front of the field name */
interfaceReference?: ClassReference;
}
}

export class Field extends AstNode {
public readonly name: string;
public readonly access: Access;
public readonly access: Access | undefined;
public readonly type: Type;
private const_: boolean;
private new_: boolean;
Expand All @@ -74,6 +76,7 @@ export class Field extends AstNode {
private static_?: boolean;
private useRequired: boolean;
private skipDefaultInitializer: boolean;
private interfaceReference?: ClassReference;

constructor({
name,
Expand All @@ -91,7 +94,8 @@ export class Field extends AstNode {
readonly,
static_,
useRequired,
skipDefaultInitializer
skipDefaultInitializer,
interfaceReference
}: Field.Args) {
super();
this.name = name;
Expand All @@ -110,6 +114,7 @@ export class Field extends AstNode {
this.static_ = static_;
this.useRequired = useRequired ?? false;
this.skipDefaultInitializer = skipDefaultInitializer ?? false;
this.interfaceReference = interfaceReference;

if (this.jsonPropertyName != null) {
this.annotations = [
Expand Down Expand Up @@ -139,7 +144,9 @@ export class Field extends AstNode {
}
}

writer.write(`${this.access} `);
if (this.access) {
writer.write(`${this.access} `);
}
if (this.const_) {
writer.write("const ");
}
Expand All @@ -159,7 +166,11 @@ export class Field extends AstNode {
writer.write("readonly ");
}
writer.writeNode(this.type);
writer.write(` ${this.name}`);
writer.write(" ");
if (this.interfaceReference) {
writer.write(`${this.interfaceReference.name}.`);
}
writer.write(this.name);

const useExpressionBodiedPropertySyntax = this.get && !this.init && !this.set && this.initializer != null;
if ((this.get || this.init || this.set) && !useExpressionBodiedPropertySyntax) {
Expand Down
25 changes: 24 additions & 1 deletion generators/csharp/codegen/src/ast/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export declare namespace Interface {
partial?: boolean;
/* Defaults to false */
isNestedInterface?: boolean;
/* Any interfaces the interface inherits */
interfaceReferences?: ClassReference[];
}
}

Expand All @@ -27,17 +29,19 @@ export class Interface extends AstNode {
public readonly partial: boolean;
public readonly reference: ClassReference;
public readonly isNestedInterface: boolean;
public readonly interfaceReferences: ClassReference[];

private fields: Field[] = [];
private methods: Method[] = [];

constructor({ name, namespace, access, partial, isNestedInterface }: Interface.Args) {
constructor({ name, namespace, access, partial, isNestedInterface, interfaceReferences }: Interface.Args) {
super();
this.name = name;
this.namespace = namespace;
this.access = access;
this.partial = partial ?? false;
this.isNestedInterface = isNestedInterface ?? false;
this.interfaceReferences = interfaceReferences ?? [];

this.reference = new ClassReference({
name: this.name,
Expand All @@ -49,10 +53,18 @@ export class Interface extends AstNode {
this.fields.push(field);
}

public addFields(fields: Field[]): void {
fields.forEach((field) => this.fields.push(field));
}

public addMethod(method: Method): void {
this.methods.push(method);
}

public getNamespace(): string {
return this.namespace;
}

public write(writer: Writer): void {
if (!this.isNestedInterface) {
writer.writeLine(`namespace ${this.namespace};`);
Expand All @@ -64,6 +76,17 @@ export class Interface extends AstNode {
}
writer.write("interface ");
writer.writeLine(`${this.name}`);

if (this.interfaceReferences.length > 0) {
writer.write(" : ");
this.interfaceReferences.forEach((interfaceReference, index) => {
interfaceReference.write(writer);
// Don't write a comma after the last interface
if (index < this.interfaceReferences.length - 1) {
writer.write(", ");
}
});
}
writer.writeLine("{");

writer.indent();
Expand Down
40 changes: 30 additions & 10 deletions generators/csharp/codegen/src/ast/Method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export declare namespace Method {
/* The name of the method */
name: string;
/* The access of the method */
access: Access;
access?: Access;
/* Whether the method is sync or async. Defaults to false. */
isAsync?: boolean;
/* The parameters of the method */
Expand All @@ -27,6 +27,8 @@ export declare namespace Method {
override?: boolean;
/* The return type of the method */
return_?: Type;
/* If true, no method body will be written. This is for interface methods. */
noBody?: boolean;
/* The body of the method */
body?: CodeBlock;
/* Summary for the method */
Expand All @@ -39,14 +41,17 @@ export declare namespace Method {
annotations?: Annotation[];
/* Any code example to add to the method */
codeExample?: string;
/* If specified, use the interface name in front of the method name */
interfaceReference?: ClassReference;
}
}

export class Method extends AstNode {
public readonly name: string;
public readonly isAsync: boolean;
public readonly access: Access;
public readonly access: Access | undefined;
public readonly return: Type | undefined;
public readonly noBody: boolean;
public readonly body: CodeBlock | undefined;
public readonly summary: string | undefined;
public readonly type: MethodType;
Expand All @@ -55,6 +60,7 @@ export class Method extends AstNode {
private readonly parameters: Parameter[];
private readonly annotations: Annotation[];
private readonly codeExample: string | undefined;
private interfaceReference?: ClassReference;

constructor({
name,
Expand All @@ -63,26 +69,30 @@ export class Method extends AstNode {
access,
return_,
body,
noBody,
summary,
type,
classReference,
parameters,
annotations,
codeExample
codeExample,
interfaceReference
}: Method.Args) {
super();
this.name = name;
this.isAsync = isAsync ?? false;
this.override = override ?? false;
this.access = access;
this.return = return_;
this.noBody = noBody ?? false;
this.body = body;
this.summary = summary;
this.type = type ?? MethodType.INSTANCE;
this.reference = classReference;
this.parameters = parameters;
this.annotations = annotations ?? [];
this.codeExample = codeExample;
this.interfaceReference = interfaceReference;
}

public addParameter(parameter: Parameter): void {
Expand Down Expand Up @@ -111,7 +121,9 @@ export class Method extends AstNode {
writer.writeNewLineIfLastLineNot();
}

writer.write(`${this.access} `);
if (this.access) {
writer.write(`${this.access} `);
}
if (this.type === MethodType.STATIC) {
writer.write("static ");
}
Expand Down Expand Up @@ -143,21 +155,29 @@ export class Method extends AstNode {
}
writer.write(" ");
}
writer.write(`${this.name}(`);
if (this.interfaceReference) {
writer.write(`${this.interfaceReference.name}.`);
}
writer.write(this.name);
writer.write("(");
this.parameters.forEach((parameter, idx) => {
parameter.write(writer);
if (idx < this.parameters.length - 1) {
writer.write(", ");
}
});
writer.write(")");
writer.writeLine(" {");
if (this.noBody) {
writer.writeLine(";");
} else {
writer.writeLine(" {");

writer.indent();
this.body?.write(writer);
writer.dedent();
writer.indent();
this.body?.write(writer);
writer.dedent();

writer.writeLine("}");
writer.writeLine("}");
}
}

public getParameters(): Parameter[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { join, RelativeFilePath } from "@fern-api/fs-utils";
import { AbstractGeneratorContext, FernGeneratorExec, GeneratorNotificationService } from "@fern-api/generator-commons";
import {
FernFilepath,
HttpHeader,
IntermediateRepresentation,
Name,
PrimitiveType,
Expand Down Expand Up @@ -109,6 +110,14 @@ export abstract class AbstractCsharpGeneratorContext<
return Object.values(this.ir.services).some((service) => service.transport?.type === "grpc");
}

public hasIdempotencyHeaders(): boolean {
return this.getIdempotencyHeaders().length > 0;
}

public getIdempotencyHeaders(): HttpHeader[] {
return this.ir.idempotencyHeaders;
}

public getConstantsClassReference(): csharp.ClassReference {
return csharp.classReference({
namespace: this.getCoreNamespace(),
Expand Down
Loading

0 comments on commit bcb5176

Please sign in to comment.