/// <summary> /// Update the OpenAPI document based on the style option /// </summary> /// <param name="style"></param> /// <param name="subsetOpenApiDocument"></param> /// <returns></returns> public static OpenApiDocument ApplyStyle(OpenApiStyleOptions styleOptions, OpenApiDocument subsetOpenApiDocument) { if (styleOptions.Style == OpenApiStyle.Plain) { return(subsetOpenApiDocument); } /* For Powershell and PowerPlatform Styles */ // Clone doc before making changes subsetOpenApiDocument = Clone(subsetOpenApiDocument); var anyOfRemover = new AnyOfRemover(); var walker = new OpenApiWalker(anyOfRemover); walker.Walk(subsetOpenApiDocument); if (styleOptions.Style == OpenApiStyle.PowerShell) { // Format the OperationId for Powershell cmdlet names generation var powershellFormatter = new PowershellFormatter(); walker = new OpenApiWalker(powershellFormatter); walker.Walk(subsetOpenApiDocument); var version = subsetOpenApiDocument.Info.Version; if (!new Regex("v\\d\\.\\d").Match(version).Success) { subsetOpenApiDocument.Info.Version = "v1.0-" + version; } } return(subsetOpenApiDocument); }
/// <summary> /// Update the OpenAPI document based on the style option /// </summary> /// <param name="style">The OpenApiStyle value.</param> /// <param name="subsetOpenApiDocument">The subset of an OpenAPI document.</param> /// <returns>An OpenAPI doc with the respective style applied.</returns> public static OpenApiDocument ApplyStyle(OpenApiStyle style, OpenApiDocument subsetOpenApiDocument) { if (style == OpenApiStyle.GEAutocomplete) { // Clone doc before making changes subsetOpenApiDocument = Clone(subsetOpenApiDocument); // The Content property and its schema $refs are unnecessary for autocomplete RemoveContent(subsetOpenApiDocument); } else if (style == OpenApiStyle.PowerShell || style == OpenApiStyle.PowerPlatform) { /* For Powershell and PowerPlatform Styles */ // Clone doc before making changes subsetOpenApiDocument = Clone(subsetOpenApiDocument); // Remove AnyOf var anyOfRemover = new AnyOfRemover(); var walker = new OpenApiWalker(anyOfRemover); walker.Walk(subsetOpenApiDocument); if (style == OpenApiStyle.PowerShell) { // Format the OperationId for Powershell cmdlet names generation var powershellFormatter = new PowershellFormatter(); walker = new OpenApiWalker(powershellFormatter); walker.Walk(subsetOpenApiDocument); var version = subsetOpenApiDocument.Info.Version; if (!new Regex("v\\d\\.\\d").Match(version).Success) { subsetOpenApiDocument.Info.Version = "v1.0-" + version; } // Remove the root path to make AutoREST happy subsetOpenApiDocument.Paths.Remove("/"); // Temp. fix - Escape the # character from description in // 'microsoft.graph.networkInterface' schema EscapePoundCharacter(subsetOpenApiDocument.Components); } } if (subsetOpenApiDocument.Paths == null || !subsetOpenApiDocument.Paths.Any()) { throw new ArgumentException("No paths found for the supplied parameters."); } return(subsetOpenApiDocument); }