{"id":15291161,"url":"https://github.com/azure/oav","last_synced_at":"2025-05-15T14:04:38.755Z","repository":{"id":37733036,"uuid":"73132751","full_name":"Azure/oav","owner":"Azure","description":"Tools for validating OpenAPI (Swagger) files.","archived":false,"fork":false,"pushed_at":"2025-05-01T01:30:43.000Z","size":25861,"stargazers_count":99,"open_issues_count":105,"forks_count":55,"subscribers_count":211,"default_branch":"develop","last_synced_at":"2025-05-10T00:12:09.534Z","etag":null,"topics":["azure","live-validation","model-validation","openapi","openapi-validation","request-validation","response-validation","semantic-validation","spec-resolver","swagger","traffic-validation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Azure.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-08T00:14:57.000Z","updated_at":"2025-04-12T05:45:48.000Z","dependencies_parsed_at":"2023-10-14T20:55:10.778Z","dependency_job_id":"93b6cd7c-8256-4b33-b73c-83c8b37eaff3","html_url":"https://github.com/Azure/oav","commit_stats":{"total_commits":711,"total_committers":45,"mean_commits":15.8,"dds":0.8115330520393811,"last_synced_commit":"bf50f770da65ab3c1026a3a6744113c061cb97f4"},"previous_names":["azure/openapi-validation-tools"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Foav","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Foav/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Foav/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Foav/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure","download_url":"https://codeload.github.com/Azure/oav/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254355334,"owners_count":22057354,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["azure","live-validation","model-validation","openapi","openapi-validation","request-validation","response-validation","semantic-validation","spec-resolver","swagger","traffic-validation"],"created_at":"2024-09-30T16:11:13.715Z","updated_at":"2025-05-15T14:04:38.701Z","avatar_url":"https://github.com/Azure.png","language":"TypeScript","readme":"# openapi-validation-tools [oav]\r\n\r\n[![Package version](https://img.shields.io/npm/v/oav)](https://www.npmjs.com/package/oav)\r\n\r\n[![Build Status](https://dev.azure.com/azure-public/adx/_apis/build/status/public.Azure.oav)](https://dev.azure.com/azure-public/adx/_build/latest?definitionId=3)\r\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\r\n\r\nRegression: [![Build Status](https://dev.azure.com/azure-sdk/public/_apis/build/status/OAV%20Validate%20Examples%20Regression?branchName=master)](https://dev.azure.com/azure-sdk/public/_build/latest?definitionId=163\u0026branchName=master) [How to fix this](#fixing-regression-builds)\r\n\r\nTools for validating OpenAPI (Swagger) files.\r\n\r\n## Requirements\r\n\r\n- **node.js version \u003e= 18.x**\r\n\r\nYou can install the latest stable release of node.js from [here](https://nodejs.org/en/download/). For a machine with a linux flavored OS, please follow the node.js installation instructions over [here](https://nodejs.org/en/download/package-manager/)\r\n\r\n### How to install the tool\r\n\r\n```bash\r\nnpm install -g oav@latest\r\n```\r\n\r\n#### Command usage:\r\n\r\n```bash\r\n$ oav -h    Commands:\r\n  analyze-dependency                        analyze swagger resource type\r\n                                            dependency.\r\n  analyze-report \u003cnewman-report-path\u003e       analyze report. default format:\r\n                                            newman json report\r\n  example-quality \u003cspec-path\u003e               Performs example quality validation\r\n                                            of x-ms-examples and examples\r\n                                            present in the spec.\r\n  extract-xmsexamples \u003cspec-path\u003e           Extracts the x-ms-examples for a\r\n  \u003crecordings\u003e                              given swagger from the .NET session\r\n                                            recordings and saves them in a file.\r\n  generate-collection                       Generate postman collection file\r\n                                            from API scenario.\r\n  generate-examples [spec-path]             Generate swagger examples from real\r\n                                            payload records.\r\n  generate-report [raw-report-path]         Generate report from postman report.\r\n  generate-api-scenario                     Generate swagger examples from real\r\n                                            payload records.\r\n  generate-static-api-scenario              Generate API-scenario from swagger.\r\n  run-api-scenario \u003capi-scenario\u003e           newman runner run API scenario\r\n                                            file.                 [aliases: run]\r\n  validate-example \u003cspec-path\u003e              Performs validation of x-ms-examples\r\n                                            and examples present in the spec.\r\n  validate-spec \u003cspec-path\u003e                 Performs semantic validation of the\r\n                                            spec.\r\n  validate-traffic \u003ctraffic-path\u003e           Validate traffic payload against the\r\n  \u003cspec-path\u003e                               spec.\r\n  traffic-convert \u003cinput-dir\u003e               Showcase what it would look like to \r\n  \u003coutput-dir\u003e                              transform a directory full of \r\n                                            [azure-sdk/test-proxy](https://github.com/Azure/azure-sdk-tools/tree/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy) \r\n                                            recordings files into traffic payloads \r\n                                            consumable by traffic validation command in oav\r\n  \r\n\r\nOptions:\r\n  --version          Show version number                               [boolean]\r\n  -l, --logLevel     Set the logging level for console.\r\n  [choices: \"off\", \"json\", \"error\", \"warn\", \"info\", \"verbose\", \"debug\", \"silly\"]\r\n                                                               [default: \"info\"]\r\n  -f, --logFilepath  Set the log file path. It must be an absolute filepath. By\r\n                     default the logs will stored in a timestamp based log file\r\n                     at \"/home/ruowan/oav_output\".\r\n  -p, --pretty       Pretty print\r\n  -h, --help         Show help                                         [boolean]\r\n\r\n```\r\n\r\n### What does the tool do? What issues does the tool catch?\r\n\r\n- Semantic validation\r\n  Semantic validation enforces correctness on the swagger specific elements. Such as paths and operations. Ensure the element definition meet the [OpenApi 2.0 specification](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md).\r\n- Model validation\r\n  Model validation enforces correctness between example and swagger. It checks whether definitions for request parameters and responses, match an expected input/output payload of the service.\r\n  \r\n     Examples of issues detected: \r\n     - Required properties not sent in requests or responses\r\n     - Defined types not matching the value provided in the payload\r\n     - Constraints on properties not met\r\n     - Enumeration values that don’t match the value used by the service.\r\n\r\n     Model validation _requires_ example payloads (request/response) of the service, so the data can be matched with the defined models. See [x-ms-examples extension](https://github.com/Azure/azure-rest-api-specs/issues/648) on how to specify the examples/payloads. Swagger “examples” is also supported and data included there is validated as well. To get the most benefit from this tool, make sure to have the simplest and most complex examples possible as part of x-ms-examples.\r\n     - Please take a look at the redis-cache swagger spec as an example for providing \"x-ms-examples\" over [here](https://github.com/Azure/azure-rest-api-specs/blob/389d3c2b3256fa48e3d78e07769907857b215536/specification/redis/resource-manager/Microsoft.Cache/stable/2016-04-01/redis.json#L68).\r\n     - The examples need to be provided in a separate file in the examples directory under the api-version directory `azure-rest-api-specs/arm-\u003cyourService\u003e/\u003capi-version\u003e/examples/\u003cexampleName\u003e.json`. You can take a look over [here](https://github.com/Azure/azure-rest-api-specs/tree/1c100daabed6a008c76f3e4e0cae4e7eac5a5bf4/specification/redis/resource-manager/Microsoft.Cache/stable/2016-04-01/examples) for the structure of examples.\r\n\r\n     - We require you to provide us a minimum (just required properties/parameters of the request/response) and a maximum (full blown) example. Feel free to provide more examples as deemed necessary.\r\n     - We have provided schemas for examples to be provided in the examples directory. It can be found over [here](https://github.com/Azure/autorest/blob/27ab06c254c99af5c7de07a550f765713b1f71ee/packages/libs/autorest-schemas/example-schema.json). This will help you with intellisense and validation.\r\n\r\n     - If you are using **vscode** to edit your swaggers in the azure-rest-api-specs repo then everything should work out of the box as the schemas have been added in the `.vscode/settings.json` file over [here](https://github.com/Azure/azure-rest-api-specs/blob/master/.vscode/settings.json).\r\n     - If you are using **Visual Studio** then you can use the urls provided in the settings.json file and put them in the drop down list at the top of a json file when the file is opened in VS.\r\n\r\n### How does this tool fit with others\r\n\r\nSwagger specs validation could be split in the following:\r\n\r\n1. Schema validation\r\n2. Semantic validation\r\n3. Model definition validation\r\n4. Swagger operations execution (against mocked data or live tests)\r\n5. Human-eye review to complement the above\r\n\r\nIn the context of “azure-rest-api-specs” repo:\r\n\r\n- #1 is being performed on every PR as part of CI.\r\n- #2 and #3 are performed by the tool currently in openapi-validation-tools repo and by AutoRest linter. We’re working towards integrating them into CI for “azure-rest-api-specs” repo.\r\n- #4 is not available yet, though we’re starting to work on it.\r\n- #5 will be done by the approvers of PRs in “azure-rest-api-specs”, as this won’t be automated.\r\n\r\n### Run API test\r\n\r\nOAV support run API test against Azure and validate request and response. You could define API scenario file which compose with several swagger example files and then use oav to execute it. For more details about API test, please refer to this [API scenario documentation](https://github.com/Azure/azure-rest-api-specs/tree/main/documentation/api-scenario).\r\n\r\n![](./documentation/runApiTest.gif)\r\n\r\n### Live Validation Mode\r\n\r\n- A **Live Validation** mode has been added to OAV with the purpose of enabling validation of live traffic.\r\n- Usage (here is a sample of a [request-response pair](./test/sampleRequestResponsePair.json)):\r\n\r\n```javascript\r\nconst liveValidatorOptions = {\r\n  git: {\r\n    url: \"https://github.com/Azure/azure-rest-api-specs.git\",\r\n    shouldClone: true,\r\n  },\r\n  directory: path.resolve(os.homedir(), \"cloneRepo\"),\r\n  swaggerPathsPattern: \"/specification/**/resource-manager/**/*.json\",\r\n  isPathCaseSensitive: false,\r\n  shouldModelImplicitDefaultResponse: true,\r\n};\r\n\r\nconst apiValidator = new oav.LiveValidator(liveValidatorOptions);\r\nawait apiValidator.initialize(); // Note that for a large number of specs this can take some time.\r\n\r\n// After `initialize()` finishes we are ready to validate\r\nconst validationResult = apiValidator.validateLiveRequestResponse(requestResponsePair);\r\n```\r\n\r\n### Regression testing\r\n\r\nOutput of the OAV tool has been snapshotted and committed to the repo. The regression test may be run on a sample or all of https://github.com/azure/azure-rest-api-specs. If there are changes to the snapshots the build produces a git patch file as an artifact which may be used to update the snapshots.\r\n\r\n[Fast Regression (~10mins)](https://dev.azure.com/azure-sdk/public/_build?definitionId=166\u0026_a=completed) is used for merge validation\r\n\r\n[Slow Regression (~1 hour)](https://dev.azure.com/azure-sdk/public/_build?definitionId=163\u0026_a=completed) is run after merge and should be fixed if it fails\r\n\r\n#### Fixing regression builds\r\n\r\n1. Go to the failed build\r\n2. Download the artifact patch file\r\n3. In the OAV directory run `git apply \u003cpath to patch file\u003e`\r\n4. Commit the patched changes and create a pull request\r\n5. Validate that the changes look ok and don't represent a breaking change in OAV\r\n6. Merge the PR\r\n\r\n---\r\n\r\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure%2Foav","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazure%2Foav","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure%2Foav/lists"}