Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: intrinsic type params are not Partial<T> #819

Merged
merged 2 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/sdk-codegen/src/typescript.gen.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ describe('typescript generator', () => {
expect(actual).toEqual(`query_id: number`)
})

it('intrinsic body', () => {
const method = apiTestModel.methods.parse_saml_idp_metadata
const param = method.params[0]
const actual = gen.declareParameter(indent, method, param)
expect(actual).toEqual(`body: string`)
})

it('optional parameter', () => {
const method = apiTestModel.methods.run_query
const param = method.params[2]
Expand Down
18 changes: 12 additions & 6 deletions packages/sdk-codegen/src/typescript.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,21 @@ export class ${this.packageName}Stream extends APIMethods {
)
}

/**
* Detect need for Partial<T> vs T for a parameter type
* @param param to cast (or not)
* @param mapped type to cast
*/
impartial(param: IParameter, mapped: IMappedType) {
if (param.type.intrinsic || param.location !== strBody) return mapped.name
return `Partial<${mapped.name}>`
}

paramComment(param: IParameter, mapped: IMappedType) {
// Don't include mapped type name for Typescript param comments in headers
let desc = param.description || param.type.description
if (!desc) {
if (param.location === strBody) {
desc = `Partial<${mapped.name}>`
}
desc = this.impartial(param, mapped)
}
return `@param ${param.name} ${desc}`
}
Expand All @@ -274,9 +282,7 @@ export class ${this.packageName}Stream extends APIMethods {
: param.type
const mapped = this.typeMap(type)
let pOpt = ''
if (param.location === strBody) {
mapped.name = `Partial<${mapped.name}>`
}
mapped.name = this.impartial(param, mapped)
if (!param.required) {
pOpt = mapped.default ? '' : '?'
}
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/3.1/funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -960,13 +960,13 @@ export const create_saml_test_config = async (
* POST /parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param sdk IAPIMethods implementation
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
export const parse_saml_idp_metadata = async (
sdk: IAPIMethods,
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>> => {
return sdk.post<ISamlMetadataParseResult, IError>(
Expand All @@ -985,13 +985,13 @@ export const parse_saml_idp_metadata = async (
* POST /fetch_and_parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param sdk IAPIMethods implementation
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
export const fetch_and_parse_saml_idp_metadata = async (
sdk: IAPIMethods,
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>> => {
return sdk.post<ISamlMetadataParseResult, IError>(
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/3.1/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,12 +914,12 @@ export class Looker31SDK extends APIMethods implements ILooker31SDK {
*
* POST /parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
async parse_saml_idp_metadata(
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>> {
return this.post<ISamlMetadataParseResult, IError>(
Expand All @@ -937,12 +937,12 @@ export class Looker31SDK extends APIMethods implements ILooker31SDK {
*
* POST /fetch_and_parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
async fetch_and_parse_saml_idp_metadata(
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>> {
return this.post<ISamlMetadataParseResult, IError>(
Expand Down
10 changes: 5 additions & 5 deletions packages/sdk/src/3.1/methodsInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

import type {
DelimArray,
IAPIMethods,
IDictionary,
IAPIMethods,
ITransportSettings,
SDKResponse,
} from '@looker/sdk-rtl'
Expand Down Expand Up @@ -756,12 +756,12 @@ export interface ILooker31SDK extends IAPIMethods {
*
* POST /parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
parse_saml_idp_metadata(
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>>

Expand All @@ -772,12 +772,12 @@ export interface ILooker31SDK extends IAPIMethods {
*
* POST /fetch_and_parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
fetch_and_parse_saml_idp_metadata(
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>>

Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/3.1/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1026,13 +1026,13 @@ export class Looker31SDKStream extends APIMethods {
* POST /parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param callback streaming output function
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
async parse_saml_idp_metadata(
callback: (readable: Readable) => Promise<ISamlMetadataParseResult>,
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
) {
return this.authStream<ISamlMetadataParseResult>(
Expand All @@ -1053,13 +1053,13 @@ export class Looker31SDKStream extends APIMethods {
* POST /fetch_and_parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param callback streaming output function
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
async fetch_and_parse_saml_idp_metadata(
callback: (readable: Readable) => Promise<ISamlMetadataParseResult>,
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
) {
return this.authStream<ISamlMetadataParseResult>(
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/4.0/funcs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1477,13 +1477,13 @@ export const create_saml_test_config = async (
* POST /parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param sdk IAPIMethods implementation
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
export const parse_saml_idp_metadata = async (
sdk: IAPIMethods,
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>> => {
return sdk.post<ISamlMetadataParseResult, IError>(
Expand All @@ -1502,13 +1502,13 @@ export const parse_saml_idp_metadata = async (
* POST /fetch_and_parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param sdk IAPIMethods implementation
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
export const fetch_and_parse_saml_idp_metadata = async (
sdk: IAPIMethods,
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>> => {
return sdk.post<ISamlMetadataParseResult, IError>(
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/4.0/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1401,12 +1401,12 @@ export class Looker40SDK extends APIMethods implements ILooker40SDK {
*
* POST /parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
async parse_saml_idp_metadata(
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>> {
return this.post<ISamlMetadataParseResult, IError>(
Expand All @@ -1424,12 +1424,12 @@ export class Looker40SDK extends APIMethods implements ILooker40SDK {
*
* POST /fetch_and_parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
async fetch_and_parse_saml_idp_metadata(
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>> {
return this.post<ISamlMetadataParseResult, IError>(
Expand Down
9 changes: 5 additions & 4 deletions packages/sdk/src/4.0/methodsInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ export interface ILooker40SDK extends IAPIMethods {
): Promise<SDKResponse<IAlert, IError | IValidationError>>

//#endregion Alert: Alert

//#region ApiAuth: API Authentication

/**
Expand Down Expand Up @@ -1130,12 +1131,12 @@ export interface ILooker40SDK extends IAPIMethods {
*
* POST /parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
parse_saml_idp_metadata(
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>>

Expand All @@ -1146,12 +1147,12 @@ export interface ILooker40SDK extends IAPIMethods {
*
* POST /fetch_and_parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
fetch_and_parse_saml_idp_metadata(
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
): Promise<SDKResponse<ISamlMetadataParseResult, IError>>

Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/src/4.0/streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1583,13 +1583,13 @@ export class Looker40SDKStream extends APIMethods {
* POST /parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param callback streaming output function
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
async parse_saml_idp_metadata(
callback: (readable: Readable) => Promise<ISamlMetadataParseResult>,
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
) {
return this.authStream<ISamlMetadataParseResult>(
Expand All @@ -1610,13 +1610,13 @@ export class Looker40SDKStream extends APIMethods {
* POST /fetch_and_parse_saml_idp_metadata -> ISamlMetadataParseResult
*
* @param callback streaming output function
* @param body Partial<string>
* @param body string
* @param options one-time API call overrides
*
*/
async fetch_and_parse_saml_idp_metadata(
callback: (readable: Readable) => Promise<ISamlMetadataParseResult>,
body: Partial<string>,
body: string,
options?: Partial<ITransportSettings>
) {
return this.authStream<ISamlMetadataParseResult>(
Expand Down
23 changes: 10 additions & 13 deletions spec/Looker.3.1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"swagger": "2.0",
"info": {
"version": "3.1.0",
"x-looker-release-version": "21.10.0",
"x-looker-release-version": "21.14.0",
"title": "Looker API 3.1 Reference",
"description": "### Authorization\n\nThe classic method of API authorization uses Looker **API3** credentials for authorization and access control.\nLooker admins can create API3 credentials on Looker's **Admin/Users** page.\n\nAPI 4.0 adds additional ways to authenticate API requests, including OAuth and CORS requests.\n\nFor details, see [Looker API Authorization](https://looker.com/docs/r/api/authorization).\n\n\n### API Explorer\n\nThe API Explorer is a Looker-provided utility with many new and unique features for learning and using the Looker API and SDKs.\nIt is a replacement for the 'api-docs' page currently provided on Looker instances.\n\nFor details, see the [API Explorer documentation](https://looker.com/docs/r/api/explorer).\n\n\n### Looker Language SDKs\n\nThe Looker API is a RESTful system that should be usable by any programming language capable of making\nHTTPS requests. SDKs for a variety of programming languages are also provided to streamline using the API. Looker\nhas an OpenSource [sdk-codegen project](https://github.com/looker-open-source/sdk-codegen) that provides several\nlanguage SDKs. Language SDKs generated by `sdk-codegen` have an Authentication manager that can automatically\nauthenticate API requests when needed.\n\nFor details on available Looker SDKs, see [Looker API Client SDKs](https://looker.com/docs/r/api/client_sdks).\n\n\n### API Versioning\n\nFuture releases of Looker expand the latest API version release-by-release to securely expose more and more of the core\npower of the Looker platform to API client applications. API endpoints marked as \"beta\" may receive breaking changes without\nwarning (but we will try to avoid doing that). Stable (non-beta) API endpoints should not receive breaking\nchanges in future releases.\n\nFor details, see [Looker API Versioning](https://looker.com/docs/r/api/versioning).\n\n\n### Try It Out!\n\nThis section describes the existing 'api-docs' page available on Looker instances. We recommend using the\n[API Explorer](https://looker.com/docs/r/api/explorer) instead.\n\nThe 'api-docs' page served by the Looker instance includes 'Try It Out!' buttons for each API method. After logging\nin with API3 credentials, you can use the \"Try It Out!\" buttons to call the API directly from the documentation\npage to interactively explore API features and responses.\n\n**NOTE**! With great power comes great responsibility: The \"Try It Out!\" button makes API calls to your live Looker\ninstance. Be especially careful with destructive API operations such as `delete_user` or similar.\nThere is no \"undo\" for API operations. (API Explorer's \"Run It\" feature requires a check mark before running\nAPI operations that can change data.)\n\n\n### In This Release\n\nThe following are a few examples of noteworthy items that have changed between API 3.0 and API 3.1.\nFor more comprehensive coverage of API changes, please see the release notes for your Looker release.\n\n### Examples of new things added in API 3.1 (compared to API 3.0):\n\n* [Dashboard construction](#!/3.1/Dashboard/) APIs\n* [Themes](#!/3.1/Theme/) and [custom color collections](#!/3.1/ColorCollection) APIs\n* Create and run [SQL Runner](#!/3.1/Query/run_sql_query) queries\n* Create and run [merged results](#!/3.1/Query/create_merge_query) queries\n* Create and modify [dashboard filters](#!/3.1/Dashboard/create_dashboard_filter)\n* Create and modify [password requirements](#!/3.1/Auth/password_config)\n\n### Deprecated in API 3.0\n\nThe following functions and properties have been deprecated in API 3.0. They continue to exist and work in API 3.0\nfor the next several Looker releases but they have not been carried forward to API 3.1:\n\n* Dashboard Prefetch functions\n* User access_filter functions\n* User API 1.0 credentials functions\n* Space.is_root and Space.is_user_root properties. Use Space.is_shared_root and Space.is_users_root instead.\n\n### Semantic changes in API 3.1:\n\n* [all_looks()](#!/3.1/Look/all_looks) no longer includes soft-deleted looks, matching [all_dashboards()](#!/3.1/Dashboard/all_dashboards) behavior.\nYou can find soft-deleted looks using [search_looks()](#!/3.1/Look/search_looks) with the `deleted` param set to True.\n* [all_spaces()](#!/3.1/Space/all_spaces) no longer includes duplicate items\n* [search_users()](#!/3.1/User/search_users) no longer accepts Y,y,1,0,N,n for Boolean params, only \"true\" and \"false\".\n* For greater client and network compatibility, [render_task_results](#!/3.1/RenderTask/render_task_results) now returns\nHTTP status **202 Accepted** instead of HTTP status **102 Processing**\n* [all_running_queries()](#!/3.1/Query/all_running_queries) and [kill_query](#!/3.1/Query/kill_query) functions have moved into the [Query](#!/3.1/Query/) function group.\n\nThe API Explorer can be used to [interactively compare](https://looker.com/docs/r/api/explorer#comparing_api_versions) the differences between API 3.1 and 4.0.\n\n\n",
"contact": {
Expand Down Expand Up @@ -17107,15 +17107,15 @@
{
"name": "page",
"in": "query",
"description": "Requested page.",
"description": "Return only page N of paginated results",
"required": false,
"type": "integer",
"format": "int64"
},
{
"name": "per_page",
"in": "query",
"description": "Results per page.",
"description": "Return N rows of data per page",
"required": false,
"type": "integer",
"format": "int64"
Expand Down Expand Up @@ -22713,7 +22713,7 @@
},
"alert_sync_with_dashboard_filter_enabled": {
"type": "boolean",
"description": "Enables alerts to keep in sync with dashboard filter changes - only available in alerts 2.0 (beta)",
"description": "Enables alerts to keep in sync with dashboard filter changes - only available in Enhanced Alerts (beta)",
"x-looker-nullable": false
},
"background_color": {
Expand Down Expand Up @@ -31411,6 +31411,12 @@
"readOnly": true,
"description": "API server base url",
"x-looker-nullable": false
},
"web_server_url": {
"type": "string",
"readOnly": true,
"description": "Web server base url",
"x-looker-nullable": false
}
},
"x-looker-status": "stable"
Expand All @@ -31437,15 +31443,6 @@
},
"WhitelabelConfiguration": {
"properties": {
"can": {
"type": "object",
"additionalProperties": {
"type": "boolean"
},
"readOnly": true,
"description": "Operations the current user is able to perform on this object",
"x-looker-nullable": false
},
"id": {
"type": "integer",
"format": "int64",
Expand Down
Loading