1

I have a json schema from which I need to generate java classes

{
    "$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"
        }
    }
}

I am trying to use the jsonschema2pojo as under.

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

For some reason I get the following error when i use mvn generate-sources

[ERROR] Failed to execute goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.1.1:generate (default) on project hsk: Execution default of goal org.jsonschema2pojo:jsonschema2pojo-maven-plugin:1.1.1:generate failed: String index out of range: 0 -> [Help 1]

Any help is highly appreciated

Regards,

Vickel
  • 7,879
  • 6
  • 35
  • 56
  • What is maven and java version? – pringi Apr 27 '22 at 08:37
  • Apache Maven 3.8.4 and Java version: 17.0.2 – user1716304 Apr 27 '22 at 08:54
  • Can you update jsonschema2pojo-maven-plugin to version 1.1.1 ? Your current version is from April 2017. – pringi Apr 27 '22 at 09:09
  • Please don't make more work for other people by vandalizing your posts. And YES, deleting the essential code block of your question is called vandalizing. By posting on Stack Overflow, you've granted a non-revocable right, under the CC BY-SA 4.0 license for Stack Overflow to distribute that content. – Vickel May 23 '23 at 20:16
  • You may dissociate a question from your account, instead of vandalizing: If you made a post that you regret posting you can [have the post dissociated from your account](https://meta.stackexchange.com/questions/96732/how-do-i-remove-my-name-from-a-post-in-accordance-with-cc-by-sa) – Vickel May 23 '23 at 20:17

1 Answers1

0

Remove the following section from the "Impact" definition:

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

It appears to be an invalid definition.

DwB
  • 37,124
  • 11
  • 56
  • 82