Skip to content

Commit

Permalink
Use OpenAPI.NET validation API
Browse files Browse the repository at this point in the history
  • Loading branch information
Caleb Magiya (from Dev Box) committed Oct 17, 2024
1 parent 2bdd1bb commit 1812e9b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
using Kiota.Builder.Extensions;
using Kiota.Builder.OpenApiExtensions;
using Microsoft.OpenApi.ApiManifest;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Writers;
using Microsoft.Plugins.Manifest;
using ValidationRuleSet = Microsoft.OpenApi.Validations.ValidationRuleSet;

namespace Kiota.Builder.Plugins;

Expand Down Expand Up @@ -258,6 +260,21 @@ private OpenApiDocument GetDocumentWithTrimmedComponentsAndResponses(OpenApiDocu

private PluginManifestDocument GetManifestDocument(string openApiDocumentPath)
{
// Validate OpenAPI
var ruleSet = new ValidationRuleSet
{
Microsoft.Plugins.Manifest.OpenApiRules.OpenApiServerUrlRule.ServerUrlMustBeHttps,
Microsoft.Plugins.Manifest.OpenApiRules.OpenApiCombinedAuthFlowRule
.PathsCanOnlyHaveOneSecuritySchemePerOperation(OAIDocument.SecurityRequirements),
Microsoft.Plugins.Manifest.OpenApiRules.OpenApiRequestBodySchemaRule.RequestBodySchemaObjectsMustNeverBeNested,
Microsoft.Plugins.Manifest.OpenApiRules.OpenApiApiKeyBearerRule.ApiKeyNotSupportedOnlyBearerPlusHttp(OAIDocument.SecurityRequirements)
};
var errors = OAIDocument.Validate(ruleSet)?.ToArray();
if (errors != null && errors.Length != 0)
{
var message = string.Join(Environment.NewLine, errors.Select(e => $"{e.Pointer}: {e.Message}"));
throw new InvalidOperationException(message);
}
var (runtimes, functions, conversationStarters) = GetRuntimesFunctionsAndConversationStartersFromTree(OAIDocument, Configuration.PluginAuthInformation, TreeNode, openApiDocumentPath);
var descriptionForHuman = OAIDocument.Info?.Description is string d && !string.IsNullOrEmpty(d) ? d : $"Description for {OAIDocument.Info?.Title}";
var manifestInfo = ExtractInfoFromDocument(OAIDocument.Info);
Expand Down Expand Up @@ -297,8 +314,6 @@ private PluginManifestDocument GetManifestDocument(string openApiDocumentPath)
.ToList()
};

var ruleSet = PluginManifestRuleSets.GetDefaultAuthoringRuleSet();
pluginManifestDocument.Validate(ruleSet, new ValidationContext(schemaVersion));
return pluginManifestDocument;
}

Expand Down

0 comments on commit 1812e9b

Please sign in to comment.