• Stars
    star
    156
  • Rank 231,665 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Specification and code generator for SignalR Core.

SigSpec for SignalR Core

Azure DevOps Azure DevOps Nuget

Experimental API endpoint specification and code generator for SignalR Core.

Run SigSpec.Console to see a demo spec and the generated TypeScript code.

Please let me know what you think here.

Based on NJsonSchema (see also: NSwag).

Original idea: RicoSuter/NSwag#691

Sample

Hub:

public class ChatHub : Hub<IChatClient>
{
    public Task Send(string message)
    {
        if (message == string.Empty)
        {
            return Clients.All.Welcome();
        }

        return Clients.All.Send(message);
    }

    public Task AddPerson(Person person)
    {
        return Task.CompletedTask;
    }

    public ChannelReader<Event> GetEvents()
    {
        var channel = Channel.CreateUnbounded<Event>();
        return channel.Reader;
    }
}

public class Event
{
    public string Type { get; set; }
}

public class Person
{
    [JsonProperty("firstName")]
    public string FirstName { get; set; }

    [JsonProperty("lastName")]
    public string LastName { get; set; }
}

public interface IChatClient
{
    Task Welcome();

    Task Send(string message);
}

Generated spec:

{
  "hubs": {
    "chat": {
      "name": "Chat",
      "description": "",
      "operations": {
        "Send": {
          "description": "",
          "parameters": {
            "message": {
              "type": [
                "null",
                "string"
              ],
              "description": ""
            }
          }
        },
        "AddPerson": {
          "description": "",
          "parameters": {
            "person": {
              "description": "",
              "oneOf": [
                {
                  "type": "null"
                },
                {
                  "$ref": "#/definitions/Person"
                }
              ]
            }
          }
        },
        "GetEvents": {
          "description": "",
          "parameters": {},
          "returntype": {
            "description": "",
            "oneOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/definitions/Event"
              }
            ]
          },
          "type": "Observable"
        }
      },
      "callbacks": {
        "Welcome": {
          "description": "",
          "parameters": {}
        },
        "Send": {
          "description": "",
          "parameters": {
            "message": {
              "type": [
                "null",
                "string"
              ],
              "description": ""
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Person": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "firstName": {
          "type": [
            "null",
            "string"
          ]
        },
        "lastName": {
          "type": [
            "null",
            "string"
          ]
        }
      }
    },
    "Event": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "Type": {
          "type": [
            "null",
            "string"
          ]
        }
      }
    }
  }
}

Generated TypeScript code:

import { HubConnection, IStreamResult } from "@aspnet/signalr"

export class ChatHub {
    constructor(private connection: HubConnection) {
    }

    send(message: string): Promise<void> {
        return this.connection.invoke('Send', message);
    }

    addPerson(person: Person): Promise<void> {
        return this.connection.invoke('AddPerson', person);
    }

    getEvents(): IStreamResult<Event> {
        return this.connection.stream('GetEvents');
    }

    registerCallbacks(implementation: IChatHubCallbacks) {
        this.connection.on('Welcome', () => implementation.welcome());
        this.connection.on('Send', (message) => implementation.send(message));
    }

    unregisterCallbacks(implementation: IChatHubCallbacks) {
        this.connection.off('Welcome', () => implementation.welcome());
        this.connection.off('Send', (message) => implementation.send(message));
    }
}

export interface IChatHubCallbacks {
    welcome(): void;
    send(message: string): void;
}

export interface Person {
    firstName: string;
    lastName: string;
}

export interface Event {
    Type: string;
}

Development

Release new version

  1. Update versions with dnt bump-versions patch
  2. Commit to "master" (via PR)
  3. Merge into "release" to start nuget.org publish (via PR)

More Repositories

1

NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
C#
6,500
star
2

NJsonSchema

JSON Schema reader, generator and validator for .NET
C#
1,325
star
3

DNT

DNT (DotNetTools): Command line tools to manage .NET projects and solutions.
C#
397
star
4

MyToolkit

MyToolkit for .NET
C#
335
star
5

VisualJsonEditor

A JSON schema based file editor for Windows.
C#
333
star
6

NuGetReferenceSwitcher

Visual Studio extension to switch between NuGet and project references.
C#
207
star
7

Namotion.Reflection

.NET library with advanced reflection APIs.
C#
202
star
8

ProjectDependencyBrowser

Application to browse, sort, filter and launch your Visual Studio projects.
C#
46
star
9

Namotion.Messaging

.NET abstractions and implementations for message brokers, event queues and data ingestion services.
C#
46
star
10

Namotion.Storage

.NET abstractions and implementations for storage services like blob storages, file systems or object storages.
C#
35
star
11

PowerCmd

PowerCmd: The Windows Prompt replacement.
C#
33
star
12

NConsole

NConsole is a .NET library to parse command line arguments and execute commands.
C#
31
star
13

HomeBlaze

Home Automation with .NET/Blazor
C#
12
star
14

DotNetMicroservice

C#
11
star
15

InsideAsyncAwait

C#
8
star
16

aurelia-bs

Bootstrap UI (CSS framework) components for Aurelia JS.
TypeScript
7
star
17

ShopOnCore

C#
7
star
18

AureliaBootstrapDialogs

JavaScript
6
star
19

SampleOutputProcessorActionFilter

Sample application for a blog article.
C#
5
star
20

ScopeCheckingNinjectKernel

C#
3
star
21

DockerDemo

ASP.NET Core with Docker sample and tutorial
C#
3
star
22

SampleWcfService

Sample application for a blog article.
C#
3
star
23

VistoJS

Visto JavaScript Framework (VistoJS)
TypeScript
2
star
24

SampleSortableChildCollectionForm

Sample ASP.NET MVC application with edit form for an entity with a collection property.
CSS
2
star
25

SampleEfMigrationsApplication

C#
2
star
26

RicoSuter

1
star
27

SampleProjectRepository

Sample projects for package and dependency management tests.
C#
1
star
28

MdFileWiki

C#
1
star