Skip to content

Commit

Permalink
Merge pull request #274 from tdakkota/fix/nil-crash
Browse files Browse the repository at this point in the history
fix: check field Spec before dereference
  • Loading branch information
ernado authored Apr 3, 2022
2 parents b8b75d3 + 2a60c43 commit ef3a7ca
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 7 deletions.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions examples/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/test_format.json --target ex_test_format --clean --generate-tests

//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/petstore.yaml --target ex_petstore --clean --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/petstore.yml --target ex_petstore --clean --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/firecracker.json --target ex_firecracker --clean --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/gotd_bot_api.json --target ex_gotd --clean --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/ent.json --target ex_ent --clean --generate-tests
Expand All @@ -23,7 +23,7 @@ import (
// Partially supported:

//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/manga.json --target ex_manga --clean --debug.noerr "unsupported content types" --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/petstore-expanded.yaml --target ex_petstore_expanded --clean --debug.noerr --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/petstore-expanded.yml --target ex_petstore_expanded --clean --debug.noerr --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/k8s.json --target ex_k8s --clean --debug.noerr --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/api.github.com.json --target ex_github --clean --infer-types --debug.noerr --generate-tests
//go:generate go run github.com/ogen-go/ogen/cmd/ogen --schema ../_testdata/positive/telegram_bot_api.json --target ex_telegram --clean --debug.noerr --generate-tests
Expand Down
3 changes: 1 addition & 2 deletions gen/gen_parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ func isParamAllowed(t *ir.Type, root bool, visited map[*ir.Type]struct{}) error
}
for _, field := range t.Fields {
if err := isParamAllowed(field.Type, false, visited); err != nil {
// TODO: Check field.Spec existence.
return errors.Wrapf(err, "field %q", field.Spec.Name)
return errors.Wrapf(err, "field %q", field.Name)
}
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/ir/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Field struct {
Tag Tag
// Whether field is inlined map (i.e. additionalProperties, patternProperties).
Inline InlineField
// Spec is property schema. May be empty.
// Spec is property schema. May be nil.
Spec *jsonschema.Property
}

Expand Down
4 changes: 2 additions & 2 deletions internal/ir/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (j JSONFields) FirstRequiredIndex() int {
// HasRequired whether object has required fields
func (j JSONFields) HasRequired() bool {
for _, f := range j {
if f.Spec.Required {
if f.Spec != nil && f.Spec.Required {
return true
}
}
Expand All @@ -66,7 +66,7 @@ func (j JSONFields) RequiredMask() (r []uint8) {
bitIdx := i % 8

set := uint8(0)
if f.Spec.Required {
if f.Spec != nil && f.Spec.Required {
set = 1
}
r[maskIdx] |= set << uint8(bitIdx)
Expand Down

0 comments on commit ef3a7ca

Please sign in to comment.