christianhelle / refitter

A tool for generating Refit interfaces and contracts from OpenAPI specifications
https://refitter.github.io
MIT License
187 stars 41 forks source link

Suggest using --skip-validation CLI tool argument validation error #329

Closed christianhelle closed 7 months ago

christianhelle commented 7 months ago

This pull request suggests to use the --skip-validation upon OpenApiUnsupportedSpecVersionException.

When OpenApiUnsupportedSpecVersionException is thrown, the user will be prompted to use the --skip-validation argument to bypass the validation process. In most cases, the code will still generate successfully, even though validation failed. However, this is no garantee

Additionally, the pull request includes some minor formatting improvements in the exception handling code.

The output of using a v3.1.0 spec is something like this:

Refitter v1.0.0.0
Support key: ptbddgt

Unsupported OpenAPI version: 3.1.0
Try using the --skip-validation argument.

Error: OpenAPI specification version '3.1.0' is not supported.
Exception: Microsoft.OpenApi.Readers.Exceptions.OpenApiUnsupportedSpecVersionException
Stack Trace:
   at Microsoft.OpenApi.Readers.ParsingContext.Parse(YamlDocument yamlDocument)
   at Microsoft.OpenApi.Readers.OpenApiYamlDocumentReader.ReadAsync(YamlDocument input, CancellationToken cancellationToken)
   at Microsoft.OpenApi.Readers.OpenApiTextReaderReader.ReadAsync(TextReader input, CancellationToken cancellationToken)
   at Microsoft.OpenApi.Readers.OpenApiStreamReader.ReadAsync(Stream input, CancellationToken cancellationToken)
   at Microsoft.OpenApi.Readers.OpenApiMultiFileReader.Read(String openApiFile, CancellationToken cancellationToken) in /home/runner/work/oasreader/oasreader/src/OasReader/OpenApiMultiFileReader.cs:line 21
   at Refitter.Validation.OpenApiValidator.Validate(String openApiFile) in C:\projects\christianhelle\refitter\src\Refitter\Validation\OpenApiValidator.cs:line 13
   at Refitter.GenerateCommand.ValidateOpenApiSpec(String openApiPath) in C:\projects\christianhelle\refitter\src\Refitter\GenerateCommand.cs:line 155
   at Refitter.GenerateCommand.ExecuteAsync(CommandContext context, Settings settings) in C:\projects\christianhelle\refitter\src\Refitter\GenerateCommand.cs:line 74

#############################################################################
#  Consider reporting the problem if you are unable to resolve it yourself  #
#  https://github.com/christianhelle/refitter/issues                        #
#############################################################################
sonarcloud[bot] commented 7 months ago

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud