java 如何从JSON模式中生成类

ohtdti5x  于 2023-05-27  发布在  Java
关注(0)|答案(1)|浏览(94)

我有一个JSON模式,我需要从中生成Java类

{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://schema.softsense.io/analysis/vulnerabilities/v1alpha1/vulnerabilities.json",
    "title": "Vulnerabilities",
    "description": "SoftSense Vulnerabilities analysis schema v1alpha3",
    
    "type": "object",
    "allOf": [ { "$ref": "https://schema.softsense.io/analysis/v1alpha3/base.json" } ],
    "properties": {
        "vulnerabilities": {
            "items": {
                "$ref": "#/definitions/Vulnerability"
            },
            "type": "array"
        }
    },
    "oneOf": [{ "required": ["vulnerabilities"] }, { "required": ["error"] }],
    "definitions": {
        "Vulnerability": {
            "required": [
                "id",
                "description",
                "sources"
            ],
            "properties": {
                "id": {
                    "description": "Identifier for the vulnerability, such as a CVE identifier (CVE-2021-12345).",
                    "type": "string"
                },
                "published": {
                    "description": "UTC time when the vulnerability was published",
                    "type": "string",
                    "format": "date-time"
                },
                "updated": {
                    "description": "UTC time when the vulnerability was updated",
                    "type": "string",
                    "format": "date-time"
                },
                "description": {
                    "description": "Description of the vulnerability",
                    "type": "string"
                },
                "sources": {
                    "description": "The collection of backing vulnerability sources that listed this vulnerability for the software component",
                    "items": {
                        "type": "string"
                    },
                    "type": "array"
                },
                "cwes": {
                    "description": "The collection of Common Weakness Enumeration (CWE) identifiers that characterize the vulnerability.",
                    "items": {
                        "$ref": "#/definitions/CWE"
                    },
                    "type": "array"
                },
                "references": {
                    "description": "External URLs related to the vulnerability, such as issue trackers, mailing list discussions, commits, or patches.",
                    "items": {
                        "$ref": "#/definitions/Reference"
                    },
                    "type": "array"
                },
                "impact": {
                    "description": "What impact this vulnerability has",
                    "$ref": "#/definitions/Impact"
                }
            },
            "type": "object"
        },
        "Impact": {
            "properties": {
                "metricV3": {
                    "$ref": "#/definitions/ImpactMetricV3"
                },
                "metricV2": {
                    "$ref": "#/definitions/ImpactMetricV2"
                },
                "*": {
                    "type": "object"
                }
            },
            "type": "object"
        },
        "ImpactMetricV3": {
            "properties": {
                "cvssV3": {
                    "$ref": "#/definitions/CVSSv3"
                },
                "exploitabilityScore": {
                    "type": "number"
                },
                "impactScore": {
                    "type": "number"
                }
            }
        },
        "CVSSv3": {
            "required": [
                "version",
                "vectorString",
                "baseScore",
                "baseSeverity"
            ],
            "properties": {
                "version": {
                    "type": "string"
                },
                "vectorString": {
                    "type": "string"
                },
                "attackVector": {
                    "type": "string"
                },
                "attackComplexity": {
                    "type": "string"
                },
                "privilegesRequired": {
                    "type": "string"
                },
                "userInteraction": {
                    "type": "string"
                },
                "scope": {
                    "type": "string"
                },
                "confidentialityImpact": {
                    "type": "string"
                },
                "integrityImpact": {
                    "type": "string"
                },
                "availabilityImpact": {
                    "type": "string"
                },
                "baseScore": {
                    "type": "number"
                },
                "baseSeverity": {
                    "type": "string"
                },
                "exploitCodeMaturity": {
                    "type": "string"
                },
                "remediationLevel": {
                    "type": "string"
                },
                "reportConfidence": {
                    "type": "string"
                },
                "temporalScore": {
                    "type": "number"
                },
                "temporalSeverity": {
                    "type": "string"
                },
                "confidentialityRequirement": {
                    "type": "string"
                },
                "integrityRequirement": {
                    "type": "string"
                },
                "availabilityRequirement": {
                    "type": "string"
                },
                "modifiedAttackVector": {
                    "type": "string"
                },
                "modifiedAttackComplexity": {
                    "type": "string"
                },
                "modifiedPrivilegesRequired": {
                    "type": "string"
                },
                "modifiedUserInteraction": {
                    "type": "string"
                },
                "modifiedScope": {
                    "type": "string"
                },
                "modifiedConfidentialityImpact": {
                    "type": "string"
                },
                "modifiedIntegrityImpact": {
                    "type": "string"
                },
                "modifiedAvailabilityImpact": {
                    "type": "string"
                },
                "environmentalScore": {
                    "type": "number"
                },
                "environmentalSeverity": {
                    "type": "string"
                }
            },
            "type": "object"
        },
        "ImpactMetricV2": {
            "required": [
                "cvssV2",
                "severity",
                "exploitabilityScore",
                "impactScore",
                "obtainAllPrivilege",
                "obtainUserPrivilege",
                "obtainOtherPrivilege",
                "userInteractionRequired"
            ],
            "properties": {
                "cvssV2": {
                "$ref": "#/definitions/CVSSv2"
                },
                "severity": {
                "type": "string"
                },
                "exploitabilityScore": {
                "type": "number"
                },
                "impactScore": {
                "type": "number"
                },
                "acInsufInfo": {
                "type": "boolean"
                },
                "obtainAllPrivilege": {
                "type": "boolean"
                },
                "obtainUserPrivilege": {
                "type": "boolean"
                },
                "obtainOtherPrivilege": {
                "type": "boolean"
                },
                "userInteractionRequired": {
                "type": "boolean"
                }
            },
            "type": "object"
        },
        "CVSSv2": {
            "required": [
                "version",
                "vectorString",
                "baseScore"
            ],
            "properties": {
                "version": {
                    "type": "string"
                },
                "vectorString": {
                    "type": "string"
                },
                "accessVector": {
                    "type": "string"
                },
                "accessComplexity": {
                    "type": "string"
                },
                "authentication": {
                    "type": "string"
                },
                "confidentialityImpact": {
                    "type": "string"
                },
                "integrityImpact": {
                    "type": "string"
                },
                "availabilityImpact": {
                    "type": "string"
                },
                "baseScore": {
                    "type": "number"
                },
                "exploitability": {
                    "type": "string"
                },
                "remediationLevel": {
                    "type": "string"
                },
                "reportConfidence": {
                    "type": "string"
                },
                "temporalScore": {
                    "type": "number"
                },
                "collateralDamagePotential": {
                    "type": "string"
                },
                "targetDistribution": {
                    "type": "string"
                },
                "confidentialityRequirement": {
                    "type": "string"
                },
                "integrityRequirement": {
                    "type": "string"
                },
                "availabilityRequirement": {
                    "type": "string"
                },
                "environmentalScore": {
                    "type": "number"
                }
            },
            "type": "object"
        },
        "CWE": {
            "required": [
                "name"
            ],
            "properties": {
                "name": {
                    "type": "string"
                },
                "description": {
                    "type": "string"
                }
            },
            "type": "object"
        },
        "Reference": {
            "required": [
                "url"
            ],
            "properties": {
                "name": {
                    "type": "string"
                },
                "url": {
                    "type": "string"
                },
                "tags": {
                    "items": {
                        "type": "string"
                    },
                    "type": "array"
                }
            },
            "type": "object"
        }
    }
}

我正在尝试使用jsonschema 2 pojo作为下。

<plugin>
                <groupId>org.jsonschema2pojo</groupId>
                <artifactId>jsonschema2pojo-maven-plugin</artifactId>
                <version>0.4.34</version>
                <configuration>
                    <sourceDirectory>${basedir}/src/main/resources/schema</sourceDirectory>
                    <targetPackage>com.test.gen</targetPackage>
                    <useCommonsLang3>true</useCommonsLang3>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

由于某些原因,我得到以下错误时,我使用mvn生成源
[错误]无法在项目hsk上执行目标org.jsonschema2pojo:jsonschema 2 pojo-maven-plugin:1.1.1:generate(default):目标org.jsonschema2pojo:jsonschema 2 pojo-maven-plugin:1.1.1的执行默认值:generate failed:字符串索引超出范围:0 -> [帮助1]
任何帮助都非常感谢
致上,

yyhrrdl8

yyhrrdl81#

从“影响”定义中删除以下部分:

"*": {
    "type": "object"
}

它似乎是一个无效的定义。

相关问题