diff --git a/.agents/summary/components.md b/.agents/summary/components.md index 633a483..fef15aa 100644 --- a/.agents/summary/components.md +++ b/.agents/summary/components.md @@ -46,6 +46,19 @@ graph LR | `OscalBaseModel.__init__` | Maps field-name kwargs to aliases; leaves the name if the alias is also passed so `extra='forbid'` rejects it. Marked `__pydantic_base_init__ = True` so `model_validate*` doesn't route through it | | `_kwarg_aliases(cls)` | `functools.cache`'d `{name: alias}` for alias-differing fields, excluding names that are also some field's alias | +### 1b. `v1/_datatypes.py` — the four datatypes that a pattern does not define (hand-written) + +**Responsibility:** The types that the models use for the OSCAL datatypes `uri`, `uri-reference`, `email-address`, and `date-time-with-timezone`. The hoist names each definition with `customTypePath`, so codegen emits these types at each site. Imports only `pydantic`, `pydantic_core`, and stdlib. + +| Symbol | Value type | Checks | +|--------|-----------|--------| +| `OscalUri` | `str` (the input text) | The OSCAL pattern, then the RFC 3986 `URI` grammar. Each scheme is valid | +| `OscalUriReference` | `str` (the input text) | The RFC 3986 `URI-reference` grammar | +| `OscalEmailAddress` | `str` (the input text) | The two OSCAL patterns, then the RFC 5321 `Mailbox` grammar with RFC 6531 | +| `OscalDateTimeWithTimezone` | `AwareDatetime` | The OSCAL pattern on the input string; in Python input also a `datetime` whose serialization matches it. One `oscal_date_time_with_timezone` error at the field | + +Each check runs in pydantic-core with the Rust `regex` engine. The pattern literals are the output of `translate` for the schema patterns; a test fails when one drifts. + ## 2. `v1/parser.py` — Runtime parse/serialize/validate **Responsibility:** Convert JSON ⇄ models and validate. @@ -126,8 +139,9 @@ Not part of the installed package. `scripts/` is not a package: a script imports | `spec_artifact.py` | The one pin of the spec artifact (`0.8.0+oscal.1.2.3` + sha256), shared by `generate` and the tests; cache `tests/.corpus_cache/`. The artifact supplies the complete OSCAL schema (`artifact_paths(...).schema`), `names.json`, and the corpus, and the pin is the only selector of the OSCAL release | `SPEC_ARTIFACT_VERSION`, `SPEC_ARTIFACT_SHA256`, `SPEC_ARTIFACT`, `OSCAL_RELEASE`, `ensure_spec_artifact`, `artifact_paths`, `ArtifactPaths` | | `pinned_archive.py` | Stdlib-only, cross-process-locked download (HTTPS only, HTTPS-only redirects, 64 MiB body cap), sha256 check before extraction, tar-slip-safe extraction with the `data` filter (Python 3.11.4+), atomic publish | `PinnedArchive`, `ensure_pinned_archive`, `http_get`, `build_https_opener`, `CorpusError`, `ResponseTooLargeError`, `FileLock` | | `manifest.py` | Validates `names.json`: JSON Schema (`jsonschema-rs`), format/release, schema sha256 against the schema bytes, unique names, resolvable pointers, type references | `validate_manifest`, `load_validated_manifest(paths, *, schema_bytes=None, schema_path=None)` (no bytes and no path means `paths.schema`), `read_schema_bytes`, `ManifestError` | -| `hoist_names.py` | Reads the artifact schema from `paths.schema` one time, and writes `build/codegen/oscal_complete_schema.json`, in which each manifest site is `definitions/` with a `$ref` at the site | `hoist`, `HoistError`, `OUTPUT` | -| `postprocess_models.py` | Phase 1 structure fixes, adds union aliases / `MappingCollectionMappings` / `OscalDocument`, names scalar aliases, applies three guards against the manifest | `postprocess`, `guard_failures`, `PostprocessError`, `add_union_aliases`, `add_single_or_many`, `rename_document_union`, `scalar_renames`, `collapse_scalar_root_models`, `fix_non_string_patterns`, `scalar_names`, `import_bindings`, `artifact_schema_path`, `load_manifest(schema_bytes)`, `write_atomically`, `parse_args`/`main` (`--models`/`--schema`, each with its own default, `--schema` resolved in `main` to the artifact schema; `--output`, defaulting to `--models`) | +| `hoist_names.py` | Reads the artifact schema from `paths.schema` one time, and writes `build/codegen/oscal_complete_schema.json`, in which each manifest site is `definitions/` with a `$ref` at the site, and the four hand-written datatypes carry `customTypePath` | `hoist`, `HoistError`, `OUTPUT` | +| `postprocess_models.py` | Phase 1 structure fixes and pattern placement (`place_patterns`), adds union aliases / `MappingCollectionMappings` / `OscalDocument`, names scalar aliases, applies three guards against the manifest | `postprocess`, `guard_failures`, `PostprocessError`, `add_union_aliases`, `add_single_or_many`, `rename_document_union`, `scalar_renames`, `collapse_scalar_root_models`, `place_patterns`, `scalar_names`, `import_bindings`, `artifact_schema_path`, `load_manifest(schema_bytes)`, `write_atomically`, `parse_args`/`main` (`--models`/`--schema`, each with its own default, `--schema` resolved in `main` to the artifact schema; `--output`, defaulting to `--models`) | +| `regex_translation.py` | `translate`: maps an ECMA-262 pattern of the schema to the Rust `regex` dialect (`.` and `\s`); errors on lookaround, back-references, `\d`, `\w`, `\b`, an inline flag | `translate`, `RegexTranslationError` | | `bench_serialization.py` | Parse and serialize time benchmark (numbers in `PERFORMANCE.md`) | — | | `bench_memory.py` | Peak-memory benchmark of a parse (numbers in `PERFORMANCE.md`) | — | diff --git a/.agents/summary/data_models.md b/.agents/summary/data_models.md index 0fe3fa8..72047ad 100644 --- a/.agents/summary/data_models.md +++ b/.agents/summary/data_models.md @@ -86,8 +86,11 @@ These recur across document types: | By-name input | Constructor kwargs accept names or aliases (`BackMatterResourceRlink(media_type=...)`). `model_validate({...})` stays alias-only (`extra_forbidden` at any depth); JSON input rejects a name key the same way (needs pydantic ≥2.14.2; earlier 2.13/2.14 dropped it, [#6](https://github.com/cairn-proofs/oscal-bindings-python/issues/6)). No `validate_by_name` in config | | Constraints | `Annotated[T, Field(...)]` with `pattern`, `min_length`, etc. (produced by `--field-constraints`) | | Scalars | Collapsed to `TypeAlias` (not `RootModel`) — e.g. a `uuid` field is a constrained `str`, accessed directly | -| Datetimes | `AwareDatetime`; `pattern=` constraints stripped by the post-processor since they're invalid on non-str types | -| Emails | `EmailStr`; redundant `pattern=` stripped | +| Patterns | A `pattern=` on a `str` stays, translated from ECMA-262 to the Rust `regex` dialect (`scripts/regex_translation.py`, PRS-007); a pattern on a number is removed | +| Datetimes | `OscalDateTimeWithTimezone` (`v1/_datatypes.py`): an `AwareDatetime` whose input string must match the OSCAL pattern; in Python input a `datetime` must serialize to text that matches it. The value is a `datetime` (a seventh fraction digit is lost, [#19](https://github.com/cairn-proofs/oscal-bindings-python/issues/19)) | +| URIs | `OscalUri`: a `str` that matches the OSCAL pattern and the RFC 3986 `URI` grammar; each scheme is valid; the value is the input text, so a serialization writes it as given | +| URI references | `OscalUriReference`: a `str` that matches the RFC 3986 `URI-reference` grammar; the value is the input text | +| Emails | `OscalEmailAddress`: a `str` that matches both OSCAL patterns and the RFC 5321 `Mailbox` grammar with the RFC 6531 extension (non-ASCII, one-label domains); the value is the input text, so case and form are kept | ## Naming diff --git a/.agents/summary/dependencies.md b/.agents/summary/dependencies.md index 43ff5a3..34b2bea 100644 --- a/.agents/summary/dependencies.md +++ b/.agents/summary/dependencies.md @@ -6,14 +6,14 @@ Declared in `pyproject.toml` `[project.dependencies]`. | Dependency | Constraint | Why it's needed | |------------|-----------|-----------------| -| `pydantic[email]` | `>=2.14.2,<3` | The generated models are Pydantic v2 models (via `OscalBaseModel`). The `email` extra provides `EmailStr` validation used by contact fields. The 2.14.2 floor is the first release whose JSON validation rejects a Python-field-name key as `extra_forbidden` instead of dropping it ([#6](https://github.com/cairn-proofs/oscal-bindings-python/issues/6), GHSA-qpmf-fgh3-ff25); `ConfigDict(serialize_by_alias=True)` in `v1/_base.py` needs 2.11+. The runtime also uses v2-only APIs (`model_validate_json`, `model_dump_json`, `RootModel`, `model_serializer`). `tests/test_pydantic_version.py` guards the range. | +| `pydantic` | `>=2.14.2,<3` | The generated models are Pydantic v2 models (via `OscalBaseModel`). The hand-written datatypes of `v1/_datatypes.py` validate with pydantic-core's Rust `regex` engine, so the package needs no `email` extra and no `email-validator`. The 2.14.2 floor is the first release whose JSON validation rejects a Python-field-name key as `extra_forbidden` instead of dropping it ([#6](https://github.com/cairn-proofs/oscal-bindings-python/issues/6), GHSA-qpmf-fgh3-ff25); `ConfigDict(serialize_by_alias=True)` in `v1/_base.py` needs 2.11+. The runtime also uses v2-only APIs (`model_validate_json`, `model_dump_json`, `RootModel`, `model_serializer`). `tests/test_pydantic_version.py` guards the range. | That is the **only** runtime dependency. The library is otherwise pure standard library (`pathlib`, `uuid`, `datetime`, `re`, `dataclasses`, `enum`, `typing`). ```mermaid graph TD APP["Downstream application"] --> OB["oscal_bindings"] - OB --> PYD["pydantic[email] >= 2.14.2, < 3"] + OB --> PYD["pydantic >= 2.14.2, < 3"] OB --> STD["Python stdlib
(pathlib, uuid, datetime, re, dataclasses)"] ``` diff --git a/.agents/summary/workflows.md b/.agents/summary/workflows.md index a1373d2..7a64121 100644 --- a/.agents/summary/workflows.md +++ b/.agents/summary/workflows.md @@ -38,6 +38,9 @@ flowchart TD must be valid for the base datatype. An open-enum site replaces only the `enum` branch of its `anyOf`. 6. Property `title`/`description` stay beside the `$ref`, and a union branch without a `description` takes that of its union, so fields and variant classes keep their docs. +7. The definitions of the four datatypes `URIDatatype`, `URIReferenceDatatype`, `EmailAddressDatatype`, and + `DateTimeWithTimezoneDatatype` become `{"type": "string", "customTypePath": "oscal_bindings.v1._datatypes."}` + with their `description`. Codegen emits the hand-written type at each site, with no `pattern` beside it. The output is deterministic: two runs give byte-identical copies. @@ -48,8 +51,8 @@ The output is deterministic: two runs give byte-identical copies. 1. **`add_single_or_many`** — `MappingCollectionMappings` as `RootModel[Mapping | list[Mapping]]`, replacing the inline union of the field. 2. **Phase 1** — `collapse_scalar_root_models` (scalar `RootModel[...]` → `Annotated` alias, manifest root models - kept), `ensure_annotated_import`, `fix_email_str_patterns` / `fix_non_string_patterns` (strip `pattern=` from - `EmailStr`, `AwareDatetime`, `AnyUrl`, and numeric fields). + kept), `ensure_annotated_import`, `place_patterns` (reads the base type of each `Annotated`: a `str` pattern stays, + translated by `regex_translation.translate`; a number pattern goes; a pattern on another base is a failure). 3. **`scalar_renames`** — each scalar alias is named from its definition key without the `oscal-complete-oscal-:` prefix (`LocationUuid`). A target name that is not PascalCase (`[A-Z][A-Za-z0-9]*`), or that a module-level import binds, is a failure. diff --git a/AGENTS.md b/AGENTS.md index ad95d8d..f1f98db 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -35,6 +35,8 @@ src/oscal_bindings/ _base.py # OscalBaseModel — hand-written base of every generated object # model (alias keys, no nulls, by-name constructor kwargs); # root_key_discriminator for OscalDocument.root + _datatypes.py # Hand-written OscalUri / OscalUriReference / OscalEmailAddress / + # OscalDateTimeWithTimezone; the hoist names them with customTypePath models.py # GENERATED Pydantic models — DO NOT hand-edit parser.py # parse_oscal / parse_oscal_file / serialize_oscal / # validate_oscal + 8 typed parse_* functions; OscalParseError @@ -53,6 +55,7 @@ scripts/ # Not a package: scripts import siblings by plain name manifest.py # Validates names.json of the pinned artifact (jsonschema-rs + rules) hoist_names.py # Writes build/codegen/oscal_complete_schema.json: each manifest # site becomes definitions/ + regex_translation.py # translate(): ECMA-262 schema pattern -> Rust regex (PRS-007) postprocess_models.py# Structure fixes, adds unions/root models, guards against manifest tests/ # One test module per source module + import smoke test support/scripts.py # load_script(): how tests import modules from scripts/ @@ -82,9 +85,9 @@ Neither `v1/__init__.py` nor the top-level `__init__.py` defines symbols — bot Names come from the store's naming manifest. The binding holds no naming rule for a manifest type. `hatch run generate` runs three steps: -1. **Hoist.** `python scripts/hoist_names.py` fetches the spec artifact pinned in `scripts/spec_artifact.py` (`0.8.0+oscal.1.2.3`, sha256-checked, cached in `tests/.corpus_cache/`), validates its `names.json` with `scripts/manifest.py` (format version first, then manifest JSON Schema via `jsonschema-rs`, release, artifact-schema sha256, unique names, resolvable pointers), reads the complete OSCAL schema of the same artifact one time (the manifest check hashes the bytes that the hoist parses), and writes `build/codegen/oscal_complete_schema.json` (git-ignored). In that copy each manifest site is `definitions/` with a `$ref` at the site. A merge with different bodies, or a closed-enum value that its base datatype rejects, fails the run. +1. **Hoist.** `python scripts/hoist_names.py` fetches the spec artifact pinned in `scripts/spec_artifact.py` (`0.8.0+oscal.1.2.3`, sha256-checked, cached in `tests/.corpus_cache/`), validates its `names.json` with `scripts/manifest.py` (format version first, then manifest JSON Schema via `jsonschema-rs`, release, artifact-schema sha256, unique names, resolvable pointers), reads the complete OSCAL schema of the same artifact one time (the manifest check hashes the bytes that the hoist parses), and writes `build/codegen/oscal_complete_schema.json` (git-ignored). In that copy each manifest site is `definitions/` with a `$ref` at the site, and the four hand-written datatypes (`URIDatatype`, `URIReferenceDatatype`, `EmailAddressDatatype`, `DateTimeWithTimezoneDatatype`) are `{"type": "string", "customTypePath": ...}`. A merge with different bodies, or a closed-enum value that its base datatype rejects, fails the run. 2. **Codegen.** `datamodel-codegen --input ./build/codegen/oscal_complete_schema.json --output ./build/codegen/models.py --base-class oscal_bindings.v1._base.OscalBaseModel --collapse-root-models ... --formatters black isort` (see DEVELOPING "Names reach codegen through the hoisted schema" for the flag choices). Each `object`, `document`, and `enum` class takes its name from its definition key. `--base-class` makes all 185 object models subclass `OscalBaseModel`; the two `RootModel`s (`OscalDocument`, `MappingCollectionMappings`) don't. -3. **Post-process.** `python scripts/postprocess_models.py --models ./build/codegen/models.py --output src/oscal_bindings/v1/models.py`. Phase 1 collapses scalar `RootModel`s to `Annotated` aliases and strips `pattern=` from non-string fields (`AwareDatetime`/`AnyUrl`/numeric/`EmailStr`). Then it adds the 13 union `TypeAlias`es (`CatalogGroup`, plain unions, so `isinstance` works) and writes each field that uses one as `Annotated[, Field(union_mode='left_to_right')]` (the variant properties are exclusive, so this picks the same variant as smart mode, faster, #43), the `MappingCollectionMappings` root model, and the `OscalDocument` root model. It discriminates `OscalDocument.root` on the root key of the input: each member is `Tag`-ged with its class name, the root key of each member is the manifest `body-field`, and `root_key_discriminator` (`v1/_base.py`) selects the one member to validate (an input with no known root key is one `oscal_document_type` error). It names each scalar alias from its definition key without the `oscal-complete-oscal-:` prefix. Three guards compare the result with the manifest and the artifact schema and report every offender: each manifest name is defined once in the form of its kind, each other name is a scalar alias named for a scalar definition of the schema, no name is defined twice, and no manifest name or scalar alias is bound by a module-level import. The manifest must record the sha256 of the `--schema` bytes. The completed module goes to `--output` through a temp file + `os.replace`; on a failure nothing is written to `--output`, so a failed `generate` leaves the committed `models.py` untouched. `generate` passes no `--schema`: an omitted `--schema` resolves at call time to `artifact_paths(ensure_spec_artifact()).schema`, and an explicit one (a candidate schema, or a small test schema) must still match `schema.sha256` of the manifest. `--models` falls back to its own default, `--output` defaults to `--models`; a missing path is a non-zero exit. +3. **Post-process.** `python scripts/postprocess_models.py --models ./build/codegen/models.py --output src/oscal_bindings/v1/models.py`. Phase 1 collapses scalar `RootModel`s to `Annotated` aliases, then places each `pattern=` by the base type of its `Annotated` (`place_patterns`): a `str` pattern stays, translated from ECMA-262 to the Rust `regex` dialect by `scripts/regex_translation.py` (PRS-007); a number pattern goes; a pattern on any other base fails the step. Then it adds the 13 union `TypeAlias`es (`CatalogGroup`, plain unions, so `isinstance` works) and writes each field that uses one as `Annotated[, Field(union_mode='left_to_right')]` (the variant properties are exclusive, so this picks the same variant as smart mode, faster, #43), the `MappingCollectionMappings` root model, and the `OscalDocument` root model. It discriminates `OscalDocument.root` on the root key of the input: each member is `Tag`-ged with its class name, the root key of each member is the manifest `body-field`, and `root_key_discriminator` (`v1/_base.py`) selects the one member to validate (an input with no known root key is one `oscal_document_type` error). It names each scalar alias from its definition key without the `oscal-complete-oscal-:` prefix. Three guards compare the result with the manifest and the artifact schema and report every offender: each manifest name is defined once in the form of its kind, each other name is a scalar alias named for a scalar definition of the schema, no name is defined twice, and no manifest name or scalar alias is bound by a module-level import. The manifest must record the sha256 of the `--schema` bytes. The completed module goes to `--output` through a temp file + `os.replace`; on a failure nothing is written to `--output`, so a failed `generate` leaves the committed `models.py` untouched. `generate` passes no `--schema`: an omitted `--schema` resolves at call time to `artifact_paths(ensure_spec_artifact()).schema`, and an explicit one (a candidate schema, or a small test schema) must still match `schema.sha256` of the manifest. `--models` falls back to its own default, `--output` defaults to `--models`; a missing path is a non-zero exit. See `.agents/summary/workflows.md` for the flow diagram. @@ -100,6 +103,7 @@ See `.agents/summary/workflows.md` for the flow diagram. - **Valid OSCAL by default; construct by name, validate by alias.** `OscalBaseModel` (`v1/_base.py`) gives every object model alias keys (`media-type`, `document-ids`) and no `null` on all serialization paths (`model_dump*`, `to_json`, `TypeAdapter`); `exclude_none=False` is a no-op, `by_alias=False` emits names. Constructor kwargs accept field names or aliases (`BackMatterResourceRlink(media_type=...)`), so a caller constructs directly. The builders validate a JSON-shaped object and raise `OscalBuilderError` (a `ValueError`, not an `OscalParseError`). OSCAL input stays alias-only: dict input rejects name keys with `extra_forbidden` at every depth (`extra='forbid'`). **Don't add `validate_by_name`/`populate_by_name` to the base config**, and don't remove `__pydantic_base_init__` from its `__init__`: either makes `model_validate*` accept name-keyed OSCAL (DEVELOPING "Valid OSCAL by default"; tripwire tests guard both). JSON input rejects name keys too, which needs the pydantic ≥2.14.2 floor (2.13.x–2.14.1 silently dropped them, [#6](https://github.com/cairn-proofs/oscal-bindings-python/issues/6)). - **`validate_element` type names are derived from model class names** (PascalCase → kebab-case, introspected at import), so they follow the manifest names (`back-matter-resource-rlink`). Each manifest type has one, whatever its kind: object/document classes, enums (`hash-algorithm`, validated from the string value), and unions (`parameter`). Use `get_supported_element_types()` for the live list; an unrecognized type raises `OscalUnknownElementTypeError`, which is not an `OscalParseError`. The corpus case `element-types/all` pins the list. The introspection keeps only `BaseModel` subclasses, `Enum` subclasses, and `types.UnionType` aliases that `models` defines, and skips pydantic parametrizations (`__pydantic_generic_metadata__["origin"]` set): since 2.14, pydantic registers the `RootModel[...]` bases of `OscalDocument` and `MappingCollectionMappings` in `models` under non-identifier names. Module scans in tests skip them the same way. - **Expected conformance failures are local.** `tests/support/expected_failures.py` (case id → issue URL) drives the strict xfails in `tests/test_conformance.py`; the runner ignores any `known-defects` in the corpus. The spec store holds no binding state, so fixing a listed defect means deleting its entry here, never a store change. +- **Four datatypes are hand-written types, and a pattern is read as ECMA-262.** The models hold `OscalUri`, `OscalUriReference`, `OscalEmailAddress` (each a `str` that keeps the input text, so a serialization writes it as given) and `OscalDateTimeWithTimezone` (an `AwareDatetime`) from `v1/_datatypes.py`, not a Pydantic URL or email type. Each checks the OSCAL pattern and the RFC grammar of the datatype (RFC 3986 `URI` / `URI-reference`, RFC 5321 `Mailbox` with RFC 6531) in pydantic-core. Each scheme is a valid `OscalUri`: the caller decides which schemes to use. The hoist replaces the four definitions with `customTypePath`, and the pattern literals of `_datatypes.py` are the output of `scripts/regex_translation.translate` (a test checks them against the pinned schema). A `str` pattern in `models.py` is the translated Rust pattern, not the schema text. Never hand-edit a literal; change the schema pin or the translator. - **Closed enums are `Enum` classes.** A closed-enum field holds its enum class (`ParameterSelectionHowMany`) and rejects any other value. An open-enum field is the union of its base datatype alias and its enum class. - **Major-version namespace, single active release.** The implementation lives in `oscal_bindings.v1` — named for the OSCAL **major** version, no minor/patch component — and is generated from exactly one OSCAL release at a time, the release of the spec artifact pin (`__oscal_schema_version__`, currently `1.2.3`). A 1.x refresh regenerates `v1` in place; only OSCAL 2.0 justifies a second version package. Minor-version namespacing (`v1_2`) was considered and rejected — read the "Major-version namespace" and "Strict models" entries under Key Design Decisions in `DEVELOPING.md` before proposing either. - **Top level re-exports; it is not the implementation.** `oscal_bindings/__init__.py` plus the alias modules `oscal_bindings/models.py`, `parser.py`, `extensions/__init__.py` are pure re-exports of their `v1` counterparts (explicit modules, not `sys.modules` tricks). Edit the `v1` copies; the top level takes its `__all__` from `oscal_bindings.v1.__all__`, so the surfaces can't drift. Names reached through either path are the same objects. @@ -121,7 +125,7 @@ See `.agents/summary/workflows.md` for the flow diagram. - **CI triggers:** once per PR update (on the trial merge into `main`), pushes to `main`, and `v*` tags. Branches without a PR run only via `workflow_dispatch`. Keep `tags: ["v*"]` under `push`: with a `branches` filter, tags don't trigger unless listed. `main` is branch-protected and requires the `build` check. - **CI** (`.github/workflows/build.yml`) runs `hatch run release`, then the drift check `git diff --exit-code -- src/oscal_bindings/v1/models.py` (the committed `models.py` must be what the pin generates), then `hatch build`, and uploads `api-docs`, `coverage-html`, and `python-packages` (wheel + sdist) artifacts. On a `v*` tag push it first checks that the tagged commit is on `main` (`git merge-base --is-ancestor`) and that the tag equals `v$(hatch version)`, and a `draft-release` job attaches the `python-packages` artifact to a **draft** GitHub release. Publishing the draft (manual) triggers `release.yml`, which downloads those assets, verifies their filenames match the tag, and uploads them to PyPI via trusted publishing. **Nothing rebuilds after CI**: PyPI gets the exact files CI tested. Release flow: bump `version` in `pyproject.toml`, commit, push tag `v`, review the draft, publish. - **CodeQL** (`.github/workflows/codeql.yml`) is separate from CI: `python` + `actions` languages, `security-extended` queries, `build-mode: none`, on PR/main plus a weekly schedule. It holds `security-events: write`, which is why it isn't a job in `build.yml`. It's not a Hatch task and doesn't gate `release`. -- **Runtime dependency is only `pydantic[email]>=2.0`;** `datamodel-code-generator[http,black,isort]` is a dev/codegen-only extra, exact-pinned in two places (`[project.optional-dependencies].codegen` and the default env) that must move together. `generate` passes `--formatters black isort` explicitly: that's the output format `models.py` is committed in, and it keeps upstream's planned switch to a builtin formatter from reformatting the file. +- **Runtime dependency is only `pydantic>=2.14.2,<3` (no `email` extra: no model validates an email through a Pydantic email type; a caller that wants `email-validator` installs it);** `datamodel-code-generator[http,black,isort]` is a dev/codegen-only extra, exact-pinned in two places (`[project.optional-dependencies].codegen` and the default env) that must move together. `generate` passes `--formatters black isort` explicitly: that's the output format `models.py` is committed in, and it keeps upstream's planned switch to a builtin formatter from reformatting the file. ## Deeper Documentation diff --git a/DEVELOPING.md b/DEVELOPING.md index 0fe185d..9dd3ecf 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -122,8 +122,12 @@ rule for a manifest type. `hatch run generate` runs three steps: manifest name. 3. `scripts/postprocess_models.py` reads `build/codegen/models.py`, completes and checks the module, and writes it to `src/oscal_bindings/v1/models.py`. - 1. Phase 1 changes structure. It collapses each scalar `RootModel` to an `Annotated` alias, and it removes - `pattern=` from fields of a type that has no regex constraint (`AwareDatetime`, `AnyUrl`, `EmailStr`, numbers). + 1. Phase 1 changes structure. It collapses each scalar `RootModel` to an `Annotated` alias. Then it reads the base + type of each `Annotated[base, ..., Field(..., pattern=P)]`. A pattern on a `str` stays, as `translate` of + `scripts/regex_translation.py` writes it for the Rust `regex` engine (see "Pattern portability (PRS-007)"). A + pattern on an `int` or `float` goes, because JSON Schema applies `pattern` only to a string. A pattern on another + base, or outside an `Annotated`, fails the step and names the class, the field, and the base. One run reports + each failure and writes no `models.py`. 2. It adds the manifest types that codegen does not emit: one `TypeAlias` per union (`CatalogGroup`), the `MappingCollectionMappings` root model, and the `OscalDocument` root model. Each union alias stays a plain union, so `isinstance(value, CatalogGroup)` works. Each field that uses an alias is @@ -168,6 +172,33 @@ A difference fails that job (and so `build`), so the committed `models.py` must To change a type name, change the manifest in the store, release a new spec artifact, and move the pin. Never rename a manifest type in the post-processor. +## Pattern portability (PRS-007) + +PRS-007 requires the binding to document how it maps each OSCAL pattern to its own regex engine, and to keep the sets +of accepted and rejected values. JSON Schema writes a `pattern` in ECMA-262 with the `u` flag. Pydantic evaluates a +`pattern` with the Rust `regex` engine of pydantic-core. The two dialects differ for `.` and `\s`, so a pattern that +Pydantic reads as written accepts values that the schema rejects. For example, `^\S(.*\S)?$` accepts `ab`. + +`translate` in `scripts/regex_translation.py` maps each pattern. It reads the pattern token by token and writes a Rust +pattern that accepts and rejects the same values. The mapping: + +1. `.` outside a class becomes a class that excludes the ECMA-262 line terminators: LF, CR, U+2028, and U+2029. In + Rust, `.` excludes only LF. +2. `\s` outside a class becomes a class of the ECMA-262 white space and line terminators: tab, LF, VT, FF, CR, space, + U+00A0, U+1680, U+2000 to U+200A, U+2028, U+2029, U+202F, U+205F, U+3000, and U+FEFF. `\S` becomes the complement. + In Rust, `\s` has U+0085 and no U+FEFF. +3. Each other token stays: a literal, an escaped literal, a code point escape (`\xHH`, `\uHHHH`, `\u{H...}`), a class, + a negated class, `\p{...}`, a group, an alternation, a quantifier, `^`, and `$`. A class holds literals, escaped + literals, code point escapes, ranges, and `\p{...}`. Without the multiline flag, `^` and `$` mean the same in both + dialects. The output of `translate` holds only these tokens, so `translate` of its own output is the same pattern. +4. Each other construct is an error that names the pattern: lookaround, a back-reference, `\d`, `\w`, `\b`, `\s` + inside a class, and an inline flag. No pattern of the OSCAL 1.2.3 schema uses one. A release that does fails the + generation, so the constraint is never dropped silently. + +`tests/test_regex_translation.py` holds the ECMA-262 result of each probe for each of the 10 patterns of the pinned +schema (Node.js with the `u` flag gave them), and it fails when a moved pin adds a pattern that the table does not +cover. + ## Moving the pin to a new spec artifact The store [cairn-proofs/oscal-bindings-specs](https://github.com/cairn-proofs/oscal-bindings-specs) vendors the NIST @@ -222,7 +253,7 @@ changes only for a new OSCAL **major** version. - **Valid OSCAL by default** — `v1/_base.py` defines `OscalBaseModel`, wired in through codegen's `--base-class` so `models.py` stays pristine generator output. It sets `serialize_by_alias=True` (needs pydantic ≥2.11; the floor is now 2.14.2, below) and adds a wrap `model_serializer` that drops None values, so every serialization path, including `pydantic_core.to_json` and `TypeAdapter` calls that never see our kwargs, emits OSCAL keys and no `null`. `serialize_oscal` keeps its explicit `by_alias=True, exclude_none=True`. The wrap serializer costs a Python callback per model node (benchmarks below). Per-field `Field(exclude_if=lambda v: v is None)` measured about 1.35× the pre-fix time in a prototype (the wrap serializer was about 2.4× there), with identical output, but it isn't implemented: the post-processor would have to rewrite all 698 optional fields, and `exclude_if` needs pydantic ≥2.12. It's the documented fallback if serialize time becomes a problem. - **Construction by name, validation by alias.** `OscalBaseModel.__init__` maps field-name kwargs to aliases, so `BackMatterResourceRlink(media_type=...)` works. The builders do not construct directly: each validates a JSON-shaped object with `model_validate` one time and raises `OscalBuilderError`. The override carries `__pydantic_base_init__ = True`, the marker `RootModel.__init__` uses. Without it pydantic sets `__pydantic_custom_init__` and routes `model_validate*` through `__init__`: a probe of that variant accepted and kept name-keyed input at every depth, in dict and JSON mode, even with `by_alias=True, by_name=False`. The marker is undocumented, so tests pin it structurally and behaviorally. - **Not config `validate_by_name`.** Setting `validate_by_name=True` in the base config, with per-call `by_alias=True, by_name=False` at our validation sites (Option A), was rejected. Alias-only would become opt-in per call, so a user's direct `Model.model_validate` would accept and populate name-keyed OSCAL. Nested plain dicts in constructor kwargs would accept names too. Don't add `validate_by_name`, `validate_by_alias`, or `populate_by_name` to the base config. Revisit if pydantic adds per-mode by-name validation (pydantic#12056). - - **Pydantic floor 2.14.2: JSON mode rejects name keys.** pydantic 2.13.x through 2.14.1 had `model_validate_json` silently discard a key equal to the Python name of one of the model's alias-differing fields, instead of reporting `extra_forbidden` ([#6](https://github.com/cairn-proofs/oscal-bindings-python/issues/6)). pydantic#13275, released in 2.14.2 (GHSA-qpmf-fgh3-ff25), made JSON mode match dict mode, so the runtime range is `pydantic[email]>=2.14.2,<3` and the JSON-mode tests require `extra_forbidden`. The base doesn't change JSON validation either way. + - **Pydantic floor 2.14.2: JSON mode rejects name keys.** pydantic 2.13.x through 2.14.1 had `model_validate_json` silently discard a key equal to the Python name of one of the model's alias-differing fields, instead of reporting `extra_forbidden` ([#6](https://github.com/cairn-proofs/oscal-bindings-python/issues/6)). pydantic#13275, released in 2.14.2 (GHSA-qpmf-fgh3-ff25), made JSON mode match dict mode, so the runtime range is `pydantic>=2.14.2,<3` and the JSON-mode tests require `extra_forbidden`. The base doesn't change JSON validation either way. - **Parametrized bases in the models namespace.** Since 2.14, pydantic registers a module-scope parametrization such as `RootModel[Mapping | list[Mapping]]` in the module that writes it, under a non-identifier name (pydantic#13243; 2.14.2 also sets its `__module__` there, pydantic#13994). So the bases of `OscalDocument` and `MappingCollectionMappings` appear in `vars(models)`. `validate_element`'s element map and the module scans in the tests skip any class whose `__pydantic_generic_metadata__["origin"]` is set, and `test_each_parametrized_generic_of_the_module_is_a_manifest_base` keeps that skip limited to those bases. `models.py` is unchanged. - **Serialization benchmarks** — the numbers are in [PERFORMANCE.md](PERFORMANCE.md#serialization). The serialize-time regression is accepted as the price of valid OSCAL on every path; parse is unchanged. - **YAML scalar typing comes from the schema, not the YAML reader** — the optional YAML path converts a YAML document to JSON text and passes it to `parse_oscal`, so the YAML result equals the JSON result for the same value (YML-004, YML-005). The OSCAL schema at a scalar's location decides its type, not PyYAML's YAML 1.1 resolver. The schema comes from the generated models at run time (`OscalDocument.model_json_schema()`), so no schema artifact ships in the wheel. A scalar keeps its text at a string location, so `version: 1.0` stays `"1.0"` and `yes` stays `"yes"`. A number location takes only the RFC 8259 JSON number grammar (no leading `+`, no leading zero, no hex), and the token goes to the JSON parser as written. A boolean location takes only `true` or `false`. Any other text is a parse error at the scalar's location. A test scans the pinned schema so that the resolver's two tie-breaks (first union branch, type priority) never decide a result. diff --git a/PERFORMANCE.md b/PERFORMANCE.md index c036865..eb2e95e 100644 --- a/PERFORMANCE.md +++ b/PERFORMANCE.md @@ -10,6 +10,7 @@ Absolute times depend on the machine, so compare ratios. Each section names its - [Memory](#memory) - [YAML cost](#yaml-cost) - [Serialization](#serialization) +- [Datatype checks](#datatype-checks) - [Design changes with a measured effect](#design-changes-with-a-measured-effect) - [How to measure](#how-to-measure) @@ -36,7 +37,7 @@ Peak traced memory of one parse, measured with `tracemalloc` on Python 3.14 (`sc | Input | Input size | Peak | Factor | |---|---|---|---| -| Catalog, `parse_oscal` | 10.4 MB | 36 MB | about 3.4x | +| Catalog, `parse_oscal` | 10.4 MB | 35 MB | about 3.4x | | Catalog, `parse_oscal_yaml` | 7.3 MB | 83 MB | about 11x | | Flow mapping of 150,000 unknown short keys, `parse_oscal` | 2.0 MB | 144 MB | about 72x | | Flow mapping of 150,000 unknown short keys, `parse_oscal_yaml` | 1.7 MB | 148 MB | about 87x | @@ -66,6 +67,26 @@ For the catalog (7.3 MB of YAML), `parse_oscal_yaml` takes 0.8 s with libyaml (` | `doc.model_dump_json()` | 66.1 (invalid) | 165.8 | 2.5x | 4.88 MB (was 7.57 MB) | | `pydantic_core.to_json(doc)` | 63.7 (invalid) | 170.6 | 2.7x | 4.88 MB (was 7.53 MB) | +## Datatype checks + +The change that enforces the OSCAL datatype constraints (#77) replaced `AnyUrl`, `EmailStr`, and the unchecked `AwareDatetime` and `str` fields with four hand-written types (`v1/_datatypes.py`). Each value of those types now passes one to three `pattern` steps in pydantic-core (the Rust `regex` engine), and a `datetime` that a caller gives in Python input passes one Python call. The target was no measurable slowdown of a parse of the catalog. + +`hatch run python scripts/bench_serialization.py`, median of 7 per run, then the median of 3 runs. The runs of the tree before and after the change alternate on one machine. Python 3.14.8, pydantic 2.14.2, pydantic-core 2.50.2. The catalog has 10.4 MB of JSON. + +| Path | Before, GC on ms | After, GC on ms | Before, GC off ms | After, GC off ms | +|---|---:|---:|---:|---:| +| `parse_oscal(bytes)` | 64.0 | 61.1 | 47.2 | 45.6 | +| `serialize_oscal(doc, indent=None)` | 135.6 | 132.7 | 128.8 | 125.7 | +| `serialize_oscal(doc)` | 144.0 | 140.4 | 137.6 | 134.1 | +| `doc.model_dump_json()` | 142.0 | 138.8 | 135.3 | 132.4 | +| `pydantic_core.to_json(doc)` | 143.0 | 138.6 | 136.0 | 132.7 | + +The after column is 2 to 5% lower in each row, also in the serialization rows that the change does not touch, so read it as no slowdown, not as a speedup. The validation of the four datatypes costs less than the difference between the runs. + +`import oscal_bindings` takes 159.5 ms before and 150.0 ms after (median of 9 fresh processes, `python -X importtime`). The runtime no longer imports `email-validator`. + +`scripts/bench_memory.py`: the peak of `parse_oscal` for the catalog is 36.5 MB before and 35.3 MB after. The other three rows of [Memory](#memory) are the same. + ## Design changes with a measured effect | Change | Effect | Measured on | diff --git a/README.md b/README.md index d312a48..9986f74 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ pip install "oscal-bindings[yaml]" uv add "oscal-bindings[yaml]" ``` -The base install keeps a single runtime dependency (`pydantic[email]`). Every import works without the extra. A call to a YAML operation without the extra raises `ImportError` with an install hint. +The base install keeps a single runtime dependency (`pydantic`). Every import works without the extra. A call to a YAML operation without the extra raises `ImportError` with an install hint. To install from a local checkout (e.g., as a `uv` workspace path dependency): diff --git a/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/.openspec.yaml b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/.openspec.yaml new file mode 100644 index 0000000..bbe8b39 --- /dev/null +++ b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-11-17 diff --git a/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/design.md b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/design.md new file mode 100644 index 0000000..7a6d3ad --- /dev/null +++ b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/design.md @@ -0,0 +1,193 @@ +# Design + +## Context + +See [proposal.md - Why](proposal.md#why) for the motivation. These facts constrain the approach. + +1. The artifact schema has 10 distinct patterns. Four datatypes have a `format` or an `allOf`: date-time-with-timezone + (15 references), uri (16), uri-reference (13, no pattern), and email-address (1, an `allOf` of the string datatype + and `^.+@.+$`). `DecimalDatatype` has a pattern on `type: number`. +2. Codegen merges the two patterns of an `allOf` into one pattern with lookahead: `(?=^\S(.*\S)?$)(?=^.+@.+$)`. The Rust + `regex` engine of pydantic-core rejects lookaround when it builds the schema. +3. Pydantic applies one `pattern` per `str`. When an `Annotated` has two `Field(pattern=...)`, the last one wins. +4. Pydantic accepts `Field(pattern=...)` on `AwareDatetime`, `AnyUrl`, or a number when it builds the class. The first + validation then raises `TypeError`, not `ValidationError`. +5. Codegen 0.83.0 reads `customTypePath` on a schema definition and emits the named type at each site of the definition. + It ignores `customTypePath` on an `allOf`. Beside the custom type, it still emits `Field(pattern=...)`. +6. A comparison of the 10 patterns in Rust `regex` and in ECMA-262 with the `u` flag (Node.js) gives differences only + for `.`: Rust matches CR, U+2028, and U+2029. In `\s`, Rust includes U+0085, and ECMA-262 includes U+FEFF. No schema + pattern uses `\d`, `\w`, `\b`, lookaround, or a back-reference. +7. `AwareDatetime` accepts the JSON number `1700000000` and the string `"1700000000"`. + +## Goals / Non-Goals + +**Goals:** + +1. Each check runs in pydantic-core with the Rust engine, so a JSON parse calls no Python function for the check. + The one exception is a `datetime` that the caller gives in Python input + ([D5](#d5-a-datetime-value-is-checked-as-text)). +2. The runtime package holds no schema and no regex translator. The generation and the tests own both. + +**Non-Goals:** + +1. A policy on URI schemes. +2. Validation of a U-label by the tables of IDNA2008. + +## Decisions + +### D1: The post-processor classifies each pattern by the base of its `Annotated` + +One function replaces `fix_email_str_patterns` and `fix_non_string_patterns`. It parses the module with `ast` and visits +each `Annotated[base, ..., Field(..., pattern=P, ...)]`. It removes `None` from the members of `base`, then: + +1. Each member is `str`: the pattern stays, as + [D2](#d2-each-pattern-is-translated-from-ecma-262-to-rust-regex) translates it. +2. Each member is `int` or `float`: the pattern goes. JSON Schema applies `pattern` only to a string. +3. Each other base: a failure that names the class, the field, and the base. + +A `pattern` keyword that is not in such an `Annotated` is also a failure. The function edits by source offset, with the +`_offsets` and `_apply` helpers. It collects each failure, and `postprocess` raises `PostprocessError` with all of them, +so a failed run writes no `models.py`. + +Alternative: keep the line scan and match the base with a regex. The scan cannot know where an `Annotated` starts. +That is the defect of [#77]. Rejected. + +### D2: Each pattern is translated from ECMA-262 to Rust `regex` + +`scripts/regex_translation.py` holds one function, `translate(pattern) -> str`. It reads the pattern token by token and +writes a Rust pattern that accepts the same values: + +1. `.` outside a class becomes a class that excludes the ECMA-262 line terminators: LF, CR, U+2028, and U+2029. +2. `\s` outside a class becomes a class of the ECMA-262 white space and line terminators: tab, LF, VT, FF, CR, + space, U+00A0, U+1680, U+2000 to U+200A, U+2028, U+2029, U+202F, U+205F, U+3000, and U+FEFF. `\S` becomes the + complement of that class. +3. Each other token stays: a literal, an escaped literal, a class, a negated class, `\p{...}`, a group, an + alternation, a quantifier, `^`, and `$`. A class or a negated class can hold literals, escaped literals, and ranges. + Without the multiline flag, `^` and `$` mean the same in both dialects. +4. Each other construct is an error that names the pattern: lookaround, a back-reference, `\d`, `\w`, `\b`, `\s` + inside a class, and an inline flag. + +The post-processor applies `translate` to each pattern of +[D1](#d1-the-post-processor-classifies-each-pattern-by-the-base-of-its-annotated) item 1. An error is a failure of the +step. `DEVELOPING.md` documents the mapping for PRS-007. + +Alternative: run the checks with Python `re`. Its `\s` includes U+001C to U+001F, and `$` also matches before a final +LF. It is a second dialect to map, and each check is a Python call. Rejected. + +### D3: The four datatypes are hand-written types that the hoist names + +`src/oscal_bindings/v1/_datatypes.py` defines `OscalDateTimeWithTimezone`, `OscalUri`, `OscalUriReference`, and +`OscalEmailAddress`. In its copy of the schema, the hoist replaces each of the four definitions with +`{"type": "string", "customTypePath": "oscal_bindings.v1._datatypes."}` and keeps its `title` and `description`. +Codegen then emits the type at each site, with no `pattern` beside it. The hoist does this after the closed-enum check, +which reads the original definitions. + +The `Oscal` prefix keeps the names apart from the manifest names and the scalar aliases. The import guard of the +post-processor checks this. + +Alternatives: + +1. The post-processor finds the sites by their pattern text. uri-reference has no pattern. Rejected. +2. `--type-mappings`. It maps a format to a built-in type only. Rejected. + +### D4: A string datatype is a chain of Rust patterns + +Each of `OscalUri`, `OscalUriReference`, and `OscalEmailAddress` is `Annotated[str, ...]` with a `GetPydanticSchema` +that returns a `chain_schema` of `str_schema(pattern=...)` steps: + +| Type | Steps | +|---|---| +| `OscalUri` | the uri pattern, then the RFC 3986 `URI` grammar | +| `OscalUriReference` | the RFC 3986 `URI-reference` grammar | +| `OscalEmailAddress` | the string-datatype pattern, the email pattern, then RFC 5321 `Mailbox` with RFC 6531 | + +Each step is a full-string match in the Rust engine. The value stays the input `str`, so a serialization writes the +input text (SER-004). The JSON schema of the type is `{"type": "string"}` with its patterns. + +The grammar patterns are hand-written from the ABNF of each RFC. The RFC 6531 sub-domain accepts a U-label as a run of +non-ASCII characters, letters, digits, and hyphens, with no hyphen at its start or end. + +Alternative: an `AfterValidator` with Python `re`. See the alternative of +[D2](#d2-each-pattern-is-translated-from-ecma-262-to-rust-regex). Rejected. + +### D5: A datetime value is checked as text + +`OscalDateTimeWithTimezone` is `AwareDatetime` with a `GetPydanticSchema` that returns a `json_or_python_schema`: + +1. JSON input: a chain of `str_schema(pattern=)` and the aware `datetime_schema`. A JSON number + fails the string step. +2. Python input: a union of the JSON chain and a strict, aware `datetime_schema` with an after-validator. The strict + schema accepts only a `datetime` instance, so a number fails. The validator writes the value as the binding + serializes it and matches the text with the pattern step of item 1. This validator is the one Python call of the + checks. + +The union sets `custom_error_type` and `custom_error_message`. Thus a rejected Python value gives one failure at the +field, not one failure for each member of the union at a location of pydantic. The root discriminator of `_base.py` +uses the same mechanism. These rules apply to the custom error: + +1. The error type is `oscal_date_time_with_timezone`. It is not `json_invalid`, the document-type error, or a key of + `_LIMIT_IDENTIFIERS`, because `parser.py` handles each of those types differently. +2. The message states the constraint of the field, not the type of the input. Thus it is correct for each value that + the union rejects. + +The value stays a `datetime`. The datetime pattern runs in pydantic-core, so the pattern of the schema decides the year +range and the set of offsets. + +Alternatives: + +1. A `str` value. It changes the type of 15 fields, and the facade operations of FAC-007 read `datetime` values. + Rejected. +2. A wrap validator that selects one branch by the type of the input. Each failure keeps its pydantic error type, but + the validator needs more hand-written schema code. Rejected. + +### D6: The patterns of the hand-written types are literals with a drift test + +`_datatypes.py` holds each OSCAL pattern as the literal output of `translate`. A test reads the four definitions of the +pinned artifact schema and checks that each literal equals `translate` of the schema pattern. A move of the pin that +changes a pattern fails this test. + +Alternative: read the schema at import. The wheel ships no schema. Rejected. + +### D7: A completeness test compares the models with the schema + +A test walks each property of each object definition in the hoisted schema of `tests/test_hoist_names.py`. In each +property, it resolves the `$ref` chain, the `allOf`, the array `items`, and each member of an `anyOf`. Each string value +that it reaches is a site. On the model side, the test resolves the field to its leaf types in the same way. It opens +`list[...]`, each member of a union, and each scalar alias. For each site: + +1. When the `$ref` chain of the site reaches one of the four datatypes, the leaf type of the model is the type of + [D3](#d3-the-four-datatypes-are-hand-written-types-that-the-hoist-names). The test selects these sites by the `$ref` + target, not by a pattern. The hoisted definitions hold no pattern, and uri-reference has no pattern in the schema. +2. Else, when the site has one or more patterns, the `pattern` of the leaf type equals `translate` of the schema + pattern. + +The test holds no list of exceptions. + +### D8: The runtime dependency is `pydantic` + +No model uses `EmailStr`, so `pyproject.toml` declares `pydantic>=2.14.2,<3`. `hatch run lock` re-locks each +environment, and `email-validator` and `dnspython` leave the lockfiles. `tests/test_pydantic_version.py` states the same +range. + +## Risks / Trade-offs + +1. [The U-label check is weaker than IDNA2008.] → [D4](#d4-a-string-datatype-is-a-chain-of-rust-patterns) states the + rule. The tables of IDNA2008 need a dependency, and the stdlib `idna` codec implements IDNA2003. +2. [Codegen can stop reading `customTypePath`, or emit `pattern` beside it.] → The completeness test of + [D7](#d7-a-completeness-test-compares-the-models-with-the-schema) fails, and + [D1](#d1-the-post-processor-classifies-each-pattern-by-the-base-of-its-annotated) fails the generation for a pattern + on an unknown base. +3. [An open-enum field is the union of a base type and its enum. With a new base type, smart mode can pick a different + member for a value that is in the enum.] → `tests/test_closed_enums.py` checks the member that each union picks. +4. [The scalar aliases `URIDatatype` and `EmailAddress` can leave `models.py`. Codegen with the `generate` flags, on a + schema of the D3 shape, emits no alias for either.] → They are binding names, not manifest names. Task 5.7 lists each + module-level name that leaves, from `git diff`. The release notes of the breaking change name each one. +5. [Each URI, email, and datetime value gets more pattern steps.] → `PERFORMANCE.md` records the medians before and + after, with GC on and off. + +## Migration Plan + +The change is breaking. It ships in the next release with the other breaking changes. Code that reads a uri or email +field as `AnyUrl` or `EmailStr` reads a `str`. Code that uses `email-validator` through this package installs it. + +[#77]: https://github.com/cairn-proofs/oscal-bindings-python/issues/77 diff --git a/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/proposal.md b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/proposal.md new file mode 100644 index 0000000..d2fb3e3 --- /dev/null +++ b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/proposal.md @@ -0,0 +1,71 @@ +# Proposal + +## Why + +The models accept values that OSCAL rejects, and they change some values that OSCAL accepts ([#77]). The store +requirement PRS-007 says that a binding MUST NOT drop a pattern constraint silently. SER-004 says that a parse and a +serialization give a document that is equivalent to the input. The binding does not meet these requirements: + +1. `fix_non_string_patterns` in `scripts/postprocess_models.py` removes `pattern=` when a type name such as `int` occurs + as a substring in the 10 lines before the pattern. The word "integrity" in a description contains `int`. Thus 23 + `str` fields lose their pattern, among them `DocumentId.identifier` and `BackMatterResource.uuid`. The corpus case + `build-resource/invalid-document-id` is an expected failure because of this defect. +2. The 17 date-time-with-timezone fields are `AwareDatetime` with no pattern. They accept `1850-01-01T00:00:00Z`, the + offset `+05:17`, a lowercase `z`, a space in place of `T`, no seconds, and a JSON number such as `1700000000`. +3. The uri fields are `AnyUrl`. Codegen drops the OSCAL pattern. `AnyUrl` accepts `a:b` and `x://`, and it changes the + value: `http://a` becomes `http://a/`, `https://example.com/a/../b` becomes `https://example.com/b`, and + `http://a\r\nb` becomes `http://ab/`. +4. The email fields are `EmailStr`. It rejects `a@b` and `x@localhost`, which OSCAL accepts. It changes the value: + `A@Example.COM` becomes `A@example.com`, and `Name ` becomes `a@example.com`. +5. The uri-reference fields are `str` with no check. They accept CR, LF, and spaces. +6. Pydantic evaluates a pattern with the Rust `regex` engine. In that engine, `.` matches CR, U+2028, and U+2029. In + ECMA-262, the regex dialect of JSON Schema, `.` matches none of them. Thus `^\S(.*\S)?$` accepts `a\rb`, which the + schema rejects. + +## What Changes + +1. One pass of the post-processor finds the base type of each pattern from the `Annotated[...]` that holds it. A + pattern on a `str` stays. A pattern on a number goes, because JSON Schema applies `pattern` only to a string. Each + other pattern stops the generation with a failure that names it. +2. The binding maps each OSCAL pattern to the regex engine of pydantic, and keeps the set of accepted values and the + set of rejected values. The mapping is documented. +3. Each value of a datatype in this list must match the OSCAL pattern and the definition of the datatype. A uri, + uri-reference, or email-address value keeps the input text: + 1. date-time-with-timezone: the value stays `AwareDatetime`. The input must be a string or a `datetime`. A + serialization writes the `datetime`, not the input text. For example, it truncates fractional seconds after six + digits ([#19]). + 2. uri: the value is a `str` that is a URI of RFC 3986. It is not `AnyUrl`. + 3. uri-reference: the value is a `str` that is a URI reference of RFC 3986. + 4. email-address: the value is a `str` that is a mailbox of RFC 6531. It is not `EmailStr`. +4. The binding accepts each URI scheme, for example `javascript:` and `file:`. The caller decides which schemes to use. +5. **BREAKING**: the models reject values that they accepted before, in each field of the list above and in the 23 + `str` fields of item 1 of [Why](#why). A uri field and an email field hold a `str`, not `AnyUrl` or `EmailStr`. +6. **BREAKING**: the runtime dependency is `pydantic`, not `pydantic[email]`. A caller that uses `email-validator` + through this package must install it. +7. The corpus case `build-resource/invalid-document-id` passes. + +## Capabilities + +### New Capabilities + +1. `datatype-constraints`: how the binding enforces the OSCAL patterns and the definitions of the datatypes + date-time-with-timezone, uri, uri-reference, and email-address, and how the generation treats a pattern that it + cannot place. + +### Modified Capabilities + +None. + +## Impact + +1. Code: `scripts/postprocess_models.py`, the `generate` script in `pyproject.toml`, a new private module in + `src/oscal_bindings/v1/` for the datatype checks, and the regenerated `src/oscal_bindings/v1/models.py`. +2. Dependencies: `pyproject.toml` and each lockfile. `email-validator` and `dnspython` leave the runtime closure. +3. Tests: `tests/test_postprocess.py`, `tests/support/expected_failures.py`, `tests/test_schema_validation.py`, + `tests/test_pydantic_version.py`, and new tests for the datatypes and for pattern completeness. +4. Docs: `README.md`, `DEVELOPING.md`, `AGENTS.md`, `.agents/summary/`, and `PERFORMANCE.md`. +5. Public API: the type of each uri, uri-reference, and email field, and the values that each field in + [What Changes](#what-changes) accepts. + +[#19]: https://github.com/cairn-proofs/oscal-bindings-python/issues/19 +[#77]: https://github.com/cairn-proofs/oscal-bindings-python/issues/77 diff --git a/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/specs/datatype-constraints/spec.md b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/specs/datatype-constraints/spec.md new file mode 100644 index 0000000..b72ce4e --- /dev/null +++ b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/specs/datatype-constraints/spec.md @@ -0,0 +1,232 @@ +# Spec Delta + +## Purpose + +Defines how the binding enforces the string patterns of the OSCAL schema and the definitions of the OSCAL datatypes +date-time-with-timezone, uri, uri-reference, and email-address. Also defines how the generation of the models treats a +pattern that it cannot place. + +## ADDED Requirements + +### Requirement: Each string pattern of the schema constrains its field + +For each string value of the schema with a `pattern`, the model SHALL reject a value that the pattern does not match. A +string value is one of these: + +1. The value of a property. +2. An item of an array. +3. A member of an `anyOf`. + +This includes a pattern that the schema gives through a reference to a datatype, and each pattern of an `allOf`. + +#### Scenario: An empty document identifier is rejected + +- **WHEN** the caller parses a document whose `document-ids` entry has the `identifier` `""` +- **THEN** parsing reports a parse error for that `identifier` + +#### Scenario: A malformed UUID is rejected + +- **WHEN** the caller parses a document with a back-matter resource whose `uuid` is `not a uuid` +- **THEN** parsing reports a parse error for that `uuid` + +#### Scenario: Both patterns of an allOf apply + +- **WHEN** the caller parses a document whose party `email-addresses` entry is U+00A0 followed by `a@example.com` +- **THEN** parsing reports a parse error, because the pattern of the string datatype rejects the leading U+00A0 + +### Requirement: A pattern matches as ECMA-262 matches it + +A pattern of the schema SHALL accept the same values and reject the same values as the pattern does in the ECMA-262 +regex dialect with the Unicode flag, which is the dialect of JSON Schema. In that dialect, `.` matches no line +terminator: LF, CR, U+2028, or U+2029. + +#### Scenario: A carriage return inside a string is rejected + +- **WHEN** the caller parses a document with a property whose `value` is `a` followed by CR followed by `b` +- **THEN** parsing reports a parse error for that `value` + +#### Scenario: A line separator inside a string is rejected + +- **WHEN** the caller parses a document with a property whose `value` contains U+2028 +- **THEN** parsing reports a parse error for that `value` + +#### Scenario: A carriage return inside a markup line is accepted + +- **WHEN** the caller parses a document with a `title` that is `a` followed by CR followed by `b` +- **THEN** parsing accepts the document, because the pattern of the markup-line datatype excludes only LF + +#### Scenario: A Unicode letter matches a letter class + +- **WHEN** the caller parses a document with a property `name` of `é1` +- **THEN** parsing accepts the document + +### Requirement: The generation fails on a pattern that it cannot place + +The generation of the models SHALL fail when it finds a pattern on a value that is not a string and not a number. The +failure SHALL name each such pattern. A pattern on a number value SHALL NOT constrain the field, because JSON Schema +applies `pattern` only to a string. + +#### Scenario: A pattern on a boolean stops the generation + +- **WHEN** the generation reads a schema with a `pattern` on a property whose type is `boolean` +- **THEN** the generation fails, names that property, and writes no models + +#### Scenario: A decimal is not checked against its pattern + +- **WHEN** the caller parses a mapping collection whose mapping has a `coverage` with the `target-coverage` `0.5` +- **THEN** parsing accepts the document + +### Requirement: A datatype value is kept as the input gives it + +A field of the datatype uri, uri-reference, or email-address SHALL hold the input text as a string, with no change. +A serialization SHALL write that text. + +#### Scenario: A URI with no path keeps its form + +- **WHEN** a document with a property whose `ns` is `http://a` is parsed and serialized +- **THEN** the output has `http://a` + +#### Scenario: A URI with a dot segment keeps its form + +- **WHEN** a document with a property whose `ns` is `https://example.com/a/../b` is parsed and serialized +- **THEN** the output has `https://example.com/a/../b` + +#### Scenario: An email address keeps its case + +- **WHEN** a document with the email address `A@Example.COM` is parsed and serialized +- **THEN** the output has `A@Example.COM` + +### Requirement: A date-time-with-timezone value matches its pattern + +A field of the datatype date-time-with-timezone SHALL accept only these values: + +1. A string that matches the pattern of the datatype. +2. In Python input, a `datetime` with a timezone whose serialization matches the pattern of the datatype. + +A value that the field rejects SHALL give one failure, at the location of the field. + +#### Scenario: A year before 1900 is rejected + +- **WHEN** the caller parses a document whose `last-modified` is `1850-01-01T00:00:00Z` +- **THEN** parsing reports a parse error for `last-modified` + +#### Scenario: An offset outside the set of the pattern is rejected + +- **WHEN** the caller parses a document whose `last-modified` is `2024-01-02T03:04:05+05:17` +- **THEN** parsing reports a parse error for `last-modified` + +#### Scenario: A lowercase zone designator is rejected + +- **WHEN** the caller parses a document whose `last-modified` is `2024-01-02T03:04:05z` +- **THEN** parsing reports a parse error for `last-modified` + +#### Scenario: A number is rejected + +- **WHEN** the caller parses a document whose `last-modified` is the JSON number `1700000000` +- **THEN** parsing reports a parse error for `last-modified` + +#### Scenario: A datetime given by name is checked + +- **WHEN** the caller constructs metadata with a `last_modified` of 1 January 1850, 00:00 UTC +- **THEN** the construction reports one validation error, at `last_modified` + +#### Scenario: A valid datetime is accepted + +- **WHEN** the caller parses a document whose `last-modified` is `2024-01-02T03:04:05.123-05:00` +- **THEN** parsing accepts the document + +### Requirement: A uri value is a URI + +A field of the datatype uri SHALL accept a value only when it matches the pattern of the datatype and is a URI by the +`URI` grammar of RFC 3986. The field SHALL accept each scheme that the grammar allows. + +#### Scenario: A fragment is accepted + +- **WHEN** the caller parses a document with a property whose `ns` is `https://example.com/ns#x` +- **THEN** parsing accepts the document + +#### Scenario: A line break is rejected + +- **WHEN** the caller parses a document with a property whose `ns` is `http://a` followed by CR, LF, and `b` +- **THEN** parsing reports a parse error for that value + +#### Scenario: A space is rejected + +- **WHEN** the caller parses a document with a property whose `ns` is `https://x.org/a b` +- **THEN** parsing reports a parse error for that value + +#### Scenario: A one-letter scheme is rejected + +- **WHEN** the caller parses a document with a property whose `ns` is `x://` +- **THEN** parsing reports a parse error for that value, because the pattern requires two or more scheme characters + +#### Scenario: Each scheme is accepted + +- **WHEN** the caller parses documents with properties whose `ns` values are `urn:ietf:rfc:3986`, + `javascript:alert(1)`, and `file:///etc/passwd` +- **THEN** parsing accepts each document + +### Requirement: A uri-reference value is a URI reference + +A field of the datatype uri-reference SHALL accept a value only when it is a URI reference by the `URI-reference` +grammar of RFC 3986. + +#### Scenario: A relative reference is accepted + +- **WHEN** the caller parses documents whose link `href` values are `#ac-1`, `../a.json`, and `https://example.com/x` +- **THEN** parsing accepts each document + +#### Scenario: A space is rejected + +- **WHEN** the caller parses a document whose link `href` is `a b` +- **THEN** parsing reports a parse error for that `href` + +#### Scenario: A line break is rejected + +- **WHEN** the caller parses a document whose link `href` is `a` followed by LF and `b` +- **THEN** parsing reports a parse error for that `href` + +### Requirement: An email-address value is a mailbox + +A field of the datatype email-address SHALL accept a value only when it matches the pattern of the datatype and is a +mailbox by the `Mailbox` grammar of RFC 5321 as RFC 6531 extends it. + +#### Scenario: A one-label domain is accepted + +- **WHEN** the caller parses documents whose email addresses are `a@b` and `x@localhost` +- **THEN** parsing accepts each document + +#### Scenario: A non-ASCII address is accepted + +- **WHEN** the caller parses a document whose email address is `ü@例え.jp` +- **THEN** parsing accepts the document + +#### Scenario: A display name is rejected + +- **WHEN** the caller parses a document whose email address is `Name ` +- **THEN** parsing reports a parse error for that address + +#### Scenario: Two at signs are rejected + +- **WHEN** the caller parses a document whose email address is `a@@b` +- **THEN** parsing reports a parse error for that address + +### Requirement: Each validation path applies the constraints + +Each check of this capability SHALL apply on each path that validates a value: a parse, the validation of an element, +the construction of a model by field name, and a back-matter builder. + +#### Scenario: Element validation rejects a malformed UUID + +- **WHEN** the caller validates a `back-matter-resource` element whose `uuid` is `not a uuid` +- **THEN** the result reports invalid + +#### Scenario: Construction rejects a malformed UUID + +- **WHEN** the caller constructs a back-matter resource by field name with the `uuid` `not a uuid` +- **THEN** the construction reports a validation error + +#### Scenario: A builder rejects an empty document identifier + +- **WHEN** the caller builds a back-matter resource with a document identifier whose `identifier` is `""` +- **THEN** the builder reports a builder error diff --git a/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/tasks.md b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/tasks.md new file mode 100644 index 0000000..d1f02cc --- /dev/null +++ b/openspec/changes/archive/2026-11-17-enforce-oscal-datatype-constraints/tasks.md @@ -0,0 +1,106 @@ +# Tasks + +## 1. Baseline before the change + +- [x] 1.1 Run `hatch run python scripts/bench_serialization.py` and `hatch run python scripts/bench_memory.py` on + `main`. Record the medians, GC on and GC off, in the scratchpad. Verify that the record is not empty. + +## 2. Tests that show each defect on `main` + +- [x] 2.1 Add `tests/test_datatype_constraints.py` with one test for each scenario of + [the spec delta](specs/datatype-constraints/spec.md). Do not change code outside `tests/`. Run + `hatch test tests/test_datatype_constraints.py` on `main` and record the output in the scratchpad. Verify that each + test whose scenario shows a defect of [proposal - Why](proposal.md#why) fails. Record the tests that pass on `main`, + for example "A Unicode letter matches a letter class" and "Each scheme is accepted". +- [x] 2.2 In `tests/test_postprocess.py`, add a test: a `str` field whose `description` contains `integrity` keeps its + `pattern` after `fix_non_string_patterns`. Verify that it fails on `main`. +- [x] 2.3 Add the completeness test of [design D7](design.md#d7-a-completeness-test-compares-the-models-with-the-schema) + to `tests/test_hoist_names.py`, with a local `translate` that returns its input. Verify that it fails on `main`, and + that the failure names the 23 `str` sites of [#77] and each site of the four datatypes, with the uri-reference sites. + +## 3. Regex translation + +- [x] 3.1 Add `scripts/regex_translation.py` with `translate`, as + [design D2](design.md#d2-each-pattern-is-translated-from-ecma-262-to-rust-regex) states. Add + `tests/test_regex_translation.py`, which loads the module with `load_script`. Verify with these tests: + 1. For each of the 10 patterns of the pinned schema and each probe of design Context item 6, the translated pattern + in pydantic gives the ECMA-262 result. The test holds the expected results as a table. + 2. Each construct of D2 item 4 raises an error that names the pattern. +- [x] 3.2 Replace the local `translate` of task 2.3 with the function of task 3.1. Verify that the test still fails + on the same sites. +- [x] 3.3 Document the mapping of D2 in `DEVELOPING.md`, in a section that cites PRS-007. Verify that the section + lists each rule of D2 items 1 to 4. + +## 4. Datatype types + +- [x] 4.1 Add `src/oscal_bindings/v1/_datatypes.py` with `OscalUri`, `OscalUriReference`, and `OscalEmailAddress`, as + [design D4](design.md#d4-a-string-datatype-is-a-chain-of-rust-patterns) states, and `OscalDateTimeWithTimezone`, as + [design D5](design.md#d5-a-datetime-value-is-checked-as-text) states. Add `tests/test_datatypes.py`. Verify with a + `TypeAdapter` of each type: + 1. The values of the uri, uri-reference, email-address, and date-time-with-timezone scenarios of the spec delta give + the expected result in JSON input and in Python input. + 2. Each accepted string value serializes to the input text. + 3. In Python input, an `int` and a naive `datetime` fail for `OscalDateTimeWithTimezone`. + 4. In Python input, a `datetime` of 1 January 1850, 00:00 UTC, gives one error for `OscalDateTimeWithTimezone`, at + the location of the value, with the error type of D5. +- [x] 4.2 Add the drift test of + [design D6](design.md#d6-the-patterns-of-the-hand-written-types-are-literals-with-a-drift-test) to + `tests/test_datatypes.py`. Verify that it passes, and that it fails when one literal in `_datatypes.py` changes. + +## 5. Generation + +- [x] 5.1 In `scripts/hoist_names.py`, replace the four datatype definitions in the copy, as + [design D3](design.md#d3-the-four-datatypes-are-hand-written-types-that-the-hoist-names) states. Add a step to the + module docstring. Verify with a test in `tests/test_hoist_names.py` that each of the four definitions of the hoisted + schema has its `customTypePath`, its `title`, and its `description`, and no `pattern`, `format`, or `allOf`. +- [x] 5.2 In `scripts/postprocess_models.py`, replace `fix_email_str_patterns` and `fix_non_string_patterns` with the + function of [design D1](design.md#d1-the-post-processor-classifies-each-pattern-by-the-base-of-its-annotated), and + apply `translate` of task 3.1. Replace the tests of the two old functions in `tests/test_postprocess.py`, and move the + test of task 2.2 to the new function. Verify with tests: + 1. A `str` pattern stays and is translated, also when the description contains `integrity` or `point`. + 2. A pattern on `int` or `float` goes. + 3. A pattern on `bool`, on `AwareDatetime`, on a union of `str` and `int`, and outside an `Annotated` each give a + failure that names the site. One run reports each failure, and writes no output file. +- [x] 5.3 Update the post-processing text in the module docstring of `scripts/postprocess_models.py`, `DEVELOPING.md` + step 3.1, and `AGENTS.md` "Code Generation Pipeline" step 3. Verify with a `grep` for `fix_non_string_patterns`, + `AnyUrl`, and `EmailStr` in the three files that no text describes the old behavior. +- [x] 5.4 Run `hatch run generate`. Verify that it passes, that `src/oscal_bindings/v1/models.py` has no `AnyUrl`, + `EmailStr`, or lookahead, and that each `pattern` of `models.py` is on a `str`. +- [x] 5.5 Remove `build-resource/invalid-document-id` from `tests/support/expected_failures.py`. Run `hatch test`. + Verify that each test of tasks 2.1, 2.3, and 4.1 passes, and that the strict expected failures of + `tests/test_conformance.py` stay expected failures. +- [x] 5.6 Fix each test that the new types break, with no change to a model. Examine `tests/test_closed_enums.py` + ([design Risks](design.md#risks--trade-offs) item 3), `tests/strategies.py`, and `tests/test_schema_validation.py`, + whose docstring names `AwareDatetime`, `EmailStr`, and `AnyUrl`. Verify that `hatch test --all` passes. +- [x] 5.7 List each module-level name that `git diff` of `src/oscal_bindings/v1/models.py` shows as removed after task + 5.4. [Design Risks](design.md#risks--trade-offs) item 4 expects `URIDatatype` and `EmailAddress`. Record the list for + the commit message of the workflow follow-up. Verify that the list holds each removed name and no other name. +- [x] 5.8 Document the four datatypes in `AGENTS.md` "Repo-Specific Patterns & Gotchas" and in + `.agents/summary/components.md` and `.agents/summary/data_models.md`: the value type, the checks, and that a uri, + uri-reference, or email-address value keeps the input text. Verify with a `grep` for `AnyUrl` and `EmailStr` in `AGENTS.md` and `.agents/summary/` that + no text describes the old types. + +## 6. Runtime dependency + +- [x] 6.1 Change the runtime dependency to `pydantic>=2.14.2,<3`, as + [design D8](design.md#d8-the-runtime-dependency-is-pydantic) states. Update `tests/test_pydantic_version.py`, the + comments in `pyproject.toml`, `README.md` line 23, the Pydantic floor entry of `DEVELOPING.md`, and the + "Config-Derived Facts" of `AGENTS.md`. Run `hatch run lock`. Verify that no lockfile has `email-validator` or + `dnspython`, and that `hatch test tests/test_pydantic_version.py` passes. + +## 7. Integration + +- [x] 7.1 Run `hatch run release`. Verify that it passes, and that a second `hatch run generate` gives no change to + `src/oscal_bindings/v1/models.py`. +- [x] 7.2 Run the two benchmark scripts of task 1.1 again. Update `PERFORMANCE.md` with the before and after medians, + GC on and GC off. Verify that the record has both runs. + +## Workflow follow-up + +- Commit as `fix!:` with a `BREAKING CHANGE` footer. The footer says that the models reject values that they accepted + before, that a uri or email field holds a `str`, that the runtime dependency is `pydantic` without the `email` extra, + and which scalar aliases of task 5.7 left the module. Close #77. +- Report the medians of task 7.2 in the PR description. +- Archive the change after review. + +[#77]: https://github.com/cairn-proofs/oscal-bindings-python/issues/77 diff --git a/openspec/specs/datatype-constraints/spec.md b/openspec/specs/datatype-constraints/spec.md new file mode 100644 index 0000000..050d2f0 --- /dev/null +++ b/openspec/specs/datatype-constraints/spec.md @@ -0,0 +1,232 @@ +# datatype-constraints Specification + +## Purpose + +Defines how the binding enforces the string patterns of the OSCAL schema and the definitions of the OSCAL datatypes +date-time-with-timezone, uri, uri-reference, and email-address. Also defines how the generation of the models treats a +pattern that it cannot place. + +## Requirements + +### Requirement: Each string pattern of the schema constrains its field + +For each string value of the schema with a `pattern`, the model SHALL reject a value that the pattern does not match. A +string value is one of these: + +1. The value of a property. +2. An item of an array. +3. A member of an `anyOf`. + +This includes a pattern that the schema gives through a reference to a datatype, and each pattern of an `allOf`. + +#### Scenario: An empty document identifier is rejected + +- **WHEN** the caller parses a document whose `document-ids` entry has the `identifier` `""` +- **THEN** parsing reports a parse error for that `identifier` + +#### Scenario: A malformed UUID is rejected + +- **WHEN** the caller parses a document with a back-matter resource whose `uuid` is `not a uuid` +- **THEN** parsing reports a parse error for that `uuid` + +#### Scenario: Both patterns of an allOf apply + +- **WHEN** the caller parses a document whose party `email-addresses` entry is U+00A0 followed by `a@example.com` +- **THEN** parsing reports a parse error, because the pattern of the string datatype rejects the leading U+00A0 + +### Requirement: A pattern matches as ECMA-262 matches it + +A pattern of the schema SHALL accept the same values and reject the same values as the pattern does in the ECMA-262 +regex dialect with the Unicode flag, which is the dialect of JSON Schema. In that dialect, `.` matches no line +terminator: LF, CR, U+2028, or U+2029. + +#### Scenario: A carriage return inside a string is rejected + +- **WHEN** the caller parses a document with a property whose `value` is `a` followed by CR followed by `b` +- **THEN** parsing reports a parse error for that `value` + +#### Scenario: A line separator inside a string is rejected + +- **WHEN** the caller parses a document with a property whose `value` contains U+2028 +- **THEN** parsing reports a parse error for that `value` + +#### Scenario: A carriage return inside a markup line is accepted + +- **WHEN** the caller parses a document with a `title` that is `a` followed by CR followed by `b` +- **THEN** parsing accepts the document, because the pattern of the markup-line datatype excludes only LF + +#### Scenario: A Unicode letter matches a letter class + +- **WHEN** the caller parses a document with a property `name` of `é1` +- **THEN** parsing accepts the document + +### Requirement: The generation fails on a pattern that it cannot place + +The generation of the models SHALL fail when it finds a pattern on a value that is not a string and not a number. The +failure SHALL name each such pattern. A pattern on a number value SHALL NOT constrain the field, because JSON Schema +applies `pattern` only to a string. + +#### Scenario: A pattern on a boolean stops the generation + +- **WHEN** the generation reads a schema with a `pattern` on a property whose type is `boolean` +- **THEN** the generation fails, names that property, and writes no models + +#### Scenario: A decimal is not checked against its pattern + +- **WHEN** the caller parses a mapping collection whose mapping has a `coverage` with the `target-coverage` `0.5` +- **THEN** parsing accepts the document + +### Requirement: A datatype value is kept as the input gives it + +A field of the datatype uri, uri-reference, or email-address SHALL hold the input text as a string, with no change. +A serialization SHALL write that text. + +#### Scenario: A URI with no path keeps its form + +- **WHEN** a document with a property whose `ns` is `http://a` is parsed and serialized +- **THEN** the output has `http://a` + +#### Scenario: A URI with a dot segment keeps its form + +- **WHEN** a document with a property whose `ns` is `https://example.com/a/../b` is parsed and serialized +- **THEN** the output has `https://example.com/a/../b` + +#### Scenario: An email address keeps its case + +- **WHEN** a document with the email address `A@Example.COM` is parsed and serialized +- **THEN** the output has `A@Example.COM` + +### Requirement: A date-time-with-timezone value matches its pattern + +A field of the datatype date-time-with-timezone SHALL accept only these values: + +1. A string that matches the pattern of the datatype. +2. In Python input, a `datetime` with a timezone whose serialization matches the pattern of the datatype. + +A value that the field rejects SHALL give one failure, at the location of the field. + +#### Scenario: A year before 1900 is rejected + +- **WHEN** the caller parses a document whose `last-modified` is `1850-01-01T00:00:00Z` +- **THEN** parsing reports a parse error for `last-modified` + +#### Scenario: An offset outside the set of the pattern is rejected + +- **WHEN** the caller parses a document whose `last-modified` is `2024-01-02T03:04:05+05:17` +- **THEN** parsing reports a parse error for `last-modified` + +#### Scenario: A lowercase zone designator is rejected + +- **WHEN** the caller parses a document whose `last-modified` is `2024-01-02T03:04:05z` +- **THEN** parsing reports a parse error for `last-modified` + +#### Scenario: A number is rejected + +- **WHEN** the caller parses a document whose `last-modified` is the JSON number `1700000000` +- **THEN** parsing reports a parse error for `last-modified` + +#### Scenario: A datetime given by name is checked + +- **WHEN** the caller constructs metadata with a `last_modified` of 1 January 1850, 00:00 UTC +- **THEN** the construction reports one validation error, at `last_modified` + +#### Scenario: A valid datetime is accepted + +- **WHEN** the caller parses a document whose `last-modified` is `2024-01-02T03:04:05.123-05:00` +- **THEN** parsing accepts the document + +### Requirement: A uri value is a URI + +A field of the datatype uri SHALL accept a value only when it matches the pattern of the datatype and is a URI by the +`URI` grammar of RFC 3986. The field SHALL accept each scheme that the grammar allows. + +#### Scenario: A fragment is accepted + +- **WHEN** the caller parses a document with a property whose `ns` is `https://example.com/ns#x` +- **THEN** parsing accepts the document + +#### Scenario: A line break is rejected + +- **WHEN** the caller parses a document with a property whose `ns` is `http://a` followed by CR, LF, and `b` +- **THEN** parsing reports a parse error for that value + +#### Scenario: A space is rejected + +- **WHEN** the caller parses a document with a property whose `ns` is `https://x.org/a b` +- **THEN** parsing reports a parse error for that value + +#### Scenario: A one-letter scheme is rejected + +- **WHEN** the caller parses a document with a property whose `ns` is `x://` +- **THEN** parsing reports a parse error for that value, because the pattern requires two or more scheme characters + +#### Scenario: Each scheme is accepted + +- **WHEN** the caller parses documents with properties whose `ns` values are `urn:ietf:rfc:3986`, + `javascript:alert(1)`, and `file:///etc/passwd` +- **THEN** parsing accepts each document + +### Requirement: A uri-reference value is a URI reference + +A field of the datatype uri-reference SHALL accept a value only when it is a URI reference by the `URI-reference` +grammar of RFC 3986. + +#### Scenario: A relative reference is accepted + +- **WHEN** the caller parses documents whose link `href` values are `#ac-1`, `../a.json`, and `https://example.com/x` +- **THEN** parsing accepts each document + +#### Scenario: A space is rejected + +- **WHEN** the caller parses a document whose link `href` is `a b` +- **THEN** parsing reports a parse error for that `href` + +#### Scenario: A line break is rejected + +- **WHEN** the caller parses a document whose link `href` is `a` followed by LF and `b` +- **THEN** parsing reports a parse error for that `href` + +### Requirement: An email-address value is a mailbox + +A field of the datatype email-address SHALL accept a value only when it matches the pattern of the datatype and is a +mailbox by the `Mailbox` grammar of RFC 5321 as RFC 6531 extends it. + +#### Scenario: A one-label domain is accepted + +- **WHEN** the caller parses documents whose email addresses are `a@b` and `x@localhost` +- **THEN** parsing accepts each document + +#### Scenario: A non-ASCII address is accepted + +- **WHEN** the caller parses a document whose email address is `ü@例え.jp` +- **THEN** parsing accepts the document + +#### Scenario: A display name is rejected + +- **WHEN** the caller parses a document whose email address is `Name ` +- **THEN** parsing reports a parse error for that address + +#### Scenario: Two at signs are rejected + +- **WHEN** the caller parses a document whose email address is `a@@b` +- **THEN** parsing reports a parse error for that address + +### Requirement: Each validation path applies the constraints + +Each check of this capability SHALL apply on each path that validates a value: a parse, the validation of an element, +the construction of a model by field name, and a back-matter builder. + +#### Scenario: Element validation rejects a malformed UUID + +- **WHEN** the caller validates a `back-matter-resource` element whose `uuid` is `not a uuid` +- **THEN** the result reports invalid + +#### Scenario: Construction rejects a malformed UUID + +- **WHEN** the caller constructs a back-matter resource by field name with the `uuid` `not a uuid` +- **THEN** the construction reports a validation error + +#### Scenario: A builder rejects an empty document identifier + +- **WHEN** the caller builds a back-matter resource with a document identifier whose `identifier` is `""` +- **THEN** the builder reports a builder error diff --git a/pyproject.toml b/pyproject.toml index 2914f5e..eeea379 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ requires-python = ">=3.11" # 2.14.2 is the floor: earlier 2.13/2.14 releases drop a JSON key spelled with a # Python field name instead of rejecting it (issue #6, GHSA-qpmf-fgh3-ff25). # tests/test_pydantic_version.py states the same range. -dependencies = ["pydantic[email]>=2.14.2,<3"] +dependencies = ["pydantic>=2.14.2,<3"] [project.urls] Homepage = "https://github.com/cairn-proofs/oscal-bindings-python" @@ -47,7 +47,7 @@ Issues = "https://github.com/cairn-proofs/oscal-bindings-python/issues" codegen = ["datamodel-code-generator[http,black,isort]==0.83.0"] # Optional YAML parse/serialize surface (v1/extensions/yaml_io.py). It imports # PyYAML, through v1/extensions/_yaml_loader.py, only when an operation is -# called. The base install keeps pydantic[email] as its one runtime dependency; +# called. The base install keeps pydantic as its one runtime dependency; # `pip install oscal-bindings[yaml]` adds PyYAML. A range, not a pin: a library # extra must let a consumer take a PyYAML security release. The YAML path uses # only PyYAML's event API, stable since 3.x. 6.0.1 is the first 6.x that builds diff --git a/requirements.txt b/requirements.txt index a0f4435..4b07abe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,7 @@ # - jsonschema-rs==0.58.6 # - pyyaml==6.0.3 # - types-PyYAML==6.0.12.20261030 -# - pydantic[email]<3,>=2.14.2 +# - pydantic<3,>=2.14.2 # annotated-types==0.8.0 \ @@ -125,14 +125,6 @@ datamodel-code-generator==0.83.0 \ --hash=sha256:30d841e31b82095c4ef11f3dbfc99525f559a146250b9e685e2a2e4a196ca0a1 \ --hash=sha256:371d80be360b2a57bc48462169553af57fa30225c0264ad85ae5f0d59b9d143a # via hatch.envs.default -dnspython==2.9.2 \ - --hash=sha256:8d4d39a513e649d634004ce4d39ade2352efcea472a0247535a5c2d18a9d7ba9 \ - --hash=sha256:af15f7d385a6ae2fb35a796fde2138004c8c42c7389090e2addc83e3b3340fd8 - # via email-validator -email-validator==2.3.0 \ - --hash=sha256:80f13f623413e6b197ae73bb10bf4eb0908faf509ad8362c5edeb0be7fd450b4 \ - --hash=sha256:9fc05c37f2f6cf439ff414f8fc46d917929974a82244c20eb10231ba60c54426 - # via pydantic genson==1.4.0 \ --hash=sha256:03bc71bbe52defde70660cc4dcd1ea1097997da5a1cbb90a9dbd3acc7c9e1b65 \ --hash=sha256:bc7f1c1bae87a21ca44d81149aec95a3f4468d676de9b8b08caa064f3c50b3da @@ -154,7 +146,6 @@ idna==3.20 \ --hash=sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c # via # anyio - # email-validator # httpx inflect==7.5.0 \ --hash=sha256:2aea70e5e70c35d8350b8097396ec155ffd68def678c7ff97f51aa69c1d92344 \ diff --git a/requirements/requirements-hatch-test.py3.11.txt b/requirements/requirements-hatch-test.py3.11.txt index 94d7619..641d985 100644 --- a/requirements/requirements-hatch-test.py3.11.txt +++ b/requirements/requirements-hatch-test.py3.11.txt @@ -1,7 +1,7 @@ # # This file is autogenerated by hatch-pip-compile with Python 3.11 # -# [constraints] requirements.txt (SHA256: f86db06684b381033e33818f586e08d72b7eb1fe6f22a67412d9f5da4daaf0fb) +# [constraints] requirements.txt (SHA256: a97c08bdc4ddb017290f2e5fddae2cb84855a5765c4ac3063bfb416246b0e942) # # - coverage-enable-subprocess==1.0 # - coverage[toml]~=7.11 @@ -13,7 +13,7 @@ # - hypothesis # - jsonschema-rs # - pyyaml -# - pydantic[email]<3,>=2.14.2 +# - pydantic<3,>=2.14.2 # annotated-types==0.8.0 \ @@ -151,18 +151,6 @@ coverage-enable-subprocess==1.0 \ --hash=sha256:27982522339ec77662965e0d859da5662162962c874d54d2250426506818cbdc \ --hash=sha256:fdbd3dc9532007cd87ef84f38e16024c5b0ccb4ab2d1755225a7edf937acc011 # via hatch.envs.hatch-test.py3.11 -dnspython==2.9.2 \ - --hash=sha256:8d4d39a513e649d634004ce4d39ade2352efcea472a0247535a5c2d18a9d7ba9 \ - --hash=sha256:af15f7d385a6ae2fb35a796fde2138004c8c42c7389090e2addc83e3b3340fd8 - # via - # -c requirements.txt - # email-validator -email-validator==2.3.0 \ - --hash=sha256:80f13f623413e6b197ae73bb10bf4eb0908faf509ad8362c5edeb0be7fd450b4 \ - --hash=sha256:9fc05c37f2f6cf439ff414f8fc46d917929974a82244c20eb10231ba60c54426 - # via - # -c requirements.txt - # pydantic execnet==2.1.2 \ --hash=sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd \ --hash=sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec @@ -254,12 +242,6 @@ hypothesis==6.168.3 \ --hash=sha256:fd7f75a2e23288ee82ee965a952473d9c5447c2cbc1afc94be09d2402201774e \ --hash=sha256:fd81241f4cd76fb18d481e87b9688b30a0cb5c30841730513323ba1c7aba1837 # via hatch.envs.hatch-test.py3.11 -idna==3.20 \ - --hash=sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44 \ - --hash=sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c - # via - # -c requirements.txt - # email-validator iniconfig==2.3.0 \ --hash=sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730 \ --hash=sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12 diff --git a/requirements/requirements-hatch-test.py3.12.txt b/requirements/requirements-hatch-test.py3.12.txt index d313576..014f92f 100644 --- a/requirements/requirements-hatch-test.py3.12.txt +++ b/requirements/requirements-hatch-test.py3.12.txt @@ -1,7 +1,7 @@ # # This file is autogenerated by hatch-pip-compile with Python 3.12 # -# [constraints] requirements.txt (SHA256: f86db06684b381033e33818f586e08d72b7eb1fe6f22a67412d9f5da4daaf0fb) +# [constraints] requirements.txt (SHA256: a97c08bdc4ddb017290f2e5fddae2cb84855a5765c4ac3063bfb416246b0e942) # # - coverage-enable-subprocess==1.0 # - coverage[toml]~=7.11 @@ -13,7 +13,7 @@ # - hypothesis # - jsonschema-rs # - pyyaml -# - pydantic[email]<3,>=2.14.2 +# - pydantic<3,>=2.14.2 # annotated-types==0.8.0 \ @@ -151,18 +151,6 @@ coverage-enable-subprocess==1.0 \ --hash=sha256:27982522339ec77662965e0d859da5662162962c874d54d2250426506818cbdc \ --hash=sha256:fdbd3dc9532007cd87ef84f38e16024c5b0ccb4ab2d1755225a7edf937acc011 # via hatch.envs.hatch-test.py3.12 -dnspython==2.9.2 \ - --hash=sha256:8d4d39a513e649d634004ce4d39ade2352efcea472a0247535a5c2d18a9d7ba9 \ - --hash=sha256:af15f7d385a6ae2fb35a796fde2138004c8c42c7389090e2addc83e3b3340fd8 - # via - # -c requirements.txt - # email-validator -email-validator==2.3.0 \ - --hash=sha256:80f13f623413e6b197ae73bb10bf4eb0908faf509ad8362c5edeb0be7fd450b4 \ - --hash=sha256:9fc05c37f2f6cf439ff414f8fc46d917929974a82244c20eb10231ba60c54426 - # via - # -c requirements.txt - # pydantic execnet==2.1.2 \ --hash=sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd \ --hash=sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec @@ -254,12 +242,6 @@ hypothesis==6.168.3 \ --hash=sha256:fd7f75a2e23288ee82ee965a952473d9c5447c2cbc1afc94be09d2402201774e \ --hash=sha256:fd81241f4cd76fb18d481e87b9688b30a0cb5c30841730513323ba1c7aba1837 # via hatch.envs.hatch-test.py3.12 -idna==3.20 \ - --hash=sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44 \ - --hash=sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c - # via - # -c requirements.txt - # email-validator iniconfig==2.3.0 \ --hash=sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730 \ --hash=sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12 diff --git a/requirements/requirements-hatch-test.py3.13.txt b/requirements/requirements-hatch-test.py3.13.txt index 53d9af2..1fd0e25 100644 --- a/requirements/requirements-hatch-test.py3.13.txt +++ b/requirements/requirements-hatch-test.py3.13.txt @@ -1,7 +1,7 @@ # # This file is autogenerated by hatch-pip-compile with Python 3.13 # -# [constraints] requirements.txt (SHA256: f86db06684b381033e33818f586e08d72b7eb1fe6f22a67412d9f5da4daaf0fb) +# [constraints] requirements.txt (SHA256: a97c08bdc4ddb017290f2e5fddae2cb84855a5765c4ac3063bfb416246b0e942) # # - coverage-enable-subprocess==1.0 # - coverage[toml]~=7.11 @@ -13,7 +13,7 @@ # - hypothesis # - jsonschema-rs # - pyyaml -# - pydantic[email]<3,>=2.14.2 +# - pydantic<3,>=2.14.2 # annotated-types==0.8.0 \ @@ -151,18 +151,6 @@ coverage-enable-subprocess==1.0 \ --hash=sha256:27982522339ec77662965e0d859da5662162962c874d54d2250426506818cbdc \ --hash=sha256:fdbd3dc9532007cd87ef84f38e16024c5b0ccb4ab2d1755225a7edf937acc011 # via hatch.envs.hatch-test.py3.13 -dnspython==2.9.2 \ - --hash=sha256:8d4d39a513e649d634004ce4d39ade2352efcea472a0247535a5c2d18a9d7ba9 \ - --hash=sha256:af15f7d385a6ae2fb35a796fde2138004c8c42c7389090e2addc83e3b3340fd8 - # via - # -c requirements.txt - # email-validator -email-validator==2.3.0 \ - --hash=sha256:80f13f623413e6b197ae73bb10bf4eb0908faf509ad8362c5edeb0be7fd450b4 \ - --hash=sha256:9fc05c37f2f6cf439ff414f8fc46d917929974a82244c20eb10231ba60c54426 - # via - # -c requirements.txt - # pydantic execnet==2.1.2 \ --hash=sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd \ --hash=sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec @@ -254,12 +242,6 @@ hypothesis==6.168.3 \ --hash=sha256:fd7f75a2e23288ee82ee965a952473d9c5447c2cbc1afc94be09d2402201774e \ --hash=sha256:fd81241f4cd76fb18d481e87b9688b30a0cb5c30841730513323ba1c7aba1837 # via hatch.envs.hatch-test.py3.13 -idna==3.20 \ - --hash=sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44 \ - --hash=sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c - # via - # -c requirements.txt - # email-validator iniconfig==2.3.0 \ --hash=sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730 \ --hash=sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12 diff --git a/requirements/requirements-hatch-test.py3.14.txt b/requirements/requirements-hatch-test.py3.14.txt index c1a40b6..38d1d00 100644 --- a/requirements/requirements-hatch-test.py3.14.txt +++ b/requirements/requirements-hatch-test.py3.14.txt @@ -1,7 +1,7 @@ # # This file is autogenerated by hatch-pip-compile with Python 3.14 # -# [constraints] requirements.txt (SHA256: f86db06684b381033e33818f586e08d72b7eb1fe6f22a67412d9f5da4daaf0fb) +# [constraints] requirements.txt (SHA256: a97c08bdc4ddb017290f2e5fddae2cb84855a5765c4ac3063bfb416246b0e942) # # - coverage-enable-subprocess==1.0 # - coverage[toml]~=7.11 @@ -13,7 +13,7 @@ # - hypothesis # - jsonschema-rs # - pyyaml -# - pydantic[email]<3,>=2.14.2 +# - pydantic<3,>=2.14.2 # annotated-types==0.8.0 \ @@ -151,18 +151,6 @@ coverage-enable-subprocess==1.0 \ --hash=sha256:27982522339ec77662965e0d859da5662162962c874d54d2250426506818cbdc \ --hash=sha256:fdbd3dc9532007cd87ef84f38e16024c5b0ccb4ab2d1755225a7edf937acc011 # via hatch.envs.hatch-test.py3.14 -dnspython==2.9.2 \ - --hash=sha256:8d4d39a513e649d634004ce4d39ade2352efcea472a0247535a5c2d18a9d7ba9 \ - --hash=sha256:af15f7d385a6ae2fb35a796fde2138004c8c42c7389090e2addc83e3b3340fd8 - # via - # -c requirements.txt - # email-validator -email-validator==2.3.0 \ - --hash=sha256:80f13f623413e6b197ae73bb10bf4eb0908faf509ad8362c5edeb0be7fd450b4 \ - --hash=sha256:9fc05c37f2f6cf439ff414f8fc46d917929974a82244c20eb10231ba60c54426 - # via - # -c requirements.txt - # pydantic execnet==2.1.2 \ --hash=sha256:63d83bfdd9a23e35b9c6a3261412324f964c2ec8dcd8d3c6916ee9373e0befcd \ --hash=sha256:67fba928dd5a544b783f6056f449e5e3931a5c378b128bc18501f7ea79e296ec @@ -254,12 +242,6 @@ hypothesis==6.168.3 \ --hash=sha256:fd7f75a2e23288ee82ee965a952473d9c5447c2cbc1afc94be09d2402201774e \ --hash=sha256:fd81241f4cd76fb18d481e87b9688b30a0cb5c30841730513323ba1c7aba1837 # via hatch.envs.hatch-test.py3.14 -idna==3.20 \ - --hash=sha256:a7db850025b95ded1eae8a46181a1a6c56c92c96f0e2b005d9ff8dc0210cab44 \ - --hash=sha256:ab7ae7122974553370f0bdb919e1a960b2cd1bc1ef0276416d896db81c14582c - # via - # -c requirements.txt - # email-validator iniconfig==2.3.0 \ --hash=sha256:c76315c77db068650d49c5b56314774a7804df16fee4402c1f19d6d15d8c4730 \ --hash=sha256:f631c04d2c48c52b84d0d0549c99ff3859c98df65b3101406327ecc7d53fbf12 diff --git a/scripts/hoist_names.py b/scripts/hoist_names.py index a1f1069..2620cbb 100644 --- a/scripts/hoist_names.py +++ b/scripts/hoist_names.py @@ -36,6 +36,12 @@ or a ``oneOf`` below the root and has no ``description`` takes the ``description`` of the schema that holds the branch, so each union variant class keeps a docstring. +7. The definitions of the four datatypes of ``HAND_WRITTEN_DATATYPES`` become + ``{"type": "string", "customTypePath": "."}``, with their + ``title`` and ``description`` kept. Codegen then emits the type of + ``oscal_bindings.v1._datatypes`` at each site, with no ``pattern`` beside it. + The step runs after the closed-enum check of step 4, which reads the original + definitions. Each site is resolved in the working copy when its turn comes. A descendant of a site has more pointer tokens than the site, so it is processed first, and no @@ -87,6 +93,16 @@ class keeps a docstring. _PAIR: Final = 2 # The combinators whose branches are union variants. _BRANCHES: Final = frozenset({"anyOf", "oneOf"}) +# The datatypes that the binding writes by hand: definition key -> the type that +# codegen emits at each site. A pattern cannot define them (design D3). +HAND_WRITTEN_DATATYPES: Final[dict[str, str]] = { + "URIDatatype": "oscal_bindings.v1._datatypes.OscalUri", + "URIReferenceDatatype": "oscal_bindings.v1._datatypes.OscalUriReference", + "EmailAddressDatatype": "oscal_bindings.v1._datatypes.OscalEmailAddress", + "DateTimeWithTimezoneDatatype": ( + "oscal_bindings.v1._datatypes.OscalDateTimeWithTimezone" + ), +} # The keys that a closed-enum allOf object can hold beside its allOf. _CLOSED_HOLDER_KEYS: Final = frozenset({"title", "description", "$id", "allOf"}) @@ -413,6 +429,22 @@ def _unresolved_refs(node: object, root: object, path: str = "#") -> list[str]: return failures +def _name_hand_written_datatypes( + definitions: dict[str, Any], failures: list[str] +) -> None: + """Replace each definition of ``HAND_WRITTEN_DATATYPES`` with its custom type.""" + for key, type_path in HAND_WRITTEN_DATATYPES.items(): + original = definitions.get(key) + if not isinstance(original, dict): + failures.append(f"the schema has no definition {key!r} to name {type_path}") + continue + definitions[key] = { + **{doc: original[doc] for doc in _DOCS if doc in original}, + "type": "string", + "customTypePath": type_path, + } + + def hoist(schema: dict[str, Any], manifest: dict[str, Any]) -> dict[str, Any]: """Return a copy of ``schema`` with each manifest site hoisted. @@ -446,6 +478,7 @@ def hoist(schema: dict[str, Any], manifest: dict[str, Any]) -> dict[str, Any]: ) working["definitions"] = definitions _rewrite_refs(working, renames) + _name_hand_written_datatypes(working["definitions"], failures) failures.extend(_unresolved_refs(working, working)) if failures: raise HoistError(failures) diff --git a/scripts/postprocess_models.py b/scripts/postprocess_models.py index c1ab96a..3f5fe29 100644 --- a/scripts/postprocess_models.py +++ b/scripts/postprocess_models.py @@ -5,9 +5,12 @@ as a class with its manifest name. This script completes the module: 1. Phase 1 changes structure. It collapses each scalar ``RootModel`` to an - ``Annotated`` alias, and it removes ``pattern=`` from the fields of a type - that has no regex constraint (``AwareDatetime``, ``AnyUrl``, ``EmailStr``, - numbers). + ``Annotated`` alias. Then it reads the base type of each + ``Annotated[base, ..., Field(..., pattern=P)]`` (``place_patterns``). A + ``pattern`` on a ``str`` stays, as ``translate`` of ``regex_translation`` + writes it for the Rust ``regex`` engine. A ``pattern`` on a number goes, + because JSON Schema applies ``pattern`` only to a string. A ``pattern`` on + another base, or outside an ``Annotated``, is a step failure that names it. 2. It adds the manifest types that codegen does not emit with their names: 1. Each ``single-or-many`` entry becomes a ``RootModel`` of the item or a @@ -64,6 +67,8 @@ from pathlib import Path from typing import TYPE_CHECKING, Any, Final +from regex_translation import RegexTranslationError, translate + if TYPE_CHECKING: from collections.abc import Iterable, Mapping, Sequence @@ -286,45 +291,192 @@ def ensure_annotated_import(content: str) -> str: return content -def fix_email_str_patterns(content: str) -> str: - """Remove pattern constraints from EmailStr fields (EmailStr validates email).""" - content = re.sub( - r"(Annotated\[\s*EmailStr,\s*Field\([^)]*?)pattern='[^']*',?\s*", - r"\1", - content, +# --------------------------------------------------------------------------- +# Patterns +# --------------------------------------------------------------------------- + +_LINE_BREAK: Final = re.compile(r"\r\n|\r|\n") +_NUMBER_BASES: Final = frozenset({"int", "float"}) + + +def _line_starts(content: str) -> list[int]: + """Return the offset of the start of each line, as ``ast`` counts lines. + + The list is 1-based: ``starts[lineno]``. ``ast`` breaks lines on CR, LF, and + CR LF only, unlike ``str.splitlines``. + """ + return [0, 0, *(m.end() for m in _LINE_BREAK.finditer(content))] + + +class _Pattern: + """The ``pattern=`` keyword of a ``Field(...)`` call and where it sits.""" + + def __init__( + self, where: str, base: ast.expr, call: ast.Call, keyword: ast.keyword + ) -> None: + self.where = where + self.base = base + self.call = call + self.keyword = keyword + + def base_kind(self) -> str | None: + """``"str"`` or ``"number"``, or ``None`` for any other base. + + ``None`` members of the base are ignored. A union of ``str`` and a + number is no kind: JSON Schema would apply the pattern to the string + member only. + """ + names = [_member_text(member) for member in _union_members(self.base)] + names = [name for name in names if name != "None"] + if names and all(name == "str" for name in names): + return "str" + if names and all(name in _NUMBER_BASES for name in names): + return "number" + return None + + +def _union_members(node: ast.expr) -> list[ast.expr]: + if isinstance(node, ast.BinOp) and isinstance(node.op, ast.BitOr): + return _union_members(node.left) + _union_members(node.right) + return [node] + + +def _member_text(node: ast.expr) -> str: + return node.id if isinstance(node, ast.Name) else ast.unparse(node) + + +def _pattern_keywords(node: ast.AST) -> Iterable[ast.keyword]: + return ( + keyword + for child in ast.walk(node) + if isinstance(child, ast.keyword) + for keyword in [child] + if keyword.arg == "pattern" ) - return re.sub(r",\s*\)", ")", content) -def fix_non_string_patterns(content: str) -> str: - """Remove pattern constraints from non-string types that don't support regex.""" - # AwareDatetime, AnyUrl, int, float, bool, EmailStr don't support pattern - # Find pattern='...' in Field() where the type is not str - # Strategy: remove all pattern= from Annotated[AwareDatetime|AnyUrl, Field(...)] - non_str_types = ["AwareDatetime", "AnyUrl", "int", "float", "bool", "EmailStr"] +def _find_patterns(tree: ast.Module) -> tuple[list[_Pattern], list[str]]: + """Return each pattern of an ``Annotated[base, ..., Field(pattern=...)]``. - # Find all Field() calls that have pattern= and check if the Annotated type is - # non-string - lines = content.split("\n") - result = [] - i = 0 - while i < len(lines): - line = lines[i] - # Check if this line has a pattern= in a Field - if "pattern=" in line and "Field(" in "\n".join(lines[max(0, i - 5) : i + 1]): - # Look backwards to find the Annotated type - context = "\n".join(lines[max(0, i - 10) : i + 1]) - # Check if any non-string type is in the Annotated context - is_non_string = any(t in context for t in non_str_types) - if is_non_string: - # Remove the pattern='...' from this line - line = re.sub(r"\s*pattern='[^']*',?", "", line) - # Clean up empty Field() or trailing commas - line = re.sub(r",\s*\)", ")", line) - line = re.sub(r"Field\(\s*\)", "Field()", line) - result.append(line) - i += 1 - return "\n".join(result) + The second value holds the name of each other ``pattern`` keyword. + """ + found: list[_Pattern] = [] + handled: set[int] = set() + + def visit(node: ast.AST, owner: str | None, where: str) -> None: + if isinstance(node, ast.ClassDef): + owner, where = node.name, node.name + elif isinstance(node, ast.AnnAssign) and isinstance(node.target, ast.Name): + where = f"{owner}.{node.target.id}" if owner else node.target.id + elif isinstance(node, ast.Assign) and isinstance(node.targets[0], ast.Name): + where = node.targets[0].id + if ( + isinstance(node, ast.Subscript) + and _is_name(node.value, "Annotated") + and isinstance(node.slice, ast.Tuple) + and len(node.slice.elts) > 1 + ): + base, *metadata = node.slice.elts + for call in metadata: + if isinstance(call, ast.Call) and _is_name(call.func, "Field"): + for keyword in call.keywords: + if keyword.arg == "pattern": + found.append(_Pattern(where, base, call, keyword)) + handled.add(id(keyword)) + for child in ast.iter_child_nodes(node): + visit(child, owner, where) + + visit(tree, None, "") + stray = [ + f"line {keyword.lineno}" + for keyword in _pattern_keywords(tree) + if id(keyword) not in handled + ] + return found, stray + + +def place_patterns(content: str, failures: list[str]) -> str: + """Keep, translate, or remove each ``pattern=`` by the base of its ``Annotated``. + + For each ``Annotated[base, ..., Field(..., pattern=P, ...)]``: + + 1. A ``str`` base keeps the pattern, as ``translate`` of + ``regex_translation`` maps it to the Rust ``regex`` dialect. + 2. An ``int`` or ``float`` base loses it. JSON Schema applies ``pattern`` only + to a string. + 3. Each other base is a failure that names the class, the field, and the + base. A ``pattern`` outside such an ``Annotated`` is also a failure. + + ``failures`` collects each failure, so one run reports all of them. + """ + tree = ast.parse(content) + found, stray = _find_patterns(tree) + failures.extend( + f"a pattern outside an Annotated Field ({where})" for where in stray + ) + span = _Spans(content) + edits: list[tuple[int, int, str]] = [] + for item in found: + keyword = item.keyword + kind = item.base_kind() + if kind == "str": + value = keyword.value + if not (isinstance(value, ast.Constant) and isinstance(value.value, str)): + failures.append(f"{item.where}: the pattern is not a string literal") + continue + try: + translated = translate(value.value) + except RegexTranslationError as error: + failures.append(f"{item.where}: {error}") + continue + edits.append((*span(value), repr(translated))) + elif kind == "number": + edits.append(_removal(item, content, span)) + else: + failures.append( + f"{item.where}: a pattern on the base {ast.unparse(item.base)}, " + "which is not str, int, or float" + ) + return _apply(content, edits) + + +class _Spans: + """The ``(start, end)`` offsets in ``content`` of an ``ast`` node.""" + + def __init__(self, content: str) -> None: + self._content = content + self._starts = _line_starts(content) + + def _offset(self, lineno: int, col: int) -> int: + # ``col`` is a UTF-8 byte offset into the line. + start = self._starts[lineno] + line = self._content[start:].split("\n", maxsplit=1)[0].encode() + return start + len(line[:col].decode()) + + def __call__(self, node: Any) -> tuple[int, int]: + if node.end_lineno is None or node.end_col_offset is None: + msg = f"the node at line {node.lineno} has no end position" + raise ValueError(msg) + return ( + self._offset(node.lineno, node.col_offset), + self._offset(node.end_lineno, node.end_col_offset), + ) + + +def _removal(item: _Pattern, content: str, span: _Spans) -> tuple[int, int, str]: + """The edit that removes the ``pattern=`` keyword and one comma.""" + arguments = sorted( + [*item.call.args, *item.call.keywords], + key=lambda node: (node.lineno, node.col_offset), + ) + index = arguments.index(item.keyword) + start, end = span(item.keyword) + if index + 1 < len(arguments): + return start, span(arguments[index + 1])[0], "" + if index > 0: + return span(arguments[index - 1])[1], end, "" + trailing = re.match(r"\s*,", content[end:]) + return start, end + (trailing.end() if trailing else 0), "" # --------------------------------------------------------------------------- @@ -1023,8 +1175,7 @@ def postprocess( ) content = collapse_scalar_root_models(content, root_models) content = ensure_annotated_import(content) - content = fix_email_str_patterns(content) - content = fix_non_string_patterns(content) + content = place_patterns(content, failures) renames = scalar_renames(content, schema, manifest, failures) content = rename_names(content, renames) diff --git a/scripts/regex_translation.py b/scripts/regex_translation.py new file mode 100644 index 0000000..a2555a3 --- /dev/null +++ b/scripts/regex_translation.py @@ -0,0 +1,176 @@ +"""Translate an ECMA-262 pattern of the OSCAL schema to a Rust ``regex`` pattern. + +JSON Schema writes a ``pattern`` in the regex dialect of ECMA-262. Pydantic +evaluates a pattern with the Rust ``regex`` engine of pydantic-core. The two +dialects differ for the constructs below, so a pattern that Pydantic reads as +written accepts values that the schema rejects (PRS-007). + +``translate`` reads a pattern token by token and writes a Rust pattern that +accepts and rejects the same values as the ECMA-262 pattern with the ``u`` flag. +It knows these constructs: + +1. ``.`` outside a class is a class that excludes the ECMA-262 line + terminators: LF, CR, U+2028, and U+2029. Rust ``.`` excludes only LF. +2. ``\\s`` outside a class is a class of the ECMA-262 white space and line + terminators. ``\\S`` is the complement. The Rust ``\\s`` has U+0085 and no + U+FEFF, and ECMA-262 has the reverse. +3. A literal, an escaped literal, a code point escape (``\\xHH``, ``\\uHHHH``, + ``\\u{H...}``), a class, a negated class, ``\\p{...}``, ``\\P{...}``, a group, + an alternation, a quantifier, ``^``, and ``$`` stay as they are. A class holds + literals, escaped literals, code point escapes, ranges, and ``\\p{...}``. + Without the multiline flag, ``^`` and ``$`` mean the same in both dialects. +4. Each other construct is an error that names the pattern: lookaround, a + back-reference, ``\\d``, ``\\w``, ``\\b``, ``\\s`` inside a class, and an + inline flag. + +The OSCAL 1.2.3 schema uses no construct of item 4. A new release that does +fails the generation here, so the mapping is never silently wrong. +""" + +from __future__ import annotations + +import re +from typing import Final + +__all__ = ["RegexTranslationError", "translate"] + +# The ECMA-262 line terminators, as Rust escapes. +_LINE_TERMINATORS: Final = r"\n\r\u{2028}\u{2029}" +# The ECMA-262 WhiteSpace and LineTerminator code points, as the body of a Rust +# class: TAB, LF, VT, FF, CR, SP, NBSP, U+1680, U+2000 to U+200A, U+2028, +# U+2029, U+202F, U+205F, U+3000, and U+FEFF. +_WHITE_SPACE: Final = ( + r"\t\n\x0b\x0c\r \u{a0}\u{1680}\u{2000}-\u{200a}" + r"\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}" +) + +_DOT: Final = f"[^{_LINE_TERMINATORS}]" +_SPACE: Final = f"[{_WHITE_SPACE}]" +_NOT_SPACE: Final = f"[^{_WHITE_SPACE}]" + +# An escaped literal: a syntax character of ECMA-262 or "-". +_SYNTAX_CHARACTERS: Final = frozenset("^$\\.*+?()[]{}|/-") +# A control escape that both dialects read the same way. +_CONTROL_ESCAPES: Final = frozenset("nrtfv") +_PROPERTY: Final = re.compile(r"\\[pP]\{[A-Za-z_=]+\}") +# A code point escape: both dialects read it alike, and ``translate`` writes +# some (``\x0b``, ``\u{2028}``), so its output is its own fixed point. +_CODE_POINT: Final = re.compile( + r"\\(?:x[0-9A-Fa-f]{2}|u[0-9A-Fa-f]{4}|u\{[0-9A-Fa-f]{1,6}\})" +) +_QUANTIFIER: Final = re.compile(r"\{\d+(?:,\d*)?\}") +# Rust uses the escape of a control character, so the output holds no raw LF. +_RAW_ESCAPES: Final = {"\n": r"\n", "\r": r"\r", "\t": r"\t"} + + +class RegexTranslationError(ValueError): + """Raised when a pattern has a construct that ``translate`` does not map.""" + + def __init__(self, pattern: str, reason: str) -> None: + self.pattern = pattern + self.reason = reason + super().__init__(f"Cannot translate the pattern {pattern!r}: {reason}") + + +def translate(pattern: str) -> str: + """Return the Rust ``regex`` pattern for an ECMA-262 ``pattern``. + + Raises: + RegexTranslationError: for a construct that the module docstring lists + as an error, and for a pattern that is not well formed. + """ + out: list[str] = [] + i = 0 + depth = 0 + while i < len(pattern): + c = pattern[i] + if c == "\\": + token, i = _escape(pattern, i, in_class=False) + elif c == "[": + token, i = _class(pattern, i) + elif c == "(": + token, i = _open_group(pattern, i) + depth += 1 + elif c == ")": + depth -= 1 + if depth < 0: + raise RegexTranslationError(pattern, "unbalanced ')'") + token, i = c, i + 1 + elif c == "{": + token, i = _quantifier(pattern, i) + elif c in "]}": + raise RegexTranslationError(pattern, f"unescaped {c!r} at {i}") + else: + token, i = (_DOT if c == "." else _RAW_ESCAPES.get(c, c)), i + 1 + out.append(token) + if depth: + raise RegexTranslationError(pattern, "unbalanced '('") + return "".join(out) + + +def _open_group(pattern: str, i: int) -> tuple[str, int]: + """Translate the group opener at ``pattern[i]``: ``(`` or ``(?:``.""" + if pattern.startswith("(?:", i): + return "(?:", i + 3 + if pattern.startswith("(?", i): + raise RegexTranslationError(pattern, f"group construct {pattern[i : i + 3]!r}") + return "(", i + 1 + + +def _quantifier(pattern: str, i: int) -> tuple[str, int]: + """Translate the ``{n}``, ``{n,}``, or ``{n,m}`` quantifier at ``pattern[i]``.""" + match = _QUANTIFIER.match(pattern, i) + if match is None: + raise RegexTranslationError(pattern, f"unescaped '{{' at {i}") + return match.group(), match.end() + + +def _escape(pattern: str, i: int, *, in_class: bool) -> tuple[str, int]: + """Translate the escape at ``pattern[i]``. Return the token and the next index.""" + if i + 1 >= len(pattern): + raise RegexTranslationError(pattern, "trailing backslash") + c = pattern[i + 1] + for kept in (_PROPERTY, _CODE_POINT): + match = kept.match(pattern, i) + if match is not None: + return match.group(), match.end() + if c in "sS": + if in_class: + raise RegexTranslationError(pattern, f"'\\{c}' inside a class") + return (_SPACE if c == "s" else _NOT_SPACE), i + 2 + if c in "dDwWbB": + raise RegexTranslationError(pattern, f"escape '\\{c}'") + if c.isdigit() or c == "k": + raise RegexTranslationError(pattern, f"back-reference '\\{c}'") + if c in _SYNTAX_CHARACTERS: + return f"\\{c}", i + 2 + if c in _CONTROL_ESCAPES: + return f"\\{c}", i + 2 + raise RegexTranslationError(pattern, f"escape '\\{c}'") + + +def _class(pattern: str, start: int) -> tuple[str, int]: + """Translate the class that starts at ``pattern[start]``.""" + out = ["["] + i = start + 1 + if i < len(pattern) and pattern[i] == "^": + out.append("^") + i += 1 + members = 0 + while i < len(pattern): + c = pattern[i] + if c == "]": + if members == 0: + raise RegexTranslationError(pattern, "empty class") + out.append("]") + return "".join(out), i + 1 + if c == "\\": + token, i = _escape(pattern, i, in_class=True) + out.append(token) + elif c == "[": + raise RegexTranslationError(pattern, f"unescaped '[' in a class at {i}") + else: + out.append(_RAW_ESCAPES.get(c, c)) + i += 1 + members += 1 + raise RegexTranslationError(pattern, "unterminated class") diff --git a/src/oscal_bindings/v1/_datatypes.py b/src/oscal_bindings/v1/_datatypes.py new file mode 100644 index 0000000..176e6b5 --- /dev/null +++ b/src/oscal_bindings/v1/_datatypes.py @@ -0,0 +1,228 @@ +"""The four OSCAL datatypes that a pattern does not define alone. + +The OSCAL schema gives the datatypes ``date-time-with-timezone``, ``uri``, +``uri-reference``, and ``email-address`` a ``format`` or an ``allOf``, not only +a ``pattern``. Codegen cannot place such a constraint in a field, and the +Pydantic types that it picks for them change the value (``AnyUrl``, +``EmailStr``) or accept too much (``AwareDatetime``, ``str``). The hoist of the +generation names each of the four definitions with ``customTypePath``, so the +models use the types of this module (design D3 of the +enforce-oscal-datatype-constraints change). + +Each type checks in pydantic-core with the Rust ``regex`` engine, so a JSON +parse calls no Python function for the check. The one exception is a +``datetime`` that the caller gives in Python input (``OscalDateTimeWithTimezone``). + +- ``OscalUri``: a ``str``. The input must match the pattern of the schema and be + a URI of RFC 3986. Each scheme is valid. The value is the input text. +- ``OscalUriReference``: a ``str``. The input must be a URI reference of + RFC 3986. The value is the input text. +- ``OscalEmailAddress``: a ``str``. The input must match the two patterns of + the schema and be a mailbox of RFC 5321 as RFC 6531 extends it. The value is + the input text. A U-label of a domain is a run of non-ASCII characters, + letters, digits, and hyphens, with no hyphen at its start or end. The tables + of IDNA2008 would need a dependency, so the type does not check them. +- ``OscalDateTimeWithTimezone``: an ``AwareDatetime``. The input must be a + string that matches the pattern of the schema, or in Python input a + ``datetime`` with a timezone whose serialization matches it. + +The pattern literals are the output of ``translate`` of +``scripts/regex_translation.py`` for the patterns of the schema. A test reads +the pinned schema and fails when a literal drifts (design D6). The runtime +package holds no schema and no translator. +""" + +from __future__ import annotations + +from typing import TYPE_CHECKING, Annotated, Any, Final + +import pydantic_core +from pydantic import AwareDatetime, GetPydanticSchema +from pydantic_core import PydanticCustomError, SchemaValidator, core_schema + +if TYPE_CHECKING: + from datetime import datetime + + from pydantic import GetCoreSchemaHandler + +__all__ = [ + "OscalDateTimeWithTimezone", + "OscalEmailAddress", + "OscalUri", + "OscalUriReference", +] + +# --- Patterns of the schema, translated to Rust (design D6) ----------------- + +_DOT: Final = r"[^\n\r\u{2028}\u{2029}]" +_NOT_SPACE: Final = ( + r"[^\t\n\x0b\x0c\r \u{a0}\u{1680}\u{2000}-\u{200a}" + r"\u{2028}\u{2029}\u{202f}\u{205f}\u{3000}\u{feff}]" +) + +# `uri`: `^[a-zA-Z][a-zA-Z0-9+\-.]+:.+$` +_URI_PATTERN: Final = rf"^[a-zA-Z][a-zA-Z0-9+\-.]+:{_DOT}+$" +# `string`: `^\S(.*\S)?$` +_STRING_PATTERN: Final = rf"^{_NOT_SPACE}({_DOT}*{_NOT_SPACE})?$" +# `email-address`, second member of its `allOf`: `^.+@.+$` +_EMAIL_PATTERN: Final = rf"^{_DOT}+@{_DOT}+$" +# `date-time-with-timezone` +_DATE_TIME_PATTERN: Final = ( + r"^(" + r"((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)" + r"|(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))" + r"|(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))" + r"|(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30))" + r")T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(\.[0-9]+)?" + r"(Z|(-((0[0-9]|1[0-2]):00|0[39]:30)" + r"|\+((0[0-9]|1[0-4]):00|(0[34569]|10):30|(0[58]|12):45)))$" +) + +# --- RFC 3986 ----------------------------------------------------------------- +# The ABNF of each rule, written as a Rust pattern. The comment of a name is the +# rule that it writes. + +_HEX2 = r"%[0-9A-Fa-f]{2}" +_UNRESERVED_SUB_DELIMS = r"A-Za-z0-9\-._~!$&'()*+,;=" +_PCHAR = rf"(?:[{_UNRESERVED_SUB_DELIMS}:@]|{_HEX2})" # pchar +_SEGMENT = rf"{_PCHAR}*" # segment +_SEGMENT_NZ = rf"{_PCHAR}+" # segment-nz +_SEGMENT_NZ_NC = rf"(?:[{_UNRESERVED_SUB_DELIMS}@]|{_HEX2})+" # segment-nz-nc +_PATH_ABEMPTY = rf"(?:/{_SEGMENT})*" # path-abempty +_PATH_ABSOLUTE = rf"/(?:{_SEGMENT_NZ}(?:/{_SEGMENT})*)?" # path-absolute +_PATH_ROOTLESS = rf"{_SEGMENT_NZ}(?:/{_SEGMENT})*" # path-rootless +_PATH_NOSCHEME = rf"{_SEGMENT_NZ_NC}(?:/{_SEGMENT})*" # path-noscheme +_H16 = r"[0-9A-Fa-f]{1,4}" # h16 +_DEC_OCTET = r"(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])" # dec-octet +_IPV4 = rf"(?:{_DEC_OCTET}\.){{3}}{_DEC_OCTET}" # IPv4address +_LS32 = rf"(?:{_H16}:{_H16}|{_IPV4})" # ls32 +_IPV6 = ( # IPv6address + r"(?:" + rf"(?:{_H16}:){{6}}{_LS32}" + rf"|::(?:{_H16}:){{5}}{_LS32}" + rf"|(?:{_H16})?::(?:{_H16}:){{4}}{_LS32}" + rf"|(?:(?:{_H16}:){{0,1}}{_H16})?::(?:{_H16}:){{3}}{_LS32}" + rf"|(?:(?:{_H16}:){{0,2}}{_H16})?::(?:{_H16}:){{2}}{_LS32}" + rf"|(?:(?:{_H16}:){{0,3}}{_H16})?::{_H16}:{_LS32}" + rf"|(?:(?:{_H16}:){{0,4}}{_H16})?::{_LS32}" + rf"|(?:(?:{_H16}:){{0,5}}{_H16})?::{_H16}" + r"|(?:(?:" + _H16 + r":){0,6}" + _H16 + r")?::" + r")" +) +_IPVFUTURE = rf"v[0-9A-Fa-f]+\.[{_UNRESERVED_SUB_DELIMS}:]+" # IPvFuture +_HOST = ( # host: IP-literal / IPv4address / reg-name + rf"(?:\[(?:{_IPV6}|{_IPVFUTURE})\]|(?:[{_UNRESERVED_SUB_DELIMS}]|{_HEX2})*)" +) +_AUTHORITY = ( # authority + rf"(?:(?:[{_UNRESERVED_SUB_DELIMS}:]|{_HEX2})*@)?{_HOST}(?::[0-9]*)?" +) +_QUERY_OR_FRAGMENT = rf"(?:{_PCHAR}|[/?])*" # query, fragment +_TAIL = rf"(?:\?{_QUERY_OR_FRAGMENT})?(?:#{_QUERY_OR_FRAGMENT})?" +_SCHEME = r"[A-Za-z][A-Za-z0-9+\-.]*" # scheme +# hier-part, with its empty alternative +_HIER_PART = rf"(?://{_AUTHORITY}{_PATH_ABEMPTY}|{_PATH_ABSOLUTE}|{_PATH_ROOTLESS}|)" +# relative-part, with its empty alternative +_RELATIVE_PART = ( + rf"(?://{_AUTHORITY}{_PATH_ABEMPTY}|{_PATH_ABSOLUTE}|{_PATH_NOSCHEME}|)" +) +_URI_GRAMMAR: Final = rf"^{_SCHEME}:{_HIER_PART}{_TAIL}$" # URI +# URI-reference: URI / relative-ref +_URI_REFERENCE_GRAMMAR: Final = rf"^(?:{_SCHEME}:{_HIER_PART}|{_RELATIVE_PART}){_TAIL}$" + +# --- RFC 5321 Mailbox with RFC 6531 -------------------------------------------- + +_NON_ASCII = r"\u{80}-\u{10ffff}" # UTF8-non-ascii +_ATEXT = rf"[A-Za-z0-9!#$%&'*+\-/=?\^_`{{|}}~{_NON_ASCII}]" # atext +_DOT_STRING = rf"{_ATEXT}+(?:\.{_ATEXT}+)*" # Dot-string +_QUOTED_STRING = ( # Quoted-string + rf'"(?:[\x20\x21\x23-\x5b\x5d-\x7e{_NON_ASCII}]|\\[\x20-\x7e])*"' +) +_LET_DIG = rf"[A-Za-z0-9{_NON_ASCII}]" # Let-dig, or a character of a U-label +_SUB_DOMAIN = rf"{_LET_DIG}(?:[A-Za-z0-9\-{_NON_ASCII}]*{_LET_DIG})?" # sub-domain +_DOMAIN = rf"{_SUB_DOMAIN}(?:\.{_SUB_DOMAIN})*" # Domain +_ADDRESS_LITERAL = ( # address-literal + rf"\[(?:{_IPV4}|IPv6:{_IPV6}" + r"|[A-Za-z0-9](?:[A-Za-z0-9\-]*[A-Za-z0-9])?:[\x21-\x5a\x5e-\x7e]+)\]" +) +_MAILBOX: Final = ( # Mailbox + rf"^(?:{_DOT_STRING}|{_QUOTED_STRING})@(?:{_DOMAIN}|{_ADDRESS_LITERAL})$" +) + +# --- The types ---------------------------------------------------------------- + + +def _chain(*patterns: str) -> core_schema.CoreSchema: + """A schema that matches the whole input against each pattern, in order.""" + return core_schema.chain_schema( + [core_schema.str_schema(pattern=pattern) for pattern in patterns] + ) + + +def _string_type(*patterns: str) -> GetPydanticSchema: + def get_schema(_source: Any, _handler: GetCoreSchemaHandler) -> Any: + return _chain(*patterns) + + return GetPydanticSchema(get_schema) + + +OscalUri = Annotated[str, _string_type(_URI_PATTERN, _URI_GRAMMAR)] +"""The datatype ``uri``: the pattern of the schema, then RFC 3986 ``URI``.""" + +OscalUriReference = Annotated[str, _string_type(_URI_REFERENCE_GRAMMAR)] +"""The datatype ``uri-reference``: RFC 3986 ``URI-reference``.""" + +OscalEmailAddress = Annotated[ + str, _string_type(_STRING_PATTERN, _EMAIL_PATTERN, _MAILBOX) +] +"""The datatype ``email-address``: the two patterns of the schema, then ``Mailbox``.""" + +_DATE_TIME_ERROR_TYPE: Final = "oscal_date_time_with_timezone" +_DATE_TIME_ERROR_MESSAGE: Final = ( + "Input should be a date-time with a timezone that matches the OSCAL pattern" +) +_DATE_TIME_TEXT: Final = SchemaValidator( + core_schema.str_schema(pattern=_DATE_TIME_PATTERN) +) + + +def _check_serialization(value: datetime) -> datetime: + """Match the text that a serialization writes with the pattern of the schema.""" + text = pydantic_core.to_json(value).decode()[1:-1] + try: + _DATE_TIME_TEXT.validate_python(text) + except pydantic_core.ValidationError as error: + raise PydanticCustomError( + _DATE_TIME_ERROR_TYPE, _DATE_TIME_ERROR_MESSAGE + ) from error + return value + + +def _date_time_schema(_source: Any, _handler: GetCoreSchemaHandler) -> Any: + # JSON input: the string must match the pattern, then it is a datetime. + from_text = core_schema.chain_schema( + [ + core_schema.str_schema(pattern=_DATE_TIME_PATTERN), + core_schema.datetime_schema(tz_constraint="aware"), + ] + ) + # Python input: the same chain, or a datetime instance (never a number) + # whose serialization matches the pattern. The union gives one error at the + # field, not one for each member. + from_datetime = core_schema.no_info_after_validator_function( + _check_serialization, + core_schema.datetime_schema(strict=True, tz_constraint="aware"), + ) + return core_schema.json_or_python_schema( + json_schema=from_text, + python_schema=core_schema.union_schema( + [from_text, from_datetime], + custom_error_type=_DATE_TIME_ERROR_TYPE, + custom_error_message=_DATE_TIME_ERROR_MESSAGE, + ), + ) + + +OscalDateTimeWithTimezone = Annotated[ + AwareDatetime, GetPydanticSchema(_date_time_schema) +] +"""The datatype ``date-time-with-timezone``: a ``datetime`` that has a timezone.""" diff --git a/src/oscal_bindings/v1/models.py b/src/oscal_bindings/v1/models.py index 7731b8d..df46f1c 100644 --- a/src/oscal_bindings/v1/models.py +++ b/src/oscal_bindings/v1/models.py @@ -7,7 +7,13 @@ from typing import Annotated, TypeAlias from oscal_bindings.v1._base import OscalBaseModel, root_key_discriminator -from pydantic import AnyUrl, AwareDatetime, ConfigDict, EmailStr, Field, RootModel, Tag +from oscal_bindings.v1._datatypes import ( + OscalDateTimeWithTimezone, + OscalEmailAddress, + OscalUri, + OscalUriReference, +) +from pydantic import ConfigDict, Field, RootModel, Tag class ParameterSelectionHowMany(Enum): @@ -25,7 +31,8 @@ class IncludeAll(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) class ControlCommonSelectControlByIdChildControls(Enum): @@ -197,7 +204,8 @@ class MergeCombine(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) class MergeFlat(OscalBaseModel): @@ -206,7 +214,8 @@ class MergeFlat(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) class MergeWithFlat(OscalBaseModel): @@ -215,18 +224,21 @@ class MergeWithFlat(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) combine: Annotated[ MergeCombine | None, Field( description='A Combine element defines how to resolve duplicate instances of the same control (e.g., controls with the same ID).', - title='Combination Rule'), + title='Combination Rule', + ), ] = None flat: Annotated[ MergeFlat, Field( description='Directs that controls appear without any grouping structure.', - title='Flat Without Grouping'), + title='Flat Without Grouping', + ), ] @@ -552,7 +564,8 @@ class AssessmentPartName(Enum): str, Field( description='A single line of Markdown content conformant to the Commonmark specification.', -), + pattern='^[^\\n]+$', + ), ] @@ -560,7 +573,8 @@ class AssessmentPartName(Enum): str, Field( description='A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+', - pattern='^\\S(.*\\S)?$'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + ), ] @@ -568,14 +582,7 @@ class AssessmentPartName(Enum): str, Field( description='A non-colonized name as defined by XML Schema Part 2: Datatypes Second Edition. https://www.w3.org/TR/xmlschema11-2/#NCName.', - pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$'), - ] - - -URIDatatype = Annotated[ - AnyUrl, - Field( - description='A universal resource identifier (URI) formatted according to RFC3986.' + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', ), ] @@ -584,7 +591,8 @@ class AssessmentPartName(Enum): str, Field( description="A type 4 ('random' or 'pseudorandom') or type 5 UUID per RFC 4122.", - pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$'), + pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', + ), ] @@ -594,12 +602,14 @@ class ParameterGuideline(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) prose: Annotated[ str, Field( description='Prose permits multiple paragraphs, lists, tables etc.', - title='Guideline Text'), + title='Guideline Text', + ), ] @@ -607,8 +617,9 @@ class ParameterGuideline(OscalBaseModel): str, Field( description='A parameter value or set of values.', - pattern='^\\S(.*\\S)?$', - title='Parameter Value'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Parameter Value', + ), ] @@ -618,13 +629,15 @@ class ParameterSelection(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) how_many: Annotated[ ParameterSelectionHowMany | None, Field( alias='how-many', description='Describes the number of selections that must occur. Without this setting, only one value should be assumed to be permitted.', - title='Parameter Cardinality'), + title='Parameter Cardinality', + ), ] = None choice: Annotated[list[MarkupLineDatatype] | None, Field(min_length=1)] = None @@ -634,7 +647,8 @@ class ParameterSelection(OscalBaseModel): Field( description='Selecting a control by its ID given as a literal.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Match Controls by Identifier'), + title='Match Controls by Identifier', + ), ] @@ -644,18 +658,21 @@ class MetadataPartyExternalId(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) scheme: Annotated[ - URIDatatype | MetadataPartyExternalIdScheme, + MetadataPartyExternalIdScheme | OscalUri, Field( description='Indicates the type of external identifier.', - title='External Identifier Schema'), + title='External Identifier Schema', + ), ] id: Annotated[ str, Field( description='A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+', - pattern='^\\S(.*\\S)?$'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + ), ] @@ -664,7 +681,8 @@ class MetadataPartyExternalId(OscalBaseModel): Field( description='Reference to a location by UUID.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Location Universally Unique Identifier Reference'), + title='Location Universally Unique Identifier Reference', + ), ] @@ -673,7 +691,8 @@ class MetadataPartyExternalId(OscalBaseModel): Field( description='Reference to a party by UUID.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Party Universally Unique Identifier Reference'), + title='Party Universally Unique Identifier Reference', + ), ] @@ -682,7 +701,8 @@ class MetadataPartyExternalId(OscalBaseModel): Field( description='Reference to a role by UUID.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Role Identifier Reference'), + title='Role Identifier Reference', + ), ] @@ -692,28 +712,32 @@ class BackMatterResourceBase64(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) filename: Annotated[ str | None, Field( description='Name of the file before it was encoded as Base64 to be embedded in a resource. This is the name that will be assigned to the file when the file is decoded.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='File Name'), + title='File Name', + ), ] = None media_type: Annotated[ str | None, Field( alias='media-type', description='A label that indicates the nature of a resource, as a data serialization or format.', - pattern='^\\S(.*\\S)?$', - title='Media Type'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Media Type', + ), ] = None value: Annotated[ str, Field( description='Binary data encoded using the Base 64 encoding algorithm as defined by RFC4648.', json_schema_extra={'contentEncoding': 'base64'}, - pattern='^[0-9A-Za-z+/]+={0,2}$'), + pattern='^[0-9A-Za-z+/]+={0,2}$', + ), ] @@ -723,41 +747,47 @@ class Link(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str, + OscalUriReference, Field( description='A resolvable URL reference to a resource.', - title='Hypertext Reference'), + title='Hypertext Reference', + ), ] rel: Annotated[ TokenDatatype | LinkRel | None, Field( description="Describes the type of relationship provided by the link's hypertext reference. This can be an indicator of the link's purpose.", - title='Link Relation Type'), + title='Link Relation Type', + ), ] = None media_type: Annotated[ str | None, Field( alias='media-type', description='A label that indicates the nature of a resource, as a data serialization or format.', - pattern='^\\S(.*\\S)?$', - title='Media Type'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Media Type', + ), ] = None resource_fragment: Annotated[ str | None, Field( alias='resource-fragment', description='In case where the href points to a back-matter/resource, this value will indicate the URI fragment to append to any rlink associated with the resource. This value MUST be URI encoded.', - - title='Resource Fragment'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Resource Fragment', + ), ] = None text: Annotated[ str | None, Field( description='A textual label to associate with the link, which may be used for presentation in a tool.', - - title='Link Text'), + pattern='^[^\\n]+$', + title='Link Text', + ), ] = None @@ -767,26 +797,21 @@ class Hash(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) algorithm: Annotated[ StringDatatype | HashAlgorithm, Field( description='The digest method by which a hash is derived.', - title='Hash algorithm'), + title='Hash algorithm', + ), ] value: Annotated[ str, Field( description='A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+', - pattern='^\\S(.*\\S)?$'), - ] - - -EmailAddress = Annotated[ - EmailStr, - Field( - description='An email address as defined by RFC 5322 Section 3.4.1.', - title='Email Address'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + ), ] @@ -796,7 +821,8 @@ class TelephoneNumber(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) type: Annotated[ StringDatatype | TelephoneNumberType | None, Field(description='Indicates the type of phone number.', title='type flag'), @@ -805,7 +831,8 @@ class TelephoneNumber(OscalBaseModel): str, Field( description='A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+', - pattern='^\\S(.*\\S)?$'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + ), ] @@ -813,8 +840,9 @@ class TelephoneNumber(OscalBaseModel): str, Field( description='A single line of an address.', - pattern='^\\S(.*\\S)?$', - title='Address line'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Address line', + ), ] @@ -824,18 +852,21 @@ class DocumentId(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) scheme: Annotated[ - URIDatatype | DocumentIdScheme | None, + DocumentIdScheme | OscalUri | None, Field( description='Qualifies the kind of document identifier using a URI. If the scheme is not provided the value of the element will be interpreted as a string of characters.', - title='Document Identification Scheme'), + title='Document Identification Scheme', + ), ] = None identifier: Annotated[ str, Field( description='A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+', -), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + ), ] @@ -845,7 +876,8 @@ class QualifierItem(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) subject: Annotated[ QualifierItemSubject, Field(description='The focus of the qualifier.', title='Subject'), @@ -854,25 +886,29 @@ class QualifierItem(OscalBaseModel): QualifierItemPredicate, Field( description='The predicate describes how the qualifer applies to the subject.', - title='Predicate'), + title='Predicate', + ), ] category: Annotated[ QualifierItemCategory, Field( description='The category expresses the resolvable nature of the predicate.', - title='Category'), + title='Category', + ), ] description: Annotated[ str, Field( description='Details that outline what requirements must be met, or cannot be met. If the qualifier identifies a gap, this should idenfity the gap, and any incompatibilities.', - title='Description of the qualifier'), + title='Description of the qualifier', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -882,12 +918,14 @@ class ConfidenceScoreWithCategory(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) category: Annotated[ str | None, Field( description='A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+', - pattern='^\\S(.*\\S)?$'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + ), ] = None @@ -897,20 +935,22 @@ class Coverage(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) generation_method: Annotated[ StringDatatype | CoverageGenerationMethod | None, Field( alias='generation-method', description='The method used to determine the coverage value.', - title='Coverage Generation Method'), + title='Coverage Generation Method', + ), ] = None target_coverage: Annotated[ float, Field( alias='target-coverage', description='A real number expressed using a whole and optional fractional part separated by a period.', -), + ), ] @@ -920,19 +960,22 @@ class MergeWithAsIs(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) combine: Annotated[ MergeCombine | None, Field( description='A Combine element defines how to resolve duplicate instances of the same control (e.g., controls with the same ID).', - title='Combination Rule'), + title='Combination Rule', + ), ] = None as_is: Annotated[ bool, Field( alias='as-is', description='Indicates that the controls selected should retain their original grouping as defined in the import source.', - title='Group As-Is'), + title='Group As-Is', + ), ] @@ -942,14 +985,16 @@ class ModifyAlterRemove(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) by_name: Annotated[ str | None, Field( alias='by-name', description='Identify items remove by matching their assigned name.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Reference by (assigned) name'), + title='Reference by (assigned) name', + ), ] = None by_class: Annotated[ str | None, @@ -957,7 +1002,8 @@ class ModifyAlterRemove(OscalBaseModel): alias='by-class', description='Identify items to remove by matching their class.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Reference by class'), + title='Reference by class', + ), ] = None by_id: Annotated[ str | None, @@ -965,27 +1011,31 @@ class ModifyAlterRemove(OscalBaseModel): alias='by-id', description='Identify items to remove indicated by their id.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Reference by ID'), + title='Reference by ID', + ), ] = None by_item_name: Annotated[ ModifyAlterRemoveByItemName | None, Field( alias='by-item-name', description="Identify items to remove by the name of the item's information object name, e.g. prop or link.", - title='Item Name Reference'), + title='Item Name Reference', + ), ] = None by_ns: Annotated[ - AnyUrl | None, + OscalUri | None, Field( alias='by-ns', description="Identify items to remove by the item's ns, which is the namespace associated with a part, or prop.", - title='Item Namespace Reference'), + title='Item Namespace Reference', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -995,18 +1045,21 @@ class ImportComponentDefinition(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str, + OscalUriReference, Field( description='A link to a resource that defines a set of components and/or capabilities to import into this collection.', - title='Hyperlink Reference'), + title='Hyperlink Reference', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1016,20 +1069,23 @@ class IncorporatesComponent(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) component_uuid: Annotated[ str, Field( alias='component-uuid', description='A machine-oriented identifier reference to a component.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Component Reference'), + title='Component Reference', + ), ] description: Annotated[ str, Field( description='A description of the component, including information about its function.', - title='Component Description'), + title='Component Description', + ), ] @@ -1039,7 +1095,8 @@ class SystemComponentStatus(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) state: Annotated[ SystemComponentStatusState, Field(description='The operational status.', title='State'), @@ -1048,7 +1105,8 @@ class SystemComponentStatus(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1058,20 +1116,23 @@ class PortRange(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) start: Annotated[ int | None, Field( description='Indicates the starting port number in a port range for a transport layer protocol', ge=0, - title='Start'), + title='Start', + ), ] = None end: Annotated[ int | None, Field( description='Indicates the ending port number in a port range for a transport layer protocol', ge=0, - title='End'), + title='End', + ), ] = None transport: Annotated[ PortRangeTransport | None, @@ -1081,7 +1142,8 @@ class PortRange(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1091,18 +1153,21 @@ class ImplementationStatus(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) state: Annotated[ TokenDatatype | ImplementationStatusState, Field( description='Identifies the implementation status of the control or control objective.', - title='Implementation State'), + title='Implementation State', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1110,8 +1175,9 @@ class ImplementationStatus(OscalBaseModel): str, Field( description='Describes a function performed for a given authorized privilege by this user class.', - pattern='^\\S(.*\\S)?$', - title='Functions Performed'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Functions Performed', + ), ] @@ -1121,21 +1187,24 @@ class SetParameter(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) param_id: Annotated[ str, Field( alias='param-id', description="A human-oriented reference to a parameter within a control, who's catalog has been imported into the current implementation context.", - - title='Parameter ID'), + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', + title='Parameter ID', + ), ] values: Annotated[list[StringDatatype], Field(min_length=1)] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1145,19 +1214,22 @@ class SystemId(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) identifier_type: Annotated[ - URIDatatype | SystemIdIdentifierType | None, + SystemIdIdentifierType | OscalUri | None, Field( alias='identifier-type', description='Identifies the identification system from which the provided identifier was assigned.', - title='Identification System Type'), + title='Identification System Type', + ), ] = None id: Annotated[ str, Field( description='A non-empty string with leading and trailing whitespace disallowed. Whitespace is: U+9, U+10, U+32 or [ \n\t]+', - pattern='^\\S(.*\\S)?$'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + ), ] @@ -1167,18 +1239,21 @@ class ImportProfile(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str, + OscalUriReference, Field( description="A resolvable URL reference to the profile or catalog to use as the system's control baseline.", - title='Profile Reference'), + title='Profile Reference', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1188,12 +1263,14 @@ class InformationTypeCategorization(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) system: Annotated[ - URIDatatype | InformationTypeCategorizationSystem, + InformationTypeCategorizationSystem | OscalUri, Field( description='Specifies the information type identification system used.', - title='Information Type Identification System'), + title='Information Type Identification System', + ), ] information_type_ids: Annotated[ list[StringDatatype] | None, Field(alias='information-type-ids', min_length=1) @@ -1206,30 +1283,34 @@ class SecurityImpactLevel(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) security_objective_confidentiality: Annotated[ str, Field( alias='security-objective-confidentiality', description='A target-level of confidentiality for the system, based on the sensitivity of information within the system.', - pattern='^\\S(.*\\S)?$', - title='Security Objective: Confidentiality'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Security Objective: Confidentiality', + ), ] security_objective_integrity: Annotated[ str, Field( alias='security-objective-integrity', description='A target-level of integrity for the system, based on the sensitivity of information within the system.', - - title='Security Objective: Integrity'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Security Objective: Integrity', + ), ] security_objective_availability: Annotated[ str, Field( alias='security-objective-availability', description='A target-level of availability for the system, based on the sensitivity of information within the system.', - - title='Security Objective: Availability'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Security Objective: Availability', + ), ] @@ -1239,7 +1320,8 @@ class Status(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) state: Annotated[ StatusState, Field(description='The current operating status.', title='State') ] @@ -1247,7 +1329,8 @@ class Status(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1257,18 +1340,21 @@ class ImportSsp(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str, + OscalUriReference, Field( description='A resolvable URL reference to the system security plan for the system being assessed.', - title='System Security Plan Reference'), + title='System Security Plan Reference', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1278,20 +1364,23 @@ class TaskDependency(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) task_uuid: Annotated[ str, Field( alias='task-uuid', description='A machine-oriented identifier reference to a unique task.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Task Universally Unique Identifier Reference'), + title='Task Universally Unique Identifier Reference', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1301,13 +1390,15 @@ class TaskTimingAtFrequency(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) period: Annotated[ int, Field( description='The task must occur after the specified period has elapsed.', ge=1, - title='Period'), + title='Period', + ), ] unit: Annotated[ TaskTimingAtFrequencyUnit, @@ -1317,7 +1408,8 @@ class TaskTimingAtFrequency(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1327,26 +1419,28 @@ class TaskTimingDateRange(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) start: Annotated[ - AwareDatetime, + OscalDateTimeWithTimezone, Field( description='The task must occur on or after the specified date.', - - title='Start Date Condition'), + title='Start Date Condition', + ), ] end: Annotated[ - AwareDatetime, + OscalDateTimeWithTimezone, Field( description='The task must occur on or before the specified date.', - - title='End Date Condition'), + title='End Date Condition', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1356,19 +1450,21 @@ class TaskTimingOnDate(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) date: Annotated[ - AwareDatetime, + OscalDateTimeWithTimezone, Field( description='The task must occur on the specified date.', - - title='On Date Condition'), + title='On Date Condition', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1378,13 +1474,15 @@ class TaskTimingWithAtFrequency(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) at_frequency: Annotated[ TaskTimingAtFrequency, Field( alias='at-frequency', description='The task is intended to occur at the specified frequency.', - title='Frequency Condition'), + title='Frequency Condition', + ), ] @@ -1394,13 +1492,15 @@ class TaskTimingWithDateRange(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) within_date_range: Annotated[ TaskTimingDateRange, Field( alias='within-date-range', description='The task is intended to occur within the specified date range.', - title='On Date Range Condition'), + title='On Date Range Condition', + ), ] @@ -1410,13 +1510,15 @@ class TaskTimingWithOnDate(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) on_date: Annotated[ TaskTimingOnDate, Field( alias='on-date', description='The task is intended to occur on the specified date.', - title='On Date Condition'), + title='On Date Condition', + ), ] @@ -1433,14 +1535,16 @@ class AssessmentCommonSelectControlById(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) control_id: Annotated[ str, Field( alias='control-id', description='A reference to a control with a corresponding id value. When referencing an externally defined control, the Control Identifier Reference must be used in the context of the external / imported OSCAL instance (e.g., uri-reference).', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Identifier Reference'), + title='Control Identifier Reference', + ), ] statement_ids: Annotated[ list[TokenDatatype] | None, Field(alias='statement-ids', min_length=1) @@ -1453,20 +1557,23 @@ class SelectObjectiveById(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) objective_id: Annotated[ str, Field( alias='objective-id', description='Points to an assessment objective.', - - title='Objective ID'), + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', + title='Objective ID', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1476,20 +1583,23 @@ class AssessmentSubjectPlaceholderSource(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) task_uuid: Annotated[ str, Field( alias='task-uuid', description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference (in this or other OSCAL instances) an assessment activity to be performed as part of the event. The locally defined UUID of the task can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Task Universally Unique Identifier'), + title='Task Universally Unique Identifier', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1499,24 +1609,28 @@ class FindingTargetStatus(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) state: Annotated[ FindingTargetStatusState, Field( description='An indication as to whether the objective is satisfied or not.', - title='Objective Status State'), + title='Objective Status State', + ), ] reason: Annotated[ TokenDatatype | FindingTargetStatusReason | None, Field( description="The reason the objective was given it's status.", - title='Objective Status Reason'), + title='Objective Status Reason', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1526,20 +1640,23 @@ class RelatedObservation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) observation_uuid: Annotated[ str, Field( alias='observation-uuid', description='A machine-oriented identifier reference to an observation defined in the list of observations.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Observation Universally Unique Identifier Reference'), + title='Observation Universally Unique Identifier Reference', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1549,20 +1666,23 @@ class AssociatedRisk(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) risk_uuid: Annotated[ str, Field( alias='risk-uuid', description='A machine-oriented identifier reference to a risk defined in the list of risks.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Risk Universally Unique Identifier Reference'), + title='Risk Universally Unique Identifier Reference', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1572,21 +1692,24 @@ class ThreatId(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) system: Annotated[ - URIDatatype | ThreatIdSystem, + ThreatIdSystem | OscalUri, Field( description='Specifies the source of the threat information.', - title='Threat Type Identification System'), + title='Threat Type Identification System', + ), ] href: Annotated[ - str | None, + OscalUriReference | None, Field( description='An optional location for the threat data, from which this ID originates.', - title='Threat Information Resource Reference'), + title='Threat Information Resource Reference', + ), ] = None id: Annotated[ - AnyUrl, + OscalUri, Field( description='A universal resource identifier (URI) formatted according to RFC3986.' ), @@ -1599,28 +1722,32 @@ class LoggedBy(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) party_uuid: Annotated[ str, Field( alias='party-uuid', description='A machine-oriented identifier reference to the party who is making the log entry.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Party UUID Reference'), + title='Party UUID Reference', + ), ] role_id: Annotated[ str | None, Field( alias='role-id', description='A point to the role-id of the role in which the party is making the log entry.', - - title='Actor Role'), + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', + title='Actor Role', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1630,18 +1757,21 @@ class ImportAp(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str, + OscalUriReference, Field( description='A resolvable URL reference to the assessment plan governing the assessment activities.', - title='Assessment Plan Reference'), + title='Assessment Plan Reference', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1651,20 +1781,23 @@ class PoamItemRelatedFinding(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) finding_uuid: Annotated[ str, Field( alias='finding-uuid', description='A machine-oriented identifier reference to a finding defined in the list of findings.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Finding Universally Unique Identifier Reference'), + title='Finding Universally Unique Identifier Reference', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1674,19 +1807,22 @@ class ParameterConstraintTest(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) expression: Annotated[ str, Field( description='A formal (executable) expression of a constraint.', - - title='Constraint test'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Constraint test', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1696,19 +1832,22 @@ class Matching(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) pattern: Annotated[ str | None, Field( description='A glob expression matching the IDs of one or more controls to be selected.', - pattern='^\\S(.*\\S)?$', - title='Pattern'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Pattern', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1718,13 +1857,15 @@ class ControlCommonSelectControlById(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) with_child_controls: Annotated[ ControlCommonSelectControlByIdChildControls | None, Field( alias='with-child-controls', description='When a control is included, whether its child (dependent) controls are also included.', - title='Include Contained Controls with Control'), + title='Include Contained Controls with Control', + ), ] = None with_ids: Annotated[ list[WithId] | None, @@ -1739,20 +1880,23 @@ class BackMatterResourceRlink(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str, + OscalUriReference, Field( description='A resolvable URL pointing to the referenced resource.', - title='Hypertext Reference'), + title='Hypertext Reference', + ), ] media_type: Annotated[ str | None, Field( alias='media-type', description='A label that indicates the nature of a resource, as a data serialization or format.', - - title='Media Type'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Media Type', + ), ] = None hashes: Annotated[list[Hash] | None, Field(min_length=1)] = None @@ -1763,33 +1907,38 @@ class Property(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) name: Annotated[ str, Field( description="A textual label, within a namespace, that identifies a specific attribute, characteristic, or quality of the property's containing object.", pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Property Name'), + title='Property Name', + ), ] uuid: Annotated[ str | None, Field( description='A unique identifier for a property.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Property Universally Unique Identifier'), + title='Property Universally Unique Identifier', + ), ] = None ns: Annotated[ - AnyUrl | None, + OscalUri | None, Field( description="A namespace qualifying the property's name. This allows different organizations to associate distinct semantics with the same name.", - title='Property Namespace'), + title='Property Namespace', + ), ] = None value: Annotated[ str, Field( description='Indicates the value of the attribute, characteristic, or quality.', - - title='Property Value'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Property Value', + ), ] class_: Annotated[ str | None, @@ -1797,20 +1946,23 @@ class Property(OscalBaseModel): alias='class', description="A textual label that provides a sub-type or characterization of the property's name.", pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Property Class'), + title='Property Class', + ), ] = None group: Annotated[ str | None, Field( description='An identifier for relating distinct sets of properties.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Property Group'), + title='Property Group', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1820,14 +1972,16 @@ class ResponsibleParty(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) role_id: Annotated[ str, Field( alias='role-id', description='A reference to a role performed by a party.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Responsible Role'), + title='Responsible Role', + ), ] party_uuids: Annotated[ list[PartyUuid], @@ -1839,7 +1993,8 @@ class ResponsibleParty(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1849,33 +2004,37 @@ class Action(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A unique identifier that can be used to reference this defined action elsewhere in an OSCAL document. A UUID should be consistently used for a given location across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Action Universally Unique Identifier'), + title='Action Universally Unique Identifier', + ), ] date: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( description='The date and time when the action occurred.', - - title='Action Occurrence Date'), + title='Action Occurrence Date', + ), ] = None type: Annotated[ str, Field( description='The type of action documented by the assembly, such as an approval.', - - title='Action Type'), + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', + title='Action Type', + ), ] system: Annotated[ - AnyUrl, + OscalUri, Field( description='Specifies the action type system used.', - title='Action Type System'), + title='Action Type System', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -1886,7 +2045,8 @@ class Action(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1896,14 +2056,16 @@ class ResponsibleRole(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) role_id: Annotated[ str, Field( alias='role-id', description='A human-oriented identifier reference to a role performed.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Responsible Role ID'), + title='Responsible Role ID', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -1915,7 +2077,8 @@ class ResponsibleRole(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -1925,7 +2088,8 @@ class Address(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) type: Annotated[ TokenDatatype | AddressType | None, Field(description='Indicates the type of address.', title='Address Type'), @@ -1938,30 +2102,34 @@ class Address(OscalBaseModel): str | None, Field( description='City, town or geographical region for the mailing address.', - pattern='^\\S(.*\\S)?$', - title='City'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='City', + ), ] = None state: Annotated[ str | None, Field( description='State, province or analogous geographical region for a mailing address.', - pattern='^\\S(.*\\S)?$', - title='State'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='State', + ), ] = None postal_code: Annotated[ str | None, Field( alias='postal-code', description='Postal or ZIP code for mailing address.', - pattern='^\\S(.*\\S)?$', - title='Postal Code'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Postal Code', + ), ] = None country: Annotated[ str | None, Field( description='The ISO 3166-1 alpha-2 country code for the mailing address.', - pattern='^\\S(.*\\S)?$', - title='Country Code'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Country Code', + ), ] = None @@ -1971,7 +2139,8 @@ class MappingItem(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) type: Annotated[ MappingItemType, Field(description='The semantic type of the subject.', title='Subject Type'), @@ -1981,8 +2150,9 @@ class MappingItem(OscalBaseModel): Field( alias='id-ref', description='A reference to an identified subject that is of the specified type .', - pattern='^\\S(.*\\S)?$', - title='Subject Identifier Reference'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Subject Identifier Reference', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -1990,7 +2160,8 @@ class MappingItem(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2000,22 +2171,25 @@ class MappingResourceReference(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) ns: Annotated[ - AnyUrl | None, + OscalUri | None, Field( description="An optional namespace qualifying the resource's type.", - title='Resource Type Namespace'), + title='Resource Type Namespace', + ), ] = None type: Annotated[ TokenDatatype | MappingResourceReferenceType, Field(description='The semantic type of the resource.', title='Resource Type'), ] href: Annotated[ - str, + OscalUriReference, Field( description='A resolvable URL reference to the base catalog or profile that this profile is tailoring.', - title='Catalog or Profile Reference'), + title='Catalog or Profile Reference', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2023,7 +2197,8 @@ class MappingResourceReference(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2033,13 +2208,15 @@ class GapSummary(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this mapping gap summary elsewhere in this or other OSCAL instances. The locally defined UUID of the SSP can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance).This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Gap Summary Universally Unique Identifier'), + title='Gap Summary Universally Unique Identifier', + ), ] unmapped_controls: Annotated[ list[ControlCommonSelectControlById], @@ -2053,13 +2230,14 @@ class ConfidenceScoreWithPercentage(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) percentage: Annotated[ float | None, Field( description='A decimal value from 0-1, representing a percentage.', - - title='Percentage'), + title='Percentage', + ), ] = None @@ -2072,12 +2250,14 @@ class ImportWithIncludeAll(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str | None, + OscalUriReference | None, Field( description='A resolvable URL reference to the base catalog or profile that this profile is tailoring.', - title='Catalog or Profile Reference'), + title='Catalog or Profile Reference', + ), ] = None include_all: Annotated[IncludeAll, Field(alias='include-all')] exclude_controls: Annotated[ @@ -2092,12 +2272,14 @@ class ImportWithIncludeControls(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str | None, + OscalUriReference | None, Field( description='A resolvable URL reference to the base catalog or profile that this profile is tailoring.', - title='Catalog or Profile Reference'), + title='Catalog or Profile Reference', + ), ] = None include_controls: Annotated[ list[ControlCommonSelectControlById], @@ -2118,12 +2300,14 @@ class InsertControlsWithIncludeAll(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) order: Annotated[ InsertControlsOrder | None, Field( description='A designation of how a selection of controls in a profile is to be ordered.', - title='Order'), + title='Order', + ), ] = None include_all: Annotated[IncludeAll, Field(alias='include-all')] exclude_controls: Annotated[ @@ -2138,12 +2322,14 @@ class InsertControlsWithIncludeControls(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) order: Annotated[ InsertControlsOrder | None, Field( description='A designation of how a selection of controls in a profile is to be ordered.', - title='Order'), + title='Order', + ), ] = None include_controls: Annotated[ list[ControlCommonSelectControlById], @@ -2167,27 +2353,31 @@ class ComponentDefinitionStatement(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) statement_id: Annotated[ str, Field( alias='statement-id', description='A human-oriented identifier reference to a control statement.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Statement Reference'), + title='Control Statement Reference', + ), ] uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this control statement elsewhere in this or other OSCAL instances. The UUID of the control statement in the source OSCAL instance is sufficient to reference the data item locally or globally (e.g., in an imported OSCAL instance).', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Control Statement Reference Universally Unique Identifier'), + title='Control Statement Reference Universally Unique Identifier', + ), ] description: Annotated[ str, Field( description='A summary of how the containing control statement is implemented by the component or capability.', - title='Statement Implementation Description'), + title='Statement Implementation Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2198,7 +2388,8 @@ class ComponentDefinitionStatement(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2208,27 +2399,31 @@ class Protocol(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str | None, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this service protocol information elsewhere in this or other OSCAL instances. The locally defined UUID of the service protocol can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Service Protocol Information Universally Unique Identifier'), + title='Service Protocol Information Universally Unique Identifier', + ), ] = None name: Annotated[ str | None, Field( description='The common name of the protocol, which should be the appropriate "service name" from the IANA Service Name and Transport Protocol Port Number Registry.', - pattern='^\\S(.*\\S)?$', - title='Protocol Name'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Protocol Name', + ), ] = None title: Annotated[ str | None, Field( description='A human readable name for the protocol (e.g., Transport Layer Security).', - pattern='^[^\n]+$', - title='Protocol Title'), + pattern='^[^\\n]+$', + title='Protocol Title', + ), ] = None port_ranges: Annotated[ list[PortRange] | None, Field(alias='port-ranges', min_length=1) @@ -2241,19 +2436,22 @@ class AuthorizedPrivilege(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) title: Annotated[ str, Field( description='A human readable name for the privilege.', - pattern='^[^\n]+$', - title='Privilege Title'), + pattern='^[^\\n]+$', + title='Privilege Title', + ), ] description: Annotated[ str | None, Field( description="A summary of the privilege's purpose within the system.", - title='Privilege Description'), + title='Privilege Description', + ), ] = None functions_performed: Annotated[ list[FunctionPerformed], @@ -2267,14 +2465,16 @@ class InventoryItemImplementedComponent(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) component_uuid: Annotated[ str, Field( alias='component-uuid', description='A machine-oriented identifier reference to a component that is implemented as part of an inventory item.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Component Universally Unique Identifier Reference'), + title='Component Universally Unique Identifier Reference', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2285,7 +2485,8 @@ class InventoryItemImplementedComponent(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2295,29 +2496,33 @@ class Impact(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None base: Annotated[ str, Field( description='The prescribed base (Confidentiality, Integrity, or Availability) security impact level.', - pattern='^\\S(.*\\S)?$', - title='Base Level (Confidentiality, Integrity, or Availability)'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Base Level (Confidentiality, Integrity, or Availability)', + ), ] selected: Annotated[ str | None, Field( description='The selected (Confidentiality, Integrity, or Availability) security impact level.', - pattern='^\\S(.*\\S)?$', - title='Selected Level (Confidentiality, Integrity, or Availability)'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Selected Level (Confidentiality, Integrity, or Availability)', + ), ] = None adjustment_justification: Annotated[ str | None, Field( alias='adjustment-justification', description='If the selected security level is different from the base security level, this contains the justification for the change.', - title='Adjustment Justification'), + title='Adjustment Justification', + ), ] = None @@ -2327,13 +2532,15 @@ class Diagram(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this diagram elsewhere in this or other OSCAL instances. The locally defined UUID of the diagram can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Diagram ID'), + title='Diagram ID', + ), ] description: Annotated[ str | None, @@ -2345,14 +2552,16 @@ class Diagram(OscalBaseModel): str | None, Field( description='A brief caption to annotate the diagram.', - pattern='^[^\n]+$', - title='Caption'), + pattern='^[^\\n]+$', + title='Caption', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2362,12 +2571,14 @@ class NetworkArchitecture(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str, Field( description="A summary of the system's network architecture.", - title='Network Architecture Description'), + title='Network Architecture Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2376,7 +2587,8 @@ class NetworkArchitecture(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2386,12 +2598,14 @@ class DataFlow(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str, Field( description="A summary of the system's data flow.", - title='Data Flow Description'), + title='Data Flow Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2400,7 +2614,8 @@ class DataFlow(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2410,20 +2625,23 @@ class SystemImplementationLeveragedAuthorization(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope and can be used to reference this leveraged authorization elsewhere in this or other OSCAL instances. The locally defined UUID of the leveraged authorization can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Leveraged Authorization Universally Unique Identifier'), + title='Leveraged Authorization Universally Unique Identifier', + ), ] title: Annotated[ str, Field( description='A human readable name for the leveraged authorization in the context of the system.', - pattern='^[^\n]+$', - title='title field'), + pattern='^[^\\n]+$', + title='title field', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2433,7 +2651,8 @@ class SystemImplementationLeveragedAuthorization(OscalBaseModel): alias='party-uuid', description='A machine-oriented identifier reference to the party that manages the leveraged system.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='party-uuid field'), + title='party-uuid field', + ), ] date_authorized: Annotated[ str, @@ -2441,13 +2660,15 @@ class SystemImplementationLeveragedAuthorization(OscalBaseModel): alias='date-authorized', description='The date the system received its authorization.', pattern='^(((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)|(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))|(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))|(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30)))(Z|(-((0[0-9]|1[0-2]):00|0[39]:30)|\\+((0[0-9]|1[0-4]):00|(0[34569]|10):30|(0[58]|12):45)))?$', - title='System Authorization Date'), + title='System Authorization Date', + ), ] remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2457,19 +2678,22 @@ class ByComponentExportProvided(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this provided entry elsewhere in this or other OSCAL instances. The locally defined UUID of the provided entry can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Provided Universally Unique Identifier'), + title='Provided Universally Unique Identifier', + ), ] description: Annotated[ str, Field( description='An implementation statement that describes the aspects of the control or control statement implementation that can be provided to another system leveraging this system.', - title='Provided Control Implementation Description'), + title='Provided Control Implementation Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2480,7 +2704,8 @@ class ByComponentExportProvided(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2490,13 +2715,15 @@ class ByComponentExportResponsibility(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this responsibility elsewhere in this or other OSCAL instances. The locally defined UUID of the responsibility can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Responsibility Universally Unique Identifier'), + title='Responsibility Universally Unique Identifier', + ), ] provided_uuid: Annotated[ str | None, @@ -2504,13 +2731,15 @@ class ByComponentExportResponsibility(OscalBaseModel): alias='provided-uuid', description='A machine-oriented identifier reference to an inherited control implementation that a leveraging system is inheriting from a leveraged system.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Provided UUID'), + title='Provided UUID', + ), ] = None description: Annotated[ str, Field( description='An implementation statement that describes the aspects of the control or control statement implementation that a leveraging system must implement to satisfy the control provided by a leveraged system.', - title='Control Implementation Responsibility Description'), + title='Control Implementation Responsibility Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2521,7 +2750,8 @@ class ByComponentExportResponsibility(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2531,13 +2761,15 @@ class ByComponentInherited(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this inherited entry elsewhere in this or other OSCAL instances. The locally defined UUID of the inherited control implementation can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Inherited Universally Unique Identifier'), + title='Inherited Universally Unique Identifier', + ), ] provided_uuid: Annotated[ str | None, @@ -2545,13 +2777,15 @@ class ByComponentInherited(OscalBaseModel): alias='provided-uuid', description='A machine-oriented identifier reference to an inherited control implementation that a leveraging system is inheriting from a leveraged system.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Provided UUID'), + title='Provided UUID', + ), ] = None description: Annotated[ str, Field( description='An implementation statement that describes the aspects of a control or control statement implementation that a leveraging system is inheriting from a leveraged system.', - title='Inherited Control Implementation Description'), + title='Inherited Control Implementation Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2566,13 +2800,15 @@ class ByComponentSatisfied(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this satisfied control implementation entry elsewhere in this or other OSCAL instances. The locally defined UUID of the control implementation can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Satisfied Universally Unique Identifier'), + title='Satisfied Universally Unique Identifier', + ), ] responsibility_uuid: Annotated[ str | None, @@ -2580,13 +2816,15 @@ class ByComponentSatisfied(OscalBaseModel): alias='responsibility-uuid', description='A machine-oriented identifier reference to a control implementation that satisfies a responsibility imposed by a leveraged system.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Responsibility UUID'), + title='Responsibility UUID', + ), ] = None description: Annotated[ str, Field( description='An implementation statement that describes the aspects of a control or control statement implementation that a leveraging system is implementing based on a requirement from a leveraged system.', - title='Satisfied Control Implementation Responsibility Description'), + title='Satisfied Control Implementation Responsibility Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2597,7 +2835,8 @@ class ByComponentSatisfied(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2607,12 +2846,14 @@ class ControlObjectiveSelectionWithIncludeAll(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str | None, Field( description='A human-readable description of this collection of control objectives.', - title='Control Objectives Description'), + title='Control Objectives Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2625,7 +2866,8 @@ class ControlObjectiveSelectionWithIncludeAll(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2635,12 +2877,14 @@ class ControlObjectiveSelectionWithIncludeObjectives(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str | None, Field( description='A human-readable description of this collection of control objectives.', - title='Control Objectives Description'), + title='Control Objectives Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2655,7 +2899,8 @@ class ControlObjectiveSelectionWithIncludeObjectives(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2671,12 +2916,14 @@ class ControlSelectionWithIncludeAll(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str | None, Field( description='A human-readable description of in-scope controls specified for assessment.', - title='Assessed Controls Description'), + title='Assessed Controls Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2689,7 +2936,8 @@ class ControlSelectionWithIncludeAll(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2699,12 +2947,14 @@ class ControlSelectionWithIncludeControls(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str | None, Field( description='A human-readable description of in-scope controls specified for assessment.', - title='Assessed Controls Description'), + title='Assessed Controls Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2720,7 +2970,8 @@ class ControlSelectionWithIncludeControls(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2736,19 +2987,22 @@ class AssessmentSubjectPlaceholder(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier for a set of assessment subjects that will be identified by a task or an activity that is part of a task. The locally defined UUID of the assessment subject placeholder can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Assessment Subject Placeholder Universally Unique Identifier'), + title='Assessment Subject Placeholder Universally Unique Identifier', + ), ] description: Annotated[ str | None, Field( description='A human-readable description of intent of this assessment subject placeholder.', - title='Assessment Subject Placeholder Description'), + title='Assessment Subject Placeholder Description', + ), ] = None sources: Annotated[list[AssessmentSubjectPlaceholderSource], Field(min_length=1)] props: Annotated[list[Property] | None, Field(min_length=1)] = None @@ -2757,7 +3011,8 @@ class AssessmentSubjectPlaceholder(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2767,20 +3022,23 @@ class SelectSubjectById(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) subject_uuid: Annotated[ str, Field( alias='subject-uuid', description="A machine-oriented identifier reference to a component, inventory-item, location, party, user, or resource using it's UUID.", pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Subject Universally Unique Identifier Reference'), + title='Subject Universally Unique Identifier Reference', + ), ] type: Annotated[ TokenDatatype | SubjectType, Field( description='Used to indicate the type of object pointed to by the uuid-ref within a subject.', - title='Subject Universally Unique Identifier Reference Type'), + title='Subject Universally Unique Identifier Reference Type', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2788,7 +3046,8 @@ class SelectSubjectById(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2798,27 +3057,31 @@ class SubjectReference(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) subject_uuid: Annotated[ str, Field( alias='subject-uuid', description="A machine-oriented identifier reference to a component, inventory-item, location, party, user, or resource using it's UUID.", pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Subject Universally Unique Identifier Reference'), + title='Subject Universally Unique Identifier Reference', + ), ] type: Annotated[ TokenDatatype | SubjectType, Field( description='Used to indicate the type of object pointed to by the uuid-ref within a subject.', - title='Subject Universally Unique Identifier Reference Type'), + title='Subject Universally Unique Identifier Reference Type', + ), ] title: Annotated[ str | None, Field( description='The title or name for the referenced subject.', - - title='Subject Reference Title'), + pattern='^[^\\n]+$', + title='Subject Reference Title', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2826,7 +3089,8 @@ class SubjectReference(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2836,14 +3100,16 @@ class AssessmentPlatformUsesComponent(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) component_uuid: Annotated[ str, Field( alias='component-uuid', description='A machine-oriented identifier reference to a component that is implemented as part of an inventory item.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Component Universally Unique Identifier Reference'), + title='Component Universally Unique Identifier Reference', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2854,7 +3120,8 @@ class AssessmentPlatformUsesComponent(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2864,12 +3131,14 @@ class FindingTarget(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) type: Annotated[ FindingTargetType, Field( description='Identifies the type of the target.', - title='Finding Target Type'), + title='Finding Target Type', + ), ] target_id: Annotated[ str, @@ -2877,20 +3146,23 @@ class FindingTarget(OscalBaseModel): alias='target-id', description='A machine-oriented identifier reference for a specific target qualified by the type.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Finding Target Identifier Reference'), + title='Finding Target Identifier Reference', + ), ] title: Annotated[ str | None, Field( description='The title for this objective status.', - pattern='^[^\n]+$', - title='Objective Status Title'), + pattern='^[^\\n]+$', + title='Objective Status Title', + ), ] = None description: Annotated[ str | None, Field( description="A human-readable description of the assessor's conclusions regarding the degree to which an objective is satisfied.", - title='Objective Status Description'), + title='Objective Status Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2898,7 +3170,8 @@ class FindingTarget(OscalBaseModel): FindingTargetStatus, Field( description='A determination of if the objective is satisfied or not within a given system.', - title='Objective Status'), + title='Objective Status', + ), ] implementation_status: Annotated[ ImplementationStatus | None, Field(alias='implementation-status') @@ -2907,7 +3180,8 @@ class FindingTarget(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2917,18 +3191,21 @@ class ObservationRelevantEvidence(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) href: Annotated[ - str | None, + OscalUriReference | None, Field( description='A resolvable URL reference to relevant evidence.', - title='Relevant Evidence Reference'), + title='Relevant Evidence Reference', + ), ] = None description: Annotated[ str, Field( description='A human-readable description of this evidence.', - title='Relevant Evidence Description'), + title='Relevant Evidence Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2936,7 +3213,8 @@ class ObservationRelevantEvidence(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -2946,7 +3224,8 @@ class OriginActor(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) type: Annotated[ OriginActorType, Field(description='The kind of actor.', title='Actor Type') ] @@ -2956,7 +3235,8 @@ class OriginActor(OscalBaseModel): alias='actor-uuid', description='A machine-oriented identifier reference to the tool or person based on the associated type.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Actor Universally Unique Identifier Reference'), + title='Actor Universally Unique Identifier Reference', + ), ] role_id: Annotated[ str | None, @@ -2964,7 +3244,8 @@ class OriginActor(OscalBaseModel): alias='role-id', description='For a party, this can optionally be used to specify the role the actor was performing.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Actor Role'), + title='Actor Role', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -2976,13 +3257,15 @@ class RiskMitigatingFactor(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this mitigating factor elsewhere in this or other OSCAL instances. The locally defined UUID of the mitigating factor can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Mitigating Factor Universally Unique Identifier'), + title='Mitigating Factor Universally Unique Identifier', + ), ] implementation_uuid: Annotated[ str | None, @@ -2990,13 +3273,15 @@ class RiskMitigatingFactor(OscalBaseModel): alias='implementation-uuid', description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this implementation statement elsewhere in this or other OSCAL instancess. The locally defined UUID of the implementation statement can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Implementation UUID'), + title='Implementation UUID', + ), ] = None description: Annotated[ str, Field( description='A human-readable description of this mitigating factor.', - title='Mitigating Factor Description'), + title='Mitigating Factor Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3009,26 +3294,30 @@ class CharacterizationFacet(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) name: Annotated[ str, Field( description='The name of the risk metric within the specified system.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Facet Name'), + title='Facet Name', + ), ] system: Annotated[ - URIDatatype | CharacterizationFacetSystem, + CharacterizationFacetSystem | OscalUri, Field( description='Specifies the naming system under which this risk metric is organized, which allows for the same names to be used in different systems controlled by different parties. This avoids the potential of a name clash.', - title='Naming System'), + title='Naming System', + ), ] value: Annotated[ str, Field( description='Indicates the value of the facet.', - pattern='^\\S(.*\\S)?$', - title='Facet Value'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Facet Value', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3036,7 +3325,8 @@ class CharacterizationFacet(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3046,27 +3336,31 @@ class ResponseRequiredAsset(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this required asset elsewhere in this or other OSCAL instances. The locally defined UUID of the asset can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Required Universally Unique Identifier'), + title='Required Universally Unique Identifier', + ), ] subjects: Annotated[list[SubjectReference] | None, Field(min_length=1)] = None title: Annotated[ str | None, Field( description='The title for this required asset.', - pattern='^[^\n]+$', - title='Title for Required Asset'), + pattern='^[^\\n]+$', + title='Title for Required Asset', + ), ] = None description: Annotated[ str, Field( description='A human-readable description of this required asset.', - title='Description of Required Asset'), + title='Description of Required Asset', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3074,7 +3368,8 @@ class ResponseRequiredAsset(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3084,47 +3379,54 @@ class AssessmentPart(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str | None, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this part elsewhere in this or other OSCAL instances. The locally defined UUID of the part can be used to reference the data item locally or globally (e.g., in an ported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Part Identifier'), + title='Part Identifier', + ), ] = None name: Annotated[ TokenDatatype | AssessmentPartName, Field( description="A textual label that uniquely identifies the part's semantic type.", - title='Part Name'), + title='Part Name', + ), ] ns: Annotated[ - AnyUrl | None, + OscalUri | None, Field( description="A namespace qualifying the part's name. This allows different organizations to associate distinct semantics with the same name.", - title='Part Namespace'), + title='Part Namespace', + ), ] = None class_: Annotated[ str | None, Field( alias='class', description="A textual label that provides a sub-type or characterization of the part's name. This can be used to further distinguish or discriminate between the semantics of multiple parts of the same control with the same name and ns.", - - title='Part Class'), + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', + title='Part Class', + ), ] = None title: Annotated[ str | None, Field( description='A name given to the part, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Part Title'), + pattern='^[^\\n]+$', + title='Part Title', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None prose: Annotated[ str | None, Field( description='Permits multiple paragraphs, lists, tables etc.', - title='Part Text'), + title='Part Text', + ), ] = None parts: Annotated[list[AssessmentPart] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3136,7 +3438,8 @@ class ResultAttestation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) responsible_parties: Annotated[ list[ResponsibleParty] | None, Field(alias='responsible-parties', min_length=1) ] = None @@ -3149,7 +3452,8 @@ class PoamItemOrigin(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) actors: Annotated[list[OriginActor], Field(min_length=1)] @@ -3159,48 +3463,55 @@ class Part(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str | None, Field( description='A unique identifier for the part.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Part Identifier'), + title='Part Identifier', + ), ] = None name: Annotated[ str, Field( description="A textual label that uniquely identifies the part's semantic type, which exists in a value space qualified by the ns.", pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Part Name'), + title='Part Name', + ), ] ns: Annotated[ - AnyUrl | None, + OscalUri | None, Field( description="An optional namespace qualifying the part's name. This allows different organizations to associate distinct semantics with the same name.", - title='Part Namespace'), + title='Part Namespace', + ), ] = None class_: Annotated[ str | None, Field( alias='class', description="An optional textual providing a sub-type or characterization of the part's name, or a category to which the part belongs.", - - title='Part Class'), + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', + title='Part Class', + ), ] = None title: Annotated[ str | None, Field( description='An optional name given to the part, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Part Title'), + pattern='^[^\\n]+$', + title='Part Title', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None prose: Annotated[ str | None, Field( description='Permits multiple paragraphs, lists, tables etc.', - title='Part Text'), + title='Part Text', + ), ] = None parts: Annotated[list[Part] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3212,12 +3523,14 @@ class ParameterConstraint(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str | None, Field( description='A textual summary of the constraint to be applied.', - title='Constraint Description'), + title='Constraint Description', + ), ] = None tests: Annotated[list[ParameterConstraintTest] | None, Field(min_length=1)] = None @@ -3228,37 +3541,40 @@ class MetadataLocation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A unique ID for the location, for reference.', - - title='Location Universally Unique Identifier'), + pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', + title='Location Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='A name given to the location, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Location Title'), + pattern='^[^\\n]+$', + title='Location Title', + ), ] = None address: Address | None = None email_addresses: Annotated[ - list[EmailAddress] | None, - Field(alias='email-addresses', min_length=1), + list[OscalEmailAddress] | None, Field(alias='email-addresses', min_length=1) ] = None telephone_numbers: Annotated[ list[TelephoneNumber] | None, Field(alias='telephone-numbers', min_length=1) ] = None - urls: Annotated[list[URIDatatype] | None, Field(min_length=1)] = None + urls: Annotated[list[OscalUri] | None, Field(min_length=1)] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3268,34 +3584,39 @@ class MetadataPartyWithAddresses(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str | None, Field( description='A unique identifier for the party.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Party Universally Unique Identifier'), + title='Party Universally Unique Identifier', + ), ] = None type: Annotated[ MetadataPartyType | None, Field( description='A category describing the kind of party the object describes.', - title='Party Type'), + title='Party Type', + ), ] = None name: Annotated[ str | None, Field( description='The full name of the party. This is typically the legal name associated with the party.', - pattern='^\\S(.*\\S)?$', - title='Party Name'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Party Name', + ), ] = None short_name: Annotated[ str | None, Field( alias='short-name', description='A short common name, abbreviation, or acronym for the party.', - pattern='^\\S(.*\\S)?$', - title='Party Short Name'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Party Short Name', + ), ] = None external_ids: Annotated[ list[MetadataPartyExternalId] | None, Field(alias='external-ids', min_length=1) @@ -3303,8 +3624,7 @@ class MetadataPartyWithAddresses(OscalBaseModel): props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None email_addresses: Annotated[ - list[EmailAddress] | None, - Field(alias='email-addresses', min_length=1), + list[OscalEmailAddress] | None, Field(alias='email-addresses', min_length=1) ] = None telephone_numbers: Annotated[ list[TelephoneNumber] | None, Field(alias='telephone-numbers', min_length=1) @@ -3317,7 +3637,8 @@ class MetadataPartyWithAddresses(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3327,34 +3648,39 @@ class MetadataPartyWithLocationUuids(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str | None, Field( description='A unique identifier for the party.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Party Universally Unique Identifier'), + title='Party Universally Unique Identifier', + ), ] = None type: Annotated[ MetadataPartyType | None, Field( description='A category describing the kind of party the object describes.', - title='Party Type'), + title='Party Type', + ), ] = None name: Annotated[ str | None, Field( description='The full name of the party. This is typically the legal name associated with the party.', - pattern='^\\S(.*\\S)?$', - title='Party Name'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Party Name', + ), ] = None short_name: Annotated[ str | None, Field( alias='short-name', description='A short common name, abbreviation, or acronym for the party.', - pattern='^\\S(.*\\S)?$', - title='Party Short Name'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Party Short Name', + ), ] = None external_ids: Annotated[ list[MetadataPartyExternalId] | None, Field(alias='external-ids', min_length=1) @@ -3362,8 +3688,7 @@ class MetadataPartyWithLocationUuids(OscalBaseModel): props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None email_addresses: Annotated[ - list[EmailAddress] | None, - Field(alias='email-addresses', min_length=1), + list[OscalEmailAddress] | None, Field(alias='email-addresses', min_length=1) ] = None telephone_numbers: Annotated[ list[TelephoneNumber] | None, Field(alias='telephone-numbers', min_length=1) @@ -3379,7 +3704,8 @@ class MetadataPartyWithLocationUuids(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3392,43 +3718,47 @@ class MetadataRevision(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) title: Annotated[ str | None, Field( description='A name given to the document revision, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Document Title'), + pattern='^[^\\n]+$', + title='Document Title', + ), ] = None published: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( description='The date and time the document was last made available.', - - title='Publication Timestamp'), + title='Publication Timestamp', + ), ] = None last_modified: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( alias='last-modified', description='The date and time the document was last stored for later retrieval.', - - title='Last Modified Timestamp'), + title='Last Modified Timestamp', + ), ] = None version: Annotated[ str, Field( description='Used to distinguish a specific revision of an OSCAL document from other previous and future versions.', - pattern='^\\S(.*\\S)?$', - title='Document Version'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Document Version', + ), ] oscal_version: Annotated[ str | None, Field( alias='oscal-version', description='The OSCAL model version the document was authored against and will conform to as valid.', - pattern='^\\S(.*\\S)?$', - title='OSCAL Version'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='OSCAL Version', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3436,7 +3766,8 @@ class MetadataRevision(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3446,34 +3777,39 @@ class MetadataRole(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str, Field( description='A unique identifier for the role.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Role Identifier'), + title='Role Identifier', + ), ] title: Annotated[ str, Field( description='A name given to the role, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Role Title'), + pattern='^[^\\n]+$', + title='Role Title', + ), ] short_name: Annotated[ str | None, Field( alias='short-name', description='A short common name, abbreviation, or acronym for the role.', - pattern='^\\S(.*\\S)?$', - title='Role Short Name'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Role Short Name', + ), ] = None description: Annotated[ str | None, Field( description="A summary of the role's purpose and associated responsibilities.", - title='Role Description'), + title='Role Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3481,7 +3817,8 @@ class MetadataRole(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3491,13 +3828,15 @@ class BackMatterResourceCitation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) text: Annotated[ str, Field( description='A line of citation text.', - pattern='^[^\n]+$', - title='Citation Text'), + pattern='^[^\\n]+$', + title='Citation Text', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3509,14 +3848,16 @@ class ModifySetParameterWithSelect(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) param_id: Annotated[ str | None, Field( alias='param-id', description='An identifier for the parameter.', - - title='Parameter ID'), + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', + title='Parameter ID', + ), ] = None class_: Annotated[ str | None, @@ -3524,7 +3865,8 @@ class ModifySetParameterWithSelect(OscalBaseModel): alias='class', description='A textual label that provides a characterization of the parameter.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Parameter Class'), + title='Parameter Class', + ), ] = None depends_on: Annotated[ str | None, @@ -3532,7 +3874,8 @@ class ModifySetParameterWithSelect(OscalBaseModel): alias='depends-on', description='**(deprecated)** Another parameter invoking this one. This construct has been deprecated and should not be used.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Depends On'), + title='Depends On', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3540,14 +3883,16 @@ class ModifySetParameterWithSelect(OscalBaseModel): str | None, Field( description='A short, placeholder name for the parameter, which can be used as a substitute for a value if no value is assigned.', - pattern='^[^\n]+$', - title='Parameter Label'), + pattern='^[^\\n]+$', + title='Parameter Label', + ), ] = None usage: Annotated[ str | None, Field( description='Describes the purpose and use of a parameter.', - title='Parameter Usage Description'), + title='Parameter Usage Description', + ), ] = None constraints: Annotated[list[ParameterConstraint] | None, Field(min_length=1)] = None guidelines: Annotated[list[ParameterGuideline] | None, Field(min_length=1)] = None @@ -3560,14 +3905,16 @@ class ModifySetParameterWithValues(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) param_id: Annotated[ str | None, Field( alias='param-id', description='An identifier for the parameter.', - - title='Parameter ID'), + pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', + title='Parameter ID', + ), ] = None class_: Annotated[ str | None, @@ -3575,7 +3922,8 @@ class ModifySetParameterWithValues(OscalBaseModel): alias='class', description='A textual label that provides a characterization of the parameter.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Parameter Class'), + title='Parameter Class', + ), ] = None depends_on: Annotated[ str | None, @@ -3583,7 +3931,8 @@ class ModifySetParameterWithValues(OscalBaseModel): alias='depends-on', description='**(deprecated)** Another parameter invoking this one. This construct has been deprecated and should not be used.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Depends On'), + title='Depends On', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3591,14 +3940,16 @@ class ModifySetParameterWithValues(OscalBaseModel): str | None, Field( description='A short, placeholder name for the parameter, which can be used as a substitute for a value if no value is assigned.', - pattern='^[^\n]+$', - title='Parameter Label'), + pattern='^[^\\n]+$', + title='Parameter Label', + ), ] = None usage: Annotated[ str | None, Field( description='Describes the purpose and use of a parameter.', - title='Parameter Usage Description'), + title='Parameter Usage Description', + ), ] = None constraints: Annotated[list[ParameterConstraint] | None, Field(min_length=1)] = None guidelines: Annotated[list[ParameterGuideline] | None, Field(min_length=1)] = None @@ -3619,13 +3970,15 @@ class ComponentDefinitionImplementedRequirement(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='Provides a globally unique means to identify a given control implementation by a component.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Control Implementation Identifier'), + title='Control Implementation Identifier', + ), ] control_id: Annotated[ str, @@ -3633,13 +3986,15 @@ class ComponentDefinitionImplementedRequirement(OscalBaseModel): alias='control-id', description='A reference to a control with a corresponding id value. When referencing an externally defined control, the Control Identifier Reference must be used in the context of the external / imported OSCAL instance (e.g., uri-reference).', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Identifier Reference'), + title='Control Identifier Reference', + ), ] description: Annotated[ str, Field( description='A suggestion from the supplier (e.g., component vendor or author) for how the specified control may be implemented if the containing component or capability is instantiated in a system security plan.', - title='Control Implementation Description'), + title='Control Implementation Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3656,7 +4011,8 @@ class ComponentDefinitionImplementedRequirement(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3666,39 +4022,45 @@ class SystemComponent(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this component elsewhere in this or other OSCAL instances. The locally defined UUID of the component can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Component Identifier'), + title='Component Identifier', + ), ] type: Annotated[ StringDatatype | SystemComponentType, Field( description='A category describing the purpose of the component.', - title='Component Type'), + title='Component Type', + ), ] title: Annotated[ str, Field( description='A human readable name for the system component.', - pattern='^[^\n]+$', - title='Component Title'), + pattern='^[^\\n]+$', + title='Component Title', + ), ] description: Annotated[ str, Field( description='A description of the component, including information about its function.', - title='Component Description'), + title='Component Description', + ), ] purpose: Annotated[ str | None, Field( description='A summary of the technological or business purpose of the component.', - pattern='^[^\n]+$', - title='Purpose'), + pattern='^[^\\n]+$', + title='Purpose', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3706,7 +4068,8 @@ class SystemComponent(OscalBaseModel): SystemComponentStatus, Field( description='Describes the operational status of the system component.', - title='Status'), + title='Status', + ), ] responsible_roles: Annotated[ list[ResponsibleRole] | None, Field(alias='responsible-roles', min_length=1) @@ -3716,7 +4079,8 @@ class SystemComponent(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3726,34 +4090,39 @@ class SystemUser(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this user class elsewhere in this or other OSCAL instances. The locally defined UUID of the system user can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', - - title='User Universally Unique Identifier'), + pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', + title='User Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='A name given to the user, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='User Title'), + pattern='^[^\\n]+$', + title='User Title', + ), ] = None short_name: Annotated[ str | None, Field( alias='short-name', description='A short common name, abbreviation, or acronym for the user.', - pattern='^\\S(.*\\S)?$', - title='User Short Name'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='User Short Name', + ), ] = None description: Annotated[ str | None, Field( description="A summary of the user's purpose within the system.", - title='User Description'), + title='User Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3769,7 +4138,8 @@ class SystemUser(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3779,19 +4149,22 @@ class InventoryItem(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this inventory item elsewhere in this or other OSCAL instances. The locally defined UUID of the inventory item can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Inventory Item Universally Unique Identifier'), + title='Inventory Item Universally Unique Identifier', + ), ] description: Annotated[ str, Field( description='A summary of the inventory item stating its purpose within the system.', - title='Inventory Item Description'), + title='Inventory Item Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3806,7 +4179,8 @@ class InventoryItem(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3816,26 +4190,30 @@ class InformationType(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str | None, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this information type elsewhere in this or other OSCAL instances. The locally defined UUID of the information type can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Information Type Universally Unique Identifier'), + title='Information Type Universally Unique Identifier', + ), ] = None title: Annotated[ str, Field( description='A human readable name for the information type. This title should be meaningful within the context of the system.', - pattern='^[^\n]+$', - title='title field'), + pattern='^[^\\n]+$', + title='title field', + ), ] description: Annotated[ str, Field( description='A summary of how this information type is used within the system.', - title='Information Type Description'), + title='Information Type Description', + ), ] categorizations: Annotated[ list[InformationTypeCategorization] | None, Field(min_length=1) @@ -3857,12 +4235,14 @@ class AuthorizationBoundary(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str, Field( description="A summary of the system's authorization boundary.", - title='Authorization Boundary Description'), + title='Authorization Boundary Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3871,7 +4251,8 @@ class AuthorizationBoundary(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3881,7 +4262,8 @@ class SystemImplementation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None leveraged_authorizations: Annotated[ @@ -3897,7 +4279,8 @@ class SystemImplementation(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3907,12 +4290,14 @@ class ByComponentExport(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str | None, Field( description='An implementation statement that describes the aspects of the control or control statement implementation that can be available to another system leveraging this system.', - title='Control Implementation Export Description'), + title='Control Implementation Export Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3926,7 +4311,8 @@ class ByComponentExport(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3936,7 +4322,8 @@ class AssessmentPlanTermsAndConditions(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) parts: Annotated[list[AssessmentPart] | None, Field(min_length=1)] = None @@ -3946,20 +4333,23 @@ class LocalObjective(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) control_id: Annotated[ str, Field( alias='control-id', description='A reference to a control with a corresponding id value. When referencing an externally defined control, the Control Identifier Reference must be used in the context of the external / imported OSCAL instance (e.g., uri-reference).', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Identifier Reference'), + title='Control Identifier Reference', + ), ] description: Annotated[ str | None, Field( description='A human-readable description of this control objective.', - title='Objective Description'), + title='Objective Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3968,7 +4358,8 @@ class LocalObjective(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -3978,19 +4369,22 @@ class AssessmentMethod(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this assessment method elsewhere in this or other OSCAL instances. The locally defined UUID of the assessment method can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Assessment Method Universally Unique Identifier'), + title='Assessment Method Universally Unique Identifier', + ), ] description: Annotated[ str | None, Field( description='A human-readable description of this assessment method.', - title='Assessment Method Description'), + title='Assessment Method Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -3999,7 +4393,8 @@ class AssessmentMethod(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4009,18 +4404,21 @@ class AssessmentSubjectWithIncludeAll(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) type: Annotated[ TokenDatatype | AssessmentSubjectType | None, Field( description='Indicates the type of assessment subject, such as a component, inventory, item, location, or party represented by this selection statement.', - title='Subject Type'), + title='Subject Type', + ), ] = None description: Annotated[ str | None, Field( description='A human-readable description of the collection of subjects being included in this assessment.', - title='Include Subjects Description'), + title='Include Subjects Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4032,7 +4430,8 @@ class AssessmentSubjectWithIncludeAll(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4042,18 +4441,21 @@ class AssessmentSubjectWithIncludeSubjects(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) type: Annotated[ TokenDatatype | AssessmentSubjectType | None, Field( description='Indicates the type of assessment subject, such as a component, inventory, item, location, or party represented by this selection statement.', - title='Subject Type'), + title='Subject Type', + ), ] = None description: Annotated[ str | None, Field( description='A human-readable description of the collection of subjects being included in this assessment.', - title='Include Subjects Description'), + title='Include Subjects Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4067,7 +4469,8 @@ class AssessmentSubjectWithIncludeSubjects(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4083,20 +4486,23 @@ class AssessmentPlatform(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this assessment platform elsewhere in this or other OSCAL instances. The locally defined UUID of the assessment platform can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Assessment Platform Universally Unique Identifier'), + title='Assessment Platform Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='The title or name for the assessment platform.', - pattern='^[^\n]+$', - title='Assessment Platform Title'), + pattern='^[^\\n]+$', + title='Assessment Platform Title', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4108,7 +4514,8 @@ class AssessmentPlatform(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4118,26 +4525,30 @@ class PoamItem(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str | None, Field( description='A machine-oriented, globally unique identifier with instance scope that can be used to reference this POA&M item entry in this OSCAL instance. This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='POA&M Item Universally Unique Identifier'), + title='POA&M Item Universally Unique Identifier', + ), ] = None title: Annotated[ str, Field( description='The title or name for this POA&M item .', - pattern='^[^\n]+$', - title='POA&M Item Title'), + pattern='^[^\\n]+$', + title='POA&M Item Title', + ), ] description: Annotated[ str, Field( description='A human-readable description of POA&M item.', - title='POA&M Item Description'), + title='POA&M Item Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4157,7 +4568,8 @@ class PoamItem(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4167,13 +4579,15 @@ class ParameterWithSelect(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str | None, Field( description='A unique identifier for the parameter.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Parameter Identifier'), + title='Parameter Identifier', + ), ] = None class_: Annotated[ str | None, @@ -4181,7 +4595,8 @@ class ParameterWithSelect(OscalBaseModel): alias='class', description='A textual label that provides a characterization of the type, purpose, use or scope of the parameter.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Parameter Class'), + title='Parameter Class', + ), ] = None depends_on: Annotated[ str | None, @@ -4189,7 +4604,8 @@ class ParameterWithSelect(OscalBaseModel): alias='depends-on', description='(deprecated) Another parameter invoking this one. This construct has been deprecated and should not be used.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Depends on'), + title='Depends on', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4197,14 +4613,16 @@ class ParameterWithSelect(OscalBaseModel): str | None, Field( description='A short, placeholder name for the parameter, which can be used as a substitute for a value if no value is assigned.', - pattern='^[^\n]+$', - title='Parameter Label'), + pattern='^[^\\n]+$', + title='Parameter Label', + ), ] = None usage: Annotated[ str | None, Field( description='Describes the purpose and use of a parameter.', - title='Parameter Usage Description'), + title='Parameter Usage Description', + ), ] = None constraints: Annotated[list[ParameterConstraint] | None, Field(min_length=1)] = None guidelines: Annotated[list[ParameterGuideline] | None, Field(min_length=1)] = None @@ -4213,7 +4631,8 @@ class ParameterWithSelect(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4223,13 +4642,15 @@ class ParameterWithValues(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str | None, Field( description='A unique identifier for the parameter.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Parameter Identifier'), + title='Parameter Identifier', + ), ] = None class_: Annotated[ str | None, @@ -4237,7 +4658,8 @@ class ParameterWithValues(OscalBaseModel): alias='class', description='A textual label that provides a characterization of the type, purpose, use or scope of the parameter.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Parameter Class'), + title='Parameter Class', + ), ] = None depends_on: Annotated[ str | None, @@ -4245,7 +4667,8 @@ class ParameterWithValues(OscalBaseModel): alias='depends-on', description='(deprecated) Another parameter invoking this one. This construct has been deprecated and should not be used.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Depends on'), + title='Depends on', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4253,14 +4676,16 @@ class ParameterWithValues(OscalBaseModel): str | None, Field( description='A short, placeholder name for the parameter, which can be used as a substitute for a value if no value is assigned.', - pattern='^[^\n]+$', - title='Parameter Label'), + pattern='^[^\\n]+$', + title='Parameter Label', + ), ] = None usage: Annotated[ str | None, Field( description='Describes the purpose and use of a parameter.', - title='Parameter Usage Description'), + title='Parameter Usage Description', + ), ] = None constraints: Annotated[list[ParameterConstraint] | None, Field(min_length=1)] = None guidelines: Annotated[list[ParameterGuideline] | None, Field(min_length=1)] = None @@ -4271,7 +4696,8 @@ class ParameterWithValues(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4284,26 +4710,30 @@ class BackMatterResource(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A unique identifier for a resource.', - - title='Resource Universally Unique Identifier'), + pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', + title='Resource Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='An optional name given to the resource, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Resource Title'), + pattern='^[^\\n]+$', + title='Resource Title', + ), ] = None description: Annotated[ str | None, Field( description='An optional short summary of the resource used to indicate the purpose of the resource.', - title='Resource Description'), + title='Resource Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None document_ids: Annotated[ @@ -4313,20 +4743,23 @@ class BackMatterResource(OscalBaseModel): BackMatterResourceCitation | None, Field( description='An optional citation consisting of end note text using structured markup.', - title='Citation'), + title='Citation', + ), ] = None rlinks: Annotated[list[BackMatterResourceRlink] | None, Field(min_length=1)] = None base64: Annotated[ BackMatterResourceBase64 | None, Field( description='A resource encoded using the Base64 alphabet defined by RFC 2045.', - title='Base64'), + title='Base64', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4336,33 +4769,38 @@ class Map(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='The unique identifier for the mapping entry.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Mapping Entry Identifier'), + title='Mapping Entry Identifier', + ), ] ns: Annotated[ - AnyUrl | None, + OscalUri | None, Field( description="A namespace qualifying the relationship's value. This allows different organizations to associate distinct semantics for relationships with the same name.", - title='Relationship Value Namespace'), + title='Relationship Value Namespace', + ), ] = None matching_rationale: Annotated[ MappingMatchingRationale | None, Field( alias='matching-rationale', description='The method used for relating controls within the mapping. The supported methods are aligned with the NIST Interagency Report (IR) 8477, Section 4.3 Set Theory Relationship Mapping.', - title='Matching'), + title='Matching', + ), ] = None relationship: Annotated[ str, Field( description='The relationship type for the mapping entry, which describes the relationship between the effective requirements of the specified source and target sets in the context of the matching-rationale method globaly defined in the provenance unless overwritten locally in the map. The relationship type and the matching-rationale must be used together. However, more than one matching-rationale method may apply to a source and target pair.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Mapping Entry Relationship'), + title='Mapping Entry Relationship', + ), ] sources: Annotated[list[MappingItem], Field(min_length=1)] targets: Annotated[list[MappingItem], Field(min_length=1)] @@ -4372,7 +4810,8 @@ class Map(OscalBaseModel): Field( alias='confidence-score', description="This records either a string category or a decimal value from 0-1 representing a percentage. Both of these values describe an estimation of the author's confidence that this mapping is correct and accurate.", - title='Confidence Score'), + title='Confidence Score', + ), ] = None coverage: Coverage | None = None props: Annotated[list[Property] | None, Field(min_length=1)] = None @@ -4381,7 +4820,8 @@ class Map(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4391,19 +4831,22 @@ class MappingProvenance(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) method: Annotated[ MappingMethod, Field( description='The method used to complete the overall mapping.', - title='Method'), + title='Method', + ), ] matching_rationale: Annotated[ MappingMatchingRationale, Field( alias='matching-rationale', description='The method used for relating controls within the mapping. The supported methods are aligned with the NIST Interagency Report (IR) 8477, Section 4.3 Set Theory Relationship Mapping.', - title='Matching'), + title='Matching', + ), ] status: Annotated[ MappingStatus, @@ -4416,7 +4859,8 @@ class MappingProvenance(OscalBaseModel): Field( alias='confidence-score', description="This records either a string category or a decimal value from 0-1 representing a percentage. Both of these values describe an estimation of the author's confidence that this mapping is correct and accurate.", - title='Confidence Score'), + title='Confidence Score', + ), ] = None coverage: Coverage | None = None mapping_description: Annotated[ @@ -4424,7 +4868,8 @@ class MappingProvenance(OscalBaseModel): Field( alias='mapping-description', description='Description of the context and intended use of the mapping set.', - title='Mapping Description'), + title='Mapping Description', + ), ] responsible_parties: Annotated[ list[ResponsibleParty] | None, Field(alias='responsible-parties', min_length=1) @@ -4435,7 +4880,8 @@ class MappingProvenance(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4445,25 +4891,29 @@ class ComponentDefinitionControlImplementation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='Provides a means to identify a set of control implementations that are supported by a given component or capability.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Control Implementation Set Identifier'), + title='Control Implementation Set Identifier', + ), ] source: Annotated[ - str, + OscalUriReference, Field( description='A reference to an OSCAL catalog or profile providing the referenced control or subcontrol definition.', - title='Source Resource Reference'), + title='Source Resource Reference', + ), ] description: Annotated[ str, Field( description='A description of how the specified set of controls are implemented for the containing component or capability.', - title='Control Implementation Description'), + title='Control Implementation Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4482,7 +4932,8 @@ class SystemInformation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None information_types: Annotated[ @@ -4496,27 +4947,31 @@ class ByComponent(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) component_uuid: Annotated[ str, Field( alias='component-uuid', description='A machine-oriented identifier reference to the component that is implementing a given control.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Component Universally Unique Identifier Reference'), + title='Component Universally Unique Identifier Reference', + ), ] uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this by-component entry elsewhere in this or other OSCAL instances. The locally defined UUID of the by-component entry can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='By-Component Universally Unique Identifier'), + title='By-Component Universally Unique Identifier', + ), ] description: Annotated[ str, Field( description='An implementation statement that describes how a control or a control statement is implemented within the referenced system component.', - title='Control Implementation Description'), + title='Control Implementation Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4530,7 +4985,8 @@ class ByComponent(OscalBaseModel): ByComponentExport | None, Field( description='Identifies content intended for external consumption, such as with leveraged organizations.', - title='Export'), + title='Export', + ), ] = None inherited: Annotated[list[ByComponentInherited] | None, Field(min_length=1)] = None satisfied: Annotated[list[ByComponentSatisfied] | None, Field(min_length=1)] = None @@ -4541,7 +4997,8 @@ class ByComponent(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4551,12 +5008,14 @@ class ReviewedControls(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str | None, Field( description='A human-readable description of control objectives.', - title='Control Objective Description'), + title='Control Objective Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4575,7 +5034,8 @@ class ReviewedControls(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4585,7 +5045,8 @@ class AssessmentAssets(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) components: Annotated[list[SystemComponent] | None, Field(min_length=1)] = None assessment_platforms: Annotated[ list[AssessmentPlatform], Field(alias='assessment-platforms', min_length=1) @@ -4598,14 +5059,16 @@ class RelatedTaskIdentifiedSubject(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) subject_placeholder_uuid: Annotated[ str, Field( alias='subject-placeholder-uuid', description='A machine-oriented identifier reference to a unique assessment subject placeholder defined by this task.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Assessment Subject Placeholder Universally Unique Identifier Reference'), + title='Assessment Subject Placeholder Universally Unique Identifier Reference', + ), ] subjects: Annotated[ list[Annotated[AssessmentSubject, Field(union_mode='left_to_right')]], @@ -4619,7 +5082,8 @@ class LocalDefinitions(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) components: Annotated[list[SystemComponent] | None, Field(min_length=1)] = None inventory_items: Annotated[ list[InventoryItem] | None, Field(alias='inventory-items', min_length=1) @@ -4631,7 +5095,8 @@ class LocalDefinitions(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4641,43 +5106,47 @@ class Metadata(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) title: Annotated[ str, Field( description='A name given to the document, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Document Title'), + pattern='^[^\\n]+$', + title='Document Title', + ), ] published: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( description='The date and time the document was last made available.', - - title='Publication Timestamp'), + title='Publication Timestamp', + ), ] = None last_modified: Annotated[ - AwareDatetime, + OscalDateTimeWithTimezone, Field( alias='last-modified', description='The date and time the document was last stored for later retrieval.', - - title='Last Modified Timestamp'), + title='Last Modified Timestamp', + ), ] version: Annotated[ str, Field( description='Used to distinguish a specific revision of an OSCAL document from other previous and future versions.', - pattern='^\\S(.*\\S)?$', - title='Document Version'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Document Version', + ), ] oscal_version: Annotated[ str, Field( alias='oscal-version', description='The OSCAL model version the document was authored against and will conform to as valid.', - pattern='^\\S(.*\\S)?$', - title='OSCAL Version'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='OSCAL Version', + ), ] revisions: Annotated[list[MetadataRevision] | None, Field(min_length=1)] = None document_ids: Annotated[ @@ -4699,7 +5168,8 @@ class Metadata(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4709,7 +5179,8 @@ class BackMatter(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) resources: Annotated[list[BackMatterResource] | None, Field(min_length=1)] = None @@ -4719,26 +5190,30 @@ class Mapping(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this mapping definition elsewhere in this or other OSCAL instances. The locally defined UUID of the mapping can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same mapping across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Mapping Universally Unique Identifier'), + title='Mapping Universally Unique Identifier', + ), ] method: Annotated[ MappingMethod | None, Field( description='The method used to complete the overall mapping.', - title='Method'), + title='Method', + ), ] = None matching_rationale: Annotated[ MappingMatchingRationale | None, Field( alias='matching-rationale', description='The method used for relating controls within the mapping. The supported methods are aligned with the NIST Interagency Report (IR) 8477, Section 4.3 Set Theory Relationship Mapping.', - title='Matching'), + title='Matching', + ), ] = None status: Annotated[ MappingStatus | None, @@ -4755,14 +5230,16 @@ class Mapping(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None mapping_description: Annotated[ str | None, Field( alias='mapping-description', description='Description of the context and intended use of the mapping set.', - title='Mapping Description'), + title='Mapping Description', + ), ] = None source_gap_summary: Annotated[ GapSummary | None, Field(alias='source-gap-summary') @@ -4775,7 +5252,8 @@ class Mapping(OscalBaseModel): Field( alias='confidence-score', description="This records either a string category or a decimal value from 0-1 representing a percentage. Both of these values describe an estimation of the author's confidence that this mapping is correct and accurate.", - title='Confidence Score'), + title='Confidence Score', + ), ] = None coverage: Coverage | None = None @@ -4786,13 +5264,15 @@ class ProfileGroupWithInsertControls(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str | None, Field( description='Identifies the group.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Group Identifier'), + title='Group Identifier', + ), ] = None class_: Annotated[ str | None, @@ -4800,14 +5280,16 @@ class ProfileGroupWithInsertControls(OscalBaseModel): alias='class', description='A textual label that provides a sub-type or characterization of the group.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Group Class'), + title='Group Class', + ), ] = None title: Annotated[ str, Field( description='A name to be given to the group for use in display.', - pattern='^[^\n]+$', - title='Group Title'), + pattern='^[^\\n]+$', + title='Group Title', + ), ] params: Annotated[ list[Annotated[Parameter, Field(union_mode='left_to_right')]] | None, Field(min_length=1) @@ -4827,12 +5309,14 @@ class ModifyAlterAdd(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) position: Annotated[ ModifyAlterAddPosition | None, Field( description='Where to add the new content with respect to the targeted element (beside it or inside it).', - title='Position'), + title='Position', + ), ] = None by_id: Annotated[ str | None, @@ -4840,14 +5324,16 @@ class ModifyAlterAdd(OscalBaseModel): alias='by-id', description='Target location of the addition.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Reference by ID'), + title='Reference by ID', + ), ] = None title: Annotated[ str | None, Field( description='A name given to the control, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Title Change'), + pattern='^[^\\n]+$', + title='Title Change', + ), ] = None params: Annotated[ list[Annotated[Parameter, Field(union_mode='left_to_right')]] | None, Field(min_length=1) @@ -4863,39 +5349,45 @@ class DefinedComponent(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='Provides a globally unique means to identify a given component.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Component Identifier'), + title='Component Identifier', + ), ] type: Annotated[ StringDatatype | DefinedComponentType, Field( description='A category describing the purpose of the component.', - title='Component Type'), + title='Component Type', + ), ] title: Annotated[ str, Field( description='A human readable name for the component.', - pattern='^[^\n]+$', - title='Component Title'), + pattern='^[^\\n]+$', + title='Component Title', + ), ] description: Annotated[ str, Field( description='A description of the component, including information about its function.', - title='Component Description'), + title='Component Description', + ), ] purpose: Annotated[ str | None, Field( description='A summary of the technological or business purpose of the component.', - pattern='^[^\n]+$', - title='Purpose'), + pattern='^[^\\n]+$', + title='Purpose', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -4911,7 +5403,8 @@ class DefinedComponent(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4921,20 +5414,23 @@ class Capability(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='Provides a globally unique means to identify a given capability.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Capability Identifier'), + title='Capability Identifier', + ), ] name: Annotated[ str, Field( description="The capability's human-readable name.", - pattern='^\\S(.*\\S)?$', - title='Capability Name'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Capability Name', + ), ] description: Annotated[ str, @@ -4956,7 +5452,8 @@ class Capability(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -4966,23 +5463,26 @@ class SystemCharacteristics(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) system_ids: Annotated[list[SystemId], Field(alias='system-ids', min_length=1)] system_name: Annotated[ str, Field( alias='system-name', description='The full name of the system.', - pattern='^\\S(.*\\S)?$', - title='System Name - Full'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='System Name - Full', + ), ] system_name_short: Annotated[ str | None, Field( alias='system-name-short', description='A short name for the system, such as an acronym, that is suitable for display in a data table or summary list.', - pattern='^\\S(.*\\S)?$', - title='System Name - Short'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='System Name - Short', + ), ] = None description: Annotated[ str, Field(description='A summary of the system.', title='System Description') @@ -4995,15 +5495,17 @@ class SystemCharacteristics(OscalBaseModel): alias='date-authorized', description='The date the system received its authorization.', pattern='^(((2000|2400|2800|(19|2[0-9](0[48]|[2468][048]|[13579][26])))-02-29)|(((19|2[0-9])[0-9]{2})-02-(0[1-9]|1[0-9]|2[0-8]))|(((19|2[0-9])[0-9]{2})-(0[13578]|10|12)-(0[1-9]|[12][0-9]|3[01]))|(((19|2[0-9])[0-9]{2})-(0[469]|11)-(0[1-9]|[12][0-9]|30)))(Z|(-((0[0-9]|1[0-2]):00|0[39]:30)|\\+((0[0-9]|1[0-4]):00|(0[34569]|10):30|(0[58]|12):45)))?$', - title='System Authorization Date'), + title='System Authorization Date', + ), ] = None security_sensitivity_level: Annotated[ str | None, Field( alias='security-sensitivity-level', description='The overall information system sensitivity categorization, such as defined by FIPS-199.', - pattern='^\\S(.*\\S)?$', - title='Security Sensitivity Level'), + pattern='^[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}]([^\\n\\r\\u{2028}\\u{2029}]*[^\\t\\n\\x0b\\x0c\\r \\u{a0}\\u{1680}\\u{2000}-\\u{200a}\\u{2028}\\u{2029}\\u{202f}\\u{205f}\\u{3000}\\u{feff}])?$', + title='Security Sensitivity Level', + ), ] = None system_information: Annotated[SystemInformation, Field(alias='system-information')] security_impact_level: Annotated[ @@ -5024,7 +5526,8 @@ class SystemCharacteristics(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5034,21 +5537,24 @@ class SspStatement(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) statement_id: Annotated[ str, Field( alias='statement-id', description='A human-oriented identifier reference to a control statement.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Statement Reference'), + title='Control Statement Reference', + ), ] uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this control statement elsewhere in this or other OSCAL instances. The UUID of the control statement in the source OSCAL instance is sufficient to reference the data item locally or globally (e.g., in an imported OSCAL instance).', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Control Statement Reference Universally Unique Identifier'), + title='Control Statement Reference Universally Unique Identifier', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5062,7 +5568,8 @@ class SspStatement(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5072,26 +5579,30 @@ class ActivityStep(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this step elsewhere in this or other OSCAL instances. The locally defined UUID of the step (in a series of steps) can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Step Universally Unique Identifier'), + title='Step Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='The title for this step.', - pattern='^[^\n]+$', - title='Step Title'), + pattern='^[^\\n]+$', + title='Step Title', + ), ] = None description: Annotated[ str, Field( description='A human-readable description of this step.', - title='Step Description'), + title='Step Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5105,7 +5616,8 @@ class ActivityStep(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5115,14 +5627,16 @@ class TaskAssociatedActivity(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) activity_uuid: Annotated[ str, Field( alias='activity-uuid', description='A machine-oriented identifier reference to an activity defined in the list of activities.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Activity Universally Unique Identifier Reference'), + title='Activity Universally Unique Identifier Reference', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5137,7 +5651,8 @@ class TaskAssociatedActivity(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5147,14 +5662,16 @@ class RelatedTask(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) task_uuid: Annotated[ str, Field( alias='task-uuid', description='A machine-oriented identifier reference to a unique task.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Task Universally Unique Identifier Reference'), + title='Task Universally Unique Identifier Reference', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5171,13 +5688,15 @@ class RelatedTask(OscalBaseModel): Field( alias='identified-subject', description='Used to detail assessment subjects that were identified by this task.', - title='Identified Subject'), + title='Identified Subject', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5187,14 +5706,16 @@ class RiskLogEntryRelatedResponse(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) response_uuid: Annotated[ str, Field( alias='response-uuid', description='A machine-oriented identifier reference to a unique risk response.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Response Universally Unique Identifier Reference'), + title='Response Universally Unique Identifier Reference', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5205,7 +5726,8 @@ class RiskLogEntryRelatedResponse(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5215,40 +5737,43 @@ class ResultAssessmentLogEntry(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference an assessment event in this or other OSCAL instances. The locally defined UUID of the assessment log entry can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Assessment Log Entry Universally Unique Identifier'), + title='Assessment Log Entry Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='The title for this event.', - pattern='^[^\n]+$', - title='Action Title'), + pattern='^[^\\n]+$', + title='Action Title', + ), ] = None description: Annotated[ str | None, Field( description='A human-readable description of this event.', - title='Action Description'), + title='Action Description', + ), ] = None start: Annotated[ - AwareDatetime, + OscalDateTimeWithTimezone, Field( - description='Identifies the start date and time of an event.', - - title='Start'), + description='Identifies the start date and time of an event.', title='Start' + ), ] end: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( description='Identifies the end date and time of an event. If the event is a point in time, the start and end will be the same date and time.', - - title='End'), + title='End', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5262,7 +5787,8 @@ class ResultAssessmentLogEntry(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5272,13 +5798,15 @@ class Control(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str, Field( description='Identifies a control such that it can be referenced in the defining catalog and other OSCAL instances (e.g., profiles).', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Identifier'), + title='Control Identifier', + ), ] class_: Annotated[ str | None, @@ -5286,14 +5814,16 @@ class Control(OscalBaseModel): alias='class', description='A textual label that provides a sub-type or characterization of the control.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Class'), + title='Control Class', + ), ] = None title: Annotated[ str, Field( description='A name given to the control, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Control Title'), + pattern='^[^\\n]+$', + title='Control Title', + ), ] params: Annotated[ list[Annotated[Parameter, Field(union_mode='left_to_right')]] | None, Field(min_length=1) @@ -5314,14 +5844,16 @@ class ModifyAlter(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) control_id: Annotated[ str, Field( alias='control-id', description='A reference to a control with a corresponding id value. When referencing an externally defined control, the Control Identifier Reference must be used in the context of the external / imported OSCAL instance (e.g., uri-reference).', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Identifier Reference'), + title='Control Identifier Reference', + ), ] removes: Annotated[list[ModifyAlterRemove] | None, Field(min_length=1)] = None adds: Annotated[list[ModifyAlterAdd] | None, Field(min_length=1)] = None @@ -5333,13 +5865,15 @@ class ComponentDefinition(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='Provides a globally unique means to identify a given component definition instance.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Component Definition Universally Unique Identifier'), + title='Component Definition Universally Unique Identifier', + ), ] metadata: Metadata import_component_definitions: Annotated[ @@ -5357,13 +5891,15 @@ class SspImplementedRequirement(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this control requirement elsewhere in this or other OSCAL instances. The locally defined UUID of the control requirement can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Control Requirement Universally Unique Identifier'), + title='Control Requirement Universally Unique Identifier', + ), ] control_id: Annotated[ str, @@ -5371,7 +5907,8 @@ class SspImplementedRequirement(OscalBaseModel): alias='control-id', description='A reference to a control with a corresponding id value. When referencing an externally defined control, the Control Identifier Reference must be used in the context of the external / imported OSCAL instance (e.g., uri-reference).', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Control Identifier Reference'), + title='Control Identifier Reference', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5389,7 +5926,8 @@ class SspImplementedRequirement(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5399,26 +5937,30 @@ class Activity(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this assessment activity elsewhere in this or other OSCAL instances. The locally defined UUID of the activity can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', - - title='Assessment Activity Universally Unique Identifier'), + pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', + title='Assessment Activity Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='The title for this included activity.', - pattern='^[^\n]+$', - title='Included Activity Title'), + pattern='^[^\\n]+$', + title='Included Activity Title', + ), ] = None description: Annotated[ str, Field( description='A human-readable description of this included activity.', - title='Included Activity Description'), + title='Included Activity Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5433,7 +5975,8 @@ class Activity(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5443,13 +5986,15 @@ class Task(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this task elsewhere in this or other OSCAL instances. The locally defined UUID of the task can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Task Universally Unique Identifier'), + title='Task Universally Unique Identifier', + ), ] type: Annotated[ TokenDatatype | TaskType, @@ -5459,14 +6004,16 @@ class Task(OscalBaseModel): str, Field( description='The title for this task.', - pattern='^[^\n]+$', - title='Task Title'), + pattern='^[^\\n]+$', + title='Task Title', + ), ] description: Annotated[ str | None, Field( description='A human-readable description of this task.', - title='Task Description'), + title='Task Description', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5474,7 +6021,8 @@ class Task(OscalBaseModel): Annotated[TaskTiming, Field(union_mode='left_to_right')] | None, Field( description='The timing under which the task is intended to occur.', - title='Event Timing'), + title='Event Timing', + ), ] = None dependencies: Annotated[list[TaskDependency] | None, Field(min_length=1)] = None tasks: Annotated[list[Task] | None, Field(min_length=1)] = None @@ -5494,7 +6042,8 @@ class Task(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5504,7 +6053,8 @@ class Origin(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) actors: Annotated[list[OriginActor], Field(min_length=1)] related_tasks: Annotated[ list[RelatedTask] | None, Field(alias='related-tasks', min_length=1) @@ -5517,40 +6067,44 @@ class RiskLogEntry(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this risk log entry elsewhere in this or other OSCAL instances. The locally defined UUID of the risk log entry can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Risk Log Entry Universally Unique Identifier'), + title='Risk Log Entry Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='The title for this risk log entry.', - pattern='^[^\n]+$', - title='Title'), + pattern='^[^\\n]+$', + title='Title', + ), ] = None description: Annotated[ str | None, Field( description='A human-readable description of what was done regarding the risk.', - title='Risk Task Description'), + title='Risk Task Description', + ), ] = None start: Annotated[ - AwareDatetime, + OscalDateTimeWithTimezone, Field( description='Identifies the start date and time of the event.', - - title='Start'), + title='Start', + ), ] end: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( description='Identifies the end date and time of the event. If the event is a point in time, the start and end will be the same date and time.', - - title='End'), + title='End', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5562,7 +6116,8 @@ class RiskLogEntry(OscalBaseModel): Field( alias='status-change', description='Describes the status of the associated risk.', - title='Risk Status'), + title='Risk Status', + ), ] = None related_responses: Annotated[ list[RiskLogEntryRelatedResponse] | None, @@ -5572,7 +6127,8 @@ class RiskLogEntry(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5582,7 +6138,8 @@ class Characterization(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None origin: Origin @@ -5595,32 +6152,37 @@ class Response(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this remediation elsewhere in this or other OSCAL instances. The locally defined UUID of the risk response can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Remediation Universally Unique Identifier'), + title='Remediation Universally Unique Identifier', + ), ] lifecycle: Annotated[ TokenDatatype | ResponseLifecycle, Field( description='Identifies whether this is a recommendation, such as from an assessor or tool, or an actual plan accepted by the system owner.', - title='Remediation Intent'), + title='Remediation Intent', + ), ] title: Annotated[ str, Field( description='The title for this response activity.', - pattern='^[^\n]+$', - title='Response Title'), + pattern='^[^\\n]+$', + title='Response Title', + ), ] description: Annotated[ str, Field( description='A human-readable description of this response plan.', - title='Response Description'), + title='Response Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5633,7 +6195,8 @@ class Response(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5643,7 +6206,8 @@ class AssessmentResultsLocalDefinitions(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) objectives_and_methods: Annotated[ list[LocalObjective] | None, Field(alias='objectives-and-methods', min_length=1) ] = None @@ -5652,7 +6216,8 @@ class AssessmentResultsLocalDefinitions(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5662,7 +6227,8 @@ class ResultAssessmentLog(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) entries: Annotated[list[ResultAssessmentLogEntry], Field(min_length=1)] @@ -5672,7 +6238,8 @@ class ResultLocalDefinitions(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) components: Annotated[list[SystemComponent] | None, Field(min_length=1)] = None inventory_items: Annotated[ list[InventoryItem] | None, Field(alias='inventory-items', min_length=1) @@ -5686,13 +6253,15 @@ class ResultLocalDefinitions(OscalBaseModel): class ComponentDefinitionDocument(OscalBaseModel): model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) field_schema: Annotated[ - str | None, + OscalUriReference | None, Field( alias='$schema', description='A JSON Schema directive to bind a specific schema to its document instance.', - title='Schema Directive'), + title='Schema Directive', + ), ] = None component_definition: Annotated[ ComponentDefinition, Field(alias='component-definition') @@ -5705,13 +6274,15 @@ class CatalogGroupWithControls(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str | None, Field( description='Identifies the group for the purpose of cross-linking within the defining instance or from other instances that reference the catalog.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Group Identifier'), + title='Group Identifier', + ), ] = None class_: Annotated[ str | None, @@ -5719,14 +6290,16 @@ class CatalogGroupWithControls(OscalBaseModel): alias='class', description='A textual label that provides a sub-type or characterization of the group.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Group Class'), + title='Group Class', + ), ] = None title: Annotated[ str, Field( description='A name given to the group, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Group Title'), + pattern='^[^\\n]+$', + title='Group Title', + ), ] params: Annotated[ list[Annotated[Parameter, Field(union_mode='left_to_right')]] | None, Field(min_length=1) @@ -5743,13 +6316,15 @@ class MappingCollection(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A globally unique identifier with cross-instance scope for this catalog instance. This UUID should be changed when this document is revised.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Mapping Collection Universally Unique Identifier'), + title='Mapping Collection Universally Unique Identifier', + ), ] metadata: Metadata provenance: MappingProvenance @@ -5763,7 +6338,8 @@ class Modify(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) set_parameters: Annotated[ list[Annotated[ModifySetParameter, Field(union_mode='left_to_right')]] | None, Field(alias='set-parameters', min_length=1), @@ -5777,12 +6353,14 @@ class SspControlImplementation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) description: Annotated[ str, Field( description='A statement describing important things to know about how this set of control satisfaction documentation is approached.', - title='Control Implementation Description'), + title='Control Implementation Description', + ), ] set_parameters: Annotated[ list[SetParameter] | None, Field(alias='set-parameters', min_length=1) @@ -5799,7 +6377,8 @@ class AssessmentPlanLocalDefinitions(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) components: Annotated[list[SystemComponent] | None, Field(min_length=1)] = None inventory_items: Annotated[ list[InventoryItem] | None, Field(alias='inventory-items', min_length=1) @@ -5813,7 +6392,8 @@ class AssessmentPlanLocalDefinitions(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5823,26 +6403,30 @@ class Finding(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this finding in this or other OSCAL instances. The locally defined UUID of the finding can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Finding Universally Unique Identifier'), + title='Finding Universally Unique Identifier', + ), ] title: Annotated[ str, Field( description='The title for this finding.', - pattern='^[^\n]+$', - title='Finding Title'), + pattern='^[^\\n]+$', + title='Finding Title', + ), ] description: Annotated[ str, Field( description='A human-readable description of this finding.', - title='Finding Description'), + title='Finding Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5854,7 +6438,8 @@ class Finding(OscalBaseModel): alias='implementation-statement-uuid', description='A machine-oriented identifier reference to the implementation statement in the SSP to which this finding is related.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Implementation Statement UUID'), + title='Implementation Statement UUID', + ), ] = None related_observations: Annotated[ list[RelatedObservation] | None, @@ -5867,7 +6452,8 @@ class Finding(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5877,26 +6463,30 @@ class Observation(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this observation elsewhere in this or other OSCAL instances. The locally defined UUID of the observation can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Observation Universally Unique Identifier'), + title='Observation Universally Unique Identifier', + ), ] title: Annotated[ str | None, Field( description='The title for this observation.', - pattern='^[^\n]+$', - title='Observation Title'), + pattern='^[^\\n]+$', + title='Observation Title', + ), ] = None description: Annotated[ str, Field( description='A human-readable description of this assessment observation.', - title='Observation Description'), + title='Observation Description', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -5911,24 +6501,25 @@ class Observation(OscalBaseModel): Field(alias='relevant-evidence', min_length=1), ] = None collected: Annotated[ - AwareDatetime, + OscalDateTimeWithTimezone, Field( description='Date/time stamp identifying when the finding information was collected.', - - title='Collected Field'), + title='Collected Field', + ), ] expires: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( description='Date/time identifying when the finding information is out-of-date and no longer valid. Typically used with continuous assessment scenarios.', - - title='Expires Field'), + title='Expires Field', + ), ] = None remarks: Annotated[ str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -5938,19 +6529,22 @@ class RiskLog(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) entries: Annotated[list[RiskLogEntry], Field(min_length=1)] class MappingCollectionDocument(OscalBaseModel): model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) field_schema: Annotated[ - str | None, + OscalUriReference | None, Field( alias='$schema', description='A JSON Schema directive to bind a specific schema to its document instance.', - title='Schema Directive'), + title='Schema Directive', + ), ] = None mapping_collection: Annotated[MappingCollection, Field(alias='mapping-collection')] @@ -5961,13 +6555,15 @@ class SystemSecurityPlan(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this system security plan (SSP) elsewhere in this or other OSCAL instances. The locally defined UUID of the SSP can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance).This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='System Security Plan Universally Unique Identifier'), + title='System Security Plan Universally Unique Identifier', + ), ] metadata: Metadata import_profile: Annotated[ImportProfile, Field(alias='import-profile')] @@ -5989,13 +6585,15 @@ class AssessmentPlan(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this assessment plan in this or other OSCAL instances. The locally defined UUID of the assessment plan can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Assessment Plan Universally Unique Identifier'), + title='Assessment Plan Universally Unique Identifier', + ), ] metadata: Metadata import_ssp: Annotated[ImportSsp, Field(alias='import-ssp')] @@ -6004,14 +6602,16 @@ class AssessmentPlan(OscalBaseModel): Field( alias='local-definitions', description='Used to define data objects that are used in the assessment plan, that do not appear in the referenced SSP.', - title='Local Definitions'), + title='Local Definitions', + ), ] = None terms_and_conditions: Annotated[ AssessmentPlanTermsAndConditions | None, Field( alias='terms-and-conditions', description='Used to define various terms and conditions under which an assessment, described by the plan, can be performed. Each child part defines a different type of term or condition.', - title='Assessment Plan Terms and Conditions'), + title='Assessment Plan Terms and Conditions', + ), ] = None reviewed_controls: Annotated[ReviewedControls, Field(alias='reviewed-controls')] assessment_subjects: Annotated[ @@ -6032,32 +6632,37 @@ class Risk(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this risk elsewhere in this or other OSCAL instances. The locally defined UUID of the risk can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Risk Universally Unique Identifier'), + title='Risk Universally Unique Identifier', + ), ] title: Annotated[ str, Field( description='The title for this risk.', - pattern='^[^\n]+$', - title='Risk Title'), + pattern='^[^\\n]+$', + title='Risk Title', + ), ] description: Annotated[ str, Field( description='A human-readable summary of the identified risk, to include a statement of how the risk impacts the system.', - title='Risk Description'), + title='Risk Description', + ), ] statement: Annotated[ str, Field( description='An summary of impact for how the risk affects the system.', - title='Risk Statement'), + title='Risk Statement', + ), ] props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -6065,7 +6670,8 @@ class Risk(OscalBaseModel): TokenDatatype | RiskStatus, Field( description='Describes the status of the associated risk.', - title='Risk Status'), + title='Risk Status', + ), ] origins: Annotated[list[Origin] | None, Field(min_length=1)] = None threat_ids: Annotated[ @@ -6079,11 +6685,11 @@ class Risk(OscalBaseModel): Field(alias='mitigating-factors', min_length=1), ] = None deadline: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( description='The date/time by which the risk must be resolved.', - - title='Risk Resolution Deadline'), + title='Risk Resolution Deadline', + ), ] = None remediations: Annotated[list[Response] | None, Field(min_length=1)] = None risk_log: Annotated[ @@ -6091,7 +6697,8 @@ class Risk(OscalBaseModel): Field( alias='risk-log', description='A log of all risk-related tasks taken.', - title='Risk Log'), + title='Risk Log', + ), ] = None related_observations: Annotated[ list[RelatedObservation] | None, @@ -6105,40 +6712,44 @@ class Result(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this set of results in this or other OSCAL instances. The locally defined UUID of the assessment result can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Results Universally Unique Identifier'), + title='Results Universally Unique Identifier', + ), ] title: Annotated[ str, Field( description='The title for this set of results.', - pattern='^[^\n]+$', - title='Results Title'), + pattern='^[^\\n]+$', + title='Results Title', + ), ] description: Annotated[ str, Field( description='A human-readable description of this set of test results.', - title='Results Description'), + title='Results Description', + ), ] start: Annotated[ - AwareDatetime, + OscalDateTimeWithTimezone, Field( description='Date/time stamp identifying the start of the evidence collection reflected in these results.', - - title='start field'), + title='start field', + ), ] end: Annotated[ - AwareDatetime | None, + OscalDateTimeWithTimezone | None, Field( description='Date/time stamp identifying the end of the evidence collection reflected in these results. In a continuous motoring scenario, this may contain the same value as start if appropriate.', - - title='end field'), + title='end field', + ), ] = None props: Annotated[list[Property] | None, Field(min_length=1)] = None links: Annotated[list[Link] | None, Field(min_length=1)] = None @@ -6147,7 +6758,8 @@ class Result(OscalBaseModel): Field( alias='local-definitions', description='Used to define data objects that are used in the assessment plan, that do not appear in the referenced SSP.', - title='Local Definitions'), + title='Local Definitions', + ), ] = None reviewed_controls: Annotated[ReviewedControls, Field(alias='reviewed-controls')] attestations: Annotated[list[ResultAttestation] | None, Field(min_length=1)] = None @@ -6156,7 +6768,8 @@ class Result(OscalBaseModel): Field( alias='assessment-log', description='A log of all assessment-related actions taken.', - title='Assessment Log'), + title='Assessment Log', + ), ] = None observations: Annotated[list[Observation] | None, Field(min_length=1)] = None risks: Annotated[list[Risk] | None, Field(min_length=1)] = None @@ -6165,7 +6778,8 @@ class Result(OscalBaseModel): str | None, Field( description='Additional commentary about the containing object.', - title='Remarks'), + title='Remarks', + ), ] = None @@ -6175,13 +6789,15 @@ class PlanOfActionAndMilestones(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with instancescope that can be used to reference this POA&M instance in this OSCAL instance. This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='POA&M Universally Unique Identifier'), + title='POA&M Universally Unique Identifier', + ), ] metadata: Metadata import_ssp: Annotated[ImportSsp | None, Field(alias='import-ssp')] = None @@ -6198,26 +6814,30 @@ class PlanOfActionAndMilestones(OscalBaseModel): class AssessmentPlanDocument(OscalBaseModel): model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) field_schema: Annotated[ - str | None, + OscalUriReference | None, Field( alias='$schema', description='A JSON Schema directive to bind a specific schema to its document instance.', - title='Schema Directive'), + title='Schema Directive', + ), ] = None assessment_plan: Annotated[AssessmentPlan, Field(alias='assessment-plan')] class PlanOfActionAndMilestonesDocument(OscalBaseModel): model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) field_schema: Annotated[ - str | None, + OscalUriReference | None, Field( alias='$schema', description='A JSON Schema directive to bind a specific schema to its document instance.', - title='Schema Directive'), + title='Schema Directive', + ), ] = None plan_of_action_and_milestones: Annotated[ PlanOfActionAndMilestones, Field(alias='plan-of-action-and-milestones') @@ -6226,13 +6846,15 @@ class PlanOfActionAndMilestonesDocument(OscalBaseModel): class SystemSecurityPlanDocument(OscalBaseModel): model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) field_schema: Annotated[ - str | None, + OscalUriReference | None, Field( alias='$schema', description='A JSON Schema directive to bind a specific schema to its document instance.', - title='Schema Directive'), + title='Schema Directive', + ), ] = None system_security_plan: Annotated[ SystemSecurityPlan, Field(alias='system-security-plan') @@ -6245,13 +6867,15 @@ class AssessmentResults(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='A machine-oriented, globally unique identifier with cross-instance scope that can be used to reference this assessment results instance in this or other OSCAL instances. The locally defined UUID of the assessment result can be used to reference the data item locally or globally (e.g., in an imported OSCAL instance). This UUID should be assigned per-subject, which means it should be consistently used to identify the same subject across revisions of the document.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Assessment Results Universally Unique Identifier'), + title='Assessment Results Universally Unique Identifier', + ), ] metadata: Metadata import_ap: Annotated[ImportAp, Field(alias='import-ap')] @@ -6260,7 +6884,8 @@ class AssessmentResults(OscalBaseModel): Field( alias='local-definitions', description='Used to define data objects that are used in the assessment plan, that do not appear in the referenced SSP.', - title='Local Definitions'), + title='Local Definitions', + ), ] = None results: Annotated[list[Result], Field(min_length=1)] back_matter: Annotated[BackMatter | None, Field(alias='back-matter')] = None @@ -6268,13 +6893,15 @@ class AssessmentResults(OscalBaseModel): class AssessmentResultsDocument(OscalBaseModel): model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) field_schema: Annotated[ - str | None, + OscalUriReference | None, Field( alias='$schema', description='A JSON Schema directive to bind a specific schema to its document instance.', - title='Schema Directive'), + title='Schema Directive', + ), ] = None assessment_results: Annotated[AssessmentResults, Field(alias='assessment-results')] @@ -6285,13 +6912,15 @@ class Catalog(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='Provides a globally unique means to identify a given catalog instance.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Catalog Universally Unique Identifier'), + title='Catalog Universally Unique Identifier', + ), ] metadata: Metadata params: Annotated[ @@ -6311,13 +6940,15 @@ class CatalogGroupWithGroups(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str | None, Field( description='Identifies the group for the purpose of cross-linking within the defining instance or from other instances that reference the catalog.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Group Identifier'), + title='Group Identifier', + ), ] = None class_: Annotated[ str | None, @@ -6325,14 +6956,16 @@ class CatalogGroupWithGroups(OscalBaseModel): alias='class', description='A textual label that provides a sub-type or characterization of the group.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Group Class'), + title='Group Class', + ), ] = None title: Annotated[ str, Field( description='A name given to the group, which may be used by a tool for display and navigation.', - pattern='^[^\n]+$', - title='Group Title'), + pattern='^[^\\n]+$', + title='Group Title', + ), ] params: Annotated[ list[Annotated[Parameter, Field(union_mode='left_to_right')]] | None, Field(min_length=1) @@ -6355,13 +6988,15 @@ class Profile(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) uuid: Annotated[ str, Field( description='Provides a globally unique means to identify a given profile instance.', pattern='^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[45][0-9A-Fa-f]{3}-[89ABab][0-9A-Fa-f]{3}-[0-9A-Fa-f]{12}$', - title='Profile Universally Unique Identifier'), + title='Profile Universally Unique Identifier', + ), ] metadata: Metadata imports: Annotated[ @@ -6371,7 +7006,8 @@ class Profile(OscalBaseModel): Annotated[Merge, Field(union_mode='left_to_right')] | None, Field( description='Provides structuring directives that instruct how controls are organized after profile resolution.', - title='Merge Controls'), + title='Merge Controls', + ), ] = None modify: Modify | None = None back_matter: Annotated[BackMatter | None, Field(alias='back-matter')] = None @@ -6383,7 +7019,8 @@ class MergeCustom(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) groups: Annotated[ list[Annotated[ProfileGroup, Field(union_mode='left_to_right')]] | None, Field(min_length=1), @@ -6400,18 +7037,21 @@ class MergeWithCustom(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) combine: Annotated[ MergeCombine | None, Field( description='A Combine element defines how to resolve duplicate instances of the same control (e.g., controls with the same ID).', - title='Combination Rule'), + title='Combination Rule', + ), ] = None custom: Annotated[ MergeCustom, Field( description='Provides an alternate grouping structure that selected controls will be placed in.', - title='Custom Grouping'), + title='Custom Grouping', + ), ] @@ -6424,13 +7064,15 @@ class ProfileGroupWithGroups(OscalBaseModel): """ model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) id: Annotated[ str | None, Field( description='Identifies the group.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Group Identifier'), + title='Group Identifier', + ), ] = None class_: Annotated[ str | None, @@ -6438,14 +7080,16 @@ class ProfileGroupWithGroups(OscalBaseModel): alias='class', description='A textual label that provides a sub-type or characterization of the group.', pattern='^(\\p{L}|_)(\\p{L}|\\p{N}|[.\\-_])*$', - title='Group Class'), + title='Group Class', + ), ] = None title: Annotated[ str, Field( description='A name to be given to the group for use in display.', - pattern='^[^\n]+$', - title='Group Title'), + pattern='^[^\\n]+$', + title='Group Title', + ), ] params: Annotated[ list[Annotated[Parameter, Field(union_mode='left_to_right')]] | None, Field(min_length=1) @@ -6464,26 +7108,30 @@ class ProfileGroupWithGroups(OscalBaseModel): class CatalogDocument(OscalBaseModel): model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) field_schema: Annotated[ - str | None, + OscalUriReference | None, Field( alias='$schema', description='A JSON Schema directive to bind a specific schema to its document instance.', - title='Schema Directive'), + title='Schema Directive', + ), ] = None catalog: Catalog class ProfileDocument(OscalBaseModel): model_config = ConfigDict( - extra='forbid') + extra='forbid', + ) field_schema: Annotated[ - str | None, + OscalUriReference | None, Field( alias='$schema', description='A JSON Schema directive to bind a specific schema to its document instance.', - title='Schema Directive'), + title='Schema Directive', + ), ] = None profile: Profile diff --git a/tests/support/expected_failures.py b/tests/support/expected_failures.py index 62895a9..ebff86e 100644 --- a/tests/support/expected_failures.py +++ b/tests/support/expected_failures.py @@ -24,8 +24,6 @@ "assessment-period/mixed-offsets": f"{ISSUES}/58", "assessment-period/equal-instant": f"{ISSUES}/58", "assessment-period/seventh-fraction-digit": f"{ISSUES}/58", - # BMB-003: the generated DocumentId.identifier has no pattern, so it accepts "". - "build-resource/invalid-document-id": f"{ISSUES}/77", # FAC-001 to FAC-003: the runner lacks the facade operation. **dict.fromkeys( ( diff --git a/tests/test_closed_enums.py b/tests/test_closed_enums.py index 3387a1f..0f67920 100644 --- a/tests/test_closed_enums.py +++ b/tests/test_closed_enums.py @@ -2,7 +2,7 @@ A closed-enum field holds the Enum class, for example ``how_many: ParameterSelectionHowMany | None``. An open-enum field is the union of a base -type (``str`` or ``AnyUrl``) and its Enum class, so it also accepts values +type (``str`` or ``OscalUri``) and its Enum class, so it also accepts values outside the enum. Both serialize to the value string. """ @@ -57,7 +57,7 @@ class EnumSite: field: str alias: str is_list: bool - # The annotation also has a base arm, for example ``str`` or ``AnyUrl``, that + # The annotation also has a base arm, for example ``str`` or ``OscalUri``, that # takes values outside the enum: an open enum. is_open: bool diff --git a/tests/test_datatype_constraints.py b/tests/test_datatype_constraints.py new file mode 100644 index 0000000..a2219c2 --- /dev/null +++ b/tests/test_datatype_constraints.py @@ -0,0 +1,278 @@ +"""Scenarios of the datatype-constraints spec delta. + +One test for each scenario of +``openspec/changes/enforce-oscal-datatype-constraints/specs/datatype-constraints/spec.md``. +Each test reads like its scenario: a document, a parse or a call, and the +accept or reject result. A document is built as a dict and sent as JSON, so +control characters travel as escapes. +""" + +from __future__ import annotations + +import json +from datetime import UTC, datetime +from typing import Any + +import pytest +from pydantic import ValidationError + +from oscal_bindings import ( + OscalBuilderError, + OscalParseError, + make_resource, + parse_oscal, + serialize_oscal, + validate_element, +) +from oscal_bindings.models import BackMatterResource, DocumentId, Metadata + +CR = "\r" +LF = "\n" +LINE_SEPARATOR = "\u2028" +NBSP = "\u00a0" +BAD_UUID = "not a uuid" +UUID = "2f6e5c2a-6b0e-4b8e-9a3e-1c7d0b5f4a10" +OTHER_UUID = "0c6b8f1e-4a2d-4b7e-9c3f-5d6e7f8a9b0c" + + +def _metadata(**extra: Any) -> dict[str, Any]: + return { + "title": "T", + "last-modified": "2024-01-02T03:04:05Z", + "version": "1.0", + "oscal-version": "1.2.3", + **extra, + } + + +def _catalog(metadata: dict[str, Any] | None = None, **body: Any) -> dict[str, Any]: + return {"catalog": {"uuid": UUID, "metadata": metadata or _metadata(), **body}} + + +def _with_prop(**prop: Any) -> dict[str, Any]: + return _catalog(_metadata(props=[{"name": "n", "value": "v", **prop}])) + + +def _with_link(href: str) -> dict[str, Any]: + return _catalog(_metadata(links=[{"href": href}])) + + +def _with_email(address: str) -> dict[str, Any]: + party = {"uuid": OTHER_UUID, "type": "person", "email-addresses": [address]} + return _catalog(_metadata(parties=[party])) + + +def _with_last_modified(value: Any) -> dict[str, Any]: + return _catalog(_metadata(**{"last-modified": value})) + + +def _parse(document: dict[str, Any]) -> Any: + return parse_oscal(json.dumps(document)) + + +def _assert_rejected(document: dict[str, Any], key: str) -> None: + """Parsing reports a parse error whose location names ``key``.""" + with pytest.raises(OscalParseError) as info: + _parse(document) + assert info.value.errors + assert any(key in error["loc"] for error in info.value.errors), info.value.errors + + +def _round_trip(document: dict[str, Any]) -> dict[str, Any]: + return json.loads(serialize_oscal(_parse(document))) + + +# --- Each string pattern of the schema constrains its field ----------------- + + +def test_empty_document_identifier_is_rejected() -> None: + document = _catalog(_metadata(**{"document-ids": [{"identifier": ""}]})) + _assert_rejected(document, "identifier") + + +def test_malformed_uuid_is_rejected() -> None: + document = _catalog(**{"back-matter": {"resources": [{"uuid": BAD_UUID}]}}) + _assert_rejected(document, "uuid") + + +def test_both_patterns_of_an_all_of_apply() -> None: + _assert_rejected(_with_email(f"{NBSP}a@example.com"), "email-addresses") + + +# --- A pattern matches as ECMA-262 matches it ------------------------------- + + +def test_carriage_return_inside_a_string_is_rejected() -> None: + _assert_rejected(_with_prop(value=f"a{CR}b"), "value") + + +def test_line_separator_inside_a_string_is_rejected() -> None: + _assert_rejected(_with_prop(value=f"a{LINE_SEPARATOR}b"), "value") + + +def test_carriage_return_inside_a_markup_line_is_accepted() -> None: + _parse(_catalog(_metadata(title=f"a{CR}b"))) + + +def test_unicode_letter_matches_a_letter_class() -> None: + _parse(_with_prop(name="é1")) + + +# --- The generation fails on a pattern that it cannot place ----------------- + + +def test_decimal_is_not_checked_against_its_pattern() -> None: + document = { + "mapping-collection": { + "uuid": UUID, + "metadata": _metadata(), + "provenance": { + "method": "human", + "matching-rationale": "semantic", + "status": "complete", + "coverage": {"target-coverage": 0.5}, + "mapping-description": "d", + }, + "mappings": [ + { + "uuid": OTHER_UUID, + "source-resource": {"type": "catalog", "href": "https://x.org/s"}, + "target-resource": {"type": "catalog", "href": "https://x.org/t"}, + "maps": [ + { + "uuid": "7e0a4d3c-1f5b-4c9a-b8e2-4a6b0c3f5d60", + "relationship": "equivalent-to", + "sources": [{"type": "control", "id-ref": "ac-1"}], + "targets": [{"type": "control", "id-ref": "pr.aa-01"}], + } + ], + } + ], + } + } + _parse(document) + + +# --- A datatype value is kept as the input gives it ------------------------- + + +@pytest.mark.parametrize( + "ns", ["http://a", "https://example.com/a/../b"], ids=["no-path", "dot-segment"] +) +def test_uri_keeps_its_form(ns: str) -> None: + output = _round_trip(_with_prop(ns=ns)) + assert output["catalog"]["metadata"]["props"][0]["ns"] == ns + + +def test_email_address_keeps_its_case() -> None: + output = _round_trip(_with_email("A@Example.COM")) + assert output["catalog"]["metadata"]["parties"][0]["email-addresses"] == [ + "A@Example.COM" + ] + + +# --- A date-time-with-timezone value matches its pattern -------------------- + + +@pytest.mark.parametrize( + "value", + [ + "1850-01-01T00:00:00Z", + "2024-01-02T03:04:05+05:17", + "2024-01-02T03:04:05z", + 1700000000, + ], + ids=["year-before-1900", "offset-outside-pattern", "lowercase-z", "json-number"], +) +def test_datetime_outside_the_pattern_is_rejected(value: Any) -> None: + _assert_rejected(_with_last_modified(value), "last-modified") + + +def test_datetime_given_by_name_is_checked() -> None: + with pytest.raises(ValidationError) as info: + Metadata( + title="T", + last_modified=datetime(1850, 1, 1, tzinfo=UTC), + version="1.0", + oscal_version="1.2.3", + ) + # A construction by name maps the name to its alias before it validates, so + # the location of an error is the OSCAL key. + assert [error["loc"] for error in info.value.errors()] == [("last-modified",)] + + +def test_valid_datetime_is_accepted() -> None: + _parse(_with_last_modified("2024-01-02T03:04:05.123-05:00")) + + +# --- A uri value is a URI --------------------------------------------------- + + +def test_uri_fragment_is_accepted() -> None: + _parse(_with_prop(ns="https://example.com/ns#x")) + + +@pytest.mark.parametrize( + "ns", + [f"http://a{CR}{LF}b", "https://x.org/a b", "x://"], + ids=["line-break", "space", "one-letter-scheme"], +) +def test_malformed_uri_is_rejected(ns: str) -> None: + _assert_rejected(_with_prop(ns=ns), "ns") + + +@pytest.mark.parametrize( + "ns", + ["urn:ietf:rfc:3986", "javascript:alert(1)", "file:///etc/passwd"], +) +def test_each_scheme_is_accepted(ns: str) -> None: + _parse(_with_prop(ns=ns)) + + +# --- A uri-reference value is a URI reference ------------------------------- + + +@pytest.mark.parametrize("href", ["#ac-1", "../a.json", "https://example.com/x"]) +def test_relative_reference_is_accepted(href: str) -> None: + _parse(_with_link(href)) + + +@pytest.mark.parametrize("href", ["a b", f"a{LF}b"], ids=["space", "line-break"]) +def test_malformed_uri_reference_is_rejected(href: str) -> None: + _assert_rejected(_with_link(href), "href") + + +# --- An email-address value is a mailbox ------------------------------------ + + +@pytest.mark.parametrize("address", ["a@b", "x@localhost", "ü@例え.jp"]) +def test_mailbox_is_accepted(address: str) -> None: + _parse(_with_email(address)) + + +@pytest.mark.parametrize( + "address", ["Name ", "a@@b"], ids=["display-name", "two-at-signs"] +) +def test_malformed_mailbox_is_rejected(address: str) -> None: + _assert_rejected(_with_email(address), "email-addresses") + + +# --- Each validation path applies the constraints --------------------------- + + +def test_element_validation_rejects_a_malformed_uuid() -> None: + result = validate_element({"uuid": BAD_UUID}, "back-matter-resource") + assert result.valid is False + + +def test_construction_rejects_a_malformed_uuid() -> None: + with pytest.raises(ValidationError): + BackMatterResource(uuid=BAD_UUID) + + +def test_builder_rejects_an_empty_document_identifier() -> None: + # model_construct skips the check of DocumentId, so the builder is the + # path under test. The builder validates each item again. + empty = DocumentId.model_construct(identifier="") + with pytest.raises(OscalBuilderError): + make_resource(uuid=OTHER_UUID, document_ids=[empty]) diff --git a/tests/test_datatypes.py b/tests/test_datatypes.py new file mode 100644 index 0000000..eb92f90 --- /dev/null +++ b/tests/test_datatypes.py @@ -0,0 +1,248 @@ +"""Tests for ``oscal_bindings.v1._datatypes``: the four hand-written datatypes. + +Each test uses a ``TypeAdapter`` of one type, with JSON input and with Python +input. The values come from the scenarios of the spec delta of the +enforce-oscal-datatype-constraints change. The drift test (design D6) compares +each pattern literal of the module with ``translate`` of the pinned schema. +""" + +from __future__ import annotations + +import json +from datetime import UTC, datetime, timedelta, timezone +from typing import Any + +import pytest +from pydantic import TypeAdapter, ValidationError +from support.scripts import load_script +from support.spec_artifact import ensure_spec_artifact + +from oscal_bindings.v1 import _datatypes +from oscal_bindings.v1._datatypes import ( + OscalDateTimeWithTimezone, + OscalEmailAddress, + OscalUri, + OscalUriReference, +) + +pin = load_script("spec_artifact") +translate = load_script("regex_translation").translate + +CR, LF, LS = "\r", "\n", "\u2028" +DATE_TIME_ERROR_TYPE = "oscal_date_time_with_timezone" + +URI_CASES = [ + ("http://a", True), + ("https://example.com/a/../b", True), + ("https://example.com/ns#x", True), + ("http://[::1]:8080/x?q=1#f", True), + ("urn:ietf:rfc:3986", True), + ("javascript:alert(1)", True), + ("file:///etc/passwd", True), + (f"http://a{CR}{LF}b", False), + ("https://x.org/a b", False), + ("x://", False), + ("a:b", False), + ("ab:", False), + ("http://a/%zz", False), + ("http://a/é", False), + (f"ab:c{LS}", False), +] + +URI_REFERENCE_CASES = [ + ("#ac-1", True), + ("../a.json", True), + ("https://example.com/x", True), + ("a:b", True), + ("//host/path?q#f", True), + ("a b", False), + (f"a{LF}b", False), + (f"a{CR}b", False), + ("%zz", False), + ("a#b#c", False), +] + +EMAIL_CASES = [ + ("a@b", True), + ("x@localhost", True), + ("ü@例え.jp", True), + ("A@Example.COM", True), + ('"a b"@example.com', True), + ("a@[192.0.2.1]", True), + ("a@[IPv6:2001:db8::1]", True), + ("Name ", False), + ("a@@b", False), + ("\u00a0a@example.com", False), + ("a..b@example.com", False), + ("a@example-", False), + ("a@-example", False), + ("a@", False), + ("@a", False), + (f"a{CR}@b", False), +] + + +def _accepts_json(adapter: TypeAdapter[Any], value: Any) -> bool: + try: + adapter.validate_json(json.dumps(value)) + except ValidationError: + return False + return True + + +def _accepts_python(adapter: TypeAdapter[Any], value: Any) -> bool: + try: + adapter.validate_python(value) + except ValidationError: + return False + return True + + +@pytest.mark.parametrize( + ("datatype", "cases"), + [ + pytest.param(OscalUri, URI_CASES, id="uri"), + pytest.param(OscalUriReference, URI_REFERENCE_CASES, id="uri-reference"), + pytest.param(OscalEmailAddress, EMAIL_CASES, id="email-address"), + ], +) +class TestStringDatatypes: + def test_json_input(self, datatype: Any, cases: list[tuple[str, bool]]) -> None: + adapter = TypeAdapter(datatype) + assert {v: _accepts_json(adapter, v) for v, _ in cases} == dict(cases) + + def test_python_input(self, datatype: Any, cases: list[tuple[str, bool]]) -> None: + adapter = TypeAdapter(datatype) + assert {v: _accepts_python(adapter, v) for v, _ in cases} == dict(cases) + + def test_an_accepted_value_serializes_to_the_input_text( + self, datatype: Any, cases: list[tuple[str, bool]] + ) -> None: + adapter = TypeAdapter(datatype) + for value in (v for v, accepted in cases if accepted): + assert adapter.validate_json(json.dumps(value)) == value + assert adapter.dump_python(adapter.validate_python(value)) == value + assert ( + adapter.dump_json(value) + == json.dumps(value, ensure_ascii=False).encode() + ) + + def test_a_number_and_a_null_are_rejected( + self, datatype: Any, cases: list[tuple[str, bool]] + ) -> None: + del cases + adapter = TypeAdapter(datatype) + for value in (1700000000, None, True, ["a:b"]): + assert not _accepts_python(adapter, value) + assert not _accepts_json(adapter, value) + + +# --- date-time-with-timezone ------------------------------------------------ + +DATE_TIME_TEXT_CASES = [ + ("2024-01-02T03:04:05Z", True), + ("2024-01-02T03:04:05.123-05:00", True), + ("2024-01-02T03:04:05.1234567Z", True), + ("2024-02-29T00:00:00+05:45", True), + ("1850-01-01T00:00:00Z", False), + ("2024-01-02T03:04:05+05:17", False), + ("2024-01-02T03:04:05z", False), + ("2024-01-02 03:04:05Z", False), + ("2024-01-02T03:04Z", False), + ("2024-01-02T03:04:05", False), + ("2023-02-29T00:00:00Z", False), + ("1700000000", False), + ("", False), +] + +DATE_TIME_ADAPTER = TypeAdapter(OscalDateTimeWithTimezone) + + +class TestDateTimeWithTimezone: + @pytest.mark.parametrize(("text", "accepted"), DATE_TIME_TEXT_CASES) + def test_text_in_json_input(self, text: str, *, accepted: bool) -> None: + assert _accepts_json(DATE_TIME_ADAPTER, text) is accepted + + @pytest.mark.parametrize(("text", "accepted"), DATE_TIME_TEXT_CASES) + def test_text_in_python_input(self, text: str, *, accepted: bool) -> None: + assert _accepts_python(DATE_TIME_ADAPTER, text) is accepted + + def test_a_json_number_is_rejected(self) -> None: + assert not _accepts_json(DATE_TIME_ADAPTER, 1700000000) + with pytest.raises(ValidationError) as info: + DATE_TIME_ADAPTER.validate_json("1700000000") + assert [e["loc"] for e in info.value.errors()] == [()] + + def test_the_value_is_a_datetime_that_keeps_its_offset(self) -> None: + value = DATE_TIME_ADAPTER.validate_json('"2024-01-02T03:04:05.5-05:00"') + assert value == datetime( + 2024, 1, 2, 3, 4, 5, 500000, tzinfo=timezone(timedelta(hours=-5)) + ) + assert DATE_TIME_ADAPTER.dump_python(value, mode="json") == ( + "2024-01-02T03:04:05.500000-05:00" + ) + + def test_an_aware_datetime_in_python_input_is_accepted(self) -> None: + value = datetime(2024, 1, 2, 3, 4, 5, tzinfo=UTC) + assert DATE_TIME_ADAPTER.validate_python(value) == value + + def test_an_int_in_python_input_fails(self) -> None: + assert not _accepts_python(DATE_TIME_ADAPTER, 1700000000) + + def test_a_naive_datetime_in_python_input_fails(self) -> None: + assert not _accepts_python(DATE_TIME_ADAPTER, datetime(2024, 1, 2, 3, 4, 5)) # noqa: DTZ001 + + @pytest.mark.parametrize( + "value", + [ + datetime(1850, 1, 1, tzinfo=UTC), + datetime( + 2024, 1, 2, 3, 4, 5, tzinfo=timezone(timedelta(hours=5, minutes=17)) + ), + datetime(2024, 1, 2, 3, 4, 5, tzinfo=None), # noqa: DTZ001 + 1700000000, + ], + ids=["year-1850", "offset-+05:17", "naive", "number"], + ) + def test_a_rejected_python_value_gives_one_error_of_the_datatype( + self, value: Any + ) -> None: + with pytest.raises(ValidationError) as info: + DATE_TIME_ADAPTER.validate_python(value) + errors = info.value.errors() + assert [(e["loc"], e["type"]) for e in errors] == [((), DATE_TIME_ERROR_TYPE)] + # The message states the constraint, not the type of the input. + assert "pattern" in errors[0]["msg"] + assert errors[0]["type"] not in {"json_invalid", "oscal_document_type"} + + +# --- Drift of the pattern literals (design D6) --------------------------------- + + +@pytest.fixture(scope="module") +def schema_definitions() -> dict[str, Any]: + paths = pin.artifact_paths(ensure_spec_artifact()) + definitions: dict[str, Any] = json.loads(paths.schema.read_bytes())["definitions"] + return definitions + + +def test_each_pattern_literal_is_the_translation_of_its_schema_pattern( + schema_definitions: dict[str, Any], +) -> None: + uri = schema_definitions["URIDatatype"] + email = schema_definitions["EmailAddressDatatype"]["allOf"] + string = schema_definitions["StringDatatype"] + date_time = schema_definitions["DateTimeWithTimezoneDatatype"] + assert email[0] == {"$ref": "#/definitions/StringDatatype"} + literals = { + "_URI_PATTERN": _datatypes._URI_PATTERN, # noqa: SLF001 + "_STRING_PATTERN": _datatypes._STRING_PATTERN, # noqa: SLF001 + "_EMAIL_PATTERN": _datatypes._EMAIL_PATTERN, # noqa: SLF001 + "_DATE_TIME_PATTERN": _datatypes._DATE_TIME_PATTERN, # noqa: SLF001 + } + assert literals == { + "_URI_PATTERN": translate(uri["pattern"]), + "_STRING_PATTERN": translate(string["pattern"]), + "_EMAIL_PATTERN": translate(email[1]["pattern"]), + "_DATE_TIME_PATTERN": translate(date_time["pattern"]), + } diff --git a/tests/test_hoist_names.py b/tests/test_hoist_names.py index a02104c..9b14448 100644 --- a/tests/test_hoist_names.py +++ b/tests/test_hoist_names.py @@ -10,22 +10,39 @@ from __future__ import annotations import copy +import enum +import importlib import json -from typing import TYPE_CHECKING, Any +import types +from dataclasses import dataclass +from typing import ( + TYPE_CHECKING, + Annotated, + Any, + Union, + get_args, + get_origin, + get_type_hints, +) import jsonschema_rs import pytest +from pydantic import BaseModel +from pydantic.fields import FieldInfo from support.corpus import AWS_CORPUS, NIST_CORPUS, load_corpus_docs from support.scripts import load_script from support.spec_artifact import ensure_spec_artifact +from oscal_bindings.v1 import models + if TYPE_CHECKING: - from collections.abc import Iterator + from collections.abc import Iterable, Iterator from pathlib import Path hoist_mod = load_script("hoist_names") manifest_mod = load_script("manifest") pin = load_script("spec_artifact") +translate = load_script("regex_translation").translate HoistError = hoist_mod.HoistError @@ -618,9 +635,18 @@ def test_schema_without_definitions_fails(manifest: dict[str, Any]) -> None: def _validators( artifact_schema: dict[str, Any], hoisted: dict[str, Any], *, formats: bool ) -> tuple[Any, Any]: + """Validators of the artifact schema and of the hoisted copy. + + The hoist replaces the four hand-written datatypes with custom types that no + schema validator reads, so the copy here gets their original definitions + back. The comparison then covers all the other changes of the hoist. + """ + restored = copy.deepcopy(hoisted) + for key in hoist_mod.HAND_WRITTEN_DATATYPES: + restored["definitions"][key] = artifact_schema["definitions"][key] return ( jsonschema_rs.Draft7Validator(artifact_schema, validate_formats=formats), - jsonschema_rs.Draft7Validator(hoisted, validate_formats=formats), + jsonschema_rs.Draft7Validator(restored, validate_formats=formats), ) @@ -751,3 +777,231 @@ def test_closed_enum_values_validate_the_same( before, after = _validators(artifact_schema, hoisted, formats=False) assert before.is_valid(catalog) is valid assert after.is_valid(catalog) is valid + + +# --------------------------------------------------------------------------- +# Completeness: each string pattern and datatype of the schema reaches a model + +DATATYPES = { + "URIDatatype": "OscalUri", + "URIReferenceDatatype": "OscalUriReference", + "EmailAddressDatatype": "OscalEmailAddress", + "DateTimeWithTimezoneDatatype": "OscalDateTimeWithTimezone", +} + + +@dataclass(frozen=True) +class Site: + """A string value that a property of an object definition reaches. + + ``datatype`` is the definition key of one of the four datatypes when the + ``$ref`` chain of the site reaches it. ``patterns`` holds each pattern of + the chain, in schema form. ``is_enum`` is true when the chain holds an + ``enum``. + """ + + owner: str + prop: str + datatype: str | None + patterns: tuple[str, ...] + is_enum: bool + + def __str__(self) -> str: + what = self.datatype or ("enum" if self.is_enum else "pattern") + return f"{self.owner}.{self.prop} ({what}) {list(self.patterns)}" + + +def _sites_of( + definitions: dict[str, Any], node: Any, owner: str, prop: str +) -> Iterator[Site]: + """Yield each string site of ``node``: an ``allOf`` is one, an ``anyOf`` many.""" + if not isinstance(node, dict): + return + for member in node.get("anyOf", node.get("oneOf", [])): + yield from _sites_of(definitions, member, owner, prop) + if "anyOf" in node or "oneOf" in node: + return + if node.get("type") == "array": + yield from _sites_of(definitions, node.get("items"), owner, prop) + return + datatype: str | None = None + patterns: list[str] = [] + is_enum = False + is_string = False + pending: list[Any] = [node] + while pending: + current = pending.pop() + if not isinstance(current, dict): + continue + ref = current.get("$ref") + if isinstance(ref, str): + key = ref.removeprefix("#/definitions/") + if key in DATATYPES: + datatype = key + is_string = True + continue + pending.append(definitions[key]) + is_string = is_string or current.get("type") == "string" + is_enum = is_enum or "enum" in current + if "pattern" in current: + patterns.append(current["pattern"]) + pending.extend(current.get("allOf", [])) + # A member of an anyOf below an allOf is its own site. + for alternative in current.get("anyOf", []): + yield from _sites_of(definitions, alternative, owner, prop) + if is_string: + yield Site(owner, prop, datatype, tuple(patterns), is_enum) + + +def _schema_sites(hoisted: dict[str, Any]) -> list[Site]: + definitions = hoisted["definitions"] + sites: list[Site] = [] + for key, definition in definitions.items(): + # An object definition has `properties`. Some have no `type` keyword. + if not isinstance(definition, dict) or "properties" not in definition: + continue + for prop, node in definition["properties"].items(): + sites.extend(_sites_of(definitions, node, key, prop)) + return sites + + +@dataclass(frozen=True) +class Leaf: + """A leaf type of a model field, with the constraints that apply to it.""" + + base: Any + markers: tuple[Any, ...] + patterns: tuple[str, ...] + + +def _flatten(metadata: Iterable[Any]) -> Iterator[Any]: + for item in metadata: + if isinstance(item, FieldInfo): + yield from _flatten(item.metadata) + else: + yield item + + +def _leaves(annotation: Any, metadata: tuple[Any, ...] = ()) -> Iterator[Leaf]: + """Open ``Annotated``, unions, and lists down to the leaf types. + + The metadata of an ``Annotated`` union applies to each arm, as pydantic + applies a ``pattern`` of ``Annotated[str | None, Field(pattern=...)]`` to + the ``str``. The metadata of a list applies to the list, not to its items. + """ + origin = get_origin(annotation) + if origin is Annotated: + base, *extra = get_args(annotation) + yield from _leaves(base, (*metadata, *extra)) + elif origin is Union or origin is types.UnionType: + for arm in get_args(annotation): + yield from _leaves(arm, metadata) + elif origin is list: + yield from _leaves(get_args(annotation)[0]) + elif annotation is not type(None): + flat = tuple(_flatten(metadata)) + patterns = tuple( + m.pattern for m in flat if isinstance(getattr(m, "pattern", None), str) + ) + yield Leaf(annotation, flat, patterns) + + +def _is_datatype(leaf: Leaf, name: str) -> bool: + """Whether ``leaf`` is the hand-written type ``name`` of ``_datatypes``.""" + try: + module = importlib.import_module("oscal_bindings.v1._datatypes") + except ImportError: + return False + declared = getattr(module, name, None) + if declared is None: + return False + markers = get_args(declared)[1:] + return get_args(declared)[0] is leaf.base and all( + any(m is marker for m in leaf.markers) for marker in markers + ) + + +def _model_leaves(owner: str, prop: str) -> list[Leaf] | None: + """The leaves of the field of ``owner`` with the alias ``prop``, or ``None``.""" + cls = getattr(models, owner, None) + if not (isinstance(cls, type) and issubclass(cls, BaseModel)): + return None + hints = get_type_hints(cls, vars(models), include_extras=True) + for name, info in cls.model_fields.items(): + if (info.alias or name) == prop: + return list(_leaves(hints[name])) + return None + + +def _site_is_covered(site: Site, leaves: list[Leaf]) -> bool: + if site.datatype is not None: + return any(_is_datatype(leaf, DATATYPES[site.datatype]) for leaf in leaves) + if site.is_enum: + return any( + isinstance(leaf.base, type) and issubclass(leaf.base, enum.Enum) + for leaf in leaves + ) + if not site.patterns: + return True + expected = sorted(translate(p) for p in site.patterns) + return any(sorted(leaf.patterns) == expected for leaf in leaves) + + +def test_each_string_site_of_the_schema_reaches_a_model( + hoisted: dict[str, Any], +) -> None: + """Design D7: a datatype site has its type, a pattern site its pattern.""" + sites = _schema_sites(hoisted) + assert {s.datatype for s in sites} >= set(DATATYPES), "a datatype has no site" + assert sum(1 for s in sites if s.patterns) > 100 + missing: list[str] = [] + uncovered: list[str] = [] + for site in sites: + leaves = _model_leaves(site.owner, site.prop) + if leaves is None: + missing.append(str(site)) + elif not _site_is_covered(site, leaves): + uncovered.append(str(site)) + assert missing == [] + assert sorted(set(uncovered)) == [] + + +# --------------------------------------------------------------------------- +# 5.1 The four hand-written datatypes get a custom type + + +@pytest.mark.parametrize("key", sorted(hoist_mod.HAND_WRITTEN_DATATYPES)) +def test_hand_written_datatype_has_its_custom_type( + hoisted: dict[str, Any], artifact_schema: dict[str, Any], key: str +) -> None: + original = artifact_schema["definitions"][key] + definition = hoisted["definitions"][key] + assert definition["customTypePath"] == hoist_mod.HAND_WRITTEN_DATATYPES[key] + assert definition["type"] == "string" + assert definition["description"] == original["description"] + assert definition.get("title") == original.get("title") + assert not {"pattern", "format", "allOf"} & set(definition) + + +def test_hand_written_datatypes_are_the_four_with_a_format( + artifact_schema: dict[str, Any], +) -> None: + assert set(hoist_mod.HAND_WRITTEN_DATATYPES) == { + "DateTimeWithTimezoneDatatype", + "EmailAddressDatatype", + "URIDatatype", + "URIReferenceDatatype", + } + assert all( + "customTypePath" not in definition + for definition in artifact_schema["definitions"].values() + ) + + +def test_a_schema_without_a_hand_written_datatype_fails( + schema: dict[str, Any], manifest: dict[str, Any] +) -> None: + del schema["definitions"]["URIDatatype"] + with pytest.raises(HoistError) as info: + hoist_mod.hoist(schema, manifest) + assert any("URIDatatype" in failure for failure in info.value.failures) diff --git a/tests/test_postprocess.py b/tests/test_postprocess.py index c8fc8e7..47cbd8e 100644 --- a/tests/test_postprocess.py +++ b/tests/test_postprocess.py @@ -68,7 +68,6 @@ def _enum(name: str, *values: str) -> str: HEADER + _enum("HashAlgorithm", "sha") + _object("Mapping", "uuid: str") - # Phase 1 reads the 10 lines above a pattern, so the imports stay out of reach. + "\n\nclass OscalCompleteOscalMetadataLocationUuid(RootModel[str]):\n" " root: Annotated[str, Field(pattern='^[0-9a-f]+$', title='Location')]\n" + "\n\nclass TokenDatatype(RootModel[str]):\n" @@ -514,21 +513,153 @@ def test_preserved_and_union_root_models_stay(self) -> None: result = pp.collapse_scalar_root_models(source, frozenset({"Keep"})) assert result == source - def test_email_pattern_is_removed(self) -> None: - source = "x: Annotated[EmailStr, Field(pattern='^.+@.+$', title='E')]" - assert pp.fix_email_str_patterns(source) == ( - "x: Annotated[EmailStr, Field(title='E')]" + +def _annotated(base: str, *fields: str) -> str: + """A field of ``base`` with a multi-line ``Field``, as codegen writes it.""" + body = "".join(f" {field},\n" for field in fields) + return f"x: Annotated[\n {base},\n Field(\n{body} ),\n]" + + +class TestPlacePatterns: + """D1: a pattern stays, goes, or fails by the base of its ``Annotated``.""" + + @staticmethod + def _place(source: str) -> tuple[str, list[str]]: + failures: list[str] = [] + return pp.place_patterns(source, failures), failures + + def test_string_pattern_stays_and_is_translated(self) -> None: + source = _annotated("str", "pattern='^\\\\S(.*\\\\S)?$'", "title='T'") + result, failures = self._place(source) + assert failures == [] + assert "pattern='^[^" in result + assert "(.*" not in result + assert result.count("title='T'") == 1 + + def test_optional_string_pattern_stays(self) -> None: + source = _annotated("str | None", "pattern='^d$'", "title='T'") + assert self._place(source) == (source, []) + + @pytest.mark.parametrize("word", ["integrity", "point", "float", "int", "bool"]) + def test_a_type_name_in_a_description_does_not_remove_a_string_pattern( + self, word: str + ) -> None: + # The line scan took the substring "int" of "integrity" for the base type + # and removed the pattern of 23 str fields (#77). + source = _annotated( + "str", f"description='Keeps the {word} of the point.'", "pattern='^d$'" + ) + assert self._place(source) == (source, []) + + def test_pattern_on_a_number_goes(self) -> None: + for base in ("int", "float", "int | None", "float | None"): + source = _annotated(base, "description='D'", "pattern='^d$'", "title='T'") + result, failures = self._place(source) + assert failures == [] + assert "pattern" not in result + assert ast_parses(result) + assert "description='D'" in result + assert "title='T'" in result + + @pytest.mark.parametrize( + ("source", "expected"), + [ + ("x: Annotated[int, Field(pattern='^d$')]", "x: Annotated[int, Field()]"), + ( + "x: Annotated[int, Field(pattern='^d$', title='T')]", + "x: Annotated[int, Field(title='T')]", + ), + ( + "x: Annotated[int, Field(title='T', pattern='^d$')]", + "x: Annotated[int, Field(title='T')]", + ), + ( + "x: Annotated[int, Field(pattern='^d$',)]", + "x: Annotated[int, Field()]", + ), + ], + ) + def test_removal_leaves_valid_source(self, source: str, expected: str) -> None: + assert self._place(source) == (expected, []) + + def test_removal_keeps_non_ascii_text_in_place(self) -> None: + source = _annotated( + "float", "description='Größe é'", "pattern='^d$'", "title='é'" ) + result, failures = self._place(source) + assert failures == [] + assert "description='Größe é'" in result + assert "title='é'" in result + assert "pattern" not in result - def test_non_string_pattern_is_removed(self) -> None: + def test_a_pattern_on_another_base_fails_and_names_the_site(self) -> None: source = ( - "x: Annotated[\n AwareDatetime,\n Field(pattern='^d$', title='T'),\n]" + "class A(OscalBaseModel):\n" + " flag: Annotated[bool, Field(pattern='^d$')]\n" + " when: Annotated[AwareDatetime, Field(pattern='^d$')]\n" + " mixed: Annotated[str | int, Field(pattern='^d$')]\n" + " many: Annotated[list[str], Field(pattern='^d$')]\n" + " typed: Annotated[AnyUrl | None, Field(pattern='^d$')]\n" + "\n\nAlias = Annotated[bool, Field(pattern='^d$')]\n" ) - assert "pattern=" not in pp.fix_non_string_patterns(source) + failures: list[str] = [] + result = pp.place_patterns(source, failures) + assert result == source + assert len(failures) == 6 + for site in ("A.flag", "A.when", "A.mixed", "A.many", "A.typed", "Alias"): + assert sum(f.startswith(f"{site}: ") for f in failures) == 1 + assert any("bool" in f for f in failures) + assert any("str | int" in f for f in failures) + assert any("AwareDatetime" in f for f in failures) + + def test_a_pattern_outside_an_annotated_fails(self) -> None: + source = "class A(OscalBaseModel):\n name: str = Field(pattern='^d$')\n" + failures: list[str] = [] + pp.place_patterns(source, failures) + assert len(failures) == 1 + assert "line 2" in failures[0] + + def test_a_pattern_that_cannot_be_translated_fails(self) -> None: + source = _annotated("str", "pattern='(?=a)b'") + failures: list[str] = [] + assert pp.place_patterns(source, failures) == source + assert len(failures) == 1 + assert "x: " in failures[0] or "(?=a)b" in failures[0] + + def test_one_run_reports_each_failure_and_writes_no_output( + self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch + ) -> None: + raw = ( + RAW + "\n\nclass Bad(OscalBaseModel):\n" + " flag: Annotated[bool, Field(pattern='^d$')]\n" + " when: Annotated[AwareDatetime, Field(pattern='^d$')]\n" + ) + failures = _failures(raw) + assert sum("Bad.flag" in f for f in failures) == 1 + assert sum("Bad.when" in f for f in failures) == 1 + monkeypatch.setattr(pp, "load_manifest", lambda _schema: _manifest()) + (tmp_path / "schema.json").write_text(json.dumps(SCHEMA)) + (tmp_path / "models.py").write_text(raw) + output = tmp_path / "out.py" + status = pp.main( + [ + "--models", + str(tmp_path / "models.py"), + "--schema", + str(tmp_path / "schema.json"), + "--output", + str(output), + ] + ) + assert status == 1 + assert not output.exists() + + +def ast_parses(source: str) -> bool: + import ast - def test_string_pattern_stays(self) -> None: - source = "x: Annotated[\n str,\n Field(pattern='^d$', title='T'),\n]" - assert pp.fix_non_string_patterns(source) == source + ast.parse(source) + return True # --------------------------------------------------------------------------- diff --git a/tests/test_pydantic_version.py b/tests/test_pydantic_version.py index 86afde1..80401df 100644 --- a/tests/test_pydantic_version.py +++ b/tests/test_pydantic_version.py @@ -1,6 +1,6 @@ """Guard the supported pydantic version range. -The runtime dependency in ``pyproject.toml`` is ``pydantic[email]>=2.14.2,<3``. +The runtime dependency in ``pyproject.toml`` is ``pydantic>=2.14.2,<3``. 2.14.2 is the first release whose JSON validation rejects a key spelled with a model's Python field name (``back_matter``) as ``extra_forbidden``. Earlier 2.13/2.14 releases drop the key and lose its value without an error (issue #6, @@ -16,7 +16,7 @@ import pydantic from packaging.version import Version -# Keep in step with ``pydantic[email]`` in pyproject.toml. +# Keep in step with ``pydantic`` in pyproject.toml. SUPPORTED_FROM = Version("2.14.2") SUPPORTED_BELOW = Version("3") diff --git a/tests/test_regex_translation.py b/tests/test_regex_translation.py new file mode 100644 index 0000000..7ffa3e6 --- /dev/null +++ b/tests/test_regex_translation.py @@ -0,0 +1,256 @@ +"""Tests for ``scripts/regex_translation.py`` (PRS-007). + +``translate`` maps a pattern of the OSCAL schema, written for ECMA-262 with the +``u`` flag, to the Rust ``regex`` dialect of pydantic-core. The tests check each +of the 10 patterns of the pinned schema against a table of expected results, and +that each construct that the mapping does not know is an error. + +The expected results in ``PROBES`` are the results of ECMA-262: a ``RegExp`` +with the ``u`` flag in Node.js gave them, and the comments say why. The +untranslated pattern gives a different result in pydantic for the probes that +``test_untranslated_patterns_differ`` lists. +""" + +from __future__ import annotations + +import json +from typing import Annotated, Any + +import pytest +from pydantic import Field, TypeAdapter, ValidationError +from support.scripts import load_script +from support.spec_artifact import ensure_spec_artifact + +translation = load_script("regex_translation") +pin = load_script("spec_artifact") + +RegexTranslationError = translation.RegexTranslationError +translate = translation.translate + +LF, CR, NEL, LS, PS = "\n", "\r", "\u0085", "\u2028", "\u2029" +NBSP, BOM = "\u00a0", "\ufeff" +UUID = "0c6b8f1e-4a2d-4b7e-9c3f-5d6e7f8a9b0c" + +# Definition key of the schema -> (probe, ECMA-262 result). +PROBES: dict[str, list[tuple[str, bool]]] = { + "Base64Datatype": [("AA==", True), ("AAA===", False), ("", False)], + "DateDatatype": [ + ("2024-01-02", True), + ("2024-01-02Z", True), + ("2024-02-30", False), + ("2024-01-02+05:17", False), + ], + "DateTimeWithTimezoneDatatype": [ + ("2024-01-02T03:04:05Z", True), + ("2024-01-02T03:04:05.5-05:00", True), + ("1850-01-01T00:00:00Z", False), + ("2024-01-02T03:04:05z", False), + ("2024-01-02T03:04:05+05:17", False), + ], + "DecimalDatatype": [ + ("0.5", True), + (".5", True), + ("5.", True), + ("1e3", False), + (f"0.5{LF}", False), + ], + # `.` matches no line terminator. + "EmailAddressDatatype": [ + ("a@b", True), + (f"a{CR}@b", False), + (f"a@b{PS}", False), + (f"a{NEL}@b", True), + ], + # Only LF is excluded. + "MarkupLineDatatype": [ + (f"a{CR}b", True), + (f"a{LS}b", True), + (f"a{LF}b", False), + ("", False), + ], + # `.` excludes CR, U+2028, U+2029. `\s` has U+FEFF and no U+0085. + "StringDatatype": [ + ("ab", True), + ("a b", True), + (f"a{CR}b", False), + (f"a{LS}b", False), + (f"a{PS}b", False), + (f"a{LF}b", False), + (f"{NEL}a", True), + (f"{BOM}a", False), + (f"a{BOM}", False), + (f"{NBSP}a", False), + ], + "TokenDatatype": [ + ("é1", True), + ("_a", True), + ("Dž", True), + ("1a", False), + (f"a{LF}", False), + ], + "URIDatatype": [ + ("ab:c", True), + ("a:b", False), + (f"ab:c{CR}d", False), + (f"ab:{LS}", False), + ], + "UUIDDatatype": [ + (UUID, True), + (UUID.replace("-4b7e", "-3b7e"), False), + (f"{UUID}{LF}", False), + ], +} + + +@pytest.fixture(scope="module") +def schema_patterns() -> dict[str, str]: + """Definition key -> the pattern of the pinned schema.""" + paths = pin.artifact_paths(ensure_spec_artifact()) + definitions = json.loads(paths.schema.read_bytes())["definitions"] + found: dict[str, str] = {} + for key, definition in definitions.items(): + for node in [definition, *definition.get("allOf", [])]: + if "pattern" in node: + found[key] = node["pattern"] + return found + + +def _accepts(pattern: str, value: str) -> bool: + try: + TypeAdapter(Annotated[str, Field(pattern=pattern)]).validate_python(value) + except ValidationError: + return False + return True + + +def _cases() -> list[Any]: + return [ + pytest.param(key, value, expected, id=f"{key}-{value!r}") + for key, probes in PROBES.items() + for value, expected in probes + ] + + +def test_the_table_has_each_pattern_of_the_schema( + schema_patterns: dict[str, str], +) -> None: + """A new pattern in a moved pin fails here until a row covers it.""" + assert set(schema_patterns) == set(PROBES) + assert len(schema_patterns) == 10 + + +@pytest.mark.parametrize(("key", "value", "expected"), _cases()) +def test_translated_pattern_gives_the_ecma_262_result( + schema_patterns: dict[str, str], key: str, value: str, *, expected: bool +) -> None: + assert _accepts(translate(schema_patterns[key]), value) is expected + + +def test_untranslated_patterns_differ(schema_patterns: dict[str, str]) -> None: + """The probes show the gap: pydantic reads each pattern as Rust, as written.""" + differ = { + (key, value) + for key, probes in PROBES.items() + for value, expected in probes + if _accepts(schema_patterns[key], value) is not expected + } + assert differ == { + ("EmailAddressDatatype", f"a{CR}@b"), + ("EmailAddressDatatype", f"a@b{PS}"), + ("StringDatatype", f"a{CR}b"), + ("StringDatatype", f"a{LS}b"), + ("StringDatatype", f"a{PS}b"), + ("StringDatatype", f"{NEL}a"), + ("StringDatatype", f"{BOM}a"), + ("StringDatatype", f"a{BOM}"), + ("URIDatatype", f"ab:c{CR}d"), + ("URIDatatype", f"ab:{LS}"), + } + + +# --- D2 item 3: the tokens that stay --------------------------------------- + + +@pytest.mark.parametrize( + "pattern", + [ + "^a$", + "^[a-zA-Z0-9+\\-.]+$", + "^[^<]+$", + "^(a|b)*$", + "^(?:a|b){2,3}$", + "^a{0,2}$", + "^\\p{L}\\P{N}[\\p{L}_]$", + "^\\.\\+\\(\\)\\[\\]\\{\\}\\|\\\\\\/$", + "^a+?b*?c??$", + "^\\x0b\\u00a0\\u{2028}[\\u{2000}-\\u{200a}\\x41]$", + ], +) +def test_a_token_that_both_dialects_read_alike_stays(pattern: str) -> None: + assert translate(pattern) == pattern + + +def test_translation_is_its_own_fixed_point(schema_patterns: dict[str, str]) -> None: + """The post-processor can run on its own output without a second translation.""" + for pattern in schema_patterns.values(): + once = translate(pattern) + assert translate(once) == once + + +def test_a_literal_line_feed_is_written_as_an_escape() -> None: + assert translate("^[^\n]+$") == "^[^\\n]+$" + + +def test_dot_excludes_the_line_terminators() -> None: + assert translate(".") == "[^\\n\\r\\u{2028}\\u{2029}]" + + +def test_space_class_and_its_complement() -> None: + space, not_space = translate("\\s"), translate("\\S") + assert not_space == "[^" + space[1:] + for terminator in (LF, CR, LS, PS, BOM, NBSP, "\t", " ", "\u3000", "\u2009"): + assert _accepts(f"^{space}$", terminator) + for member in (NEL, "a", "\u180e", "\u200b"): + assert not _accepts(f"^{space}$", member) + + +# --- D2 item 4: each other construct is an error ---------------------------- + + +@pytest.mark.parametrize( + "pattern", + [ + "(?=a)b", + "(?!a)b", + "(?<=a)b", + "(?a)\\k", + "\\d", + "\\D", + "\\w", + "\\W", + "\\b", + "\\B", + "[\\s]", + "[^\\S]", + "(?i)a", + "(?a)", + ], +) +def test_an_unknown_construct_is_an_error_that_names_the_pattern( + pattern: str, +) -> None: + with pytest.raises(RegexTranslationError) as info: + translate(pattern) + assert repr(pattern) in str(info.value) + assert info.value.pattern == pattern + + +@pytest.mark.parametrize( + "pattern", + ["a\\", "[a", "(a", "a)", "a]", "a}", "a{", "a{x}", "[]", "[a[b]]", "\\q", "\\p"], +) +def test_a_pattern_that_is_not_well_formed_is_an_error(pattern: str) -> None: + with pytest.raises(RegexTranslationError): + translate(pattern) diff --git a/tests/test_schema_validation.py b/tests/test_schema_validation.py index 663da24..c9ac4bb 100644 --- a/tests/test_schema_validation.py +++ b/tests/test_schema_validation.py @@ -16,7 +16,8 @@ - **``format`` is not asserted** (``validate_formats=False``). The schema uses ``date-time``, ``email``, ``uri`` and ``uri-reference``; each sits beside a ``pattern`` on the same datatype, which is enforced, and the model fields are - already ``AwareDatetime`` / ``EmailStr`` / ``AnyUrl``. + ``OscalDateTimeWithTimezone`` / ``OscalEmailAddress`` / ``OscalUri`` / + ``OscalUriReference``, which check that pattern and the grammar of the datatype. Negative controls prove the validator is not vacuous: snake_case keys (``model_dump(by_alias=False)``), an injected ``null``, and a ``\\p{L}``