Skip to content

Commit

Permalink
fix: remove unused net/url import from go (#767)
Browse files Browse the repository at this point in the history
url.URL type properties were removed in v4 as of 21.8

fixes: #765
  • Loading branch information
joeldodge79 authored Jul 27, 2021
1 parent 025618c commit 35d912c
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
1 change: 0 additions & 1 deletion go/sdk/v4/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ package v4

import (
"github.com/looker-open-source/sdk-codegen/go/rtl"
"net/url"
"time"
)

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"lint-quiet:es": "eslint 'packages/**/*.ts{,x}' --cache --quiet",
"lint:ts": "tsc",
"lint-staged": "yarn exec lint-staged",
"lint-changed": "eslint $(git diff --name-only --diff-filter=ACMRTUXB main | grep -E \"(.js$|.ts$|.tsx$)\") --quiet",
"lint-changed-fix": "eslint $(git diff --name-only --diff-filter=ACMRTUXB main | grep -E \"(.js$|.ts$|.tsx$)\") --quiet --fix",
"lint-changed": "eslint $(git diff --name-only --diff-filter=ACMRTUXB origin/main | grep -E \"(.js$|.ts$|.tsx$)\") --quiet",
"lint-changed-fix": "eslint $(git diff --name-only --diff-filter=ACMRTUXB origin/main | grep -E \"(.js$|.ts$|.tsx$)\") --quiet --fix",
"lint:spec": "SUPPRESS_NO_CONFIG_WARNING=1 ts-node -O '{ \"module\": \"commonjs\", \"target\": \"es2019\" }' packages/sdk-codegen-scripts/scripts/specLinter.ts",
"refresh": "SUPPRESS_NO_CONFIG_WARNING=1 ts-node -O '{ \"module\": \"commonjs\", \"target\": \"es2019\" }' packages/sdk-codegen-scripts/scripts/refresh_specs.ts",
"register": "SUPPRESS_NO_CONFIG_WARNING=1 ts-node -O '{ \"module\": \"commonjs\", \"target\": \"es2019\" }' packages/sdk-codegen-scripts/scripts/register.ts",
Expand Down
35 changes: 35 additions & 0 deletions packages/sdk-codegen/src/go.gen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,41 @@ const gen = new GoGen(apiTestModel)
const indent = ''

describe('Go generator', () => {
describe('bookends', () => {
it('has a v3 models prologue', () => {
const origPkgName = gen.packageName
gen.packageName = gen.apiVersion = 'v3'
const prologue = gen.modelsPrologue('')
gen.packageName = gen.apiVersion = origPkgName
expect(prologue).toEqual(`
// NOTE: Do not edit this file generated by Looker SDK Codegen for API v3
package v3
import (
"github.com/looker-open-source/sdk-codegen/go/rtl"
"net/url"
"time"
)
`)
})
it('has a default models prologue', () => {
const origPkgName = gen.packageName
gen.packageName = gen.apiVersion = 'v4'
const prologue = gen.modelsPrologue('')
gen.packageName = gen.apiVersion = origPkgName
expect(prologue).toEqual(`
// NOTE: Do not edit this file generated by Looker SDK Codegen for API v4
package v4
import (
"github.com/looker-open-source/sdk-codegen/go/rtl"
"time"
)
`)
})
})
describe('comment header', () => {
it('is empty with no comment', () => {
expect(gen.commentHeader(indent, '')).toEqual('')
Expand Down
20 changes: 15 additions & 5 deletions packages/sdk-codegen/src/go.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,16 +375,26 @@ func NewLookerSDK(session *rtl.AuthSession) *LookerSDK {
}

modelsPrologue(_indent: string) {
return `
// ${this.warnEditing()}
package ${this.packageName}
let goImport = `
import (
"github.com/looker-open-source/sdk-codegen/go/rtl"
"time"
)`

// v3 still uses url.URL
if (this.packageName === 'v3') {
goImport = `
import (
"github.com/looker-open-source/sdk-codegen/go/rtl"
"net/url"
"time"
)
)`
}
return `
// ${this.warnEditing()}
package ${this.packageName}
${goImport}
`
}

Expand Down

0 comments on commit 35d912c

Please sign in to comment.