mirror of
https://github.com/ysoftdevs/wapifuzz.git
synced 2026-03-14 06:15:48 +01:00
Init WFuzz state
This commit is contained in:
59
parser/Parser/RequestParser.cs
Normal file
59
parser/Parser/RequestParser.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Models;
|
||||
|
||||
namespace Parser
|
||||
{
|
||||
public static class RequestParser
|
||||
{
|
||||
public static Request ParseRequest(KeyValuePair<OperationType, OpenApiOperation> operation)
|
||||
{
|
||||
var request = new Request(operation.Key.ToString())
|
||||
{
|
||||
Summary = operation.Value.Summary,
|
||||
BodyExample = GetBodyExample(operation.Value.RequestBody),
|
||||
BodySchema = GetBodySchema(operation.Value.RequestBody),
|
||||
UriAttributes = ParseUriAttributes(operation.Value),
|
||||
Responses = ParseResponses(operation.Value)
|
||||
};
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
static string GetBodyExample(OpenApiRequestBody body)
|
||||
{
|
||||
return body != null ? ExamplesParser.ParseExample(body.Content) : null;
|
||||
}
|
||||
|
||||
static Dictionary<string, object> GetBodySchema(OpenApiRequestBody body)
|
||||
{
|
||||
return body != null ? SchemaParser.ParseSchema(body.Content) : null;
|
||||
}
|
||||
|
||||
static List<UriAttribute> ParseUriAttributes(OpenApiOperation operation)
|
||||
{
|
||||
List<UriAttribute> attributes = new List<UriAttribute>();
|
||||
foreach (var parameter in operation.Parameters)
|
||||
{
|
||||
var attribute = AttributeParser.ParseAttribute(parameter);
|
||||
if (attribute != null)
|
||||
{
|
||||
attributes.Add(attribute);
|
||||
}
|
||||
}
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
static List<Response> ParseResponses(OpenApiOperation operation)
|
||||
{
|
||||
List<Response> responses = new List<Response>();
|
||||
foreach (var openApiResponse in operation.Responses)
|
||||
{
|
||||
responses.Add(ResponseParser.ParseResponse(openApiResponse));
|
||||
}
|
||||
|
||||
return responses;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user