Created
October 31, 2023 04:42
-
-
Save shino/961a61a52cdbdd6861a6e2939bacbc2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This file was generated from JSON Schema using quicktype, do not modify it directly. | |
// To parse and unparse this JSON data, add this code to your project and do: | |
// | |
// cveAPIJSON20, err := UnmarshalCveAPIJSON20(bytes) | |
// bytes, err = cveAPIJSON20.Marshal() | |
package main | |
import "bytes" | |
import "errors" | |
import "encoding/json" | |
func UnmarshalCveAPIJSON20(data []byte) (CveAPIJSON20, error) { | |
var r CveAPIJSON20 | |
err := json.Unmarshal(data, &r) | |
return r, err | |
} | |
func (r *CveAPIJSON20) Marshal() ([]byte, error) { | |
return json.Marshal(r) | |
} | |
type CveAPIJSON20 struct { | |
Format string `json:"format"` | |
ResultsPerPage int64 `json:"resultsPerPage"` | |
StartIndex int64 `json:"startIndex"` | |
Timestamp string `json:"timestamp"` | |
TotalResults int64 `json:"totalResults"` | |
Version string `json:"version"` | |
// NVD feed array of CVE | |
Vulnerabilities []DefCveItem `json:"vulnerabilities"` | |
} | |
type DefCveItemClass struct { | |
Cve CveItem `json:"cve"` | |
} | |
type CveItem struct { | |
CisaActionDue *string `json:"cisaActionDue,omitempty"` | |
CisaExploitAdd *string `json:"cisaExploitAdd,omitempty"` | |
CisaRequiredAction *string `json:"cisaRequiredAction,omitempty"` | |
CisaVulnerabilityName *string `json:"cisaVulnerabilityName,omitempty"` | |
Configurations []Config `json:"configurations,omitempty"` | |
Descriptions []LangString `json:"descriptions"` | |
EvaluatorComment *string `json:"evaluatorComment,omitempty"` | |
EvaluatorImpact *string `json:"evaluatorImpact,omitempty"` | |
EvaluatorSolution *string `json:"evaluatorSolution,omitempty"` | |
ID string `json:"id"` | |
LastModified string `json:"lastModified"` | |
// Metric scores for a vulnerability as found on NVD. | |
Metrics *Metrics `json:"metrics,omitempty"` | |
Published string `json:"published"` | |
References []Reference `json:"references"` | |
SourceIdentifier *string `json:"sourceIdentifier,omitempty"` | |
VendorComments []VendorComment `json:"vendorComments,omitempty"` | |
VulnStatus *string `json:"vulnStatus,omitempty"` | |
Weaknesses []Weakness `json:"weaknesses,omitempty"` | |
} | |
type ConfigClass struct { | |
Negate *bool `json:"negate,omitempty"` | |
Nodes []Node `json:"nodes"` | |
Operator *Operator `json:"operator,omitempty"` | |
} | |
type NodeClass struct { | |
CpeMatch []CpeMatch `json:"cpeMatch"` | |
Negate *bool `json:"negate,omitempty"` | |
Operator Operator `json:"operator"` | |
} | |
// CPE match string or range | |
type CpeMatch struct { | |
Criteria string `json:"criteria"` | |
MatchCriteriaID string `json:"matchCriteriaId"` | |
VersionEndExcluding *string `json:"versionEndExcluding,omitempty"` | |
VersionEndIncluding *string `json:"versionEndIncluding,omitempty"` | |
VersionStartExcluding *string `json:"versionStartExcluding,omitempty"` | |
VersionStartIncluding *string `json:"versionStartIncluding,omitempty"` | |
Vulnerable bool `json:"vulnerable"` | |
} | |
type LangString struct { | |
Lang string `json:"lang"` | |
Value string `json:"value"` | |
} | |
// Metric scores for a vulnerability as found on NVD. | |
type Metrics struct { | |
// CVSS V2.0 score. | |
CvssMetricV2 []CvssV2 `json:"cvssMetricV2,omitempty"` | |
// CVSS V3.0 score. | |
CvssMetricV30 []CvssV30 `json:"cvssMetricV30,omitempty"` | |
// CVSS V3.1 score. | |
CvssMetricV31 []CvssV31 `json:"cvssMetricV31,omitempty"` | |
} | |
type CvssV2Class struct { | |
ACInsufInfo *bool `json:"acInsufInfo,omitempty"` | |
BaseSeverity *string `json:"baseSeverity,omitempty"` | |
CvssData JSONSchemaForCommonVulnerabilityScoringSystemVersion20 `json:"cvssData"` | |
ExploitabilityScore *float64 `json:"exploitabilityScore,omitempty"` | |
ImpactScore *float64 `json:"impactScore,omitempty"` | |
ObtainAllPrivilege *bool `json:"obtainAllPrivilege,omitempty"` | |
ObtainOtherPrivilege *bool `json:"obtainOtherPrivilege,omitempty"` | |
ObtainUserPrivilege *bool `json:"obtainUserPrivilege,omitempty"` | |
Source string `json:"source"` | |
Type Type `json:"type"` | |
UserInteractionRequired *bool `json:"userInteractionRequired,omitempty"` | |
} | |
type JSONSchemaForCommonVulnerabilityScoringSystemVersion20 struct { | |
AccessComplexity *AccessComplexityType `json:"accessComplexity,omitempty"` | |
AccessVector *AccessVectorType `json:"accessVector,omitempty"` | |
Authentication *AuthenticationType `json:"authentication,omitempty"` | |
AvailabilityImpact *CiaType `json:"availabilityImpact,omitempty"` | |
AvailabilityRequirement *CiaRequirementType `json:"availabilityRequirement,omitempty"` | |
BaseScore float64 `json:"baseScore"` | |
CollateralDamagePotential *CollateralDamagePotentialType `json:"collateralDamagePotential,omitempty"` | |
ConfidentialityImpact *CiaType `json:"confidentialityImpact,omitempty"` | |
ConfidentialityRequirement *CiaRequirementType `json:"confidentialityRequirement,omitempty"` | |
EnvironmentalScore *float64 `json:"environmentalScore,omitempty"` | |
Exploitability *ExploitityType `json:"exploitability,omitempty"` | |
IntegrityImpact *CiaType `json:"integrityImpact,omitempty"` | |
IntegrityRequirement *CiaRequirementType `json:"integrityRequirement,omitempty"` | |
RemediationLevel *RemediationLevelType `json:"remediationLevel,omitempty"` | |
ReportConfidence *ReportConfidenceType `json:"reportConfidence,omitempty"` | |
TargetDistribution *TargetDistributionType `json:"targetDistribution,omitempty"` | |
TemporalScore *float64 `json:"temporalScore,omitempty"` | |
VectorString string `json:"vectorString"` | |
// CVSS Version | |
Version PurpleVersion `json:"version"` | |
} | |
type CvssV30Class struct { | |
CvssData JSONSchemaForCommonVulnerabilityScoringSystemVersion30 `json:"cvssData"` | |
ExploitabilityScore *float64 `json:"exploitabilityScore,omitempty"` | |
ImpactScore *float64 `json:"impactScore,omitempty"` | |
Source string `json:"source"` | |
Type Type `json:"type"` | |
} | |
type JSONSchemaForCommonVulnerabilityScoringSystemVersion30 struct { | |
AttackComplexity *AttackComplexityType `json:"attackComplexity,omitempty"` | |
AttackVector *AttackVectorType `json:"attackVector,omitempty"` | |
AvailabilityImpact *AvailabilityImpactEnum `json:"availabilityImpact,omitempty"` | |
AvailabilityRequirement *CiaRequirementType `json:"availabilityRequirement,omitempty"` | |
BaseScore float64 `json:"baseScore"` | |
BaseSeverity SeverityType `json:"baseSeverity"` | |
ConfidentialityImpact *AvailabilityImpactEnum `json:"confidentialityImpact,omitempty"` | |
ConfidentialityRequirement *CiaRequirementType `json:"confidentialityRequirement,omitempty"` | |
EnvironmentalScore *float64 `json:"environmentalScore,omitempty"` | |
EnvironmentalSeverity *SeverityType `json:"environmentalSeverity,omitempty"` | |
ExploitCodeMaturity *ExploitityType `json:"exploitCodeMaturity,omitempty"` | |
IntegrityImpact *AvailabilityImpactEnum `json:"integrityImpact,omitempty"` | |
IntegrityRequirement *CiaRequirementType `json:"integrityRequirement,omitempty"` | |
ModifiedAttackComplexity *ModifiedAttackComplexityType `json:"modifiedAttackComplexity,omitempty"` | |
ModifiedAttackVector *ModifiedAttackVectorType `json:"modifiedAttackVector,omitempty"` | |
ModifiedAvailabilityImpact *ModifiedType `json:"modifiedAvailabilityImpact,omitempty"` | |
ModifiedConfidentialityImpact *ModifiedType `json:"modifiedConfidentialityImpact,omitempty"` | |
ModifiedIntegrityImpact *ModifiedType `json:"modifiedIntegrityImpact,omitempty"` | |
ModifiedPrivilegesRequired *ModifiedType `json:"modifiedPrivilegesRequired,omitempty"` | |
ModifiedScope *ModifiedScopeType `json:"modifiedScope,omitempty"` | |
ModifiedUserInteraction *ModifiedUserInteractionType `json:"modifiedUserInteraction,omitempty"` | |
PrivilegesRequired *AvailabilityImpactEnum `json:"privilegesRequired,omitempty"` | |
RemediationLevel *RemediationLevelType `json:"remediationLevel,omitempty"` | |
ReportConfidence *ConfidenceType `json:"reportConfidence,omitempty"` | |
Scope *ScopeType `json:"scope,omitempty"` | |
TemporalScore *float64 `json:"temporalScore,omitempty"` | |
TemporalSeverity *SeverityType `json:"temporalSeverity,omitempty"` | |
UserInteraction *UserInteractionType `json:"userInteraction,omitempty"` | |
VectorString string `json:"vectorString"` | |
// CVSS Version | |
Version FluffyVersion `json:"version"` | |
} | |
type CvssV31Class struct { | |
CvssData JSONSchemaForCommonVulnerabilityScoringSystemVersion31 `json:"cvssData"` | |
ExploitabilityScore *float64 `json:"exploitabilityScore,omitempty"` | |
ImpactScore *float64 `json:"impactScore,omitempty"` | |
Source string `json:"source"` | |
Type Type `json:"type"` | |
} | |
type JSONSchemaForCommonVulnerabilityScoringSystemVersion31 struct { | |
AttackComplexity *AttackComplexityType `json:"attackComplexity,omitempty"` | |
AttackVector *AttackVectorType `json:"attackVector,omitempty"` | |
AvailabilityImpact *AvailabilityImpactEnum `json:"availabilityImpact,omitempty"` | |
AvailabilityRequirement *CiaRequirementType `json:"availabilityRequirement,omitempty"` | |
BaseScore float64 `json:"baseScore"` | |
BaseSeverity SeverityType `json:"baseSeverity"` | |
ConfidentialityImpact *AvailabilityImpactEnum `json:"confidentialityImpact,omitempty"` | |
ConfidentialityRequirement *CiaRequirementType `json:"confidentialityRequirement,omitempty"` | |
EnvironmentalScore *float64 `json:"environmentalScore,omitempty"` | |
EnvironmentalSeverity *SeverityType `json:"environmentalSeverity,omitempty"` | |
ExploitCodeMaturity *ExploitityType `json:"exploitCodeMaturity,omitempty"` | |
IntegrityImpact *AvailabilityImpactEnum `json:"integrityImpact,omitempty"` | |
IntegrityRequirement *CiaRequirementType `json:"integrityRequirement,omitempty"` | |
ModifiedAttackComplexity *ModifiedAttackComplexityType `json:"modifiedAttackComplexity,omitempty"` | |
ModifiedAttackVector *ModifiedAttackVectorType `json:"modifiedAttackVector,omitempty"` | |
ModifiedAvailabilityImpact *ModifiedType `json:"modifiedAvailabilityImpact,omitempty"` | |
ModifiedConfidentialityImpact *ModifiedType `json:"modifiedConfidentialityImpact,omitempty"` | |
ModifiedIntegrityImpact *ModifiedType `json:"modifiedIntegrityImpact,omitempty"` | |
ModifiedPrivilegesRequired *ModifiedType `json:"modifiedPrivilegesRequired,omitempty"` | |
ModifiedScope *ModifiedScopeType `json:"modifiedScope,omitempty"` | |
ModifiedUserInteraction *ModifiedUserInteractionType `json:"modifiedUserInteraction,omitempty"` | |
PrivilegesRequired *AvailabilityImpactEnum `json:"privilegesRequired,omitempty"` | |
RemediationLevel *RemediationLevelType `json:"remediationLevel,omitempty"` | |
ReportConfidence *ConfidenceType `json:"reportConfidence,omitempty"` | |
Scope *ScopeType `json:"scope,omitempty"` | |
TemporalScore *float64 `json:"temporalScore,omitempty"` | |
TemporalSeverity *SeverityType `json:"temporalSeverity,omitempty"` | |
UserInteraction *UserInteractionType `json:"userInteraction,omitempty"` | |
VectorString string `json:"vectorString"` | |
// CVSS Version | |
Version TentacledVersion `json:"version"` | |
} | |
type Reference struct { | |
Source *string `json:"source,omitempty"` | |
Tags []string `json:"tags,omitempty"` | |
URL string `json:"url"` | |
} | |
type VendorComment struct { | |
Comment string `json:"comment"` | |
LastModified string `json:"lastModified"` | |
Organization string `json:"organization"` | |
} | |
type WeaknessClass struct { | |
Description []LangString `json:"description"` | |
Source string `json:"source"` | |
Type string `json:"type"` | |
} | |
type Operator string | |
const ( | |
And Operator = "AND" | |
Or Operator = "OR" | |
) | |
type AccessComplexityType string | |
const ( | |
AccessComplexityTypeHIGH AccessComplexityType = "HIGH" | |
AccessComplexityTypeLOW AccessComplexityType = "LOW" | |
AccessComplexityTypeMEDIUM AccessComplexityType = "MEDIUM" | |
) | |
type AccessVectorType string | |
const ( | |
AccessVectorTypeADJACENTNETWORK AccessVectorType = "ADJACENT_NETWORK" | |
AccessVectorTypeLOCAL AccessVectorType = "LOCAL" | |
AccessVectorTypeNETWORK AccessVectorType = "NETWORK" | |
) | |
type AuthenticationType string | |
const ( | |
AuthenticationTypeNONE AuthenticationType = "NONE" | |
Multiple AuthenticationType = "MULTIPLE" | |
Single AuthenticationType = "SINGLE" | |
) | |
type CiaType string | |
const ( | |
CiaTypeNONE CiaType = "NONE" | |
Complete CiaType = "COMPLETE" | |
Partial CiaType = "PARTIAL" | |
) | |
type CiaRequirementType string | |
const ( | |
CiaRequirementTypeHIGH CiaRequirementType = "HIGH" | |
CiaRequirementTypeLOW CiaRequirementType = "LOW" | |
CiaRequirementTypeMEDIUM CiaRequirementType = "MEDIUM" | |
CiaRequirementTypeNOTDEFINED CiaRequirementType = "NOT_DEFINED" | |
) | |
type CollateralDamagePotentialType string | |
const ( | |
CollateralDamagePotentialTypeHIGH CollateralDamagePotentialType = "HIGH" | |
CollateralDamagePotentialTypeLOW CollateralDamagePotentialType = "LOW" | |
CollateralDamagePotentialTypeNONE CollateralDamagePotentialType = "NONE" | |
CollateralDamagePotentialTypeNOTDEFINED CollateralDamagePotentialType = "NOT_DEFINED" | |
LowMedium CollateralDamagePotentialType = "LOW_MEDIUM" | |
MediumHigh CollateralDamagePotentialType = "MEDIUM_HIGH" | |
) | |
type ExploitityType string | |
const ( | |
ExploitityTypeHIGH ExploitityType = "HIGH" | |
ExploitityTypeNOTDEFINED ExploitityType = "NOT_DEFINED" | |
Functional ExploitityType = "FUNCTIONAL" | |
ProofOfConcept ExploitityType = "PROOF_OF_CONCEPT" | |
Unproven ExploitityType = "UNPROVEN" | |
) | |
type RemediationLevelType string | |
const ( | |
OfficialFix RemediationLevelType = "OFFICIAL_FIX" | |
RemediationLevelTypeNOTDEFINED RemediationLevelType = "NOT_DEFINED" | |
TemporaryFix RemediationLevelType = "TEMPORARY_FIX" | |
Unavailable RemediationLevelType = "UNAVAILABLE" | |
Workaround RemediationLevelType = "WORKAROUND" | |
) | |
type ReportConfidenceType string | |
const ( | |
ReportConfidenceTypeCONFIRMED ReportConfidenceType = "CONFIRMED" | |
ReportConfidenceTypeNOTDEFINED ReportConfidenceType = "NOT_DEFINED" | |
Unconfirmed ReportConfidenceType = "UNCONFIRMED" | |
Uncorroborated ReportConfidenceType = "UNCORROBORATED" | |
) | |
type TargetDistributionType string | |
const ( | |
TargetDistributionTypeHIGH TargetDistributionType = "HIGH" | |
TargetDistributionTypeLOW TargetDistributionType = "LOW" | |
TargetDistributionTypeMEDIUM TargetDistributionType = "MEDIUM" | |
TargetDistributionTypeNONE TargetDistributionType = "NONE" | |
TargetDistributionTypeNOTDEFINED TargetDistributionType = "NOT_DEFINED" | |
) | |
// CVSS Version | |
type PurpleVersion string | |
const ( | |
The20 PurpleVersion = "2.0" | |
) | |
type Type string | |
const ( | |
Primary Type = "Primary" | |
Secondary Type = "Secondary" | |
) | |
type AttackComplexityType string | |
const ( | |
AttackComplexityTypeHIGH AttackComplexityType = "HIGH" | |
AttackComplexityTypeLOW AttackComplexityType = "LOW" | |
) | |
type AttackVectorType string | |
const ( | |
AttackVectorTypeADJACENTNETWORK AttackVectorType = "ADJACENT_NETWORK" | |
AttackVectorTypeLOCAL AttackVectorType = "LOCAL" | |
AttackVectorTypeNETWORK AttackVectorType = "NETWORK" | |
AttackVectorTypePHYSICAL AttackVectorType = "PHYSICAL" | |
) | |
type AvailabilityImpactEnum string | |
const ( | |
TypeHIGH AvailabilityImpactEnum = "HIGH" | |
TypeLOW AvailabilityImpactEnum = "LOW" | |
TypeNONE AvailabilityImpactEnum = "NONE" | |
) | |
type SeverityType string | |
const ( | |
Critical SeverityType = "CRITICAL" | |
SeverityTypeHIGH SeverityType = "HIGH" | |
SeverityTypeLOW SeverityType = "LOW" | |
SeverityTypeMEDIUM SeverityType = "MEDIUM" | |
SeverityTypeNONE SeverityType = "NONE" | |
) | |
type ModifiedAttackComplexityType string | |
const ( | |
ModifiedAttackComplexityTypeHIGH ModifiedAttackComplexityType = "HIGH" | |
ModifiedAttackComplexityTypeLOW ModifiedAttackComplexityType = "LOW" | |
ModifiedAttackComplexityTypeNOTDEFINED ModifiedAttackComplexityType = "NOT_DEFINED" | |
) | |
type ModifiedAttackVectorType string | |
const ( | |
ModifiedAttackVectorTypeADJACENTNETWORK ModifiedAttackVectorType = "ADJACENT_NETWORK" | |
ModifiedAttackVectorTypeLOCAL ModifiedAttackVectorType = "LOCAL" | |
ModifiedAttackVectorTypeNETWORK ModifiedAttackVectorType = "NETWORK" | |
ModifiedAttackVectorTypeNOTDEFINED ModifiedAttackVectorType = "NOT_DEFINED" | |
ModifiedAttackVectorTypePHYSICAL ModifiedAttackVectorType = "PHYSICAL" | |
) | |
type ModifiedType string | |
const ( | |
ModifiedTypeHIGH ModifiedType = "HIGH" | |
ModifiedTypeLOW ModifiedType = "LOW" | |
ModifiedTypeNONE ModifiedType = "NONE" | |
ModifiedTypeNOTDEFINED ModifiedType = "NOT_DEFINED" | |
) | |
type ModifiedScopeType string | |
const ( | |
ModifiedScopeTypeCHANGED ModifiedScopeType = "CHANGED" | |
ModifiedScopeTypeNOTDEFINED ModifiedScopeType = "NOT_DEFINED" | |
ModifiedScopeTypeUNCHANGED ModifiedScopeType = "UNCHANGED" | |
) | |
type ModifiedUserInteractionType string | |
const ( | |
ModifiedUserInteractionTypeNONE ModifiedUserInteractionType = "NONE" | |
ModifiedUserInteractionTypeNOTDEFINED ModifiedUserInteractionType = "NOT_DEFINED" | |
ModifiedUserInteractionTypeREQUIRED ModifiedUserInteractionType = "REQUIRED" | |
) | |
type ConfidenceType string | |
const ( | |
ConfidenceTypeCONFIRMED ConfidenceType = "CONFIRMED" | |
ConfidenceTypeNOTDEFINED ConfidenceType = "NOT_DEFINED" | |
Reasonable ConfidenceType = "REASONABLE" | |
Unknown ConfidenceType = "UNKNOWN" | |
) | |
type ScopeType string | |
const ( | |
ScopeTypeCHANGED ScopeType = "CHANGED" | |
ScopeTypeUNCHANGED ScopeType = "UNCHANGED" | |
) | |
type UserInteractionType string | |
const ( | |
UserInteractionTypeNONE UserInteractionType = "NONE" | |
UserInteractionTypeREQUIRED UserInteractionType = "REQUIRED" | |
) | |
// CVSS Version | |
type FluffyVersion string | |
const ( | |
The30 FluffyVersion = "3.0" | |
) | |
// CVSS Version | |
type TentacledVersion string | |
const ( | |
The31 TentacledVersion = "3.1" | |
) | |
type DefCveItem struct { | |
AnythingArray []interface{} | |
Bool *bool | |
DefCveItemClass *DefCveItemClass | |
Double *float64 | |
Integer *int64 | |
String *string | |
} | |
func (x *DefCveItem) UnmarshalJSON(data []byte) error { | |
x.AnythingArray = nil | |
x.DefCveItemClass = nil | |
var c DefCveItemClass | |
object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true) | |
if err != nil { | |
return err | |
} | |
if object { | |
x.DefCveItemClass = &c | |
} | |
return nil | |
} | |
func (x *DefCveItem) MarshalJSON() ([]byte, error) { | |
return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.DefCveItemClass != nil, x.DefCveItemClass, false, nil, false, nil, true) | |
} | |
type Config struct { | |
AnythingArray []interface{} | |
Bool *bool | |
ConfigClass *ConfigClass | |
Double *float64 | |
Integer *int64 | |
String *string | |
} | |
func (x *Config) UnmarshalJSON(data []byte) error { | |
x.AnythingArray = nil | |
x.ConfigClass = nil | |
var c ConfigClass | |
object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true) | |
if err != nil { | |
return err | |
} | |
if object { | |
x.ConfigClass = &c | |
} | |
return nil | |
} | |
func (x *Config) MarshalJSON() ([]byte, error) { | |
return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.ConfigClass != nil, x.ConfigClass, false, nil, false, nil, true) | |
} | |
// Defines a configuration node in an NVD applicability statement. | |
type Node struct { | |
AnythingArray []interface{} | |
Bool *bool | |
Double *float64 | |
Integer *int64 | |
NodeClass *NodeClass | |
String *string | |
} | |
func (x *Node) UnmarshalJSON(data []byte) error { | |
x.AnythingArray = nil | |
x.NodeClass = nil | |
var c NodeClass | |
object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true) | |
if err != nil { | |
return err | |
} | |
if object { | |
x.NodeClass = &c | |
} | |
return nil | |
} | |
func (x *Node) MarshalJSON() ([]byte, error) { | |
return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.NodeClass != nil, x.NodeClass, false, nil, false, nil, true) | |
} | |
type CvssV2 struct { | |
AnythingArray []interface{} | |
Bool *bool | |
CvssV2Class *CvssV2Class | |
Double *float64 | |
Integer *int64 | |
String *string | |
} | |
func (x *CvssV2) UnmarshalJSON(data []byte) error { | |
x.AnythingArray = nil | |
x.CvssV2Class = nil | |
var c CvssV2Class | |
object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true) | |
if err != nil { | |
return err | |
} | |
if object { | |
x.CvssV2Class = &c | |
} | |
return nil | |
} | |
func (x *CvssV2) MarshalJSON() ([]byte, error) { | |
return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.CvssV2Class != nil, x.CvssV2Class, false, nil, false, nil, true) | |
} | |
type CvssV30 struct { | |
AnythingArray []interface{} | |
Bool *bool | |
CvssV30Class *CvssV30Class | |
Double *float64 | |
Integer *int64 | |
String *string | |
} | |
func (x *CvssV30) UnmarshalJSON(data []byte) error { | |
x.AnythingArray = nil | |
x.CvssV30Class = nil | |
var c CvssV30Class | |
object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true) | |
if err != nil { | |
return err | |
} | |
if object { | |
x.CvssV30Class = &c | |
} | |
return nil | |
} | |
func (x *CvssV30) MarshalJSON() ([]byte, error) { | |
return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.CvssV30Class != nil, x.CvssV30Class, false, nil, false, nil, true) | |
} | |
type CvssV31 struct { | |
AnythingArray []interface{} | |
Bool *bool | |
CvssV31Class *CvssV31Class | |
Double *float64 | |
Integer *int64 | |
String *string | |
} | |
func (x *CvssV31) UnmarshalJSON(data []byte) error { | |
x.AnythingArray = nil | |
x.CvssV31Class = nil | |
var c CvssV31Class | |
object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true) | |
if err != nil { | |
return err | |
} | |
if object { | |
x.CvssV31Class = &c | |
} | |
return nil | |
} | |
func (x *CvssV31) MarshalJSON() ([]byte, error) { | |
return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.CvssV31Class != nil, x.CvssV31Class, false, nil, false, nil, true) | |
} | |
type Weakness struct { | |
AnythingArray []interface{} | |
Bool *bool | |
Double *float64 | |
Integer *int64 | |
String *string | |
WeaknessClass *WeaknessClass | |
} | |
func (x *Weakness) UnmarshalJSON(data []byte) error { | |
x.AnythingArray = nil | |
x.WeaknessClass = nil | |
var c WeaknessClass | |
object, err := unmarshalUnion(data, &x.Integer, &x.Double, &x.Bool, &x.String, true, &x.AnythingArray, true, &c, false, nil, false, nil, true) | |
if err != nil { | |
return err | |
} | |
if object { | |
x.WeaknessClass = &c | |
} | |
return nil | |
} | |
func (x *Weakness) MarshalJSON() ([]byte, error) { | |
return marshalUnion(x.Integer, x.Double, x.Bool, x.String, x.AnythingArray != nil, x.AnythingArray, x.WeaknessClass != nil, x.WeaknessClass, false, nil, false, nil, true) | |
} | |
func unmarshalUnion(data []byte, pi **int64, pf **float64, pb **bool, ps **string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) (bool, error) { | |
if pi != nil { | |
*pi = nil | |
} | |
if pf != nil { | |
*pf = nil | |
} | |
if pb != nil { | |
*pb = nil | |
} | |
if ps != nil { | |
*ps = nil | |
} | |
dec := json.NewDecoder(bytes.NewReader(data)) | |
dec.UseNumber() | |
tok, err := dec.Token() | |
if err != nil { | |
return false, err | |
} | |
switch v := tok.(type) { | |
case json.Number: | |
if pi != nil { | |
i, err := v.Int64() | |
if err == nil { | |
*pi = &i | |
return false, nil | |
} | |
} | |
if pf != nil { | |
f, err := v.Float64() | |
if err == nil { | |
*pf = &f | |
return false, nil | |
} | |
return false, errors.New("Unparsable number") | |
} | |
return false, errors.New("Union does not contain number") | |
case float64: | |
return false, errors.New("Decoder should not return float64") | |
case bool: | |
if pb != nil { | |
*pb = &v | |
return false, nil | |
} | |
return false, errors.New("Union does not contain bool") | |
case string: | |
if haveEnum { | |
return false, json.Unmarshal(data, pe) | |
} | |
if ps != nil { | |
*ps = &v | |
return false, nil | |
} | |
return false, errors.New("Union does not contain string") | |
case nil: | |
if nullable { | |
return false, nil | |
} | |
return false, errors.New("Union does not contain null") | |
case json.Delim: | |
if v == '{' { | |
if haveObject { | |
return true, json.Unmarshal(data, pc) | |
} | |
if haveMap { | |
return false, json.Unmarshal(data, pm) | |
} | |
return false, errors.New("Union does not contain object") | |
} | |
if v == '[' { | |
if haveArray { | |
return false, json.Unmarshal(data, pa) | |
} | |
return false, errors.New("Union does not contain array") | |
} | |
return false, errors.New("Cannot handle delimiter") | |
} | |
return false, errors.New("Cannot unmarshal union") | |
} | |
func marshalUnion(pi *int64, pf *float64, pb *bool, ps *string, haveArray bool, pa interface{}, haveObject bool, pc interface{}, haveMap bool, pm interface{}, haveEnum bool, pe interface{}, nullable bool) ([]byte, error) { | |
if pi != nil { | |
return json.Marshal(*pi) | |
} | |
if pf != nil { | |
return json.Marshal(*pf) | |
} | |
if pb != nil { | |
return json.Marshal(*pb) | |
} | |
if ps != nil { | |
return json.Marshal(*ps) | |
} | |
if haveArray { | |
return json.Marshal(pa) | |
} | |
if haveObject { | |
return json.Marshal(pc) | |
} | |
if haveMap { | |
return json.Marshal(pm) | |
} | |
if haveEnum { | |
return json.Marshal(pe) | |
} | |
if nullable { | |
return json.Marshal(nil) | |
} | |
return nil, errors.New("Union must not be null") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment