Skip to content

Commit

Permalink
Fix linter issues in sdk for generated clients - remove dependency in…
Browse files Browse the repository at this point in the history
… ioutil
  • Loading branch information
etabak committed Aug 21, 2022
1 parent a1c5c53 commit b818d75
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
7 changes: 3 additions & 4 deletions pkg/generators/golang/clients_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ func (g *ClientsGenerator) generateRequestSource(method *concepts.Method) {
g.buffer.Import("bytes", "")
g.buffer.Import("context", "")
g.buffer.Import("io", "")
g.buffer.Import("io/ioutil", "")
g.buffer.Import("os", "")
g.buffer.Import("net/http", "")
g.buffer.Import("net/url", "")
g.buffer.Import(g.packages.ErrorsImport(), "")
Expand Down Expand Up @@ -862,7 +862,7 @@ func (g *ClientsGenerator) generateRequestSource(method *concepts.Method) {
URL: uri,
Header: header,
{{ if $requestBodyParameters }}
Body: ioutil.NopCloser(buffer),
Body: io.NopCloser(buffer),
{{ end }}
}
if ctx != nil {
Expand Down Expand Up @@ -1251,5 +1251,4 @@ var builtinGetters = map[string]interface{}{
"Status": nil,
}

var builtinSetters = map[string]interface{}{
}
var builtinSetters = map[string]interface{}{}
5 changes: 2 additions & 3 deletions pkg/generators/golang/openapi_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package golang

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -142,7 +141,7 @@ func (b *OpenAPIGeneratorBuilder) Build() (generator *OpenAPIGenerator, err erro
// Run executes the code generator.
func (g *OpenAPIGenerator) Run() error {
// Create a temporary directory to write the OpenAPI JSON to, and remember to delete it:
jsonDir, err := ioutil.TempDir("", "openapi")
jsonDir, err := os.MkdirTemp("", "openapi")
if err != nil {
return g.reporter.Errorf("Can't create temporary OpenAPI directory: %v", err)
}
Expand Down Expand Up @@ -200,7 +199,7 @@ func (g *OpenAPIGenerator) generateSpec(version *concepts.Version, jsonDir strin

// Read the JSON file that contains the previously generated OpenAPI specification:
jsonFile := filepath.Join(jsonDir, g.names.FileName(version))
jsonData, err := ioutil.ReadFile(jsonFile)
jsonData, err := os.ReadFile(jsonFile)
if err != nil {
return g.reporter.Errorf(
"Can't read JSON file '%s' for version '%s': %v",
Expand Down
5 changes: 2 additions & 3 deletions pkg/language/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package language

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand All @@ -37,7 +36,7 @@ func TestLanguage(t *testing.T) {
// given in the list of pairs. It then reads those model files and returns the resulting model.
func MakeModel(pairs ...string) *concepts.Model {
// Create a temporary directory for the model files:
root, err := ioutil.TempDir("", "model-*")
root, err := os.MkdirTemp("", "model-*")
Expect(err).ToNot(HaveOccurred())
defer func() {
err = os.RemoveAll(root)
Expand All @@ -56,7 +55,7 @@ func MakeModel(pairs ...string) *concepts.Model {
err = os.MkdirAll(dir, 0700)
Expect(err).ToNot(HaveOccurred())
}
err = ioutil.WriteFile(path, []byte(data), 0600)
err = os.WriteFile(path, []byte(data), 0600)
Expect(err).ToNot(HaveOccurred())
}

Expand Down
12 changes: 3 additions & 9 deletions pkg/language/model_parser.go

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

4 changes: 2 additions & 2 deletions pkg/language/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (r *Reader) loadModel(dir string) {
}

// List the services:
fileInfos, err := ioutil.ReadDir(dir)
fileInfos, err := os.ReadDir(dir)
if err != nil {
r.reporter.Errorf("Can't list model directory '%s': %v", dir, err)
return
Expand Down Expand Up @@ -231,7 +231,7 @@ func (r *Reader) loadService(dir string) {
}

// List the versions:
fileInfos, err := ioutil.ReadDir(dir)
fileInfos, err := os.ReadDir(dir)
if err != nil {
r.reporter.Errorf("Can't list service directory '%s': %v", dir, err)
return
Expand Down

0 comments on commit b818d75

Please sign in to comment.