Skip to content

Commit 590c85c

Browse files
authored
Define missing XML in schema, minor fixes and doc additions (#508)
1 parent 32d9f54 commit 590c85c

28 files changed

+187
-54
lines changed

.github/workflows/go.yml

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,25 @@ jobs:
4747
path: ${{ steps.go-cache-paths.outputs.go-mod }}
4848
key: ${{ runner.os }}-go-${{ matrix.go }}-mod-${{ hashFiles('**/go.sum') }}
4949

50+
- if: runner.os == 'Linux'
51+
run: sudo apt install silversearcher-ag
52+
5053
- uses: actions/checkout@v2
5154

5255
- run: go mod download && go mod tidy && go mod verify
53-
- if: runner.os == 'Linux'
54-
run: git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]]
56+
- run: git --no-pager diff --exit-code
5557

5658
- run: go vet ./...
57-
- if: runner.os == 'Linux'
58-
run: git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]]
59+
- run: git --no-pager diff --exit-code
5960

6061
- run: go fmt ./...
61-
- if: runner.os == 'Linux'
62-
run: git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]]
62+
- run: git --no-pager diff --exit-code
6363

6464
- run: go test ./...
6565
- run: go test -v -run TestRaceyPatternSchema -race ./...
6666
env:
6767
CGO_ENABLED: '1'
68-
- if: runner.os == 'Linux'
69-
run: git --no-pager diff && [[ $(git --no-pager diff --name-only | wc -l) = 0 ]]
68+
- run: git --no-pager diff --exit-code
7069

