typescript JSON中的OCPP类型

gjmwrych  于 2023-03-31  发布在  TypeScript
关注(0)|答案(2)|浏览(165)

我正在使用node.js和typescript实现ocpp2.0.1充电站。JSON类型的消息在我所拥有的时间内处理起来非常复杂。
这是一个例子:

{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "$id": "urn:OCPP:Cp:2:2020:3:CertificateSignedRequest",
    "comment": "OCPP 2.0.1 FINAL",
    "definitions": {
        "CustomDataType": {
            "description": "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.",
            "javaType": "CustomData",
            "type": "object",
            "properties": {
                "vendorId": {
                    "type": "string",
                    "maxLength": 255
                }
            },
            "required": [
                "vendorId"
            ]
        },
        "CertificateSigningUseEnumType": {
            "description": "Indicates the type of the signed certificate that is returned. When omitted the certificate is used for both the 15118 connection (if implemented) and the Charging Station to CSMS connection. This field is required when a typeOfCertificate was included in the <<signcertificaterequest,SignCertificateRequest>> that requested this certificate to be signed AND both the 15118 connection and the Charging Station connection are implemented.\r\n\r\n",
            "javaType": "CertificateSigningUseEnum",
            "type": "string",
            "additionalProperties": false,
            "enum": [
                "ChargingStationCertificate",
                "V2GCertificate"
            ]
        }
    },
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "customData": {
            "$ref": "#/definitions/CustomDataType"
        },
        "certificateChain": {
            "description": "The signed PEM encoded X.509 certificate. This can also contain the necessary sub CA certificates. In that case, the order of the bundle should follow the certificate chain, starting from the leaf certificate.\r\n\r\nThe Configuration Variable <<configkey-max-certificate-chain-size,MaxCertificateChainSize>> can be used to limit the maximum size of this field.\r\n",
            "type": "string",
            "maxLength": 10000
        },
        "certificateType": {
            "$ref": "#/definitions/CertificateSigningUseEnumType"
        }
    },
    "required": [
        "certificateChain"
    ]
}

这是最小的一个。
有没有什么解决方案可以从这些JSON中创建typescript接口?

dgsult0t

dgsult0t1#

这里有两个用于typescript的ocpp类型接口源:

  1. https://github.com/gregszalay/ocpp-messages-ts-纯类型
  2. https://www.npmjs.com/package/@extrawest/node-ts-ocpp-已经为客户端和中央系统实现了处理程序。
vsdwdz23

vsdwdz232#

你可以使用MakeTypes。要么使用web界面手动生成类型,要么使用它们的NPM package在代码中完成。
例如,请参阅您发布的示例

的屏幕截图(web)

相关问题