mirror of
https://github.com/ysoftdevs/wapifuzz.git
synced 2026-03-18 23:43:58 +01:00
Init WFuzz state
This commit is contained in:
16
parser/OpenApiParserCLI/OpenApiParserCLI.csproj
Normal file
16
parser/OpenApiParserCLI/OpenApiParserCLI.csproj
Normal file
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Parser\Parser.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
67
parser/OpenApiParserCLI/Program.cs
Normal file
67
parser/OpenApiParserCLI/Program.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Models;
|
||||
using Newtonsoft.Json;
|
||||
using Parser;
|
||||
|
||||
namespace OpenApiParserCLI
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
static int Main(string[] args)
|
||||
{
|
||||
if (args.Length != 2)
|
||||
{
|
||||
Console.WriteLine("Bad arguments provided.");
|
||||
PrintHelp();
|
||||
return 1;
|
||||
}
|
||||
|
||||
string openApiDocFilePath = args[0];
|
||||
string outputEndpointsFilePath = args[1];
|
||||
|
||||
if (!ValidateArguments(openApiDocFilePath, outputEndpointsFilePath))
|
||||
{
|
||||
PrintHelp();
|
||||
return 1;
|
||||
}
|
||||
|
||||
OpenApiDocument openApiDocument = OpenApiDocumentParser.ParseOpenApiDocument(openApiDocFilePath);
|
||||
List<Endpoint> endpoints = EndpointParser.ParseAllEndpoints(openApiDocument);
|
||||
string json = JsonConvert.SerializeObject(endpoints, Formatting.Indented);
|
||||
File.WriteAllText(outputEndpointsFilePath, json);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool ValidateArguments(string openApiDocFilePath, string outputEndpointsFilePath)
|
||||
{
|
||||
if (!File.Exists(openApiDocFilePath))
|
||||
{
|
||||
Console.WriteLine("Cannot find specified OpenApi file");
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.Create(outputEndpointsFilePath).Close();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Cannot create output file on defined path.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void PrintHelp()
|
||||
{
|
||||
Console.WriteLine("Arguments:");
|
||||
Console.WriteLine("1] OpenAPI doc. file");
|
||||
Console.WriteLine("2] Output file with JSON endpoints specification");
|
||||
Console.WriteLine("Example: parser.exe api.yaml output.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user