Skip to content

Commit 4823fcb

Browse files
authored
fix: runtime error for API Explorer (#973)
```ts item instanceof Method ``` checks started failing for some obscure reason, so a new `isMethod()` check is now used ```sh yarn test:apix && yarn test:apix-e2e ``` passes again. End-to-end tests needed to be updated for the `(Beta)` string also
1 parent be2f189 commit 4823fcb

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

packages/api-explorer/e2e/e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('API Explorer', () => {
173173
'ul[aria-label="spec selector"] > li:last-child'
174174
)
175175
await expect(page).toMatchElement('h2', {
176-
text: 'Looker API 4.0 (Experimental) Reference',
176+
text: 'Looker API 4.0 (Beta) Reference',
177177
})
178178
})
179179
})

packages/api-explorer/src/components/DocSDKs/DocSDKs.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ import type {
3434
KeyedCollection,
3535
CodeGen,
3636
} from '@looker/sdk-codegen'
37-
import { Method } from '@looker/sdk-codegen'
3837
import { CollapserCard, getGenerators } from '@looker/run-it'
3938

4039
import { DocCode } from '../DocCode'
4140
import { selectSdkLanguage } from '../../state'
41+
import { isMethod } from '../../utils/path'
4242
import { noComment } from './utils'
4343
import { DocDeclarations } from './DocDeclarations'
4444

@@ -59,10 +59,9 @@ const getDeclarations = (
5959
const declarations: KeyedCollection<string> = {}
6060
Object.entries(generators).forEach(([language, gen]) => {
6161
if (sdkLanguage === 'All' || language === sdkLanguage) {
62-
const code =
63-
item instanceof Method
64-
? gen.declareMethod('', item as IMethod)
65-
: gen.declareType('', item as IType)
62+
const code = isMethod(item)
63+
? gen.declareMethod('', item as IMethod)
64+
: gen.declareType('', item as IType)
6665
declarations[language] = code
6766
}
6867
})

packages/api-explorer/src/utils/path.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
import type { ApiModel, IMethod, IType } from '@looker/sdk-codegen'
28-
import { firstMethodRef, Method } from '@looker/sdk-codegen'
28+
import { firstMethodRef } from '@looker/sdk-codegen'
2929

3030
/**
3131
* Builds a path matching the route used by MethodScene
@@ -66,6 +66,12 @@ const getMethodTag = (api: ApiModel, methodName: string) => {
6666
.map(([methodTag]) => methodTag)[0]
6767
}
6868

69+
/**
70+
* Is this item a method? Check without requiring `instanceof Method`
71+
* @param item to check for method or type
72+
*/
73+
export const isMethod = (item: IMethod | IType) => 'params' in item
74+
6975
/**
7076
* Return the tag for a give type
7177
* @param api Parsed api
@@ -89,7 +95,7 @@ export const buildPath = (
8995
specKey: string
9096
) => {
9197
let path
92-
if (item instanceof Method) {
98+
if (isMethod(item)) {
9399
const tag = getMethodTag(api, item.name)
94100
path = buildMethodPath(specKey, tag, item.name)
95101
} else {

yarn.lock

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,12 +2358,22 @@
23582358
dependencies:
23592359
"@styled-icons/styled-icon" "^10.6.3"
23602360

2361-
"@looker/sdk@21.20.0 - 2.0", "@looker/sdk@21.4.1 - 2.0":
2362-
version "21.20.0"
2363-
resolved "https://registry.yarnpkg.com/@looker/sdk/-/sdk-21.20.0.tgz#81f00b6bddc3d47406c3dc74ad2480004622a567"
2364-
integrity sha512-h4cmD3zACcAQZ+3P9iSO1OzXUqdNq+1iaaVO4Py8IY9LPArkwZghlTIzKMG9XAqUM+xqXDTKXI88vFmBllCy5w==
2365-
dependencies:
2366-
"@looker/sdk-rtl" "^21.2.0"
2361+
"@looker/sdk-codegen@^21.0.12", "@looker/sdk-codegen@^21.3.1":
2362+
version "21.3.1"
2363+
resolved "https://registry.yarnpkg.com/@looker/sdk-codegen/-/sdk-codegen-21.3.1.tgz#8af443062d6948600327c5e52615751951cc906c"
2364+
integrity sha512-kUHs6+8DrLpMWYrJ2ACrwnjczb7HyMrvESUZuk0RqrXc8si48CcuQq5/RI+Ver+7SnzVtct4hJZa+fpSF789TA==
2365+
dependencies:
2366+
"@looker/sdk-codegen-utils" "^21.0.11"
2367+
"@looker/sdk-rtl" "^21.3.1"
2368+
blueimp-md5 "^2.13.0"
2369+
openapi3-ts "^1.3.0"
2370+
2371+
"@looker/sdk@^21.20.1", "@looker/sdk@^21.4.1":
2372+
version "21.20.1"
2373+
resolved "https://registry.yarnpkg.com/@looker/sdk/-/sdk-21.20.1.tgz#3d257309c2fe5ad1246e01837ea71aeeb7f4df22"
2374+
integrity sha512-t54yXAMeJAIeq7uUc1Oa3SdFsE3zvQaL9S28ebXy9TrljbnHG4FsVMacfq0XQGYPDzYUIoEySShWcBOsFZ+eyw==
2375+
dependencies:
2376+
"@looker/sdk-rtl" "^21.3.1"
23672377
ini "^1.3.8"
23682378
readable-stream "^3.4.0"
23692379
request "^2.88.0"

0 commit comments

Comments
 (0)