Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Features/two-phase generation #19

Closed
wants to merge 3 commits into from
Closed
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
21 changes: 15 additions & 6 deletions src/SigSpec.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
using HelloSignalR;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using SigSpec.CodeGeneration.TypeScript;
using SigSpec.Core;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

namespace SigSpec
{
class Program
{
static void Main(string[] args)
static async Task Main(string[] args)
{
Console.WriteLine("SigSpec for SignalR Core");
RunAsync().GetAwaiter().GetResult();
}

static async Task RunAsync()
{
var serializerSettings = new Lazy<JsonSerializerSettings>(() => new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver(),
Converters = new List<JsonConverter> { new StringEnumConverter() }
});

var settings = new SigSpecGeneratorSettings();
var generator = new SigSpecGenerator(settings);

Expand All @@ -30,11 +36,14 @@ static async Task RunAsync()

Console.WriteLine("\nGenerated SigSpec document:");
Console.WriteLine(json);
File.WriteAllText("signalr.spec", json);
Console.ReadKey();

var codeGeneratorSettings = new SigSpecToTypeScriptGeneratorSettings();
var codeGenerator = new SigSpecToTypeScriptGenerator(codeGeneratorSettings);
var file = codeGenerator.GenerateFile(document);
var content = File.ReadAllText("signalr.spec");
var deserializedDocument = JsonConvert.DeserializeObject<SigSpecDocument>(content, serializerSettings.Value);
var file = codeGenerator.GenerateFile(deserializedDocument);

Console.WriteLine("\n\nGenerated SigSpec TypeScript code:");
Console.WriteLine(file);
Expand Down
2 changes: 1 addition & 1 deletion src/SigSpec.Core/SigSpec.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
Expand Down
2 changes: 0 additions & 2 deletions src/SigSpec.Core/SigSpecDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using NJsonSchema;
using NJsonSchema.Converters;
using System;
using System.Collections.Generic;

namespace SigSpec.Core
{
[JsonConverter(typeof(JsonReferenceConverter))]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove this? I think it's needed for correct $ref handling

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to properly serialize and then deserialize SigSpecDocument. Deserialization always threw StackOverflowException. It looked has an infinite loop while trying to deserialize the document (commit aeeaf90 depicts the problem) . Removing the attribute solved the problem and I was able to deserialize and generate the TS client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think my solution does not work, please indicate and I revoke my PR.

public class SigSpecDocument
{
private static Lazy<JsonSerializerSettings> _serializerSettings = new Lazy<JsonSerializerSettings>(() => new JsonSerializerSettings
Expand Down