Skip to content
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
71 changes: 58 additions & 13 deletions gen/apiGen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@

// No-op: Handlebars template handles optional params signature.
const importedTypes: string[] = []
// When response schemas are complex (e.g., objects with index signatures)
// we may want to explicitly override the computed return type.
// If set, this takes precedence over the union of importedTypes.
let returnTypeOverride: string | undefined
let pagerItemTypeName: string | undefined
if (!isWebSocket) {
Object.values(operation.specSection?.responses).forEach(
Expand Down Expand Up @@ -534,18 +538,57 @@
schema.type === 'object' &&
'additionalProperties' in schema
) {
schema.additionalProperties
const addProps =
schema.additionalProperties as OpenAPIV3.SchemaObject
if (addProps.type === 'array' && '$ref' in addProps.items) {
const typeReference = lookup[addProps.items.$ref]
if (
typeReference &&
typeReference !== 'Error' &&
!importedTypes.includes(typeReference + '[]')
const addProps = schema.additionalProperties as
| OpenAPIV3.ReferenceObject
| OpenAPIV3.SchemaObject

// Handle maps (index signatures) properly. Previously we
// collapsed `{ [k: string]: T[] }` into just `T[]`, which
// dropped the object shape. Build a Record<key, value> type
// and import the inner model type when applicable.
if (isRef(addProps)) {
const t = lookup[addProps.$ref]
if (t && t !== 'Error' && !importedTypes.includes(t))
importedTypes.push(t)
returnTypeOverride = `Record<string, ${t || 'unknown'}>`

Check warning on line 553 in gen/apiGen.ts

View workflow job for this annotation

GitHub Actions / semgrep-oss/scan

html-in-template-string

This template literal looks like HTML and has interpolated variables. These variables are not HTMLencoded by default. If the variables contain HTML tags these may be interpreted by the browser resulting in crosssite scripting XSS.
} else if (isArraySchema(addProps as OpenAPIV3.SchemaObject)) {
const items = (addProps as OpenAPIV3.ArraySchemaObject).items
if (isRef(items)) {
const t = lookup[items.$ref]
if (t && t !== 'Error' && !importedTypes.includes(t))
importedTypes.push(t)
returnTypeOverride = `Record<string, ${t || 'unknown'}[]>`

Check warning on line 560 in gen/apiGen.ts

View workflow job for this annotation

GitHub Actions / semgrep-oss/scan

html-in-template-string

This template literal looks like HTML and has interpolated variables. These variables are not HTMLencoded by default. If the variables contain HTML tags these may be interpreted by the browser resulting in crosssite scripting XSS.
} else if (
(items as OpenAPIV3.SchemaObject)?.type === 'string'
) {
importedTypes.push(typeReference + '[]')
returnTypeOverride = 'Record<string, string[]>'
} else if (
(items as OpenAPIV3.SchemaObject)?.type === 'number' ||
(items as OpenAPIV3.SchemaObject)?.type === 'integer'
) {
returnTypeOverride = 'Record<string, number[]>'
} else if (
(items as OpenAPIV3.SchemaObject)?.type === 'boolean'
) {
returnTypeOverride = 'Record<string, boolean[]>'
} else {
returnTypeOverride = 'Record<string, unknown[]>'
}
} else if (
(addProps as OpenAPIV3.SchemaObject)?.type === 'string'
) {
returnTypeOverride = 'Record<string, string>'
} else if (
(addProps as OpenAPIV3.SchemaObject)?.type === 'number' ||
(addProps as OpenAPIV3.SchemaObject)?.type === 'integer'
) {
returnTypeOverride = 'Record<string, number>'
} else if (
(addProps as OpenAPIV3.SchemaObject)?.type === 'boolean'
) {
returnTypeOverride = 'Record<string, boolean>'
} else {
returnTypeOverride = 'Record<string, unknown>'
}
} else {
// Fallback: accept unknown for unhandled response shapes
Expand Down Expand Up @@ -582,9 +625,11 @@
const returnTyping = `type ${pascalName}Return = ${
has204
? 'void'
: importedTypes.length
? importedTypes.join(' | ')
: 'unknown'
: returnTypeOverride
? returnTypeOverride
: importedTypes.length
? importedTypes.join(' | ')
: 'unknown'
}`
const paramsInterfaceName = `${pascalName}Input`
const returnTypeName = `${pascalName}Return`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kittycad/lib",
"version": "3.0.3",
"version": "3.0.4",
"description": "Javascript library for KittyCAD API",
"type": "module",
"keywords": [
Expand Down
4 changes: 2 additions & 2 deletions src/api/meta/get_pricing_subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface GetPricingSubscriptionsInput {
client?: Client
}

type GetPricingSubscriptionsReturn = ZooProductSubscription[]
type GetPricingSubscriptionsReturn = Record<string, ZooProductSubscription[]>

/**
* Get the pricing for our subscriptions.
Expand All @@ -20,7 +20,7 @@ type GetPricingSubscriptionsReturn = ZooProductSubscription[]
* @property {Client} [client] Optional client with auth token.
* @returns {Promise<GetPricingSubscriptionsReturn>} successful operation
*
* Possible return types: ZooProductSubscription[]
* Possible return types: ZooProductSubscription
*/
export default async function get_pricing_subscriptions(
{ client }: GetPricingSubscriptionsInput = {} as GetPricingSubscriptionsInput
Expand Down
Loading