Skip to content
Merged
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ help:
@echo " lint lint the project"

$(GOBIN)/golangci-lint:
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v1.64.5
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOBIN) v2.1.6

.PHONY: tools
tools: $(GOBIN)/golangci-lint
Expand All @@ -23,7 +23,7 @@ lint: tools

lint-ci: tools
# for the root module, explicitly run the step, to prevent recursive calls
$(GOBIN)/golangci-lint run ./... --out-format=colored-line-number --timeout=5m
$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m
# then, for all child modules, use a module-managed `Makefile`
git ls-files '**/*go.mod' -z | xargs -0 -I{} bash -xc 'cd $$(dirname {}) && env GOBIN=$(GOBIN) make lint-ci'

Expand Down
2 changes: 1 addition & 1 deletion cmd/oapi-codegen/oapi-codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func main() {
}

if len(noVCSVersionOverride) > 0 {
opts.Configuration.NoVCSVersionOverride = &noVCSVersionOverride
opts.NoVCSVersionOverride = &noVCSVersionOverride
}

code, err := codegen.Generate(swagger, opts.Configuration)
Expand Down
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lint:
$(GOBIN)/golangci-lint run ./...

lint-ci:
$(GOBIN)/golangci-lint run ./... --out-format=colored-line-number --timeout=5m
$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m

