Skip to content

Commit

Permalink
Merge pull request #500 from tdakkota/feat/ref-pathitem
Browse files Browse the repository at this point in the history
feat(openapi): support Path Item references
  • Loading branch information
ernado authored Jul 25, 2022
2 parents c53ca41 + da08bfb commit 914b4eb
Show file tree
Hide file tree
Showing 29 changed files with 984 additions and 146 deletions.
39 changes: 39 additions & 0 deletions _testdata/negative/cyclic/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"openapi": "3.0.3",
"info": {
"title": "title",
"version": "v0.1.0"
},
"paths": {
"/foo": {
"get": {
"parameters": [
{
"name": "param",
"in": "query",
"schema": {
"type": "string"
},
"examples": {
"ParameterExample": {
"$ref": "#/components/examples/Example"
}
}
}
],
"responses": {
"200": {
"description": "User info"
}
}
}
}
},
"components": {
"examples": {
"Example": {
"$ref": "#/components/examples/Example"
}
}
}
}
19 changes: 19 additions & 0 deletions _testdata/negative/cyclic/pathItem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"openapi": "3.1.0",
"info": {
"title": "title",
"version": "v0.1.0"
},
"paths": {
"/foo": {
"$ref": "#/components/pathItems/PathItem"
}
},
"components": {
"pathItems": {
"PathItem": {
"$ref": "#/components/pathItems/PathItem"
}
}
}
}
17 changes: 17 additions & 0 deletions _testdata/negative/null/components_pathItem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"openapi": "3.1.0",
"info": {
"title": "title",
"version": "v0.1.0"
},
"paths": {
"/foo": {
"$ref": "#/components/pathItems/PathItem"
}
},
"components": {
"pathItems": {
"PathItem": null
}
}
}
32 changes: 32 additions & 0 deletions _testdata/positive/referenced_pathItem.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"openapi": "3.1.0",
"info": {
"title": "title",
"version": "v0.1.0"
},
"paths": {
"/foo": {
"$ref": "#/components/pathItems/Foo"
}
},
"components": {
"pathItems": {
"Foo": {
"get": {
"responses": {
"200": {
"description": "Response",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
}
}
}
2 changes: 2 additions & 0 deletions internal/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ package internal
//go:generate go run ../cmd/ogen -v --clean --target test_http_requests ../_testdata/positive/http_requests.json
//go:generate go run ../cmd/ogen -v --clean --target test_form ../_testdata/positive/form.json
//
//go:generate go run ../cmd/ogen -v --clean --target referenced_path_item ../_testdata/positive/referenced_pathItem.json
//
//go:generate go run ../cmd/ogen -v --clean --generate-tests --target test_allof ../_testdata/positive/allof.yml
3 changes: 3 additions & 0 deletions internal/jsonpointer/jsonpointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import (
// Resolve takes given pointer and returns byte slice of requested value if any.
// If value not found, returns NotFoundError.
func Resolve(ptr string, node *yaml.Node) (*yaml.Node, error) {
if node == nil {
return nil, errors.New("root is nil")
}
if node.Kind == yaml.DocumentNode && len(node.Content) > 0 {
node = node.Content[0]
}
Expand Down
9 changes: 9 additions & 0 deletions internal/jsonpointer/jsonpointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ func TestSpecification(t *testing.T) {
}
}

func TestResolveNilNode(t *testing.T) {
a := require.New(t)
var err error
a.NotPanics(func() {
_, err = Resolve("", nil)
})
a.EqualError(err, "root is nil")
}

func BenchmarkResolve(b *testing.B) {
var specExample = getNode(b, []byte(`{
"openapi": "3.0.3",
Expand Down
143 changes: 143 additions & 0 deletions internal/referenced_path_item/oas_cfg_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 89 additions & 0 deletions internal/referenced_path_item/oas_client_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions internal/referenced_path_item/oas_defaults_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 914b4eb

Please sign in to comment.