@mitre-attack/attack-data-model
Version:
A TypeScript API for the MITRE ATT&CK data model
71 lines (68 loc) • 2.83 kB
JavaScript
import {
stixIdentifierSchema
} from "./chunk-E3OY6DRE.js";
import {
nonEmptyRequiredString,
stixListOfString
} from "./chunk-KFUJRXYX.js";
// src/schemas/common/property-schemas/stix-granular-marking.ts
import { z } from "zod";
var granularMarkingSchema = z.object({
lang: nonEmptyRequiredString.optional().meta({
description: "The lang property identifies the language of the text identified by this marking. The value of the lang property, if present, MUST be an [RFC5646] language code. If the marking_ref property is not present, this property MUST be present. If the marking_ref property is present, this property MUST NOT be present."
}),
marking_ref: stixIdentifierSchema.optional().meta({
description: "The marking_ref property specifies the ID of the marking-definition object that describes the marking. If the lang property is not present, this property MUST be present. If the lang property is present, this property MUST NOT be present."
}),
selectors: stixListOfString.meta({
description: "The selectors property specifies a list of selectors for content contained within the STIX Object in which this property appears."
})
}).check((ctx) => {
const { lang, marking_ref } = ctx.value;
const hasLang = lang !== void 0;
const hasMarkingRef = marking_ref !== void 0;
if (hasLang && hasMarkingRef) {
ctx.issues.push({
path: ["lang"],
message: "If the marking_ref property is present, the lang property MUST NOT be present.",
code: "custom",
input: {
lang: ctx.value.lang,
marking_ref: ctx.value.marking_ref
}
});
ctx.issues.push({
path: ["marking_ref"],
message: "If the lang property is present, the marking_ref property MUST NOT be present.",
code: "custom",
input: {
lang: ctx.value.lang,
marking_ref: ctx.value.marking_ref
}
});
} else if (!hasLang && !hasMarkingRef) {
ctx.issues.push({
path: ["lang"],
message: "If the marking_ref property is not present, the lang property MUST be present.",
code: "custom",
input: {
lang: ctx.value.lang,
marking_ref: ctx.value.marking_ref
}
});
ctx.issues.push({
path: ["marking_ref"],
message: "If the lang property is not present, the marking_ref property MUST be present.",
code: "custom",
input: {
lang: ctx.value.lang,
marking_ref: ctx.value.marking_ref
}
});
}
}).meta({
description: "The `granular-marking` type defines how the `marking-definition` object referenced by the **marking_ref** property or a language specified by the **lang** property applies to a set of content identified by the list of selectors in the selectors property."
});
export {
granularMarkingSchema
};