Commit e64e3b18 authored by Rostislav Spinar's avatar Rostislav Spinar

Moved here from daemon repo

parent cc166b56
drwxr-xr-x 1 E520 197121 0 srp 2 23:01 DotLiquid.2.0.254/
drwxr-xr-x 1 E520 197121 0 srp 2 23:01 Newtonsoft.Json.9.0.1/
drwxr-xr-x 1 E520 197121 0 srp 2 23:01 NJsonSchema.9.10.56/
drwxr-xr-x 1 E520 197121 0 srp 2 23:01 NJsonSchema.CodeGeneration.9.10.56/
drwxr-xr-x 1 E520 197121 0 srp 2 23:01 NJsonSchema.CodeGeneration.CSharp.9.10.56/
\ No newline at end of file

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "schemas-to-classes", "schemas-to-classes\schemas-to-classes.csproj", "{569C62CA-9C78-4A66-BDE4-B274DBBD7C60}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{569C62CA-9C78-4A66-BDE4-B274DBBD7C60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{569C62CA-9C78-4A66-BDE4-B274DBBD7C60}.Debug|Any CPU.Build.0 = Debug|Any CPU
{569C62CA-9C78-4A66-BDE4-B274DBBD7C60}.Release|Any CPU.ActiveCfg = Release|Any CPU
{569C62CA-9C78-4A66-BDE4-B274DBBD7C60}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
</configuration>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NJsonSchema;
using NJsonSchema.CodeGeneration.CSharp;
namespace schemas_to_classes
{
class Program
{
static void Main(string[] args)
{
// Generate c# classes from JSON schema
generateCSClassFromJSON(@"..\\..\\..\\..\\..\\..\\api", @"..\\..\\..\\..\\..\\..\\examples\\c#\\test-api-app\\test-api-app\\api\\");
}
/// <summary>
/// Generate cs class from JSON schema
/// </summary>
/// <param name="dirAPI"></param>
/// <param name="dirClass"></param>
private static void generateCSClassFromJSON(string dirAPI, string dirClass)
{
Console.WriteLine("Generating files..");
// Generate C# class from the json schema
try
{
DirectoryInfo d = new DirectoryInfo(dirAPI);
FileInfo[] Files = d.GetFiles("*.json*"); //Getting Text files
foreach (FileInfo file in Files)
{
var schemaJson = File.ReadAllText(file.FullName);
var schema = JsonSchema4.FromJsonAsync(schemaJson).Result;
string fName = file.FullName;
string nameSpace = file.Name.Substring(0, file.Name.IndexOf('-', 0));
string dir = nameSpace;
if (dir.Contains('_'))
dir = dir.Substring(0, dir.IndexOf('_', 0));
if (file.Name.Contains("request"))
{
nameSpace += "_Request";
}
if (file.Name.Contains("response"))
{
nameSpace += "_Response";
}
string className = char.ToUpper(nameSpace[0]) + nameSpace.Substring(1);
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings
{
ClassStyle = CSharpClassStyle.Poco,
Namespace = nameSpace,
SchemaType = SchemaType.Swagger2,
});
if (!Directory.Exists(dirClass + dir))
Directory.CreateDirectory(dirClass + dir);
Console.Write("Generating " + file.Name.Replace("json", "cs") + "..");
var generatedFile = generator.GenerateFile(className);
string targetFile = dirClass + dir + '\\' + file.Name.Replace("json", "cs");
File.WriteAllText(targetFile, generatedFile);
Console.WriteLine(" OK");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.Write("Completed..");
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("schemas-to-classes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("schemas-to-classes")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("569c62ca-9c78-4a66-bde4-b274dbbd7c60")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DotLiquid" version="2.0.254" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="NJsonSchema" version="9.10.56" targetFramework="net452" />
<package id="NJsonSchema.CodeGeneration" version="9.10.56" targetFramework="net452" />
<package id="NJsonSchema.CodeGeneration.CSharp" version="9.10.56" targetFramework="net452" />
</packages>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{569C62CA-9C78-4A66-BDE4-B274DBBD7C60}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>schemas_classes_util</RootNamespace>
<AssemblyName>schemas-classes-util</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotLiquid, Version=2.0.254.0, Culture=neutral, PublicKeyToken=82e46016ecf9f07c, processorArchitecture=MSIL">
<HintPath>..\packages\DotLiquid.2.0.254\lib\net45\DotLiquid.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema, Version=9.10.56.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.9.10.56\lib\net45\NJsonSchema.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema.CodeGeneration, Version=9.10.56.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.CodeGeneration.9.10.56\lib\net451\NJsonSchema.CodeGeneration.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="NJsonSchema.CodeGeneration.CSharp, Version=9.10.56.0, Culture=neutral, PublicKeyToken=c2f9c3bdfae56102, processorArchitecture=MSIL">
<HintPath>..\packages\NJsonSchema.CodeGeneration.CSharp.9.10.56\lib\net451\NJsonSchema.CodeGeneration.CSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Net" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment