Skip to content

Commit

Permalink
Bugfixes for endpoint model generator
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaumov committed Jan 20, 2022
1 parent 7fcf5ab commit 48b49fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 16 additions & 11 deletions EndpointModelGenerator/EndpointModelGenerator/SchemaGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace EndpointSchemaGenerator
{
Expand Down Expand Up @@ -56,27 +57,28 @@ private static void WriteActions(Schema schema,
if (schema.Parameters.ContainsKey(action.Key))
{
StreamWriter writer = new StreamWriter(modelActionsFilesDirectory + filename);
string content = "";

StringBuilder content = new StringBuilder();
foreach (var parameter in schema.Parameters[action.Key])
{
content += String.Format(Templates.InActionParameterTemplate, parameter.Key, parameter.Value);
content.Append(String.Format(Templates.InActionParameterTemplate, parameter.Key, parameter.Value));
}
string result = String.Format(Templates.ActionWithParametersTemplate, endpointNamespace, action.Key, action.Value, content);
string result = String.Format(Templates.ActionWithParametersTemplate, endpointNamespace, action.Key, action.Value, content.ToString());

writer.Write(Templates.ActionUsingsTemplate + result);
writer.Close();

string paramFileName = action.Key + "Parameters.cs";
writer = new StreamWriter(modelParametersFilesDirectory + paramFileName);


content = "";

content = new StringBuilder();
foreach (var parameter in schema.Parameters[action.Key])
{
content += "\r\n" + String.Format(Templates.ParameterTemplate, parameter.Key, parameter.Value);
content.Append("\r\n");
content.Append(String.Format(Templates.ParameterTemplate, parameter.Key, parameter.Value));
}
result = String.Format(Templates.ActionParametersTemplate, endpointNamespace, action.Key, content);
result = String.Format(Templates.ActionParametersTemplate, endpointNamespace, action.Key, content.ToString());
writeLogDelegate.Invoke("ActionsWithParameters/" + action.Key);
writer.Write(result);
writer.Close();
Expand Down Expand Up @@ -134,12 +136,15 @@ private static void WriteEntities(Schema schema,
{
string filename = entity.Key + ".cs";
StreamWriter writer = new StreamWriter(modelFilesDirectory + filename);
string body = "";
StringBuilder body = new StringBuilder();
foreach (var field in entity.Value)
{
body += string.Format(Templates.FieldTemplate, field.Key, field.Value);
if (field.Key == entity.Key)
body.Append(string.Format(Templates.FieldTemplate, field.Key.ToLowerInvariant(), field.Value));
else
body.Append(string.Format(Templates.FieldTemplate, field.Key, field.Value));
}
string result = String.Format(Templates.EntityTemplate, endpointNamespace, entity.Key, body, schema.Info.Version);
string result = String.Format(Templates.EntityTemplate, endpointNamespace, entity.Key, body.ToString(), schema.Info.Version);
writeLogDelegate.Invoke(entity.Key);
writer.Write(Templates.EntityUsingsTemplate + result);
writer.Close();
Expand Down
2 changes: 1 addition & 1 deletion EndpointModelGenerator/EndpointModelGenerator/Templates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static class Templates
//{1} = Endpoint Path
public static string BaseEndpointApiTemplate = "using Acumatica.RESTClient.Api;\r\nusing Acumatica.RESTClient.Client;\r\nusing Acumatica.RESTClient.Model;\r\n\r\nnamespace {0}.Api\r\n{{\r\n\tpublic abstract class BaseEndpointApi<EntityType> : EntityAPI<EntityType>\r\n\t\twhere EntityType : Entity\r\n\t{{\r\n\t\tpublic BaseEndpointApi(Configuration configuration) : base(configuration)\r\n\t\t{{ }}\r\n\t\tpublic override string GetEndpointPath()\r\n\t\t{{\r\n\t\t\treturn \"entity/{1}\";\r\n\t\t}}\r\n\t}}\r\n}}";

public static string ProjectTemplate = "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n\r\n <PropertyGroup>\r\n <TargetFramework>netstandard2.0</TargetFramework>\r\n </PropertyGroup>\r\n\r\n <ItemGroup>\r\n <ProjectReference Include = \"..\\Acumatica.RESTClient\\Acumatica.RESTClient.csproj\" />\r\n </ItemGroup >\r\n\r\n</Project >\r\n";
public static string ProjectTemplate = "<Project Sdk=\"Microsoft.NET.Sdk\">\r\n\r\n <PropertyGroup>\r\n <TargetFramework>netstandard2.0</TargetFramework>\r\n </PropertyGroup>\r\n\r\n <ItemGroup>\r\n <PackageReference Include=\"Newtonsoft.Json\" Version=\"13.0.1\" />\r\n </ItemGroup> <ItemGroup>\r\n <ProjectReference Include = \"..\\Acumatica.RESTClient\\Acumatica.RESTClient.csproj\" />\r\n </ItemGroup >\r\n\r\n</Project >\r\n";


}
Expand Down

0 comments on commit 48b49fb

Please sign in to comment.