7170
- if: runner.os == 'Linux'
7271
name: Errors must not be capitalized https://github.com/golang/go/wiki/CodeReviewComments#error-strings
@@ -77,3 +76,61 @@ jobs:
7776
name: Did you mean %q
7877
run: |
7978
! git grep -E "'[%].'"
79+
80+
- if: runner.os == 'Linux'
81+
name: Also add yaml tags
82+
run: |
83+
! git grep -InE 'json:"' | grep -v _test.go | grep -v yaml:
84+
85+
- if: runner.os == 'Linux'
86+
name: Missing specification object link to definition
87+
run: |
88+
[[ 30 -eq $(git grep -InE '^// See https:.+OpenAPI-Specification.+3[.]0[.]3[.]md#.+bject$' openapi3/*.go | grep -v _test.go | grep -v doc.go | wc -l) ]]
89+
90+
- if: runner.os == 'Linux'
91+
name: Style around ExtensionProps embedding
92+
run: |
93+
! ag -B2 -A2 'type.[A-Z].+struct..\n.+ExtensionProps\n[^\n]' openapi3/*.go
94+
95+
- if: runner.os == 'Linux'
96+
name: Ensure all exported fields are mentioned in Validate() impls
97+
run: |
98+
for ty in $TYPES; do
99+
# Ensure definition
100+
if ! ag 'type.[A-Z].+struct..\n.+ExtensionProps' openapi3/*.go | grep -F "type $ty struct"; then
101+
echo "OAI type $ty is not defined" && exit 1
102+
fi
103+
104+
# Ensure impl Validate()
105+
if ! git grep -InE 'func [(].+Schema[)] Validate[(]ctx context.Context[)].+error.+[{]'; then
106+
echo "OAI type $ty does not implement Validate()" && exit 1
107+
fi
108+
109+
# TODO: $ty mention all its exported fields within Validate()
110+
done
111+
env:
112+
TYPES: >
113+
Components
114+
Contact
115+
Discriminator
116+
Encoding
117+
Example
118+
ExternalDocs
119+
Info
120+
License
121+
Link
122+
MediaType
123+
OAuthFlow
124+
OAuthFlows
125+
Operation
126+
Parameter
127+
PathItem
128+
RequestBody
129+
Response
130+
Schema
131+
SecurityScheme
132+
Server
133+
ServerVariable
134+
T
135+
Tag
136+
XML

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Introduction
77
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.
88

9-
Licensed under the [MIT License](LICENSE).
9+
Licensed under the [MIT License](./LICENSE).
1010

1111
## Contributors and users
1212
The project has received pull requests from many people. Thanks to everyone!
@@ -27,7 +27,8 @@ Here's some projects that depend on _kin-openapi_:
2727
* [go-openapi](https://github.com/go-openapi)'s [spec3](https://github.com/go-openapi/spec3)
2828
* an iteration on [spec](https://github.com/go-openapi/spec) (for OpenAPIv2)
2929
* see [README](https://github.com/go-openapi/spec3/tree/3fab9faa9094e06ebd19ded7ea96d156c2283dca#oai-object-model---) for the missing parts
30-
* See [https://github.com/OAI](https://github.com/OAI)'s [great tooling list](https://github.com/OAI/OpenAPI-Specification/blob/master/IMPLEMENTATIONS.md)
30+
31+
Be sure to check [OpenAPI Initiative](https://github.com/OAI)'s [great tooling list](https://github.com/OAI/OpenAPI-Specification/blob/master/IMPLEMENTATIONS.md) as well as [OpenAPI.Tools](https://openapi.tools/).
3132

3233
# Structure
3334
* _openapi2_ ([godoc](https://godoc.org/github.com/getkin/kin-openapi/openapi2))

jsoninfo/marshal_ref.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
func MarshalRef(value string, otherwise interface{}) ([]byte, error) {
8-
if len(value) > 0 {
8+
if value != "" {
99
return json.Marshal(&refProps{
1010
Ref: value,
1111
})
@@ -17,7 +17,7 @@ func UnmarshalRef(data []byte, destRef *string, destOtherwise interface{}) error
1717
refProps := &refProps{}
1818
if err := json.Unmarshal(data, refProps); err == nil {
1919
ref := refProps.Ref
20-
if len(ref) > 0 {
20+
if ref != "" {
2121
*destRef = ref
2222
return nil
2323
}
@@ -26,5 +26,5 @@ func UnmarshalRef(data []byte, destRef *string, destOtherwise interface{}) error
2626
}
2727

2828
type refProps struct {
29-
Ref string `json:"$ref,omitempty"`
29+
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
3030
}

openapi3/callback.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ func (c Callbacks) JSONLookup(token string) (interface{}, error) {
2323
return ref.Value, nil
2424
}
2525

26-
// Callback is specified by OpenAPI/Swagger standard version 3.0.
26+
// Callback is specified by OpenAPI/Swagger standard version 3.
27+
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#callbackObject
2728
type Callback map[string]*PathItem
2829

2930
func (value Callback) Validate(ctx context.Context) error {

openapi3/components.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"github.com/getkin/kin-openapi/jsoninfo"
99
)
1010

11-
// Components is specified by OpenAPI/Swagger standard version 3.0.
11+
// Components is specified by OpenAPI/Swagger standard version 3.
12+
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#componentsObject
1213
type Components struct {
1314
ExtensionProps
15+
1416
Schemas Schemas `json:"schemas,omitempty" yaml:"schemas,omitempty"`
1517
Parameters ParametersMap `json:"parameters,omitempty" yaml:"parameters,omitempty"`
1618
Headers Headers `json:"headers,omitempty" yaml:"headers,omitempty"`

openapi3/discriminator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import (
66
"github.com/getkin/kin-openapi/jsoninfo"
77
)
88

9-
// Discriminator is specified by OpenAPI/Swagger standard version 3.0.
9+
// Discriminator is specified by OpenAPI/Swagger standard version 3.
10+
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#discriminatorObject
1011
type Discriminator struct {
1112
ExtensionProps
13+
1214
PropertyName string `json:"propertyName" yaml:"propertyName"`
1315
Mapping map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
1416
}

openapi3/encoding.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
)
99

1010
// Encoding is specified by OpenAPI/Swagger 3.0 standard.
11+
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#encodingObject
1112
type Encoding struct {
1213
ExtensionProps
1314

openapi3/examples.go renamed to openapi3/example.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func (e Examples) JSONLookup(token string) (interface{}, error) {
2525
}
2626

2727
// Example is specified by OpenAPI/Swagger 3.0 standard.
28+
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#exampleObject
2829
type Example struct {
2930
ExtensionProps
3031

openapi3/external_docs.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import (
99
"github.com/getkin/kin-openapi/jsoninfo"
1010
)
1111

12-
// ExternalDocs is specified by OpenAPI/Swagger standard version 3.0.
12+
// ExternalDocs is specified by OpenAPI/Swagger standard version 3.
13+
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#external-documentation-object
1314
type ExternalDocs struct {
1415
ExtensionProps
1516

16-
Description string `json:"description,omitempty"`
17-
URL string `json:"url,omitempty"`
17+
Description string `json:"description,omitempty" yaml:"description,omitempty"`
18+
URL string `json:"url,omitempty" yaml:"url,omitempty"`
1819
}
1920

2021
func (e *ExternalDocs) MarshalJSON() ([]byte, error) {

openapi3/header.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func (h Headers) JSONLookup(token string) (interface{}, error) {
2626
}
2727

2828
// Header is specified by OpenAPI/Swagger 3.0 standard.
29-
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#headerObject
29+
// See https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#headerObject
3030
type Header struct {
3131
Parameter
3232
}

0 commit comments

Comments
 (0)