Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
node_version:
description: The Node.js version.
required: false
default: '18'
default: '24'
registry_url:
description: The Node.js package registry URL.
required: false
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
os:
- ubuntu-latest
node:
- '16'
- '18'
- '22'
include:
- os: ubuntu-latest
os_name: Linux
Expand All @@ -40,8 +39,7 @@ jobs:
fail-fast: false
matrix:
node:
- '16'
- '18'
- '22'
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -65,8 +63,7 @@ jobs:
fail-fast: false
matrix:
node:
- '16'
- '18'
- '22'
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
# For more details, visit the project page:
# https://github.com/github/gitignore

# Codegen
CODEGEN.md

# TypeScript build output
*.d.ts
*.js
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lts/hydrogen
24
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Prettier exceptions

*.hbs
CODEGEN.md
1 change: 1 addition & 0 deletions codegen/content/CODEGEN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Codegen
1 change: 1 addition & 0 deletions codegen/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default null
52 changes: 52 additions & 0 deletions codegen/layouts/api.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Runtime.Serialization;
using System.Text;
using JsonSubTypes;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Seam.Client;
using Seam.Model;

namespace Seam.Api
{
public class {{className}}
{
private ISeamClient _seam;

public {{className}}(ISeamClient seam)
{
_seam = seam;
}
{{#each routes}}

{{> model-class request}}
{{#each requestSiblings}}

{{> model-class this}}
{{/each}}
{{#if response}}

{{> model-class response}}
{{/if}}
{{#each responseSiblings}}

{{> model-class this}}
{{/each}}

{{> route-methods this}}
{{/each}}
}
}

namespace Seam.Client
{
public partial class SeamClient
{
public Api.{{className}} {{className}} => new(this);
}

public partial interface ISeamClient
{
public Api.{{className}} {{className}} { get; }
}
}
1 change: 1 addition & 0 deletions codegen/layouts/default.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{contents}}
19 changes: 19 additions & 0 deletions codegen/layouts/model.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Runtime.Serialization;
using System.Text;
using JsonSubTypes;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Seam.Model;

namespace Seam.Model
{
{{#each decls}}
{{#if (eq kind "union")}}
{{> oneof-union this}}
{{else}}
{{> model-class this}}
{{/if}}

{{/each}}
}
2 changes: 2 additions & 0 deletions codegen/layouts/partials/data-member.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[DataMember(Name = "{{snakeName}}", IsRequired = {{isRequired}}, EmitDefaultValue = false)]
public {{#if isOverride}}override {{/if}}{{type}} {{pascalName}} {{#if getOnly}}{ get; }{{else}}{ get; set; }{{/if}}{{#if initializer}} = {{initializer}};{{/if}}
13 changes: 13 additions & 0 deletions codegen/layouts/partials/enum-def.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{#if isString}}
[JsonConverter(typeof(SafeStringEnumConverter))]
{{/if}}
public enum {{name}}
{
{{#each members}}
[EnumMember(Value = {{#if ../isString}}"{{value}}"{{else}}{{value}}{{/if}})]
{{identifier}} = {{assign}},
{{#unless @last}}

{{/unless}}
{{/each}}
}
29 changes: 29 additions & 0 deletions codegen/layouts/partials/model-class.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[DataContract(Name = "{{dataContractName}}")]
public class {{className}}{{#if baseClass}} : {{baseClass}}{{/if}}
{
[JsonConstructorAttribute]
{{#if properties.length}}protected{{else}}public{{/if}} {{className}}() { }
{{#if properties.length}}

public {{className}}({{csParams properties}})
{
{{#each properties}}
{{pascalName}} = {{camelName}};
{{/each}}
}
{{/if}}
{{#each nested}}

{{#if enum}}
{{> enum-def enum}}
{{else}}
{{> oneof-union union}}
{{/if}}
{{/each}}
{{#each properties}}

{{> data-member this}}
{{/each}}

{{> tostring}}
}
17 changes: 17 additions & 0 deletions codegen/layouts/partials/oneof-union.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[JsonConverter(typeof(JsonSubtypes), "{{discriminatorSnake}}")]
[JsonSubtypes.FallBackSubType(typeof({{unrecognizedTypeName}}))]
{{#each knownSubTypes}}
[JsonSubtypes.KnownSubType(typeof({{typeName}}), "{{value}}")]
{{/each}}
public abstract class {{className}}
{
{{#each abstractProps}}
public abstract {{type}} {{pascalName}} {{#if getOnly}}{ get; }{{else}}{ get; set; }{{/if}}

{{/each}}
public abstract override string ToString();
}
{{#each subclasses}}

{{> model-class this}}
{{/each}}
39 changes: 39 additions & 0 deletions codegen/layouts/partials/route-methods.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
public {{#if isVoid}}void{{else}}{{returnType}}{{/if}} {{methodName}}({{methodName}}Request request)
{
var requestOptions = new RequestOptions();
requestOptions.Data = request;
{{#if isVoid}}
_seam.Post<object>("{{path}}", requestOptions);
{{else}}
return _seam.Post<{{responseTypeArg}}>("{{path}}", requestOptions).Data.{{returnProp}};
{{/if}}
}

public {{#if isVoid}}void{{else}}{{returnType}}{{/if}} {{methodName}}({{csParams params}})
{
{{#if isVoid}}
{{methodName}}(new {{methodName}}Request({{csNamedArgs params}}));
{{else}}
return {{methodName}}(new {{methodName}}Request({{csNamedArgs params}}));
{{/if}}
}

public async {{#if isVoid}}Task{{else}}Task<{{returnType}}>{{/if}} {{methodName}}Async({{methodName}}Request request)
{
var requestOptions = new RequestOptions();
requestOptions.Data = request;
{{#if isVoid}}
await _seam.PostAsync<object>("{{path}}", requestOptions);
{{else}}
return (await _seam.PostAsync<{{responseTypeArg}}>("{{path}}", requestOptions)).Data.{{returnProp}};
{{/if}}
}

public async {{#if isVoid}}Task{{else}}Task<{{returnType}}>{{/if}} {{methodName}}Async({{csParams params}})
{
{{#if isVoid}}
await {{methodName}}Async(new {{methodName}}Request({{csNamedArgs params}}));
{{else}}
return (await {{methodName}}Async(new {{methodName}}Request({{csNamedArgs params}})));
{{/if}}
}
18 changes: 18 additions & 0 deletions codegen/layouts/partials/tostring.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public override string ToString()
{
JsonSerializer jsonSerializer = JsonSerializer.CreateDefault(null);

StringWriter stringWriter = new StringWriter(
new StringBuilder(256),
System.Globalization.CultureInfo.InvariantCulture
);
using (JsonTextWriter jsonTextWriter = new JsonTextWriter(stringWriter))
{
jsonTextWriter.IndentChar = ' ';
jsonTextWriter.Indentation = 2;
jsonTextWriter.Formatting = Formatting.Indented;
jsonSerializer.Serialize(jsonTextWriter, this, null);
}

return stringWriter.ToString();
}
Loading
Loading