mirror of
https://github.com/ysoftdevs/wapifuzz.git
synced 2026-01-12 06:40:30 +01:00
33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using System;
|
|
using Microsoft.OpenApi.Models;
|
|
using Models;
|
|
|
|
namespace Parser
|
|
{
|
|
public static class AttributeParser
|
|
{
|
|
public static UriAttribute ParseAttribute(OpenApiParameter parameter)
|
|
{
|
|
if (parameter.In == ParameterLocation.Path || parameter.In == ParameterLocation.Query)
|
|
{
|
|
if (parameter.Schema == null || parameter.Schema.Type == null && parameter.Schema.Format == null)
|
|
{
|
|
throw new ArgumentException("We do not know anything useful about passed URI parameter.");
|
|
}
|
|
|
|
UriAttribute attribute = new UriAttribute(parameter.Name, parameter.Required)
|
|
{
|
|
ExampleValue = ContentParser.GetStringExampleFromContent(parameter.Example, parameter.Examples) ??
|
|
ContentParser.GetSingleExample(parameter.Schema?.Example) ??
|
|
PrimitiveDataTypeExampleGenerator.GenerateExampleValueByType(parameter.Schema.Type, parameter.Schema.Format),
|
|
Type = parameter.Schema.Type,
|
|
Format = parameter.Schema.Format,
|
|
Location = parameter.In == ParameterLocation.Path ? "Path" : "Query"
|
|
};
|
|
return attribute;
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|