Skip to content

Commit

Permalink
Merge pull request citrineos#254 from citrineos/feature/null-for-arra…
Browse files Browse the repository at this point in the history
…ys-json-schemas

Feature/null for arrays json schemas
  • Loading branch information
ChrisWeissmann authored Sep 13, 2024
2 parents f04bea1 + 2ecc4b3 commit bed511a
Show file tree
Hide file tree
Showing 25 changed files with 55 additions and 44 deletions.
3 changes: 1 addition & 2 deletions 00_Base/json-schema-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ async function processJsonSchema(data, writeToFile = true) {

// Add null type to all optional properties
// This regex means a string starts with '?:' and ends with ';'
// and contains no '[' or ']' in between
const regex = /(\?:[^;\[\]]*);/g;
const regex = /(\?:[^;]*);/g;
ts = ts.replaceAll(regex, '$1 | null;');

if (writeToFile) {
Expand Down
5 changes: 3 additions & 2 deletions 00_Base/src/ocpp/model/types/AuthorizeRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export interface AuthorizeRequest extends OcppRequest {
OCSPRequestDataType,
OCSPRequestDataType,
OCSPRequestDataType,
];
]
| null;
}
/**
* This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.
Expand All @@ -52,7 +53,7 @@ export interface IdTokenType {
/**
* @minItems 1
*/
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]];
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]] | null;
/**
* IdToken is case insensitive. Might hold the hidden id of an RFID tag, but can for example also contain a UUID.
*
Expand Down
4 changes: 2 additions & 2 deletions 00_Base/src/ocpp/model/types/AuthorizeResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface IdTokenInfoType {
*
* @minItems 1
*/
evseId?: [number, ...number[]];
evseId?: [number, ...number[]] | null;
groupIdToken?: IdTokenType | null;
/**
* ID_ Token. Language2. Language_ Code
Expand All @@ -87,7 +87,7 @@ export interface IdTokenType {
/**
* @minItems 1
*/
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]];
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]] | null;
/**
* IdToken is case insensitive. Might hold the hidden id of an RFID tag, but can for example also contain a UUID.
*
Expand Down
2 changes: 1 addition & 1 deletion 00_Base/src/ocpp/model/types/CustomerInformationRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface IdTokenType {
/**
* @minItems 1
*/
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]];
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]] | null;
/**
* IdToken is case insensitive. Might hold the hidden id of an RFID tag, but can for example also contain a UUID.
*
Expand Down
2 changes: 1 addition & 1 deletion 00_Base/src/ocpp/model/types/DataTransferRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface DataTransferRequest extends OcppRequest {
*
*/
data?: {
[k: string]: unknown;
[k: string]: unknown | null;
};
/**
* This identifies the Vendor specific implementation
Expand Down
2 changes: 1 addition & 1 deletion 00_Base/src/ocpp/model/types/DataTransferResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface DataTransferResponse extends OcppResponse {
*
*/
data?: {
[k: string]: unknown;
[k: string]: unknown | null;
};
}
/**
Expand Down
5 changes: 3 additions & 2 deletions 00_Base/src/ocpp/model/types/GetChargingProfilesRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export interface ChargingProfileCriterionType {
*
* @minItems 1
*/
chargingProfileId?: [number, ...number[]];
chargingProfileId?: [number, ...number[]] | null;
/**
* For which charging limit sources, charging profiles SHALL be reported. If omitted, the Charging Station SHALL not filter on chargingLimitSource.
*
Expand All @@ -81,5 +81,6 @@ export interface ChargingProfileCriterionType {
ChargingLimitSourceEnumType,
ChargingLimitSourceEnumType,
ChargingLimitSourceEnumType,
];
]
| null;
}
2 changes: 1 addition & 1 deletion 00_Base/src/ocpp/model/types/GetDisplayMessagesRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface GetDisplayMessagesRequest extends OcppRequest {
*
* @minItems 1
*/
id?: [number, ...number[]];
id?: [number, ...number[]] | null;
/**
* The Id of this request.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ export interface GetInstalledCertificateIdsRequest extends OcppRequest {
*
* @minItems 1
*/
certificateType?: [
GetCertificateIdUseEnumType,
...GetCertificateIdUseEnumType[],
];
certificateType?:
| [GetCertificateIdUseEnumType, ...GetCertificateIdUseEnumType[]]
| null;
}
/**
* This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ export interface GetInstalledCertificateIdsResponse extends OcppResponse {
/**
* @minItems 1
*/
certificateHashDataChain?: [
CertificateHashDataChainType,
...CertificateHashDataChainType[],
];
certificateHashDataChain?:
| [CertificateHashDataChainType, ...CertificateHashDataChainType[]]
| null;
}
/**
* This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.
Expand Down Expand Up @@ -74,7 +73,8 @@ export interface CertificateHashDataChainType {
CertificateHashDataType,
CertificateHashDataType,
CertificateHashDataType,
];
]
| null;
}
export interface CertificateHashDataType {
customData?: CustomDataType | null;
Expand Down
7 changes: 5 additions & 2 deletions 00_Base/src/ocpp/model/types/GetMonitoringReportRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export interface GetMonitoringReportRequest extends OcppRequest {
/**
* @minItems 1
*/
componentVariable?: [ComponentVariableType, ...ComponentVariableType[]];
componentVariable?:
| [ComponentVariableType, ...ComponentVariableType[]]
| null;
/**
* The Id of the request.
*
Expand All @@ -38,7 +40,8 @@ export interface GetMonitoringReportRequest extends OcppRequest {
MonitoringCriterionEnumType,
MonitoringCriterionEnumType,
MonitoringCriterionEnumType,
];
]
| null;
}
/**
* This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.
Expand Down
7 changes: 5 additions & 2 deletions 00_Base/src/ocpp/model/types/GetReportRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export interface GetReportRequest extends OcppRequest {
/**
* @minItems 1
*/
componentVariable?: [ComponentVariableType, ...ComponentVariableType[]];
componentVariable?:
| [ComponentVariableType, ...ComponentVariableType[]]
| null;
/**
* The Id of the request.
*
Expand All @@ -44,7 +46,8 @@ export interface GetReportRequest extends OcppRequest {
ComponentCriterionEnumType,
ComponentCriterionEnumType,
ComponentCriterionEnumType,
];
]
| null;
}
/**
* This class does not get 'AdditionalProperties = false' in the schema generation, so it can be extended with arbitrary JSON properties to allow adding custom data.
Expand Down
5 changes: 3 additions & 2 deletions 00_Base/src/ocpp/model/types/NotifyChargingLimitRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface NotifyChargingLimitRequest extends OcppRequest {
/**
* @minItems 1
*/
chargingSchedule?: [ChargingScheduleType, ...ChargingScheduleType[]];
chargingSchedule?: [ChargingScheduleType, ...ChargingScheduleType[]] | null;
/**
* The charging schedule contained in this notification applies to an EVSE. evseId must be > 0.
*
Expand Down Expand Up @@ -175,7 +175,8 @@ export interface SalesTariffEntryType {
consumptionCost?:
| [ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType];
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType]
| null;
}
/**
* Relative_ Timer_ Interval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface NotifyDisplayMessagesRequest extends OcppRequest {
/**
* @minItems 1
*/
messageInfo?: [MessageInfoType, ...MessageInfoType[]];
messageInfo?: [MessageInfoType, ...MessageInfoType[]] | null;
/**
* The id of the <<getdisplaymessagesrequest,GetDisplayMessagesRequest>> that requested this message.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ export interface SalesTariffEntryType {
consumptionCost?:
| [ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType];
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType]
| null;
}
/**
* Relative_ Timer_ Interval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface NotifyMonitoringReportRequest extends OcppRequest {
/**
* @minItems 1
*/
monitor?: [MonitoringDataType, ...MonitoringDataType[]];
monitor?: [MonitoringDataType, ...MonitoringDataType[]] | null;
/**
* The id of the GetMonitoringRequest that requested this report.
*
Expand Down
2 changes: 1 addition & 1 deletion 00_Base/src/ocpp/model/types/NotifyReportRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface NotifyReportRequest extends OcppRequest {
/**
* @minItems 1
*/
reportData?: [ReportDataType, ...ReportDataType[]];
reportData?: [ReportDataType, ...ReportDataType[]] | null;
/**
* “to be continued” indicator. Indicates whether another part of the report follows in an upcoming notifyReportRequest message. Default value when omitted is false.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface PublishFirmwareStatusNotificationRequest extends OcppRequest {
*
* @minItems 1
*/
location?: [string, ...string[]];
location?: [string, ...string[]] | null;
/**
* The request id that was
* provided in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ export interface SalesTariffEntryType {
consumptionCost?:
| [ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType];
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType]
| null;
}
/**
* Relative_ Timer_ Interval
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface IdTokenType {
/**
* @minItems 1
*/
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]];
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]] | null;
/**
* IdToken is case insensitive. Might hold the hidden id of an RFID tag, but can for example also contain a UUID.
*
Expand Down Expand Up @@ -268,7 +268,8 @@ export interface SalesTariffEntryType {
consumptionCost?:
| [ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType];
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType]
| null;
}
/**
* Relative_ Timer_ Interval
Expand Down
2 changes: 1 addition & 1 deletion 00_Base/src/ocpp/model/types/ReserveNowRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface IdTokenType {
/**
* @minItems 1
*/
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]];
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]] | null;
/**
* IdToken is case insensitive. Might hold the hidden id of an RFID tag, but can for example also contain a UUID.
*
Expand Down
6 changes: 3 additions & 3 deletions 00_Base/src/ocpp/model/types/SendLocalListRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface SendLocalListRequest extends OcppRequest {
/**
* @minItems 1
*/
localAuthorizationList?: [AuthorizationData, ...AuthorizationData[]];
localAuthorizationList?: [AuthorizationData, ...AuthorizationData[]] | null;
/**
* In case of a full update this is the version number of the full list. In case of a differential update it is the version number of the list after the update has been applied.
*
Expand Down Expand Up @@ -56,7 +56,7 @@ export interface IdTokenType {
/**
* @minItems 1
*/
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]];
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]] | null;
/**
* IdToken is case insensitive. Might hold the hidden id of an RFID tag, but can for example also contain a UUID.
*
Expand Down Expand Up @@ -118,7 +118,7 @@ export interface IdTokenInfoType {
*
* @minItems 1
*/
evseId?: [number, ...number[]];
evseId?: [number, ...number[]] | null;
groupIdToken?: IdTokenType | null;
/**
* ID_ Token. Language2. Language_ Code
Expand Down
3 changes: 2 additions & 1 deletion 00_Base/src/ocpp/model/types/SetChargingProfileRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ export interface SalesTariffEntryType {
consumptionCost?:
| [ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType]
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType];
| [ConsumptionCostType, ConsumptionCostType, ConsumptionCostType]
| null;
}
/**
* Relative_ Timer_ Interval
Expand Down
4 changes: 2 additions & 2 deletions 00_Base/src/ocpp/model/types/TransactionEventRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface TransactionEventRequest extends OcppRequest {
/**
* @minItems 1
*/
meterValue?: [MeterValueType, ...MeterValueType[]];
meterValue?: [MeterValueType, ...MeterValueType[]] | null;
/**
* The date and time at which this transaction event occurred.
*
Expand Down Expand Up @@ -220,7 +220,7 @@ export interface IdTokenType {
/**
* @minItems 1
*/
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]];
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]] | null;
/**
* IdToken is case insensitive. Might hold the hidden id of an RFID tag, but can for example also contain a UUID.
*
Expand Down
4 changes: 2 additions & 2 deletions 00_Base/src/ocpp/model/types/TransactionEventResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface IdTokenInfoType {
*
* @minItems 1
*/
evseId?: [number, ...number[]];
evseId?: [number, ...number[]] | null;
groupIdToken?: IdTokenType | null;
/**
* ID_ Token. Language2. Language_ Code
Expand All @@ -97,7 +97,7 @@ export interface IdTokenType {
/**
* @minItems 1
*/
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]];
additionalInfo?: [AdditionalInfoType, ...AdditionalInfoType[]] | null;
/**
* IdToken is case insensitive. Might hold the hidden id of an RFID tag, but can for example also contain a UUID.
*
Expand Down

0 comments on commit bed511a

Please sign in to comment.