Skip to content

Commit

Permalink
Merge pull request #5238 from microsoft/fix/plugin-type-validation
Browse files Browse the repository at this point in the history
fix/plugin type validation
  • Loading branch information
baywet authored Aug 26, 2024
2 parents bc68b4f + 7e5fd68 commit 4af9013
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- Fixed missing type options in help for plugin commands. [#5230](https://github.com/microsoft/kiota/issues/5230)
- Removed OpenAI plugins generation since the service does not support them anymore.
- Fixed an issue where models would be missing when they had no properties and a single allOf entry. [#5014](https://github.com/microsoft/kiota/issues/5014)
- Reverts modification of responses in output openApi file when generating plugins [#4945](https://github.com/microsoft/kiota/issues/4945)
Expand Down
12 changes: 2 additions & 10 deletions src/kiota/KiotaHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -585,26 +585,18 @@ internal static void ValidateKnownValues(OptionResult input, string parameterNam
input.ErrorMessage = $"{unknownValue} is not a supported {parameterName}, supported values are {validOptionsList}";
}
}
private static void ValidateEnumValue<T>(OptionResult input, string parameterName) where T : struct, Enum
{
if (input.Tokens.Any() && !Enum.TryParse<T>(input.Tokens[0].Value, true, out var _))
{
var validOptionsList = Enum.GetValues<T>().Select(static x => x.ToString()).Aggregate(static (x, y) => x + ", " + y);
input.ErrorMessage = $"{input.Tokens[0].Value} is not a supported generation {parameterName}, supported values are {validOptionsList}";
}
}
private static void AddEnumValidator<T>(Option<T> option, string parameterName) where T : struct, Enum
{
option.AddValidator(input =>
{
ValidateEnumValue<T>(input, parameterName);
ValidateKnownValues(input, parameterName, Enum.GetValues<T>().Select(static x => x.ToString()));
});
}
private static void AddEnumValidator<T>(Option<T?> option, string parameterName) where T : struct, Enum
{
option.AddValidator(input =>
{
ValidateEnumValue<T>(input, parameterName);
ValidateKnownValues(input, parameterName, Enum.GetValues<T>().Select(static x => x.ToString()));
});
}
}
1 change: 1 addition & 0 deletions src/kiota/KiotaPluginCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ internal static Option<List<PluginType>> GetPluginTypeOption(bool isRequired = t
typeOption.IsRequired = true;
typeOption.Arity = ArgumentArity.OneOrMore;
}
typeOption.AddCompletions(Enum.GetNames<PluginType>());
typeOption.AddValidator(x => KiotaHost.ValidateKnownValues(x, "type", Enum.GetNames<PluginType>()));
return typeOption;
}
Expand Down

0 comments on commit 4af9013

Please sign in to comment.