Skip to content

Commit 313ac68

Browse files
author
Alex Cheng
committed
feat: gen ocpp type from json
1 parent 289cb20 commit 313ac68

File tree

209 files changed

+10538
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+10538
-0
lines changed

genTypeFromJson.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const { compile } = require('json-schema-to-typescript');
2+
const fs = require('fs');
3+
const ocpp1_6_json = require('./lib/schemas/ocpp1_6.json');
4+
const ocpp2_0_1json = require('./lib/schemas/ocpp2_0_1.json');
5+
const jsonArray = [
6+
{
7+
version: 'v16',
8+
json: ocpp1_6_json
9+
},
10+
{
11+
version: 'v201',
12+
json: ocpp2_0_1json
13+
}
14+
];
15+
/**
16+
*
17+
* @param {string} id
18+
*/
19+
const compileSchemaId = (id) => {
20+
const [method, type] = id.substring(4).split('.');
21+
switch (type) {
22+
case 'req':
23+
return method + 'Request';
24+
case 'conf':
25+
return method + 'Response';
26+
default:
27+
throw Error('Invalid Schema $id:' + id)
28+
}
29+
}
30+
(async function loop() {
31+
for (const data of jsonArray) {
32+
console.log(data.version);
33+
for (const schema of data.json) {
34+
const name = compileSchemaId(schema.$id);
35+
const ts = await compile(schema, name, {
36+
ignoreMinAndMaxItems: true
37+
})
38+
await fs.writeFileSync(`./lib/types/${data.version}/${name}.d.ts`, ts);
39+
console.log(name);
40+
}
41+
}
42+
})()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface AuthorizeRequest {
9+
idTag: string;
10+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface AuthorizeResponse {
9+
idTagInfo: {
10+
expiryDate?: string;
11+
parentIdTag?: string;
12+
status: "Accepted" | "Blocked" | "Expired" | "Invalid" | "ConcurrentTx";
13+
};
14+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface BootNotificationRequest {
9+
chargePointVendor: string;
10+
chargePointModel: string;
11+
chargePointSerialNumber?: string;
12+
chargeBoxSerialNumber?: string;
13+
firmwareVersion?: string;
14+
iccid?: string;
15+
imsi?: string;
16+
meterType?: string;
17+
meterSerialNumber?: string;
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface BootNotificationResponse {
9+
status: "Accepted" | "Pending" | "Rejected";
10+
currentTime: string;
11+
interval: number;
12+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface CancelReservationRequest {
9+
reservationId: number;
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface CancelReservationResponse {
9+
status: "Accepted" | "Rejected";
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface CertificateSignedRequest {
9+
certificateChain: string;
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export type CertificateSignedStatusEnumType = "Accepted" | "Rejected";
9+
10+
export interface CertificateSignedResponse {
11+
status: CertificateSignedStatusEnumType;
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/* tslint:disable */
2+
/**
3+
* This file was automatically generated by json-schema-to-typescript.
4+
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
5+
* and run json-schema-to-typescript to regenerate this file.
6+
*/
7+
8+
export interface ChangeAvailabilityRequest {
9+
connectorId: number;
10+
type: "Inoperative" | "Operative";
11+
}

0 commit comments

Comments
 (0)