|
1 | 1 | [](https://travis-ci.com/getkin/kin-openapi)
|
2 | 2 | [](https://goreportcard.com/report/github.com/getkin/kin-openapi)
|
3 | 3 | [](https://godoc.org/github.com/getkin/kin-openapi)
|
| 4 | +[](https://gitter.im/getkin/kin?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
4 | 5 |
|
5 |
| -# Overview |
6 |
| -This library provides packages for dealing with OpenAPI specifications. |
| 6 | +# Introduction |
| 7 | +A [Go](https://golang.org) project for handling [OpenAPI](https://www.openapis.org/) files. We target the latest OpenAPI version (currently 3), but the project contains support for older OpenAPI versions too. |
7 | 8 |
|
8 |
| -## Status |
9 |
| -### Current |
10 |
| - * [X] Reads and writes [OpenAPI version 3.0 documents](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/README.md) |
11 |
| - * [X] Reads and writes [OpenAPI version 2.0 documents](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) and converts 2.0 -> 3.0 and 3.0->2.0. |
12 |
| - * Does NOT support all features. |
13 |
| - * [X] Validates: |
14 |
| - * [X] That a Go value matches [OpenAPI 3.0 schema object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.md#schemaObject) |
15 |
| - * [X] That HTTP request matches [OpenAPI operation object](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/versions/3.0.md#operationObject) |
16 |
| - * [X] That HTTP response matches OpenAPI 3.0 operation object |
17 |
| - * [X] Generates JSON schemas for Go types. |
| 9 | +Licensed under the [MIT License](LICENSE). |
18 | 10 |
|
19 |
| -### TODO |
20 |
| - * [ ] More tests |
| 11 | +## Contributors and users |
| 12 | +The project has received pull requests from many people. Thanks to everyone! |
21 | 13 |
|
22 |
| -## Dependencies |
23 |
| - * Go 1.7 or greater. |
24 |
| - * No other dependencies! |
| 14 | +Here's some projects that depend on _kin-openapi_: |
| 15 | + * [github.com/getkin/kin](https://github.com/getkin/kin) - "A configurable backend" |
| 16 | + * [github.com/danielgtaylor/apisprout](https://github.com/danielgtaylor/apisprout) - "Lightweight, blazing fast, cross-platform OpenAPI 3 mock server with validation" |
| 17 | + * (Feel free to add your project by [creating an issue](https://github.com/getkin/kin-openapi/issues/new) or a pull request) |
25 | 18 |
|
26 |
| -## License |
27 |
| - * [MIT License](LICENSE) |
28 |
| - |
29 |
| -## Alternatives |
| 19 | +## Alternative projects |
30 | 20 | * [go-openapi](https://github.com/go-openapi)
|
31 |
| - * Provides a stable and well-tested implementation of OpenAPI version 2. |
| 21 | + * Supports OpenAPI version 2. |
32 | 22 | * See [this list](https://github.com/OAI/OpenAPI-Specification/blob/OpenAPI.next/IMPLEMENTATIONS.md).
|
33 | 23 |
|
34 |
| -# Packages |
35 |
| - * `jsoninfo` |
36 |
| - * Provides information and functions for marshalling/unmarshalling JSON. The purpose is a clutter-free implementation of JSON references and OpenAPI extension properties. |
37 |
| - * `openapi2` |
38 |
| - * Parses/writes OpenAPI 2. |
39 |
| - * `openapi2conv` |
40 |
| - * Converts OpenAPI 2 specification into OpenAPI 3 specification. |
41 |
| - * `openapi3` |
42 |
| - * Parses/writes OpenAPI 3. Includes OpenAPI schema / JSON schema valdation. |
43 |
| - * `openapi3filter` |
44 |
| - * Validates that HTTP request and HTTP response match an OpenAPI specification file. |
45 |
| - * `openapi3gen` |
46 |
| - * Generates OpenAPI 3 schemas for Go types. |
47 |
| - * `pathpattern` |
48 |
| - * Support for OpenAPI style path patterns. |
49 |
| - |
50 |
| - |
51 |
| -# Getting started |
| 24 | +# Structure |
| 25 | + * _openapi2_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi2)) |
| 26 | + * Support for OpenAPI 2 files, including serialization, deserialization, and validation. |
| 27 | + * _openapi2conv_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi2conv)) |
| 28 | + * Converts OpenAPI 2 files into OpenAPI 3 files. |
| 29 | + * _openapi3_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi3)) |
| 30 | + * Support for OpenAPI 3 files, including serialization, deserialization, and validation. |
| 31 | + * _openapi3filter_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi3filter)) |
| 32 | + * Validates HTTP requests and responses |
| 33 | + * _openapi3gen_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi3gen)) |
| 34 | + * Generates `*openapi3.Schema` values for Go types. |
| 35 | + * _pathpattern_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/pathpattern)) |
| 36 | + * Matches strings with OpenAPI path patterns ("/path/{parameter}") |
| 37 | + |
| 38 | +# Some recipes |
52 | 39 | ## Loading OpenAPI document
|
53 | 40 | Use `SwaggerLoader`, which resolves all JSON references:
|
54 | 41 | ```go
|
@@ -96,26 +83,4 @@ func ValidateRequest(req *http.Request) {
|
96 | 83 | })
|
97 | 84 | }
|
98 | 85 |
|
99 |
| -``` |
100 |
| - |
101 |
| -## Having extension properties in your own structs |
102 |
| -The package `jsoninfo` marshals/unmarshal JSON extension properties (`"x-someExtension"`) |
103 |
| - |
104 |
| -Usage looks like: |
105 |
| -```go |
106 |
| -type Example struct { |
107 |
| - // Allow extension properties ("x-someProperty") |
108 |
| - openapi3.ExtensionProps |
109 |
| - |
110 |
| - // Normal properties |
111 |
| - SomeField float64 |
112 |
| -} |
113 |
| - |
114 |
| -func (example *Example) MarshalJSON() ([]byte, error) { |
115 |
| - return jsoninfo.MarshalStrictStruct(example) |
116 |
| -} |
117 |
| - |
118 |
| -func (example *Example) UnmarshalJSON(data []byte) error { |
119 |
| - return jsoninfo.UnmarshalStrictStruct(data, example) |
120 |
| -} |
121 |
| -``` |
| 86 | +``` |
0 commit comments