Debian Codegraph @

README.md

raw
1 īģŋ<p align="center">
2 <img src="libopenapi-logo.png" alt="libopenapi" height="300px" width="450px"/>
3 </p>
4
5 # Enterprise grade OpenAPI validation tools for golang.
6
7 ![Pipeline](https://github.com/pb33f/libopenapi-validator/workflows/Build/badge.svg)
8 [![codecov](https://codecov.io/gh/pb33f/libopenapi-validator/branch/main/graph/badge.svg?)](https://codecov.io/gh/pb33f/libopenapi-validator)
9 [![discord](https://img.shields.io/discord/923258363540815912)](https://discord.gg/x7VACVuEGP)
10 [![Docs](https://img.shields.io/badge/godoc-reference-5fafd7)](https://pkg.go.dev/github.com/pb33f/libopenapi-validator)
11
12 A validation module for [libopenapi](https://github.com/pb33f/libopenapi).
13
14 `libopenapi-validator` will validate the following elements against an OpenAPI 3+ specification
15
16 - *http.Request* - Validates the request against the OpenAPI specification
17 - *http.Response* - Validates the response against the OpenAPI specification
18 - *libopenapi.Document* - Validates the OpenAPI document against the OpenAPI specification
19 - *base.Schema* - Validates a schema against a JSON or YAML blob / unmarshalled object
20
21 👉👉 [Check out the full documentation](https://pb33f.io/libopenapi/validation/) 👈👈
22
23 ---
24
25 ## Installation
26
27 ```bash
28 go get github.com/pb33f/libopenapi-validator
29 ```
30
31 ## Validate OpenAPI Document
32
33 ```bash
34 go run github.com/pb33f/libopenapi-validator/cmd/validate@latest [--regexengine] [--yaml2json] <file>
35 ```
36
37 ## Install pre-commit hook
38
39 To install the pre-commit hook, run the following command in your terminal:
40
41 ```bash
42 pre-commit install
43 ```
44
45 ### Options
46
47 #### --regexengine
48 🔍 Example: Use a custom regex engine/flag (e.g., ecmascript)
49 ```bash
50 go run github.com/pb33f/libopenapi-validator/cmd/validate@latest --regexengine=ecmascript <file>
51 ```
52 🔧 Supported **--regexengine** flags/values (â„šī¸ Default: re2)
53 - none
54 - ignorecase
55 - multiline
56 - explicitcapture
57 - compiled
58 - singleline
59 - ignorepatternwhitespace
60 - righttoleft
61 - debug
62 - ecmascript
63 - re2
64 - unicode
65
66 #### --yaml2json
67 🔍 Convert YAML files to JSON before validation (â„šī¸ Default: false)
68
69 [libopenapi](https://github.com/pb33f/libopenapi/blob/main/datamodel/spec_info.go#L115) passes `map[interface{}]interface{}` structures for deeply nested objects or complex mappings in the OpenAPI specification, which are not allowed in JSON.
70 These structures cannot be properly converted to JSON by libopenapi and cannot be validated by jsonschema, resulting in ambiguous errors.
71
72 This flag allows pre-converting from YAML to JSON to bypass this limitation of the libopenapi.
73
74 **When does this happen?**
75 - OpenAPI specs with deeply nested schema definitions
76 - Complex `allOf`, `oneOf`, or `anyOf` structures with multiple levels
77 - Specifications with intricate object mappings in examples or schema properties
78
79 Enabling this flag pre-converts the YAML document from YAML to JSON, ensuring a clean JSON structure before validation.
80
81 Example:
82 ```bash
83 go run github.com/pb33f/libopenapi-validator/cmd/validate@latest --yaml2json <file>
84 ```
85
86 ## Documentation
87
88 - [The structure of the validator](https://pb33f.io/libopenapi/validation/#the-structure-of-the-validator)
89 - [Validation errors](https://pb33f.io/libopenapi/validation/#validation-errors)
90 - [Schema errors](https://pb33f.io/libopenapi/validation/#schema-errors)
91 - [High-level validation](https://pb33f.io/libopenapi/validation/#high-level-validation)
92 - [Validating http.Request](https://pb33f.io/libopenapi/validation/#validating-httprequest)
93 - [Validating http.Request and http.Response](https://pb33f.io/libopenapi/validation/#validating-httprequest-and-httpresponse)
94 - [Validating just http.Response](https://pb33f.io/libopenapi/validation/#validating-just-httpresponse)
95 - [Validating HTTP Parameters](https://pb33f.io/libopenapi/validation/#validating-http-parameters)
96 - [Validating an OpenAPI document](https://pb33f.io/libopenapi/validation/#validating-an-openapi-document)
97 - [Validating Schemas](https://pb33f.io/libopenapi/validation/#validating-schemas)
98
99 [libopenapi](https://github.com/pb33f/libopenapi) and [libopenapi-validator](https://github.com/pb33f/libopenapi-validator) are
100 products of Princess Beef Heavy Industries, LLC