Skip to content
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

Introduce OpenAPI validation #141

Merged
merged 6 commits into from
Sep 5, 2023
Merged

Introduce OpenAPI validation #141

merged 6 commits into from
Sep 5, 2023

Conversation

christianhelle
Copy link
Owner

The changes here implement OpenAPI validation using Microsoft OpenAPI libraries. With the changes here, Refitter will print out validation errors (in red) and warnings (in yellow).

A user can also choose to opt out of OpenAPI validation by using the --skip-validation CLI tool argument

This pull request also includes a new feature that prints out OpenAPI specification statistics for the number of operations, links, parameters, requests, responses, etc...

It looks something like this:

OpenAPI document statistics:
- Path Items: 13
- Operations: 19
- Parameters: 17
- Request Bodies: 9
- Responses: 19
- Links: 0
- Callbacks: 0
- Schemas: 73

New packages Microsoft.OpenApi.OData and Microsoft.OpenApi.Readers were added to the csproj file to support OData and improved API documentation efforts. They were chosen for their comprehensive features and broad compatibility.
Implemented new classes for adding OpenAPI validation. The included changes allow us to validate the correctness and adherence of a given OpenAPI schema and report statistics about the schema elements such as the number of parameters, operations, headers, etc. The changes also handle exceptions encountered during validation and provide diagnostic details about the encountered issues.
In this commit, I have introduced the OpenAPI specification validation to the 'GenerateCommand' execution command.
This will enable the application to validate the OpenAPI specifications before trying to generate any code, thus adding a layer of protection against invalid specifications. I have used the OpenApiValidator to perform the validation.
I have also refined the error display, replacing generic Exception handling with specialized handling for OpenApiValidationException to improve error diagnosis.
A new option '--skip-validation' was introduced in the Settings class, allowing users to bypass the OpenAPI specification validation. This change was implemented to give users more flexibility. In the GenerateCommand class, a conditional statement checking this setting was also added to alter the execution flow based on the user's preference.
Included a new command line flag to README files, '--skip-validation', to allow users to skip validation of the OpenAPI specification. This is particularly useful when users want to expedite the testing process without validating the OpenAPI specification, wherein the tool will trust the input spec and won't raise any validation errors.
@christianhelle christianhelle added the enhancement New feature, bug fix, or request label Sep 5, 2023
@christianhelle christianhelle self-assigned this Sep 5, 2023
@codecov
Copy link

codecov bot commented Sep 5, 2023

Codecov Report

Merging #141 (0802d7b) into main (11d699d) will not change coverage.
Report is 9 commits behind head on main.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #141   +/-   ##
=======================================
  Coverage   98.55%   98.55%           
=======================================
  Files          37       37           
  Lines        1176     1176           
=======================================
  Hits         1159     1159           
  Misses          6        6           
  Partials       11       11           
Flag Coverage Δ
unittests 98.55% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 5, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@christianhelle christianhelle merged commit b06c3b6 into main Sep 5, 2023
@christianhelle christianhelle deleted the openapi-validation branch September 5, 2023 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, bug fix, or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant