Skip to content

Commit

Permalink
feature(models): convert models to be only types
Browse files Browse the repository at this point in the history
This fixes an import bug but also simplifies the design alot.

1. Before this change the object literal created within an api client by JSON.parse(), was only
   type casted to a class instance. This meant that optional fields were
   actually undefined, as they're missing in the object literal. But
   typescript reported them to be null, as any class instance would
   initialize them null. Because the constructor was never called, this
   never happened.
2. The advantage of the new approach comes from the fact, that
   typescript will not emit an import, when a type is imported using
   'type import ...'. The latter can be enforced by using setting
   verbatimModuleSyntax within the tsconfig file. Because no import is
   emitted, no code is loaded. This significantly improves load times,
   as the engine does not has to read and parse all the 100'ish files.
  • Loading branch information
lrosenfeldt committed Aug 9, 2024
1 parent 42596f8 commit ec7fecf
Show file tree
Hide file tree
Showing 139 changed files with 1,798 additions and 6,451 deletions.
112 changes: 37 additions & 75 deletions src/models/APIError.ts
Original file line number Diff line number Diff line change
@@ -1,88 +1,50 @@
/**
* Commerce Platform API
* RESTful API for the creation of Commerce Cases with Checkouts and the execution of Payments.
*
* OpenAPI spec version: 1.8.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/**
* Contains detailed information on one single error.
*/
export class APIError {
/** @description Contains detailed information on one single error. */
export interface APIError {
/**
* Error code
* @description Error code
* @example 50001130
*/
'errorCode': string;
errorCode: string;
/**
* Category the error belongs to. The category should give an indication of the type of error you are dealing with. Possible values: * DIRECT_PLATFORM_ERROR - indicating that a functional error has occurred in the platform. * PAYMENT_PLATFORM_ERROR - indicating that a functional error has occurred in the payment platform. * IO_ERROR - indicating that a technical error has occurred within the payment platform or between the payment platform and third party systems. * COMMERCE_PLATFORM_ERROR - indicating an error originating from the Commerce Platform. * COMMERCE_PORTAL_BACKEND_ERROR - indicating an error originating from the Commerce Portal Backend.
* @description Category the error belongs to. The category should give an indication of the type of error you are dealing
* with. Possible values:
* * DIRECT_PLATFORM_ERROR - indicating that a functional error has occurred in the platform.
* * PAYMENT_PLATFORM_ERROR - indicating that a functional error has occurred in the payment platform.
* * IO_ERROR - indicating that a technical error has occurred within the payment platform or between the
* payment platform and third party systems.
* * COMMERCE_PLATFORM_ERROR - indicating an error originating from the Commerce Platform.
* * COMMERCE_PORTAL_BACKEND_ERROR - indicating an error originating from the Commerce Portal Backend.
* @example PAYMENT_PLATFORM_ERROR
*/
'category'?: string;
category?: string;
/**
* HTTP status code for this error that can be used to determine the type of error
* Format: int32
* @description HTTP status code for this error that can be used to determine the type of error
* @example 404
*/
'httpStatusCode'?: number;
httpStatusCode?: number;
/**
* ID of the error. This is a short human-readable message that briefly describes the error.
* @description ID of the error. This is a short human-readable message that briefly describes the error.
* @example general-error-technical-fault-internal
*/
'id'?: string;
id?: string;
/**
* Human-readable error message that is not meant to be relayed to customer as it might tip off people who are trying to commit fraud
* @description Human-readable error message that is not meant to be relayed to customer as it might tip off people who are
* trying to commit fraud
* @example Authorisation declined
*/
'message'?: string;
message?: string;
/**
* Returned only if the error relates to a value that was missing or incorrect. Contains a location path to the value as a JSonata query. Some common examples: * a.b selects the value of property b of root property a, * a[1] selects the first element of the array in root property a, * a[b=\'some value\'] selects all elements of the array in root property a that have a property b with value \'some value\'.
* @description Returned only if the error relates to a value that was missing or incorrect.
*
* Contains a location path to the value as a JSonata query.
*
* Some common examples:
* * a.b selects the value of property b of root property a,
* * a[1] selects the first element of the array in root property a,
* * a[b='some value'] selects all elements of the array in root property a that have a property b with value
* 'some value'.
* @example paymentId
*/
'propertyName'?: string;

static readonly discriminator: string | undefined = undefined;

static readonly attributeTypeMap: Array<{ name: string; baseName: string; type: string; format: string }> = [
{
name: 'errorCode',
baseName: 'errorCode',
type: 'string',
format: '',
},
{
name: 'category',
baseName: 'category',
type: 'string',
format: '',
},
{
name: 'httpStatusCode',
baseName: 'httpStatusCode',
type: 'number',
format: 'int32',
},
{
name: 'id',
baseName: 'id',
type: 'string',
format: '',
},
{
name: 'message',
baseName: 'message',
type: 'string',
format: '',
},
{
name: 'propertyName',
baseName: 'propertyName',
type: 'string',
format: '',
},
];

static getAttributeTypeMap() {
return APIError.attributeTypeMap;
}

public constructor() {}
propertyName?: string;
}
64 changes: 24 additions & 40 deletions src/models/Address.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,39 @@
/**
* Commerce Platform API
* RESTful API for the creation of Commerce Cases with Checkouts and the execution of Payments.
*
* OpenAPI spec version: 1.8.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/**
* Object containing billing address details
*/
export class Address {
/** @description Object containing billing address details */
export interface Address {
/**
* Second line of street or additional address information such as apartments and suits
* @description Second line of street or additional address information such as apartments and suits
* @example Apartment 203
*/
additionalInfo: string | null;
additionalInfo?: string;
/**
* City
* @description City
* @example Kiel
*/
city: string | null;
city?: string;
/**
* ISO 3166-1 alpha-2 country code
* @description ISO 3166-1 alpha-2 country code
* @example DE
*/
countryCode: string | null;
countryCode?: string;
/**
* House number
* @description House number
* @example 3
*/
houseNumber: string | null;
houseNumber?: string;
/**
* State (ISO 3166-2 subdivisions), only if country=US, CA, CN, JP, MX, BR, AR, ID, TH, IN.
* @description State (ISO 3166-2 subdivisions), only if country=US, CA, CN, JP, MX, BR, AR, ID, TH, IN.
* @example BR
*/
state: string | null;
state?: string;
/**
* Street name
* @description Street name
* @example Coral Avenue
*/
street: string | null;
street?: string;
/**
* Zip code
* @description Zip code
* @example 12345
*/
zip: string | null;

public constructor() {
this.additionalInfo = null;
this.city = null;
this.countryCode = null;
this.houseNumber = null;
this.state = null;
this.street = null;
this.zip = null;
}
zip?: string;
}

68 changes: 25 additions & 43 deletions src/models/AddressPersonal.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,41 @@
/**
* Commerce Platform API
* RESTful API for the creation of Commerce Cases with Checkouts and the execution of Payments.
*
* OpenAPI spec version: 1.8.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import type { PersonalName } from './PersonalName.js';

import { PersonalName } from './PersonalName.js';

/**
* Object containing personal or shipping address information.
*/
export class AddressPersonal {
/** @description Object containing personal or shipping address information. */
export interface AddressPersonal {
/**
* Second line of street or additional address information such as apartments and suits
* @description Second line of street or additional address information such as apartments and suits
* @example Apartment 203
*/
additionalInfo: string | null;
additionalInfo?: string;
/**
* City
* @description City
* @example Kiel
*/
city: string | null;
city?: string;
/**
* ISO 3166-1 alpha-2 country code
* @description ISO 3166-1 alpha-2 country code
* @example DE
*/
countryCode: string | null;
countryCode?: string;
/**
* House number
* @description House number
* @example 3
*/
houseNumber: string | null;
houseNumber?: string;
/**
* State (ISO 3166-2 subdivisions), only if country=US, CA, CN, JP, MX, BR, AR, ID, TH, IN.
* @description State (ISO 3166-2 subdivisions), only if country=US, CA, CN, JP, MX, BR, AR, ID, TH, IN.
* @example MX
*/
state: string | null;
state?: string;
/**
* Street name
* @description Street name
* @example Coral Avenue
*/
street: string | null;
street?: string;
/**
* Zip code
* @description Zip code
* @example 1234
*/
zip: string | null;
name: PersonalName | null;

public constructor() {
this.additionalInfo = null;
this.city = null;
this.countryCode = null;
this.houseNumber = null;
this.state = null;
this.street = null;
this.zip = null;
this.name = null;
}
zip?: string;
name?: PersonalName;
}
19 changes: 6 additions & 13 deletions src/models/AllowedPaymentActions.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/**
* Commerce Platform API
* RESTful API for the creation of Commerce Cases with Checkouts and the execution of Payments.
*
* OpenAPI spec version: 1.8.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/**
* Indicates which payment endpoints can be used for the respective Checkout. The systems offers two alternatives to trigger a payment and consecutive events: OrderManagementCheckoutActions or the Payment Execution resource. Both alternatives can be used simultaneously but once one of the Payment Execution endpoints is used the Order Management endpoints can no longer be used for that Checkout since it is no longer possible to match payment events to items of the Checkout.
* @description Indicates which payment endpoints can be used for the respective Checkout.
* The systems offers two alternatives to trigger a payment and consecutive events:
* OrderManagementCheckoutActions or the Payment Execution resource.
* Both alternatives can be used simultaneously but once one of the Payment Execution endpoints is used the
* Order Management endpoints can no longer be used for that Checkout since it is no longer possible to match
* payment events to items of the Checkout.
*/
export enum AllowedPaymentActions {
OrderManagement = 'ORDER_MANAGEMENT',
Expand Down
53 changes: 10 additions & 43 deletions src/models/AmountOfMoney.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,15 @@
/**
* Commerce Platform API
* RESTful API for the creation of Commerce Cases with Checkouts and the execution of Payments.
*
* OpenAPI spec version: 1.8.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

/**
* Object containing amount and ISO currency code attributes
*/
export class AmountOfMoney {
/** @description Object containing amount and ISO currency code attributes */
export interface AmountOfMoney {
/**
* Amount in cents and always having 2 decimals
* Format: int64
* @description Amount in cents and always having 2 decimals
* @example 1000
*/
'amount': number;
amount: number;
/**
* Three-letter ISO currency code representing the currency for the amount
* @description Three-letter ISO currency code representing the currency for the amount
* @example EUR
*/
'currencyCode': string;

static readonly discriminator: string | undefined = undefined;

static readonly attributeTypeMap: Array<{ name: string; baseName: string; type: string; format: string }> = [
{
name: 'amount',
baseName: 'amount',
type: 'number',
format: 'int64',
},
{
name: 'currencyCode',
baseName: 'currencyCode',
type: 'string',
format: '',
},
];

static getAttributeTypeMap() {
return AmountOfMoney.attributeTypeMap;
}

public constructor() {}
currencyCode: string;
}

Loading

0 comments on commit ec7fecf

Please sign in to comment.