generate:
go generate ./...
Expand Down
6 changes: 3 additions & 3 deletions examples/authenticated-api/echo/server/jwt_authenticator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ type JWSValidator interface {
const JWTClaimsContextKey = "jwt_claims"

var (
ErrNoAuthHeader = errors.New("Authorization header is missing")
ErrInvalidAuthHeader = errors.New("Authorization header is malformed")
ErrClaimsInvalid = errors.New("Provided claims do not match expected scopes")
ErrNoAuthHeader = errors.New("authorization header is missing")
ErrInvalidAuthHeader = errors.New("authorization header is malformed")
ErrClaimsInvalid = errors.New("provided claims do not match expected scopes")
)

// GetJWSFromRequest extracts a JWS string from an Authorization: Bearer <jws> header
Expand Down
2 changes: 1 addition & 1 deletion examples/authenticated-api/stdhttp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lint:

lint-ci:

$(call execute-if-go-122,$(GOBIN)/golangci-lint run ./... --out-format=github-actions --timeout=5m)
$(call execute-if-go-122,$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m)

generate:
$(call execute-if-go-122,go generate ./...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type JWSValidator interface {
const JWTClaimsContextKey = "jwt_claims"

var (
ErrNoAuthHeader = errors.New("Authorization header is missing")
ErrInvalidAuthHeader = errors.New("Authorization header is malformed")
ErrClaimsInvalid = errors.New("Provided claims do not match expected scopes")
ErrNoAuthHeader = errors.New("authorization header is missing")
ErrInvalidAuthHeader = errors.New("authorization header is malformed")
ErrClaimsInvalid = errors.New("provided claims do not match expected scopes")
)

// GetJWSFromRequest extracts a JWS string from an Authorization: Bearer <jws> header
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-server/stdhttp-go-tool/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lint:

lint-ci:

$(call execute-if-go-124,$(GOBIN)/golangci-lint run ./... --out-format=colored-line-number --timeout=5m)
$(call execute-if-go-124,$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m)

generate:
$(call execute-if-go-124,go generate ./...)
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal-server/stdhttp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lint:

lint-ci:

$(call execute-if-go-122,$(GOBIN)/golangci-lint run ./... --out-format=colored-line-number --timeout=5m)
$(call execute-if-go-122,$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m)

generate:
$(call execute-if-go-122,go generate ./...)
Expand Down
2 changes: 1 addition & 1 deletion examples/petstore-expanded/stdhttp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lint:

lint-ci:

$(call execute-if-go-122,$(GOBIN)/golangci-lint run ./... --out-format=colored-line-number --timeout=5m)
$(call execute-if-go-122,$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m)

generate:
$(call execute-if-go-122,go generate ./...)
Expand Down
2 changes: 1 addition & 1 deletion internal/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lint:
$(GOBIN)/golangci-lint run ./...

lint-ci:
$(GOBIN)/golangci-lint run ./... --out-format=colored-line-number --timeout=5m
$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m

generate:
go generate ./...
Expand Down
2 changes: 1 addition & 1 deletion internal/test/strict-server/stdhttp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lint:

lint-ci:

$(call execute-if-go-122,$(GOBIN)/golangci-lint run ./... --out-format=github-actions --timeout=5m)
$(call execute-if-go-122,$(GOBIN)/golangci-lint run ./... --output.text.path=stdout --timeout=5m)

generate:
$(call execute-if-go-122,go generate ./...)
Expand Down
4 changes: 3 additions & 1 deletion pkg/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,9 @@ func GetUserTemplateText(inputData string) (template string, err error) {
return "", fmt.Errorf("failed to execute GET request data from %s: %w", inputData, err)
}
if resp != nil {
defer resp.Body.Close()
defer func() {
_ = resp.Body.Close()
}()
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return "", fmt.Errorf("got non %d status code on GET %s", resp.StatusCode, inputData)
Expand Down
4 changes: 2 additions & 2 deletions pkg/codegen/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func (o *OperationDefinition) GetResponseTypeDefinitions() ([]ResponseTypeDefini
if contentType.Schema != nil {
responseSchema, err := GenerateGoSchema(contentType.Schema, []string{o.OperationId, responseName})
if err != nil {
return nil, fmt.Errorf("Unable to determine Go type for %s.%s: %w", o.OperationId, contentTypeName, err)
return nil, fmt.Errorf("unable to determine Go type for %s.%s: %w", o.OperationId, contentTypeName, err)
}

var typeName string
Expand All @@ -309,7 +309,7 @@ func (o *OperationDefinition) GetResponseTypeDefinitions() ([]ResponseTypeDefini
// HAL+JSON:
case StringInArray(contentTypeName, contentTypesHalJSON):
typeName = fmt.Sprintf("HALJSON%s", nameNormalizer(responseName))
case "application/json" == contentTypeName:
case contentTypeName == "application/json":
// if it's the standard application/json
typeName = fmt.Sprintf("JSON%s", nameNormalizer(responseName))
// Vendored JSON
Expand Down
41 changes: 17 additions & 24 deletions pkg/codegen/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,37 +583,30 @@ func oapiSchemaToGoType(schema *openapi3.Schema, path []string, outSchema *Schem

} else if t.Is("integer") {
// We default to int if format doesn't ask for something else.
if f == "int64" {
outSchema.GoType = "int64"
} else if f == "int32" {
outSchema.GoType = "int32"
} else if f == "int16" {
outSchema.GoType = "int16"
} else if f == "int8" {
outSchema.GoType = "int8"
} else if f == "int" {
outSchema.GoType = "int"
} else if f == "uint64" {
outSchema.GoType = "uint64"
} else if f == "uint32" {
outSchema.GoType = "uint32"
} else if f == "uint16" {
outSchema.GoType = "uint16"
} else if f == "uint8" {
outSchema.GoType = "uint8"
} else if f == "uint" {
outSchema.GoType = "uint"
} else {
switch f {
case "int64",
"int32",
"int16",
"int8",
"int",
"uint64",
"uint32",
"uint16",
"uint8",
"uint":
outSchema.GoType = f
default:
outSchema.GoType = "int"
}
outSchema.DefineViaAlias = true
} else if t.Is("number") {
// We default to float for "number"
if f == "double" {
switch f {
case "double":
outSchema.GoType = "float64"
} else if f == "float" || f == "" {
case "float", "":
outSchema.GoType = "float32"
} else {
default:
return fmt.Errorf("invalid number format: %s", f)
}
outSchema.DefineViaAlias = true
Expand Down
2 changes: 1 addition & 1 deletion pkg/codegen/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ func isAdditionalPropertiesExplicitFalse(s *openapi3.Schema) bool {
return false
}

return *s.AdditionalProperties.Has == false //nolint:gosimple
return *s.AdditionalProperties.Has == false //nolint:staticcheck
}

func sliceContains[E comparable](s []E, v E) bool {
Expand Down
4 changes: 2 additions & 2 deletions pkg/ecdsafile/ecdsafile.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func LoadEcdsaPublicKey(buf []byte) (*ecdsa.PublicKey, error) {
// which supports multiple types of keys.
keyIface, err := x509.ParsePKIXPublicKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("Error loading public key: %w", err)
return nil, fmt.Errorf("error loading public key: %w", err)
}

// Now, we're assuming the key content is ECDSA, and converting.
Expand All @@ -53,7 +53,7 @@ func LoadEcdsaPrivateKey(buf []byte) (*ecdsa.PrivateKey, error) {
// and we're assuming this encoding contains X509 key material.
privateKey, err := x509.ParseECPrivateKey(block.Bytes)
if err != nil {
return nil, fmt.Errorf("Error loading private ECDSA key: %w", err)
return nil, fmt.Errorf("error loading private ECDSA key: %w", err)
}
return privateKey, nil
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/util/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,24 +66,24 @@ func LoadSwaggerWithOverlay(filePath string, opts LoadSwaggerWithOverlayOpts) (s

err = overlay.Validate()
if err != nil {
return nil, fmt.Errorf("The Overlay in %#v was not valid: %v", opts.Path, err)
return nil, fmt.Errorf("the Overlay in %#v was not valid: %v", opts.Path, err)
}

if opts.Strict {
err, vs := overlay.ApplyToStrict(&node)
if err != nil {
return nil, fmt.Errorf("Failed to apply Overlay %#v to specification %#v: %v\nAdditionally, the following validation errors were found:\n- %s", opts.Path, filePath, err, strings.Join(vs, "\n- "))
return nil, fmt.Errorf("failed to apply Overlay %#v to specification %#v: %v\nAdditionally, the following validation errors were found:\n- %s", opts.Path, filePath, err, strings.Join(vs, "\n- "))
}
} else {
err = overlay.ApplyTo(&node)
if err != nil {
return nil, fmt.Errorf("Failed to apply Overlay %#v to specification %#v: %v", opts.Path, filePath, err)
return nil, fmt.Errorf("failed to apply Overlay %#v to specification %#v: %v", opts.Path, filePath, err)
}
}

b, err := yaml.Marshal(&node)
if err != nil {
return nil, fmt.Errorf("Failed to serialize Overlay'd specification %#v: %v", opts.Path, err)
return nil, fmt.Errorf("failed to serialize Overlay'd specification %#v: %v", opts.Path, err)
}

loader := openapi3.NewLoader()
Expand All @@ -93,7 +93,7 @@ func LoadSwaggerWithOverlay(filePath string, opts LoadSwaggerWithOverlayOpts) (s
Path: filepath.ToSlash(filePath),
})
if err != nil {
return nil, fmt.Errorf("Failed to serialize Overlay'd specification %#v: %v", opts.Path, err)
return nil, fmt.Errorf("failed to serialize Overlay'd specification %#v: %v", opts.Path, err)
}

return swagger, nil
Expand Down