-
Notifications
You must be signed in to change notification settings - Fork 281
feat: openapiformat enum cleanup #2326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,7 @@ | |
| /// <summary> | ||
| /// Implementation of the transform command | ||
| /// </summary> | ||
| public static async Task TransformOpenApiDocumentAsync(HidiOptions options, ILogger logger, CancellationToken cancellationToken = default) | ||
| { | ||
| if (string.IsNullOrEmpty(options.OpenApi) && string.IsNullOrEmpty(options.Csdl) && string.IsNullOrEmpty(options.FilterOptions?.FilterByApiManifest)) | ||
| { | ||
|
|
@@ -55,7 +55,7 @@ | |
| if (options.Output == null) | ||
| { | ||
| #pragma warning disable CA1308 // Normalize strings to uppercase | ||
| var extension = options.OpenApiFormat?.GetDisplayName().ToLowerInvariant(); | ||
| var extension = options.OpenApiFormat?.ToLowerInvariant(); | ||
| var inputExtension = !string.IsNullOrEmpty(extension) ? string.Concat(".", extension) | ||
| : GetInputPathExtension(options.OpenApi, options.Csdl); | ||
|
|
||
|
|
@@ -73,7 +73,7 @@ | |
| } | ||
|
|
||
| // Default to yaml and OpenApiVersion 3_1 during csdl to OpenApi conversion | ||
| var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml); | ||
| var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml); | ||
| var openApiVersion = options.Version != null ? TryParseOpenApiSpecVersion(options.Version) : OpenApiSpecVersion.OpenApi3_1; | ||
|
|
||
| // If ApiManifest is provided, set the referenced OpenAPI document | ||
|
|
@@ -92,7 +92,7 @@ | |
| } | ||
|
|
||
| // Load OpenAPI document | ||
| var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false); | ||
| var document = await GetOpenApiAsync(options, openApiFormat, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| if (options.FilterOptions != null && document is not null) | ||
| { | ||
|
|
@@ -189,7 +189,7 @@ | |
| return document; | ||
| } | ||
|
|
||
| private static async Task WriteOpenApiAsync(HidiOptions options, OpenApiFormat openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken) | ||
| private static async Task WriteOpenApiAsync(HidiOptions options, string openApiFormat, OpenApiSpecVersion openApiVersion, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken) | ||
| { | ||
| using (logger.BeginScope("Output")) | ||
| { | ||
|
|
@@ -205,8 +205,8 @@ | |
|
|
||
| IOpenApiWriter writer = openApiFormat switch | ||
| { | ||
| OpenApiFormat.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false), | ||
| OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings), | ||
| OpenApiConstants.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false), | ||
| OpenApiConstants.Yaml => new OpenApiYamlWriter(textWriter, settings), | ||
| _ => throw new ArgumentException("Unknown format"), | ||
| }; | ||
|
|
||
|
|
@@ -560,10 +560,10 @@ | |
| /// <param name="input"></param> | ||
| /// <param name="logger"></param> | ||
| /// <returns></returns> | ||
| private static OpenApiFormat GetOpenApiFormat(string input, ILogger logger) | ||
| private static string GetOpenApiFormat(string input, ILogger logger) | ||
| { | ||
| logger.LogTrace("Getting the OpenApi format"); | ||
| return !input.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml; | ||
| return !input.StartsWith("http", StringComparison.OrdinalIgnoreCase) && Path.GetExtension(input) == ".json" ? OpenApiConstants.Json : OpenApiConstants.Yaml; | ||
| } | ||
|
|
||
| private static string GetInputPathExtension(string? openapi = null, string? csdl = null) | ||
|
|
@@ -590,8 +590,8 @@ | |
| throw new ArgumentException("Please input a file path or URL"); | ||
| } | ||
|
|
||
| var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml); | ||
| var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, null, cancellationToken).ConfigureAwait(false); | ||
| var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml); | ||
| var document = await GetOpenApiAsync(options, openApiFormat, logger, null, cancellationToken).ConfigureAwait(false); | ||
| if (document is not null) | ||
| { | ||
| using (logger.BeginScope("Creating diagram")) | ||
|
|
@@ -754,10 +754,10 @@ | |
| } | ||
|
|
||
| var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) | ||
| ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml); | ||
| ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiConstants.Yaml); | ||
|
|
||
| // Load OpenAPI document | ||
| var document = await GetOpenApiAsync(options, openApiFormat.GetDisplayName(), logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false); | ||
| var document = await GetOpenApiAsync(options, openApiFormat, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| cancellationToken.ThrowIfCancellationRequested(); | ||
|
|
||
|
|
@@ -777,14 +777,14 @@ | |
| options.TerseOutput = true; | ||
| if (document is not null) | ||
| { | ||
| await WriteOpenApiAsync(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false); | ||
| await WriteOpenApiAsync(options, OpenApiConstants.Json, OpenApiSpecVersion.OpenApi3_1, document, logger, cancellationToken).ConfigureAwait(false); | ||
|
|
||
| // Create OpenAIPluginManifest from ApiDependency and OpenAPI document | ||
| var manifest = new OpenAIPluginManifest(document.Info.Title ?? "Title", | ||
| document.Info.Title ?? "Title", | ||
| "https://go.microsoft.com/fwlink/?LinkID=288890", | ||
| document.Info?.Contact?.Email ?? "[email protected]", | ||
| document.Info?.License?.Url?.ToString() ?? "https://placeholderlicenseurl.com") | ||
| { | ||
| DescriptionForHuman = document.Info?.Description ?? "Description placeholder", | ||
| Api = new("openapi", "./openapi.json"), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.