Skip to content

Commit

Permalink
Merge pull request #395 from pespantelis/main
Browse files Browse the repository at this point in the history
fix(parser): pass componentsResolver to schemaParser
  • Loading branch information
tdakkota authored Jun 15, 2022
2 parents ccedfb5 + 2879080 commit 56b498e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 5 additions & 2 deletions openapi/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ func Parse(spec *ogen.Spec, s Settings) (*openapi.API, error) {
"": spec.Raw,
},
schemaParser: jsonschema.NewParser(jsonschema.Settings{
External: s.External,
Resolver: jsonschema.NewRootResolver(spec.Raw),
External: s.External,
Resolver: componentsResolver{
components: spec.Components.Schemas,
root: jsonschema.NewRootResolver(spec.Raw),
},
InferTypes: s.InferTypes,
}),
}
Expand Down
15 changes: 11 additions & 4 deletions openapi/parser/ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func TestExternalReference(t *testing.T) {
},
},
Components: &ogen.Components{
Schemas: map[string]*ogen.Schema{
"LocalSchema": {
Ref: "foo.json#/components/schemas/RemoteSchema",
},
},
Responses: map[string]*ogen.Response{
"LocalResponse": {
Ref: "foo.json#/components/responses/RemoteResponse",
Expand Down Expand Up @@ -83,7 +88,7 @@ func TestExternalReference(t *testing.T) {
"foo.json": &ogen.Spec{
Components: &ogen.Components{
Schemas: map[string]*ogen.Schema{
"Schema": {
"RemoteSchema": {
Ref: "bar.json#/components/schemas/Schema",
},
},
Expand All @@ -98,7 +103,7 @@ func TestExternalReference(t *testing.T) {
In: "query",
Style: "form",
Schema: &ogen.Schema{
Ref: "#/components/schemas/Schema",
Ref: "#/components/schemas/RemoteSchema",
},
},
},
Expand All @@ -121,7 +126,7 @@ func TestExternalReference(t *testing.T) {
Content: map[string]ogen.Media{
"application/json": {
Schema: &ogen.Schema{
Ref: "foo.json#/components/schemas/Schema",
Ref: "foo.json#/components/schemas/RemoteSchema",
},
Examples: map[string]*ogen.Example{
"ref": {
Expand Down Expand Up @@ -254,7 +259,9 @@ func TestExternalReference(t *testing.T) {
Parameters: map[string]*openapi.Parameter{
"LocalParameter": param,
},
Schemas: map[string]*jsonschema.Schema{},
Schemas: map[string]*jsonschema.Schema{
"LocalSchema": schema,
},
RequestBodies: map[string]*openapi.RequestBody{
"LocalRequestBody": requestBody,
},
Expand Down

0 comments on commit 56b498e

Please sign in to comment.