1.0.1 • Published 7 years ago
@microsoft.azure/classic-openapi-arm-validator v1.0.1
Contributing
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Build dependencies
- Node (6.9.5 or higher)
- Node Package Manager
- Typescript (2.3.0 or higher)
Build scripts
How to build
The first step would be to run npm install so we have all the required modules installed.
How to build the whole repo
gulp buildHow to build the typescript repo
gulp build/typescriptHow to build the dotnet repo
To restore the dotnet packages
gulp restore/dotnetThis builds the dotnet projects.
gulp build/dotnetHow to test
To run all tests under the repo
gulp testHow to run the typescript tests
gulp test/typescriptHow to run the dotnet tests
gulp test/dotnetHow to debug the dotnet repo
This extension runs the validation on two threads:
- Individual merge state: validates each individual OpenAPI file.
- Composed merge state: validates the full OpenAPI spec.
For debugging both composed and individual merge state at the same time
autorest input/file --validation --azure-arm-validator --use=path/to/your/repo/sr
c/dotnet/AutoRest --azure-arm-validator.debugger For debugging composed merge state
autorest input/file --validation --azure-arm-validator --use=path/to/your/repo/sr
c/dotnet/AutoRest --azure-arm-validator.composed-debugger For debugging individual merge state
autorest --input-file=path/to/swagger --validation --azure-arm-validator --use=path/to/your/repo/sr
c/dotnet/AutoRest --azure-arm-validator.individual-debugger How to debug the typescript repo
Temporarily change the start script in src/typescript/package.json to "start": "node --inspect-brk ./index.js".
Then run:
autorest input/file --validation --azure-arm-validator --use=path/to/your/repo/src/typescriptThe typescript repo can be debugged with VS Code or Chrome.
How to write a new validation rule using typescript
- Add a typescript file under
azure-openapi-validatordirectory named same as the name of the rule. Add theid,name,severity,category,mergeState,openapiType,appliesTo_JsonQueryproperties to the rule.appliesTo_JsonQueryis the node(s) to which the rule needs to be applied. This is evaluated using JsonPaths. Please refer here for a brief tutorial about JsonPaths. - Next, implement the
runmethod under the rule that actually does the validation. Add a reference to this script file undersrc/typescript/azure-openapi-validator/index.ts. - Lastly add a test case for the validation rule, by adding a test json/yaml under
src/typescript/azure-openapi-validator/tests/resourcesand a script undersrc/typescript/azure-openapi-validator/testsdepending on the type of the validation rule.