Skip to content

Commit 1f2871a

Browse files
TS SDK
1 parent e93b325 commit 1f2871a

File tree

186 files changed

+37341
-15
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

186 files changed

+37341
-15
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Nuget Package
1+
name: SDK DotNet
22

33
on:
44
push:
@@ -19,8 +19,8 @@ jobs:
1919

2020
- name: Pack
2121
run: |
22-
cd tools/sdk/Notifo.SDK && dotnet pack -c Release
22+
cd tools/sdk-dotnet/Notifo.SDK && dotnet pack -c Release
2323
2424
- name: Publish
2525
run: |
26-
cd tools/sdk/Notifo.SDK && dotnet nuget push **/*.nupkg --source 'https://api.nuget.org/v3/index.json' --skip-duplicate -k ${{ secrets.NUGET }}
26+
cd tools/sdk-dotnet/Notifo.SDK && dotnet nuget push **/*.nupkg --source 'https://api.nuget.org/v3/index.json' --skip-duplicate -k ${{ secrets.NUGET }}

.github/workflows/sdk-ts.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: SDK Typescript
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
compile:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repo
14+
uses: actions/checkout@v4.1.0
15+
16+
- name: Set up node
17+
uses: actions/setup-node@v4.0.3
18+
with:
19+
node-version: 20
20+
21+
- name: Build - Install
22+
run: |
23+
cd tools/sdk-ts && npm i
24+
25+
- name: Build - Compile
26+
run: |
27+
cd tools/sdk-ts && npm run build
28+
29+
- name: Publish to npm
30+
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
31+
run: |
32+
cd tools/sdk-ts
33+
npm config set //registry.npmjs.org/:_authToken ${NPM_TOKEN}
34+
npm publish --access public
35+
env:
36+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

backend/src/Notifo/Areas/Api/Controllers/Ping/PingController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public sealed class PingController : BaseController
2222
/// </summary>
2323
/// <response code="204">Service ping successful.</response>.
2424
/// <remarks>
25-
/// Can be used to test, if the Squidex API is alive and responding.
25+
/// Can be used to test, if the API is alive and responding.
2626
/// </remarks>
2727
[HttpGet]
2828
[Route("ping/")]
@@ -38,7 +38,7 @@ public IActionResult GetOldPing()
3838
/// </summary>
3939
/// <response code="204">Service ping successful.</response>.
4040
/// <remarks>
41-
/// Can be used to test, if the Squidex API is alive and responding.
41+
/// Can be used to test, if the API is alive and responding.
4242
/// </remarks>
4343
[HttpGet]
4444
[Route("api/ping/")]
@@ -53,7 +53,7 @@ public IActionResult GetPing()
5353
/// </summary>
5454
/// <response code="204">Service info returned.</response>.
5555
/// <remarks>
56-
/// Can be used to test, if the Squidex API is alive and responding.
56+
/// Can be used to test, if the API is alive and responding.
5757
/// </remarks>
5858
[HttpGet]
5959
[Route("api/info/")]

frontend/src/app/service/service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7437,6 +7437,7 @@ export interface IntegrationPropertyDto {
74377437
}
74387438

74397439
export type PropertyType = "Text" | "Number" | "MultilineText" | "Password" | "Boolean";
7440+
74407441
export type PropertyFormat = "None" | "Email" | "HttpUrl";
74417442

