Skip to content

Commit

Permalink
chore: fix go linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
omissis committed Oct 3, 2023
1 parent 28363d3 commit 1c44284
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
16 changes: 8 additions & 8 deletions pkg/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"strings"
"unicode"

"github.com/google/go-cmp/cmp"

"github.com/atombender/go-jsonschema/pkg/cmputil"
"github.com/atombender/go-jsonschema/pkg/codegen"
"github.com/atombender/go-jsonschema/pkg/schemas"
"github.com/google/go-cmp/cmp"
)

type Config struct {
Expand Down Expand Up @@ -250,7 +251,7 @@ func (g *Generator) findOutputFileForSchemaID(id string) (*output, error) {
return g.beginOutput(id, g.config.DefaultOutputName, g.config.DefaultPackageName)
}

func (g *Generator) beginOutput(id string, outputName, packageName string) (*output, error) {
func (g *Generator) beginOutput(id, outputName, packageName string) (*output, error) {
if packageName == "" {
return nil, fmt.Errorf("%w: %q", errMapURIToPackageName, id)
}
Expand Down Expand Up @@ -574,8 +575,7 @@ func (g *schemaGenerator) generateDeclaredType(t *schemas.Type, scope nameScope)
if structType, ok := theType.(*codegen.StructType); ok {
var validators []validator

switch t.GetSubSchemaType() {
case schemas.SubSchemaTypeAnyOf:
if t.GetSubSchemaType() == schemas.SubSchemaTypeAnyOf {
validators = append(validators, &anyOfValidator{decl.Name, t.GetSubSchemasCount()})

g.generateUnmarshaler(decl, validators)
Expand Down Expand Up @@ -711,8 +711,7 @@ func (g *schemaGenerator) structFieldValidators(

func (g *schemaGenerator) generateUnmarshaler(decl codegen.TypeDecl, validators []validator) {
for _, v := range validators {
switch v.(type) {
case *anyOfValidator:
if _, ok := v.(*anyOfValidator); ok {
g.output.file.Package.AddImport("errors", "")
}

Expand Down Expand Up @@ -1025,7 +1024,9 @@ func (g *schemaGenerator) generateTypeInline(t *schemas.Type, scope nameScope) (
for i, typ := range t.AnyOf {
typ.SetSubSchemaTypeElem()

g.generateTypeInline(typ, scope.add(fmt.Sprintf("_%d", i)))
if _, err := g.generateTypeInline(typ, scope.add(fmt.Sprintf("_%d", i))); err != nil {
return nil, err
}
}

anyOfType, err := schemas.AnyOf(t.AnyOf)
Expand Down Expand Up @@ -1355,5 +1356,4 @@ func fileExists(fileName string) bool {
_, err := os.Stat(fileName)

return err == nil || !os.IsNotExist(err)

}
3 changes: 3 additions & 0 deletions pkg/generator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func (v *defaultValidator) dumpDefaultValue(out *codegen.Emitter) any {
for _, k := range sortedKeys(dvm) {
namedFields += fmt.Sprintf("\n%s: %s,", upperFirst(k), litter.Sdump(dvm[k]))
}

namedFields += "\n"

return fmt.Sprintf(`%s{%s}`, nt.Decl.GetName(), namedFields)
Expand Down Expand Up @@ -288,7 +289,9 @@ func (v *anyOfValidator) generate(out *codegen.Emitter) {
for i := 0; i < v.elemCount; i++ {
out.Printlnf(`var %s_%d %s_%d`, lowerFirst(v.fieldName), i, upperFirst(v.fieldName), i)
}

out.Printlnf(`var errs []error`)

for i := 0; i < v.elemCount; i++ {
out.Printlnf(`if err := %s_%d.UnmarshalJSON(b); err != nil {`, lowerFirst(v.fieldName), i)
out.Indent(1)
Expand Down
4 changes: 2 additions & 2 deletions pkg/schemas/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ type Type struct {
// to use for the field.
GoJSONSchemaExtension *GoJSONSchemaExtension `json:"goJSONSchema,omitempty"` //nolint:tagliatelle // breaking change

// subSchemaType marks the type as being a subschema type
// SubSchemaType marks the type as being a subschema type.
subSchemaType SubSchemaType
subSchemasCount int
subSchemaTypeElem bool
Expand Down Expand Up @@ -273,7 +273,7 @@ func MergeTypes(types []*Type) (*Type, error) {
return nil, ErrEmptyTypesList
}

var result = &Type{}
result := &Type{}

if isPrimitiveTypeList(types) {
return result, nil
Expand Down

0 comments on commit 1c44284

Please sign in to comment.