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

Client classes in FileTemplateModel #255

Merged
merged 1 commit into from
Aug 24, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ public FileTemplateModel(string clientCode, IEnumerable<string> clientClasses, S
_settings = settings;
_resolver = resolver;
_clientCode = clientCode;
ClientClasses = clientClasses.ToArray();

Types = GenerateDtoTypes();
ExtensionCodeAfter = GenerateExtensionCodeAfter(clientClasses);
ExtensionCodeAfter = GenerateExtensionCodeAfter();
}

/// <summary>Gets a value indicating whether the generated code is for Angular 2.</summary>
Expand Down Expand Up @@ -61,14 +62,17 @@ public FileTemplateModel(string clientCode, IEnumerable<string> clientClasses, S
/// <summary>Gets the namespace.</summary>
public string Namespace => _settings.TypeScriptGeneratorSettings.Namespace;

/// <summary>Table containing list of the generated classes.</summary>
public string[] ClientClasses { get; }

private string GenerateDtoTypes()
{
return _settings.GenerateDtoTypes ? _resolver.GenerateTypes(_settings.TypeScriptGeneratorSettings.ProcessedExtensionCode) : string.Empty;
}

private string GenerateExtensionCodeAfter(IEnumerable<string> clientClasses)
private string GenerateExtensionCodeAfter()
{
var clientClassesVariable = "{" + string.Join(", ", clientClasses.Select(c => "'" + c + "': " + c)) + "}";
var clientClassesVariable = "{" + string.Join(", ", ClientClasses.Select(c => "'" + c + "': " + c)) + "}";
return _settings.TypeScriptGeneratorSettings.ProcessedExtensionCode.CodeAfter.Replace("{clientClasses}", clientClassesVariable);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
using NJsonSchema.CodeGeneration;
using NSwag.CodeGeneration.CodeGenerators.TypeScript.Models;

namespace NSwag.CodeGeneration.CodeGenerators.TypeScript.Templates
{
internal partial class FileTemplate : ITemplate
{
public FileTemplate(object model)
{
Model = model;
Model = (FileTemplateModel)model;
}

public dynamic Model { get; }
public FileTemplateModel Model { get; }

public string Render()
{
Expand Down