diff --git a/scripts/generate-types.ts b/scripts/generate-types.ts index 1c558f7..3f613c7 100644 --- a/scripts/generate-types.ts +++ b/scripts/generate-types.ts @@ -5,14 +5,20 @@ import path from 'path'; const GENERATED_DIR = path.join(process.cwd(), 'src', 'generated'); const OUTPUT_DIR = path.join(process.cwd(), 'src', 'types'); +const DEEP_REQUIRED_TYPE = ` +type DeepRequired = T extends object + ? { [K in keyof T]-?: DeepRequired> } + : T; +`; + function normalizeModuleName(file: string): string { return file.replace('.d.ts', '').split(/[-_]/g).join(''); } function toPascalCase(raw: string): string { return raw - .replace(/-a-/g, '-') // drop -a- - .replace(/-an-/g, '-') // drop -an- + .replace(/-a-/g, '-') + .replace(/-an-/g, '-') .split(/[-_]/g) .map((w) => w.charAt(0).toUpperCase() + w.slice(1)) .join(''); @@ -59,7 +65,13 @@ function processModuleFile(alias: string, content: string): string[] { if (seen.has(finalName)) continue; seen.add(finalName); - out.push(`export type ${finalName} = ${alias}['schemas']['${raw}'];`); + if (finalName.endsWith('Response')) { + out.push( + `export type ${finalName} = DeepRequired<${alias}['schemas']['${raw}']>;` + ); + } else { + out.push(`export type ${finalName} = ${alias}['schemas']['${raw}'];`); + } } return out; @@ -96,7 +108,7 @@ function generate() { const final = [ `import type { components as ${alias} } from '../generated/${modulePath}';`, - '', + DEEP_REQUIRED_TYPE, ...exports, '', ].join('\n'); diff --git a/specs/salesorders.yml b/specs/salesorders.yml index 3dd5832..cbc81cb 100644 --- a/specs/salesorders.yml +++ b/specs/salesorders.yml @@ -903,10 +903,20 @@ components: $ref: '#/components/schemas/total' balance: $ref: '#/components/schemas/balance' + attention: + type: string + description: "Name of the person to whose attention the shipment is sent." + example: "Marie-Louise Kurz" + company_name: + type: string + description: "Company name associated with the shipping address." address: description: "Name of the street of the customer's shipping address." type: string example: 'No:432,Bayside,Queens' + street2: + type: string + description: "Additional address line for the customer's shipping address." city: description: "Name of the city of the customer's shipping address." type: string @@ -915,6 +925,10 @@ components: description: "Name of the state of the customer's shipping address." type: string example: 'New York' + state_code: + type: string + description: "Abbreviated code for the state." + example: "RP" zip: description: "Zip code of the customer's shipping address." type: string @@ -923,26 +937,42 @@ components: description: "Name of the country of the customer's shipping address." type: string example: U.S.A + country_code: + type: string + description: "ISO code of the country." + example: "DE" fax: description: "Fax number of the customer's shipping address." type: string - example: 424-524242 + example: 424-524242 shipping_address: description: "Customer's shipping address. It contains - address, city, state, zip, country and fax." type: object properties: + attention: + $ref: '#/components/schemas/attention' + company_name: + $ref: '#/components/schemas/company_name' address: $ref: '#/components/schemas/address' + street2: + $ref: '#/components/schemas/street2' city: $ref: '#/components/schemas/city' state: $ref: '#/components/schemas/state' + state_code: + $ref: '#/components/schemas/state_code' zip: $ref: '#/components/schemas/zip' country: $ref: '#/components/schemas/country' + country_code: + $ref: '#/components/schemas/country_code' + phone: + $ref: '#/components/schemas/phone' fax: - $ref: '#/components/schemas/fax' + $ref: '#/components/schemas/fax' shipping_address_id: description: 'Unique Id generated by the server for address in contacts page. To add a shipping address to sales order, send the address_id using this node. Else, the default shipping address for that contact is used' type: integer @@ -954,16 +984,24 @@ components: properties: address: $ref: '#/components/schemas/address' + street2: + $ref: '#/components/schemas/street2' city: $ref: '#/components/schemas/city' state: $ref: '#/components/schemas/state' + state_code: + $ref: '#/components/schemas/state_code' zip: $ref: '#/components/schemas/zip' country: $ref: '#/components/schemas/country' + country_code: + $ref: '#/components/schemas/country_code' + phone: + $ref: '#/components/schemas/phone' fax: - $ref: '#/components/schemas/fax' + $ref: '#/components/schemas/fax' billing_address_id: description: 'Unique Id generated by the server for address in contacts page. To add a billing address to sales order, send the address_id using this node. Else, the default billing address for that contact is used' type: integer