Skip to content

Commit

Permalink
Fix build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
viceroypenguin committed Feb 19, 2025
1 parent 35081f1 commit 0cc6dab
Showing 1 changed file with 97 additions and 78 deletions.
175 changes: 97 additions & 78 deletions src/Plaid.OpenApiParser/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,17 @@ static string GetEnumName(string name) =>
BasePath = basePath,
Name = name,
Description = pd,
Properties = GetEnumValues(schema)
.OfType<OpenApiString>()
.Select(e => new Property(
e.Value,
string.Empty,
GetEnumName(e.Value),
ed.GetValueOrDefault(e.Value)
))
.ToList(),
Properties =
[
.. GetEnumValues(schema)
.OfType<OpenApiString>()
.Select(e => new Property(
e.Value,
string.Empty,
GetEnumName(e.Value),
ed.GetValueOrDefault(e.Value)
))
],
};
}
else
Expand All @@ -194,41 +196,43 @@ static string GetEnumName(string name) =>
properties.AddRange(s.Properties);
}

e.Properties = properties
.Where(p => baseType switch
{
BaseType.Request => p.Key is not "client_id" and not "secret" and not "access_token",
BaseType.Response => p.Key is not "request_id" and not "error",
BaseType.Webhook or BaseType.ProcessorWebhook => p.Key is not "environment",
BaseType.None => true,
_ => true,
})
.Select(p =>
{
var propertyName = p.Key.ToLower(null).ToPascalCase();
if (baseType is BaseType.Webhook or BaseType.ProcessorWebhook && p.Key is "webhook_type" or "webhook_code")
e.Properties =
[
.. properties
.Where(p => baseType switch
{
var code = p.Value.Description.Trim('`', '"');
return new Property(code, propertyName, propertyName, code.ToLower(null).ToPascalCase());
}

var typeName = GetPropertyType(name, propertyName, p.Value, type);
if (p.Value.Nullable
|| p.Value is { AllOf: [{ Nullable: true }] }
|| !schema.Required.Contains(p.Key))
BaseType.Request => p.Key is not "client_id" and not "secret" and not "access_token",
BaseType.Response => p.Key is not "request_id" and not "error",
BaseType.Webhook or BaseType.ProcessorWebhook => p.Key is not "environment",
BaseType.None => true,
_ => true,
})
.Select(p =>
{
typeName += "?";
}

return new Property(
p.Key,
typeName,
propertyName,
GetPropertyDescription(p.Value),
IsDeprecated: p.Value.Deprecated
);
})
.ToList();
var propertyName = p.Key.ToLower(null).ToPascalCase();
if (baseType is BaseType.Webhook or BaseType.ProcessorWebhook && p.Key is "webhook_type" or "webhook_code")
{
var code = p.Value.Description.Trim('`', '"');
return new Property(code, propertyName, propertyName, code.ToLower(null).ToPascalCase());
}

var typeName = GetPropertyType(name, propertyName, p.Value, type);
if (p.Value.Nullable
|| p.Value is { AllOf: [{ Nullable: true }] }
|| !schema.Required.Contains(p.Key))
{
typeName += "?";
}

return new Property(
p.Key,
typeName,
propertyName,
GetPropertyDescription(p.Value),
IsDeprecated: p.Value.Deprecated
);
})
];
}
}

Expand Down Expand Up @@ -407,13 +411,16 @@ private static void ProcessAccountTypes(OpenApiDocument doc)
BasePath = "Entity",
Name = "AccountType",
Description = "The general type of an account.",
Properties = pd
.Select(e => new Property(
e.Key,
string.Empty,
GetEnumName(e.Key),
e.Value))
.ToList(),
Properties =
[
.. pd
.Select(e => new Property(
e.Key,
string.Empty,
GetEnumName(e.Key),
e.Value
))
],
};
pd.Clear();

Expand All @@ -438,13 +445,16 @@ private static void ProcessAccountTypes(OpenApiDocument doc)
BasePath = "Entity",
Name = "AccountSubtype",
Description = "The specific type of an account.",
Properties = pd
.Select(e => new Property(
e.Key,
string.Empty,
GetEnumName(e.Key),
e.Value))
.ToList(),
Properties =
[
.. pd
.Select(e => new Property(
e.Key,
string.Empty,
GetEnumName(e.Key),
e.Value
))
],
};
}

Expand Down Expand Up @@ -487,13 +497,16 @@ private static void ProcessWebhookTypes(OpenApiDocument doc, bool isProcessor, D
BasePath = "Entity",
Name = prefix + "WebhookType",
Description = "A list of supported Webhook Payload types.",
Properties = types
.Select(e => new Property(
e.jsonName,
string.Empty,
e.name,
null))
.ToList(),
Properties =
[
.. types
.Select(e => new Property(
e.jsonName,
string.Empty,
e.name,
null
))
],
};

s_schemaEntities[prefix + "WebhookCode"] = new()
Expand All @@ -502,13 +515,16 @@ private static void ProcessWebhookTypes(OpenApiDocument doc, bool isProcessor, D
BasePath = "Entity",
Name = prefix + "WebhookCode",
Description = "A list of supported Webhook Payload codes.",
Properties = codes
.Select(e => new Property(
e.jsonName,
string.Empty,
e.name,
null))
.ToList(),
Properties =
[
.. codes
.Select(e => new Property(
e.jsonName,
string.Empty,
e.name,
null
))
],
};
}

Expand All @@ -522,14 +538,17 @@ private static void AddAccountSubtype(OpenApiDocument doc, string subtypeName, s
BasePath = "Entity",
Name = subtypeName,
Description = FixupDescription(schema.Description),
Properties = schema.Enum
.OfType<OpenApiString>()
.Select(e => new Property(
e.Value,
string.Empty,
GetEnumName(e.Value),
e.Value == "all" ? "Allow all of the above subtypes" : descriptions[e.Value].Description))
.ToList(),
Properties =
[
.. schema.Enum
.OfType<OpenApiString>()
.Select(e => new Property(
e.Value,
string.Empty,
GetEnumName(e.Value),
e.Value == "all" ? "Allow all of the above subtypes" : descriptions[e.Value].Description
))
],
};
}

Expand Down

0 comments on commit 0cc6dab

Please sign in to comment.