Skip to content

Commit cde09bb

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

File tree

209 files changed

+10541
-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

+10541
-0
lines changed

genTypeFromJson.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 $if of schema
18+
* @returns {string} The name used for namespace and filename
19+
*/
20+
const compileSchemaId = (id) => {
21+
const [method, type] = id.substring(4).split('.');
22+
switch (type) {
23+
case 'req':
24+
return method + 'Request';
25+
case 'conf':
26+
return method + 'Response';
27+
default:
28+
throw Error('Invalid Schema $id:' + id)
29+
}
30+
}
31+
(async function loop() {
32+
for (const data of jsonArray) {
33+
console.log(data.version);
34+
for (const schema of data.json) {
35+
const name = compileSchemaId(schema.$id);
36+
const ts = await compile(schema, name, {
37+
// The array type will be too large if the maxItem property is too large.
38+
// Ref: https://github.com/bcherny/json-schema-to-typescript/issues/372
39+
ignoreMinAndMaxItems: true
40+
})
41+
await fs.writeFileSync(`./lib/types/${data.version}/${name}.d.ts`, ts);
42+
console.log(name);
43+
}
44+
}
45+
})()
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)