74427443
export interface IntegrationCreatedDto {
File renamed without changes.

tools/sdk/CodeGenerator/CodeGenerator.csproj renamed to tools/sdk-dotnet/CodeGenerator/CodeGenerator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<PackageReference Include="NSwag.CodeGeneration.CSharp" Version="14.0.3" />
1515
<PackageReference Include="NSwag.CodeGeneration.TypeScript" Version="14.0.3" />
1616
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
17+
<PackageReference Include="Squidex.Text" Version="7.31.0" />
1718
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
1819
</ItemGroup>
1920

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using System;
99
using System.IO;
10+
using Google.Protobuf.WellKnownTypes;
1011
using NJsonSchema;
1112
using NJsonSchema.CodeGeneration;
1213
using NJsonSchema.CodeGeneration.CSharp;
@@ -30,6 +31,8 @@ public static void Main()
3031

3132
private static void GenerateCSharp(OpenApiDocument document)
3233
{
34+
var rootFolder = GetRootFolder();
35+
3336
var generatorSettings = new CSharpClientGeneratorSettings
3437
{
3538
ExceptionClass = "NotifoException",
@@ -55,7 +58,26 @@ private static void GenerateCSharp(OpenApiDocument document)
5558

5659
var code = new CSharpClientGenerator(document, generatorSettings).GenerateFile();
5760

58-
File.WriteAllText(@"..\..\..\..\Notifo.SDK\Generated.cs", code);
61+
File.WriteAllText(Path.Combine(rootFolder, "sdk-dotnet", "Notifo.SDK", "Generated.cs"), code);
62+
63+
SchemaCleaner.AddExtensions(document);
64+
WriteToFile(rootFolder, document, "sdk-ts/openapi.json");
65+
}
66+
67+
private static string GetRootFolder()
68+
{
69+
var folder = new DirectoryInfo(Directory.GetCurrentDirectory());
70+
while (folder != null)
71+
{
72+
if (folder.Name == "tools")
73+
{
74+
return folder.FullName;
75+
}
76+
77+
folder = folder.Parent;
78+
}
79+
80+
throw new InvalidOperationException("Root directory not found.");
5981
}
6082

6183
private static void GenerateTypescript(OpenApiDocument document)
@@ -102,4 +124,14 @@ public override string GetClientName(OpenApiDocument document, string path, stri
102124
return base.GetClientName(document, path, httpMethod, operation);
103125
}
104126
}
127+
128+
private static void WriteToFile(string rootFolder, OpenApiDocument document, string path)
129+
{
130+
var targetFile = new FileInfo(Path.Combine(rootFolder, path));
131+
132+
if (targetFile.Directory!.Exists)
133+
{
134+
File.WriteAllText(targetFile.FullName, document.ToJson());
135+
}
136+
}
105137
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// ==========================================================================
2+
// Notifo.io
3+
// ==========================================================================
4+
// Copyright (c) Sebastian Stehle
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using System;
9+
using System.Collections.Generic;
10+
using System.Linq;
11+
using NSwag;
12+
using Squidex.Text;
13+
14+
namespace CodeGenerator;
15+
16+
internal static class SchemaCleaner
17+
{
18+
public static void AddExtensions(OpenApiDocument document)
19+
{
20+
document.Security = null;
21+
document.Components.SecuritySchemes.Clear();
22+
23+
static void AddExtensions(OpenApiOperation operation)
24+
{
25+
operation.ExtensionData ??= new Dictionary<string, object>();
26+
operation.ExtensionData["x-method-name"] = operation.OperationId.Split('_')[^1].ToCamelCase();
27+
28+
foreach (var parameter in operation.Parameters.ToList())
29+
{
30+
if (parameter.Kind == OpenApiParameterKind.Header)
31+
{
32+
const string Prefix = "X-";
33+
34+
var name = parameter.Name;
35+
36+
parameter.ExtensionData ??= new Dictionary<string, object>();
37+
parameter.ExtensionData["x-header-name"] = name;
38+
39+
if (name.StartsWith(Prefix, StringComparison.Ordinal))
40+
{
41+
name = name[Prefix.Length..];
42+
}
43+
44+
parameter.Name = name.ToCamelCase();
45+
}
46+
47+
operation.Security = null;
48+
}
49+
}
50+
51+
foreach (var description in document.Operations)
52+
{
53+
AddExtensions(description.Operation);
54+
}
55+
56+
document.ExtensionData ??= new Dictionary<string, object>();
57+
}
58+
}
File renamed without changes.

0 commit comments

Comments
 (0)