From 85f1944e889ce8e1c542917e797bb7a2c6163a97 Mon Sep 17 00:00:00 2001 From: Sava Znatnov Date: Sat, 10 Oct 2026 23:08:04 +0700 Subject: [PATCH] feat(datalens): `-o name` prints the identifier of DataLens objects too The models generated from the DataLens specification now mark the field that names the object. The generator reads it from one table, a key for each section of the specification (`_IDENTIFIERS`, or `_NO_IDENTIFIER` with the reason), and from the operations whose reply holds objects of another kind than their section (`_RETURNS_ANOTHER_KIND`). Only a row of a reply is marked: the reply itself or an item of a list in it. The generator stops on a section in neither table, a declared key no row has, an operation the specification no longer has, and a schema two keys would name. A reply that leaves the identifier out now says that the request was sent, so a script does not take a failed naming for a change that did not happen. Co-Authored-By: Claude Opus 5.5 --- docs/conventions/resources.md | 6 +- docs/en/how-to/script-the-cli.md | 2 +- docs/ru/how-to/script-the-cli.md | 2 +- scripts/datalens_schemas.sha256 | 42 ++--- .../pydantic_v2/BaseModel.jinja2 | 5 + scripts/gen_datalens_models.py | 164 +++++++++++++++++- src/ycli/cli/output.py | 3 +- src/ycli/yandex/datalens/schemas/access.py | 5 +- src/ycli/yandex/datalens/schemas/audit.py | 3 +- .../datalens/schemas/cloud_environments.py | 7 +- .../yandex/datalens/schemas/collection.py | 9 +- .../yandex/datalens/schemas/connection.py | 61 +++---- src/ycli/yandex/datalens/schemas/dataset.py | 3 +- .../datalens/schemas/embedding_secrets.py | 8 +- src/ycli/yandex/datalens/schemas/embeds.py | 6 +- src/ycli/yandex/datalens/schemas/entries.py | 7 +- .../yandex/datalens/schemas/entry_lock.py | 4 +- .../yandex/datalens/schemas/html_pages.py | 3 +- src/ycli/yandex/datalens/schemas/licensing.py | 5 +- .../yandex/datalens/schemas/navigation.py | 7 +- .../yandex/datalens/schemas/rest_catalogs.py | 7 +- src/ycli/yandex/datalens/schemas/shared.py | 7 +- .../datalens/schemas/spark_applications.py | 5 +- .../yandex/datalens/schemas/spark_clusters.py | 11 +- .../yandex/datalens/schemas/trino_clusters.py | 11 +- src/ycli/yandex/datalens/schemas/workbook.py | 11 +- .../datalens/schemas/workbook_export.py | 11 +- .../datalens/schemas/workbook_import.py | 5 +- tests/architecture/test_names.py | 22 ++- tests/contract/test_output_formats.py | 26 +++ tests/tooling/test_gen_datalens_models.py | 152 +++++++++++++++- tests/unit/cli/test_output_strategies.py | 3 +- 32 files changed, 504 insertions(+), 119 deletions(-) diff --git a/docs/conventions/resources.md b/docs/conventions/resources.md index f8792595a..9244ec829 100644 --- a/docs/conventions/resources.md +++ b/docs/conventions/resources.md @@ -133,8 +133,10 @@ has `get` and `get-by-id`, plain `get` decides), so `ycli … list -o name | xar works. `-o name` prints it, and a command whose result has no such field is refused before any request. An item of a listing with no identifier of its own stands in `NO_NAME` of `tests/architecture/test_names.py` with its reason. The models generated from the DataLens -specification are not marked yet: their resources will name the identifier where the -generator reads it. +specification get the mark from the generator: `_IDENTIFIERS` in +`scripts/gen_datalens_models.py` names the key of each section of the specification (or +`_NO_IDENTIFIER` says why it has none), and `_RETURNS_ANOTHER_KIND` the operations whose +reply holds objects of another kind. --- diff --git a/docs/en/how-to/script-the-cli.md b/docs/en/how-to/script-the-cli.md index 9ff25b945..338e1a792 100644 --- a/docs/en/how-to/script-the-cli.md +++ b/docs/en/how-to/script-the-cli.md @@ -55,9 +55,9 @@ new=$(ycli tracker issues create --queue TEST --summary 'From a script' -o name) - An object that lies inside another one prints its own identifier: `ycli tracker comments list TEST-1 -o name` prints comment ids, and the issue key is yours to add. - A command whose result has no identifier (a grant of access, a count) is refused before it sends anything, with exit code 2. +- A DataLens command that starts a long operation (a cloud environment, a Spark or Trino cluster) answers with the operation, so `-o name` prints the operation's id, the one `ycli datalens lakehouseoperations get` takes, not the id of what is being made. - A reply that leaves the identifier of an item out is an error: nothing is printed, so a script never acts on fewer objects than were listed. - With `--dry-run` the plan comes back in place of the object, and it is printed as JSON. -- DataLens commands do not print names yet. ## Take a long listing in pieces diff --git a/docs/ru/how-to/script-the-cli.md b/docs/ru/how-to/script-the-cli.md index 01b505bff..213563bee 100644 --- a/docs/ru/how-to/script-the-cli.md +++ b/docs/ru/how-to/script-the-cli.md @@ -55,9 +55,9 @@ new=$(ycli tracker issues create --queue TEST --summary 'From a script' -o name) - Объект, который лежит внутри другого, печатает свой идентификатор: `ycli tracker comments list TEST-1 -o name` печатает id комментариев, а ключ задачи добавляете вы. - Команде, у результата которой нет идентификатора (выдача доступа, счётчик), отказывают до отправки запроса, код возврата 2. +- Команда DataLens, которая запускает долгую операцию (облачное окружение, кластер Spark или Trino), отвечает операцией, поэтому `-o name` печатает id операции — тот, что принимает `ycli datalens lakehouseoperations get`, а не id создаваемого объекта. - Ответ, в котором у объекта нет идентификатора, — это ошибка: ничего не печатается, поэтому скрипт не обработает меньше объектов, чем было в списке. - С `--dry-run` вместо объекта приходит план, и он печатается как JSON. -- Команды DataLens имён пока не печатают. ## Длинный список по частям diff --git a/scripts/datalens_schemas.sha256 b/scripts/datalens_schemas.sha256 index 39737513d..6f3ef31c8 100644 --- a/scripts/datalens_schemas.sha256 +++ b/scripts/datalens_schemas.sha256 @@ -1,36 +1,36 @@ d4da030189150eaa647c63816c298abd279c661822f5ead6b1ce0086af78ef87 __init__.py -cc78dadc9f3ccb748213d701738c47d1d6243da4a068be7ad9c1b3f52f8d19fe access.py -fa198200babe9e1ba210f6fdd71a2c4a86a62860ceb8ae323dd16e292337d480 audit.py +1204722677ff5b338fe6d4fad9342f9a09782be86fd7b85b05822d7ba9de3574 access.py +f0e012b853d8c0acd2a3706c7fe5a28985c6b8756e05d9b09061d64403fad61b audit.py e10c5765c9d57f100994680815c7571cb1b4e025623098d13feac39592a3da5c cloud_environment_storage.py -ef89732c72b852ed0834f28446cada5abbe64c8f8816d132bd1a096ef018bfcf cloud_environments.py -00b2f07711b669204a64e6b993ea86856579ad7dff47bc61d101c592ae0f5cf9 collection.py -65a4c8a13d688f8ec8d826da14b8507d90376e7c19365a031aea4d51d87c45d8 connection.py +024afe0197430fc56f770b5cca97b4c2f2841517edd9052e02cc631f86dd8d88 cloud_environments.py +6b954a5659ae499e5c61ba5761fb3f2061b8e61ce5dcc99dd856083e6dab2fcf collection.py +4dbbcb6e4448b96aa429ad4cbbc0229c888028f1c4d86dd032f3350bb5b7c0e1 connection.py 7d8e086b5f1a9160a6267cb1b0565646e172d47fc4c99bb97f6465802a8c638d dashboard.py 8221cb538ba20d8925975e3122d924514b829cbd4069f5c0aee7ed6f245bfb72 data.py -f9efb961a99c1207768c0625821389dcd3595a81bf1691118a94d74dd48beb2f dataset.py +77d5a961a803628ff7c7299b1a4c047b33038a9c4b26c676a4b448ecabe5c9df dataset.py 11d59eae9dab5ebed2873ff1ab328bd0229f28ca59fb6d7429f6e5ca5a5c4bd0 editor.py -e1e8a0118aa1d3cfcd48dfe33a096714c65a7e87114176541bf099da426f96d8 embedding_secrets.py -a5800b847aa019f81329833fe28e3823ce42d9ee607e648b6e99acee1a4bdc10 embeds.py -878dfcfb5d640d231efd8d0993c2064d02b711d1774c7a931d521db99f7fa168 entries.py -6b8f7ec8053181c928c14dc50aeb727e8c82cf8a883a5eae37778150ab304cc6 entry_lock.py +ce3be106f1236b30e9c384d20b73090161ee606f78b954e85bef19e4847b1bad embedding_secrets.py +a9c9f5dee262fbc0db60cfcd3ac7dad9a741361f002737af674a01949f13f59a embeds.py +f2b3d03d70c85db44fd23dc661e4b9ba37973df4546d50c97df6fa8a57152917 entries.py +dcfb8803b0af388376e77369d3d5bdbfe31aedd9bc5ba11c2e37ae59d5747178 entry_lock.py 16a8cd8d0de9e26cb20ca8048e57e61a82cad3edbd2cadc3691f8a295674d22c favorites.py 9b9d22497a187f120dd81712c1a6efb8f5936db8fa52ca5b2824e1661ba889fe folder.py -f4558dffe77955f1a0cf4aaebb5fa351ecb8dd696f3d01d8c3c1268061a3f713 html_pages.py +ff0fc2461a6f0e0c6aa39a7350fce33d0f45f298768fce0d483edf46b62f73dd html_pages.py a2944d4ad4e3dd23aaeb641801bafb825e1621a38238194226925b4f5a2c99ee lakehouse_operations.py -32679a24c9b1c2bb50d77f6d8903f2a4c4532d84c7b17679ad0f1d86cb109c8d licensing.py -3f28a3426aecd531abf24774b1762a11ca43860fa759185dd6a2571cbcc903e3 navigation.py +bee8ea2dee160e38057d32b7fa0b9a90390888f4f44bb5da8e991da008375064 licensing.py +733300f988cf96804d1397ba0e73f5f51f5cb86df4fcee327d499f0358be04e9 navigation.py 5fb735a13f5958b75052c1f8e486c0987933a424f3f3cc31f9ed9bbfe2a09a46 permissions.py 007e77c5ce13e8a59145112ee40219fcec55973b9f6f095cb48bab7b419b951d ql.py bf9a01057114a3fda9e1854e9df59f77bf81009b43f49985ed790ebb818637d7 reports.py -660c36e0d9980caaa7ab77b81a7ae91d32b9c9c575be1aa74997edf3f2504c6f rest_catalogs.py -72278dc25dc6ce3a56c0910d8498ed2fa6703bcf1457b8e5622368a953481c20 shared.py +c845b1acfd36711850ca78a649a9ac9352705d9d87d193464c3af06ae5e43526 rest_catalogs.py +a9601ed30129141d23efab390f6e3812a99b8e07e3a059a2673c37dbbe50c8a0 shared.py 186d90efa73a171d65c47a0f31e63fcd0988801e78f029a17659328106160e10 shared_entry.py -c7c5f6dbdb8037594e0526c425d6702026013566cd7d882968a60941bbc30d77 spark_applications.py -c007eaa70d4622c8e4c31863c1d80104e73f9145624dd2781236fc109f4a7de0 spark_clusters.py +a154501fcef69a2c307ef0ee20f4034e6a8e594cb5115f2cf847740f7be23d56 spark_applications.py +9f456027e2ce1b27ef9747a1033875e3f6f692fa7126e2db270fe3c3a4efabbc spark_clusters.py 5fe0117796e50b5bd88b4fa2e1310c9ee9c73a650171a1ae9f6870e917fd0d79 sql_queries.py 5e61dbf756b08efc5dee106611379bf15bde50c1fb6c3725a4137f4a77f21bc9 tenants.py -a691214c05a4267714d4c646580fa23374370a7e85675fb508a1ceca1fa5dcb2 trino_clusters.py +33c3cb4318099d33c18ad4fbe82093583c7d2b801ce610abba98745eb69214ef trino_clusters.py b60c79744cf6e230401b5ac593df912ce683d1dc074886944411617e16159d15 wizard.py -37d89fa2d64450e2a49e5f9d8dc06239f55d137c2358c22b8a05919422ed2886 workbook.py -b8d351d03d0191744034b9b94c2278600b5513926136b86cd3bdb7ce44df3699 workbook_export.py -5a22a5c3cd2d32cca64c1e5e5e508b822f64120b2a924fbfbdb3b83e45f5d3f8 workbook_import.py +937d3bf38e786643985870d78e7beca1597a206e0ad665762fe4997485aea83a workbook.py +6c8300eabeeeca4cd603ead573f99a5f43361e7e22dd9d84a3c6326c5fefdc03 workbook_export.py +69c0d72090bcc5470155c83e5f06eb5ae3944a69a77878893894c8e6fdce225b workbook_import.py diff --git a/scripts/datalens_templates/pydantic_v2/BaseModel.jinja2 b/scripts/datalens_templates/pydantic_v2/BaseModel.jinja2 index a91fe6e22..3d22e320d 100644 --- a/scripts/datalens_templates/pydantic_v2/BaseModel.jinja2 +++ b/scripts/datalens_templates/pydantic_v2/BaseModel.jinja2 @@ -30,6 +30,9 @@ class {{ class_name }}({%- if schema_runtime_validation_use_base -%}{{ schema_ru {#- ycli: a field the API requires as null carries the typed mark (gen_datalens_models) #} {%- if field.original_name in (no_drop_null or []) %} {{ field.name }}: Annotated[{{ field.type_hint }}, NoDropNull()] = {{ field.field }} + {#- ycli: the field that names the object carries the typed mark (gen_datalens_models) #} + {%- elif field.original_name in (identity or []) %} + {{ field.name }}: Annotated[{{ field.type_hint }}, Identity()] = {{ field.field }} {%- else %} {{ field.name }}: {{ field.type_hint }} = {{ field.field }} {%- endif %} @@ -38,6 +41,8 @@ class {{ class_name }}({%- if schema_runtime_validation_use_base -%}{{ schema_ru {{ field.name }}: {{ field.annotated }} {%- elif field.original_name in (no_drop_null or []) %} {{ field.name }}: Annotated[{{ field.type_hint }}, NoDropNull()] + {%- elif field.original_name in (identity or []) %} + {{ field.name }}: Annotated[{{ field.type_hint }}, Identity()] {%- else %} {{ field.name }}: {{ field.type_hint }} {%- endif %} diff --git a/scripts/gen_datalens_models.py b/scripts/gen_datalens_models.py index adaf9127e..e0f063fc4 100644 --- a/scripts/gen_datalens_models.py +++ b/scripts/gen_datalens_models.py @@ -74,9 +74,9 @@ _BASE = "customBasePath" _CLOSED = "ycli.yandex.models.RequestBody" # What a generated module may import, inherit from and call (``foreign``). -_MODULES = {"typing", "datetime", "pydantic", "ycli.yandex.models"} +_MODULES = {"typing", "datetime", "pydantic", "ycli.yandex.models", "ycli.yandex.sync.marks"} _BASES = {"APIModel", "RequestBody", "RootModel"} -_CALLS = {"Field", "ConfigDict", "NoDropNull", "KindByOwnField"} +_CALLS = {"Field", "ConfigDict", "NoDropNull", "KindByOwnField", "Identity"} def _snake(name: str) -> str: @@ -709,6 +709,7 @@ def _mark_union_envelopes(spec: dict[str, Any]) -> int: _KEEPS_NULL = "x-ycli-no-drop-null" +_NAMES = "x-ycli-identity" TEMPLATES = ROOT / "scripts" / "datalens_templates" @@ -748,6 +749,154 @@ def _mark_nulls_to_keep(spec: dict[str, Any]) -> int: return marked +# The key of a reply that says which object it is: what the command that reads the object +# takes, so ``-o name`` can print it. One line for each section of the specification. The +# specification itself names it in 9 sections of 34 (the required argument of ``get…`` that +# its reply repeats); elsewhere the reply wraps the object, names the key otherwise than the +# request does, or the section has no ``get``. +_IDENTIFIERS = { + "Access": "sub", + "Audit": "entryId", + "CloudEnvironments": "id", + "Collection": "collectionId", + "Connection": "id", + "Dataset": "id", + "EmbeddingSecrets": "embeddingSecretId", + "Embeds": "embedId", + "Entries": "entryId", + "EntryLock": "entryId", + "HtmlPages": "entryId", + "LakehouseOperations": "id", + "Licensing": "userId", + "Navigation": "entryId", + "RestCatalogs": "id", + "SparkApplications": "id", + "SparkClusters": "id", + "TrinoClusters": "id", + "Workbook": "workbookId", + "WorkbookExport": "exportId", + "WorkbookImport": "importId", +} +# A section whose replies are no object a command reads back, and why. +_NO_IDENTIFIER = { + "CloudEnvironmentStorage": "a file of a bucket is told by its path, which the caller gave", + **dict.fromkeys( + ("Dashboard", "Editor", "Reports", "SqlQueries", "Wizard"), + "its replies wrap the object in `entry`; a mark that reaches into a wrapper is not decided", + ), + "Data": "rows of data, not objects", + "Favorites": "not wrapped: wrapping the section is not decided", + "Folder": "not wrapped: the old placement model", + "Permissions": "what the caller may do, not an object", + "QL": "its replies are read into a model written by hand", + "SharedEntry": "who has access, told by the subject and the role together", + "Tenants": "the one tenant of the caller", +} +# An operation whose reply holds objects of another kind than its section's, which carry the +# section's key as a reference to their parent: the key of what it returns, or ``None`` where +# it returns several kinds and an identifier alone would not say which command reads it. +_RETURNS_ANOTHER_KIND: dict[str, str | None] = { + "getWorkbookEntries": "entryId", + "getCollectionContent": None, + "getRevisions": "revId", +} + + +def _rows(schemas: dict[str, Any], reply: dict[str, Any]) -> set[str]: + """The schemas a command prints as rows: the reply itself, or the items of a list in it. + + A reply that is one of several kinds is each of them. What lies deeper (the fields of a + dataset, the object inside an ``entry`` wrapper) is not a row: no command reads it by + the key it holds. + """ + found: set[str] = set() + + def take(schema: Any, *, lists: bool) -> None: + if not isinstance(schema, dict): + return + name = schema.get("$ref", "").removeprefix(_REF) + if name and name not in found: + found.add(name) + take(schemas[name], lists=lists) + for member in (*schema.get("oneOf", []), *schema.get("anyOf", [])): + take(member, lists=lists) + take(schema.get("items"), lists=False) + if lists: # the list a reply wraps: ``{entries: [...], nextPageToken}`` + for field in (schema.get("properties") or {}).values(): + held = schemas.get(field.get("$ref", "").removeprefix(_REF), field) + take(held.get("items"), lists=False) + + take(reply, lists=True) + return found + + +def _mark_identifiers(spec: dict[str, Any]) -> int: + """Mark the field that names the object in every row of a reply; return how many. + + A row (:func:`_rows`) takes the key of the section whose operation returns it, or the key + :data:`_RETURNS_ANOTHER_KIND` gives that operation. The mark becomes + ``Annotated[..., Identity()]`` in the generated class (``ycli.yandex.sync.marks``). + + Raises: + SystemExit: A section stands in neither table or in both; an operation of + :data:`_RETURNS_ANOTHER_KIND` is not in the specification; a key that no reply + schema it is declared for has; a schema that two keys would name. + """ + schemas = spec["components"]["schemas"] + keys: dict[str, set[str]] = {} # the keys declared for each schema, by what reaches it + marked: dict[str, int] = {} # how many schemas each declaration named + replies = [(name, tag, body) for name, tag, kind, body in _bodies(spec) if kind == "Response"] + sections = {tag for _, tag, _, _ in _bodies(spec)} + undeclared = sections - _IDENTIFIERS.keys() - _NO_IDENTIFIER.keys() + twice = _IDENTIFIERS.keys() & _NO_IDENTIFIER.keys() + gone = _RETURNS_ANOTHER_KIND.keys() - {name for name, _, _ in replies} + stale = (_IDENTIFIERS.keys() | _NO_IDENTIFIER.keys()) - sections + if undeclared or twice or gone or stale: + raise SystemExit( + "the identifier of a section is declared once, in _IDENTIFIERS or _NO_IDENTIFIER: " + f"neither {sorted(undeclared)}, both {sorted(twice)}, no such section " + f"{sorted(stale)}, no such operation {sorted(gone)}" + ) + reached: dict[str, set[str]] = {} # the schemas each declaration reaches + for operation, tag, holder in replies: + declared = operation if operation in _RETURNS_ANOTHER_KIND else tag + key = _RETURNS_ANOTHER_KIND.get(operation, _IDENTIFIERS.get(tag)) + seen = _rows(schemas, holder["schema"]) + reached.setdefault(declared, set()).update(seen) + marked.setdefault(declared, 0) + for name in seen: + keys.setdefault(name, set()).update([key] if key else []) + # What an operation of another kind returns is named by that operation alone. + apart = set().union(*(reached.get(name, set()) for name in _RETURNS_ANOTHER_KIND)) + for name in apart: + keys[name] = { + key + for operation in _RETURNS_ANOTHER_KIND + if name in reached[operation] + if (key := _RETURNS_ANOTHER_KIND[operation]) + } + total = 0 + for name, declared_keys in sorted(keys.items()): + properties = schemas[name].get("properties") + held = sorted(declared_keys & properties.keys()) if isinstance(properties, dict) else [] + if len(held) > 1: + raise SystemExit(f"{name} would be named by two keys: {held}") + for key in held: + properties[key][_NAMES] = True + total += 1 + for declared, names in reached.items(): + own = _RETURNS_ANOTHER_KIND.get(declared, _IDENTIFIERS.get(declared)) + marked[declared] += name in names and own == key + unused = sorted( + declared + for declared, count in marked.items() + if not count and _RETURNS_ANOTHER_KIND.get(declared, _IDENTIFIERS.get(declared)) + ) + if unused: + raise SystemExit(f"no reply schema has the key declared for: {unused}") + return total + + def _union_members(spec: dict[str, Any]) -> set[int]: """The objects that are members of a union of objects, by ``id``.""" members: set[int] = set() @@ -931,6 +1080,7 @@ def prepare(spec: dict[str, Any]) -> dict[str, Any]: _close_only_requests(spec) _mark_union_envelopes(spec) _name_every_object(spec) + _mark_identifiers(spec) section = _sections(spec) schemas = { name: schema for name, schema in spec["components"]["schemas"].items() if name in section @@ -1095,15 +1245,15 @@ def foreign(text: str) -> list[str]: return found -def _taken_marks(schema: dict[str, Any]) -> list[str]: - """The fields of ``schema`` marked to keep their null, with the mark taken off them.""" +def _taken_marks(schema: dict[str, Any], mark: str = _KEEPS_NULL) -> list[str]: + """The fields of ``schema`` that carry ``mark``, with the mark taken off them.""" properties = schema.get("properties") if not isinstance(properties, dict): return [] return [ name for name, field in properties.items() - if isinstance(field, dict) and field.pop(_KEEPS_NULL, False) + if isinstance(field, dict) and field.pop(mark, False) ] @@ -1123,6 +1273,8 @@ def generate(spec: dict[str, Any]) -> dict[str, str]: data: dict[str, Any] = {} if kept := _taken_marks(schema): data["no_drop_null"] = kept + if named := _taken_marks(schema, _NAMES): + data["identity"] = named if schema.pop(_TOLD_APART, False): data["kind_by_own_field"] = True if data: @@ -1148,7 +1300,7 @@ def generate(spec: dict[str, Any]) -> dict[str, str]: *( "--additional-imports", "typing.Annotated,ycli.yandex.models.NoDropNull," - "ycli.yandex.models.KindByOwnField", + "ycli.yandex.models.KindByOwnField,ycli.yandex.sync.marks.Identity", ), *("--base-class", "ycli.yandex.models.APIModel", "--openapi-scopes", "schemas"), *("--enum-field-as-literal", "all", "--treat-dot-as-module"), diff --git a/src/ycli/cli/output.py b/src/ycli/cli/output.py index ca99cef1f..2292d167f 100644 --- a/src/ycli/cli/output.py +++ b/src/ycli/cli/output.py @@ -439,7 +439,8 @@ def render(self, result: BaseModel, console: Console) -> None: more = f" (and {len(unnamed) - 1} more)" if len(unnamed) > 1 else "" key = ".".join(columns[first - 1] or ()) raise YandexUnexpectedReplyError( - f"item {first} of this listing has no {key}{more}: `-o name` cannot name it" + f"item {first} of this listing has no {key}{more}: `-o name` cannot name it. " + "The request was sent: a command that changes something has changed it" ) console.file.writelines(name + "\n" for name in names) diff --git a/src/ycli/yandex/datalens/schemas/access.py b/src/ycli/yandex/datalens/schemas/access.py index a2635fa67..579e344b0 100644 --- a/src/ycli/yandex/datalens/schemas/access.py +++ b/src/ycli/yandex/datalens/schemas/access.py @@ -1,14 +1,15 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. -from typing import Any, Literal +from typing import Annotated, Any, Literal from pydantic import Field from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity class AccessExtSubjectClaims(APIModel): - sub: str | None = Field(default=None, description="Subject identifier.") + sub: Annotated[str | None, Identity()] = Field(default=None, description="Subject identifier.") sub_type: ( Literal[ "SUBJECT_TYPE_UNSPECIFIED", diff --git a/src/ycli/yandex/datalens/schemas/audit.py b/src/ycli/yandex/datalens/schemas/audit.py index a62e46827..704352a65 100644 --- a/src/ycli/yandex/datalens/schemas/audit.py +++ b/src/ycli/yandex/datalens/schemas/audit.py @@ -5,12 +5,13 @@ from pydantic import AwareDatetime, Field, RootModel from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared class AuditEntry(APIModel): - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="Unique identifier of the entry" ) key: Annotated[str | None, NoDropNull()] = Field( diff --git a/src/ycli/yandex/datalens/schemas/cloud_environments.py b/src/ycli/yandex/datalens/schemas/cloud_environments.py index 644517da7..930c7cda7 100644 --- a/src/ycli/yandex/datalens/schemas/cloud_environments.py +++ b/src/ycli/yandex/datalens/schemas/cloud_environments.py @@ -1,10 +1,11 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. -from typing import Literal +from typing import Annotated, Literal from pydantic import Field from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity class ListCloudEnvironmentsArgs(RequestBody): @@ -91,7 +92,9 @@ class UpdateCloudEnvironmentArgsStorage(APIModel): class CloudEnvironment(APIModel): - id: str | None = Field(default=None, description="ID of the cloud environment.") + id: Annotated[str | None, Identity()] = Field( + default=None, description="ID of the cloud environment." + ) name: str | None = Field(default=None, description="Name of the cloud environment.") description: str | None = Field( default=None, description="Description of the cloud environment." diff --git a/src/ycli/yandex/datalens/schemas/collection.py b/src/ycli/yandex/datalens/schemas/collection.py index 5e567bb94..ea0a0764b 100644 --- a/src/ycli/yandex/datalens/schemas/collection.py +++ b/src/ycli/yandex/datalens/schemas/collection.py @@ -5,6 +5,7 @@ from pydantic import Field, RootModel from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared @@ -20,7 +21,7 @@ class CreateCollectionArgs(RequestBody): class Collection(APIModel): - collection_id: str | None = Field( + collection_id: Annotated[str | None, Identity()] = Field( default=None, alias="collectionId", description="Unique identifier of the collection.", @@ -479,7 +480,7 @@ class GetStructureItemsResultItemsItemVariant2Permissions(APIModel): class CreateCollectionResult(APIModel): - collection_id: str | None = Field( + collection_id: Annotated[str | None, Identity()] = Field( default=None, alias="collectionId", description="Unique identifier of the collection.", @@ -517,7 +518,7 @@ class CreateCollectionResult(APIModel): class GetCollectionResult(APIModel): - collection_id: str | None = Field( + collection_id: Annotated[str | None, Identity()] = Field( default=None, alias="collectionId", description="Unique identifier of the collection.", @@ -597,7 +598,7 @@ class StructureItemEntry(APIModel): class GetCollectionBreadcrumbsResultItem(APIModel): - collection_id: str | None = Field( + collection_id: Annotated[str | None, Identity()] = Field( default=None, alias="collectionId", description="Unique identifier of the collection.", diff --git a/src/ycli/yandex/datalens/schemas/connection.py b/src/ycli/yandex/datalens/schemas/connection.py index 56021b632..7b192cb1c 100644 --- a/src/ycli/yandex/datalens/schemas/connection.py +++ b/src/ycli/yandex/datalens/schemas/connection.py @@ -5,12 +5,13 @@ from pydantic import AwareDatetime, Field, RootModel, SecretStr from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared class ConnectionCreateResponse(APIModel): - id: str | None = None + id: Annotated[str | None, Identity()] = None operation: dict[str, Any] | None = None @@ -1343,7 +1344,7 @@ class AppmetricaApi1(APIModel): created_at: str | None = None data_export_forbidden: Literal["on", "off"] | str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1362,7 +1363,7 @@ class Bigquery1(APIModel): created_at: str | None = None credentials: SecretStr | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1384,7 +1385,7 @@ class Bitrix241(APIModel): created_at: str | None = None data_export_forbidden: Literal["on", "off"] | str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1401,7 +1402,7 @@ class ChBillingAnalytics1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1416,7 +1417,7 @@ class ChYaMusicPodcastStats1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1437,7 +1438,7 @@ class Chyt1(APIModel): data_export_forbidden: Literal["on", "off"] | str | None = None description: str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1474,7 +1475,7 @@ class Clickhouse1(APIModel): dlp_managed_folder_id: str | None = None experimental_features: Literal["on", "off"] | str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None mdb_cluster_id: str | None = None mdb_folder_id: str | None = None @@ -1504,7 +1505,7 @@ class Equeo1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1520,7 +1521,7 @@ class Extractor1c1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1541,7 +1542,7 @@ class Greenplum1(APIModel): description: str | None = None enforce_collate: Literal["auto", "on", "off"] | str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None mdb_cluster_id: str | None = None mdb_folder_id: str | None = None @@ -1569,7 +1570,7 @@ class Gsheets1(APIModel): created_at: str | None = None data_export_forbidden: Literal["on", "off"] | str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1587,7 +1588,7 @@ class JsonApi1(APIModel): created_at: str | None = None description: str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1608,7 +1609,7 @@ class KonturMarket1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1626,7 +1627,7 @@ class MetrikaApi1(APIModel): created_at: str | None = None data_export_forbidden: Literal["on", "off"] | str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1647,7 +1648,7 @@ class Monitoring1(APIModel): delegation_is_set: bool | None = None description: str | None = None folder_id: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1664,7 +1665,7 @@ class Moysklad1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1684,7 +1685,7 @@ class Mssql1(APIModel): db_name: str | None = None description: str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1721,7 +1722,7 @@ class Mysql1(APIModel): dlp_managed_folder_id: str | None = None enforce_collate: Literal["auto", "on", "off"] | str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None mdb_cluster_id: str | None = None mdb_folder_id: str | None = None @@ -1754,7 +1755,7 @@ class Oracle1(APIModel): db_name: str | None = None description: str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1793,7 +1794,7 @@ class Postgres1(APIModel): dlp_managed_folder_id: str | None = None enforce_collate: Literal["auto", "on", "off"] | str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None mdb_cluster_id: str | None = None mdb_folder_id: str | None = None @@ -1827,7 +1828,7 @@ class Promql1(APIModel): db_name: str | None = None description: str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1847,7 +1848,7 @@ class SmbHeatmaps1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1868,7 +1869,7 @@ class Snowflake1(APIModel): data_export_forbidden: Literal["on", "off"] | str | None = None db_name: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1897,7 +1898,7 @@ class Speechsense1(APIModel): delegation_is_set: bool | None = None description: str | None = None folder_id: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1930,7 +1931,7 @@ class Trino1(APIModel): folder_id: str | None = None form_fill_mode: Literal["cloud", "manually", "platform"] | str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None jwt: SecretStr | None = None key: str | None = None listing_sources: Literal["on", "off"] | str | None = None @@ -1957,7 +1958,7 @@ class UsageAnalyticsDetailed1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1972,7 +1973,7 @@ class UsageAnalyticsLight1(APIModel): collection_id: str | None = None created_at: str | None = None description: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None @@ -1996,7 +1997,7 @@ class Ydb1(APIModel): description: str | None = None folder_id: str | None = None host: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None mdb_cluster_id: str | None = None mdb_folder_id: str | None = None @@ -2028,7 +2029,7 @@ class Yq1(APIModel): delegation_is_set: bool | None = None description: str | None = None folder_id: str | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None key: str | None = None meta: dict[str, Any] | None = None name: str | None = None diff --git a/src/ycli/yandex/datalens/schemas/dataset.py b/src/ycli/yandex/datalens/schemas/dataset.py index a2b6a3415..10609bd94 100644 --- a/src/ycli/yandex/datalens/schemas/dataset.py +++ b/src/ycli/yandex/datalens/schemas/dataset.py @@ -6,6 +6,7 @@ from pydantic import AwareDatetime, Field, RootModel from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared @@ -2835,7 +2836,7 @@ class DatasetRead(APIModel): ctime: str | None = None dataset: DatasetContentInternal | None = None full_permissions: dict[str, bool] | None = None - id: str | None = None + id: Annotated[str | None, Identity()] = None is_favorite: bool | None = None key: str | None = None mtime: str | None = None diff --git a/src/ycli/yandex/datalens/schemas/embedding_secrets.py b/src/ycli/yandex/datalens/schemas/embedding_secrets.py index 233435352..7e50ace49 100644 --- a/src/ycli/yandex/datalens/schemas/embedding_secrets.py +++ b/src/ycli/yandex/datalens/schemas/embedding_secrets.py @@ -1,13 +1,15 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. +from typing import Annotated from pydantic import Field, RootModel from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity class CreateEmbeddingSecretResult(APIModel): - embedding_secret_id: str | None = Field( + embedding_secret_id: Annotated[str | None, Identity()] = Field( default=None, alias="embeddingSecretId", description="ID of the newly created key for embedding.", @@ -29,7 +31,7 @@ class CreateEmbeddingSecretArgs(RequestBody): class EmbeddingSecret(APIModel): - embedding_secret_id: str | None = Field( + embedding_secret_id: Annotated[str | None, Identity()] = Field( default=None, alias="embeddingSecretId", description="Unique identifier of the key for embedding.", @@ -61,7 +63,7 @@ class ListEmbeddingSecretsArgs(RequestBody): class DeleteEmbeddingSecretResult(APIModel): - embedding_secret_id: str | None = Field( + embedding_secret_id: Annotated[str | None, Identity()] = Field( default=None, alias="embeddingSecretId", description="ID of the deleted key for embedding.", diff --git a/src/ycli/yandex/datalens/schemas/embeds.py b/src/ycli/yandex/datalens/schemas/embeds.py index 808b3d5ef..86536509f 100644 --- a/src/ycli/yandex/datalens/schemas/embeds.py +++ b/src/ycli/yandex/datalens/schemas/embeds.py @@ -1,9 +1,11 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. +from typing import Annotated from pydantic import Field, RootModel from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity class EmbedSettings(APIModel): @@ -15,7 +17,7 @@ class EmbedSettings(APIModel): class Embed(APIModel): - embed_id: str | None = Field( + embed_id: Annotated[str | None, Identity()] = Field( default=None, alias="embedId", description="Unique identifier of the embedding." ) title: str | None = Field(default=None, description="Name of the embedding.") @@ -106,7 +108,7 @@ class ListEmbedsArgs(RequestBody): class DeleteEmbedResult(APIModel): - embed_id: str | None = Field( + embed_id: Annotated[str | None, Identity()] = Field( default=None, alias="embedId", description="ID of the deleted embedding." ) diff --git a/src/ycli/yandex/datalens/schemas/entries.py b/src/ycli/yandex/datalens/schemas/entries.py index b7fc104bb..0e4f68e45 100644 --- a/src/ycli/yandex/datalens/schemas/entries.py +++ b/src/ycli/yandex/datalens/schemas/entries.py @@ -5,6 +5,7 @@ from pydantic import Field, RootModel from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared @@ -35,7 +36,7 @@ class GetEntriesRelationsArgs(RequestBody): class RenameEntryResultEntry(APIModel): - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="ID of the renamed entry." ) key: str | None = Field(default=None, description="Updated key of the entry.") @@ -155,7 +156,7 @@ class GetEntriesPermissionsResultValuePermissions(APIModel): class GetRevisionsResultEntriesItem(APIModel): - rev_id: str | None = Field( + rev_id: Annotated[str | None, Identity()] = Field( default=None, alias="revId", description="Unique identifier of the revision." ) updated_at: str | None = Field( @@ -181,7 +182,7 @@ class GetRevisionsResultEntriesItem(APIModel): class GetEntriesRelationsEntry(APIModel): - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="Unique identifier of the entry." ) key: Annotated[str | None, NoDropNull()] = Field( diff --git a/src/ycli/yandex/datalens/schemas/entry_lock.py b/src/ycli/yandex/datalens/schemas/entry_lock.py index ab12d6a9f..e1e9e7ba0 100644 --- a/src/ycli/yandex/datalens/schemas/entry_lock.py +++ b/src/ycli/yandex/datalens/schemas/entry_lock.py @@ -1,9 +1,11 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. +from typing import Annotated from pydantic import Field from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity class CreateEntryLockResult(APIModel): @@ -15,7 +17,7 @@ class CreateEntryLockResult(APIModel): class EntryLock(APIModel): - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="ID of the locked entry." ) lock_id: str | None = Field( diff --git a/src/ycli/yandex/datalens/schemas/html_pages.py b/src/ycli/yandex/datalens/schemas/html_pages.py index 4d79b22eb..f3d7ff0e4 100644 --- a/src/ycli/yandex/datalens/schemas/html_pages.py +++ b/src/ycli/yandex/datalens/schemas/html_pages.py @@ -5,6 +5,7 @@ from pydantic import Field, RootModel from ycli.yandex.models import APIModel, KindByOwnField, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity class GetHtmlPageArgs(RequestBody): @@ -211,7 +212,7 @@ class CreateHtmlPageArgs(RequestBody): class GetHtmlPageResult(APIModel): - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="Unique identifier of the HTML page." ) scope: Literal["artifact"] | None = Field( diff --git a/src/ycli/yandex/datalens/schemas/licensing.py b/src/ycli/yandex/datalens/schemas/licensing.py index 1662f3569..cc9f74aa9 100644 --- a/src/ycli/yandex/datalens/schemas/licensing.py +++ b/src/ycli/yandex/datalens/schemas/licensing.py @@ -5,6 +5,7 @@ from pydantic import Field, RootModel from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity class LicenseWithLastLogin(APIModel): @@ -17,7 +18,7 @@ class LicenseWithLastLogin(APIModel): alias="tenantId", description="ID of the tenant that owns the license.", ) - user_id: str | None = Field( + user_id: Annotated[str | None, Identity()] = Field( default=None, alias="userId", description="ID of the user assigned the license." ) license_type: Literal["creator", "viewer"] | str | None = Field( @@ -110,7 +111,7 @@ class License(APIModel): alias="tenantId", description="ID of the tenant that owns the license.", ) - user_id: str | None = Field( + user_id: Annotated[str | None, Identity()] = Field( default=None, alias="userId", description="ID of the user assigned the license." ) license_type: Literal["creator", "viewer"] | str | None = Field( diff --git a/src/ycli/yandex/datalens/schemas/navigation.py b/src/ycli/yandex/datalens/schemas/navigation.py index 5f61de03d..c9076e41c 100644 --- a/src/ycli/yandex/datalens/schemas/navigation.py +++ b/src/ycli/yandex/datalens/schemas/navigation.py @@ -5,6 +5,7 @@ from pydantic import Field from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared @@ -167,7 +168,7 @@ class GetEntriesV2Args(RequestBody): class ListDirectoryBreadCrumb(APIModel): title: str | None = Field(default=None, description="Title of the breadcrumb item.") path: str | None = Field(default=None, description="Path of the breadcrumb item.") - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="Entry ID of the breadcrumb item." ) is_locked: bool | None = Field( @@ -177,7 +178,7 @@ class ListDirectoryBreadCrumb(APIModel): class ListDirectoryEntry(APIModel): - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="Unique identifier of the entry." ) key: str | None = Field(default=None, description="Key identifier of the entry.") @@ -277,7 +278,7 @@ class GetEntriesV2ResultEntriesItem(APIModel): alias="isLocked", description="Indicates that the entry is locked.", ) - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="Unique identifier of the locked entry.", diff --git a/src/ycli/yandex/datalens/schemas/rest_catalogs.py b/src/ycli/yandex/datalens/schemas/rest_catalogs.py index 9c3622fba..40228a3a4 100644 --- a/src/ycli/yandex/datalens/schemas/rest_catalogs.py +++ b/src/ycli/yandex/datalens/schemas/rest_catalogs.py @@ -1,10 +1,11 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. -from typing import Literal +from typing import Annotated, Literal from pydantic import Field from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity class ListCatalogsArgs(RequestBody): @@ -149,7 +150,9 @@ class ListCatalogsResultRestCatalogsItemBucket(APIModel): class ListCatalogsResultRestCatalogsItem(APIModel): - id: str | None = Field(default=None, description="ID of the REST catalog.") + id: Annotated[str | None, Identity()] = Field( + default=None, description="ID of the REST catalog." + ) organization_id: str | None = Field( default=None, alias="organizationId", diff --git a/src/ycli/yandex/datalens/schemas/shared.py b/src/ycli/yandex/datalens/schemas/shared.py index 9ea631d0f..88e0b2ffb 100644 --- a/src/ycli/yandex/datalens/schemas/shared.py +++ b/src/ycli/yandex/datalens/schemas/shared.py @@ -1,10 +1,11 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. -from typing import Any, Literal +from typing import Annotated, Any, Literal from pydantic import Field, RootModel from ycli.yandex.models import APIModel +from ycli.yandex.sync.marks import Identity class EntryScope( @@ -785,7 +786,9 @@ class ListAccessBindingsResult(APIModel): class LakehouseOperation(APIModel): - id: str | None = Field(default=None, description="Unique ID of the operation.") + id: Annotated[str | None, Identity()] = Field( + default=None, description="Unique ID of the operation." + ) description: str | None = Field(default=None, description="Description of the operation.") created_at: LakehouseOperationCreatedAt | None = Field(default=None, alias="createdAt") created_by: str | None = Field( diff --git a/src/ycli/yandex/datalens/schemas/spark_applications.py b/src/ycli/yandex/datalens/schemas/spark_applications.py index 6284f4f88..59bfb0b0e 100644 --- a/src/ycli/yandex/datalens/schemas/spark_applications.py +++ b/src/ycli/yandex/datalens/schemas/spark_applications.py @@ -5,6 +5,7 @@ from pydantic import Field, RootModel from ycli.yandex.models import APIModel, KindByOwnField, RequestBody +from ycli.yandex.sync.marks import Identity class ListSparkApplicationsArgs(RequestBody): @@ -359,7 +360,9 @@ class CreateSparkApplicationArgsVariant3SparkConnectApplication(APIModel): class SparkApplication(APIModel): - id: str | None = Field(default=None, description="ID of the Spark application.") + id: Annotated[str | None, Identity()] = Field( + default=None, description="ID of the Spark application." + ) cluster_id: str | None = Field( default=None, alias="clusterId", description="ID of the Spark cluster." ) diff --git a/src/ycli/yandex/datalens/schemas/spark_clusters.py b/src/ycli/yandex/datalens/schemas/spark_clusters.py index 5a35724a0..e3372d709 100644 --- a/src/ycli/yandex/datalens/schemas/spark_clusters.py +++ b/src/ycli/yandex/datalens/schemas/spark_clusters.py @@ -1,10 +1,11 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. -from typing import Literal +from typing import Annotated, Literal from pydantic import Field from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity class ListSparkClustersArgs(RequestBody): @@ -46,7 +47,9 @@ class StopSparkClusterArgs(RequestBody): class SparkResourcePreset(APIModel): - id: str | None = Field(default=None, description="ID of the resource preset.") + id: Annotated[str | None, Identity()] = Field( + default=None, description="ID of the resource preset." + ) cores: str | None = Field( default=None, description="Number of CPU cores for an instance created with the preset.", @@ -376,7 +379,9 @@ class CreateSparkClusterArgsConfig(APIModel): class SparkCluster(APIModel): - id: str | None = Field(default=None, description="ID of the Spark cluster.") + id: Annotated[str | None, Identity()] = Field( + default=None, description="ID of the Spark cluster." + ) cluster_id: str | None = Field( default=None, alias="clusterId", description="ID of the managed Spark cluster." ) diff --git a/src/ycli/yandex/datalens/schemas/trino_clusters.py b/src/ycli/yandex/datalens/schemas/trino_clusters.py index d8cf33ec7..107feda32 100644 --- a/src/ycli/yandex/datalens/schemas/trino_clusters.py +++ b/src/ycli/yandex/datalens/schemas/trino_clusters.py @@ -1,10 +1,11 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. -from typing import Literal +from typing import Annotated, Literal from pydantic import Field from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity class ListTrinoClustersArgs(RequestBody): @@ -56,7 +57,9 @@ class DeleteTrinoClusterCatalogArgs(RequestBody): class TrinoResourcePreset(APIModel): - id: str | None = Field(default=None, description="ID of the resource preset.") + id: Annotated[str | None, Identity()] = Field( + default=None, description="ID of the resource preset." + ) cores: str | None = Field( default=None, description="Number of CPU cores for an instance created with the preset.", @@ -268,7 +271,9 @@ class TrinoClusterConfig(APIModel): class TrinoCluster(APIModel): - id: str | None = Field(default=None, description="ID of the Trino cluster.") + id: Annotated[str | None, Identity()] = Field( + default=None, description="ID of the Trino cluster." + ) cluster_id: str | None = Field( default=None, alias="clusterId", description="ID of the managed Trino cluster." ) diff --git a/src/ycli/yandex/datalens/schemas/workbook.py b/src/ycli/yandex/datalens/schemas/workbook.py index 995721c2e..2163e0ac9 100644 --- a/src/ycli/yandex/datalens/schemas/workbook.py +++ b/src/ycli/yandex/datalens/schemas/workbook.py @@ -5,6 +5,7 @@ from pydantic import Field, RootModel from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared @@ -282,7 +283,7 @@ class GetWorkbookEntriesArgsFilters(APIModel): class CreateWorkbookResult(APIModel): - workbook_id: str | None = Field( + workbook_id: Annotated[str | None, Identity()] = Field( default=None, alias="workbookId", description="Unique identifier of the workbook.", @@ -323,7 +324,7 @@ class CreateWorkbookResult(APIModel): class Workbook(APIModel): - workbook_id: str | None = Field( + workbook_id: Annotated[str | None, Identity()] = Field( default=None, alias="workbookId", description="Unique identifier of the workbook.", @@ -363,7 +364,7 @@ class Workbook(APIModel): class GetWorkbookResult(APIModel): - workbook_id: str | None = Field( + workbook_id: Annotated[str | None, Identity()] = Field( default=None, alias="workbookId", description="Unique identifier of the workbook.", @@ -404,7 +405,7 @@ class GetWorkbookResult(APIModel): class GetWorkbookEntriesEntry(APIModel): - entry_id: str | None = Field( + entry_id: Annotated[str | None, Identity()] = Field( default=None, alias="entryId", description="Unique identifier of the entry." ) scope: shared.EntryScope | None = None @@ -526,7 +527,7 @@ class MoveWorkbooksResponse(APIModel): class GetWorkbooksListResultWorkbooksItem(APIModel): - workbook_id: str | None = Field( + workbook_id: Annotated[str | None, Identity()] = Field( default=None, alias="workbookId", description="Unique identifier of the workbook.", diff --git a/src/ycli/yandex/datalens/schemas/workbook_export.py b/src/ycli/yandex/datalens/schemas/workbook_export.py index e817db554..8e42ba3e3 100644 --- a/src/ycli/yandex/datalens/schemas/workbook_export.py +++ b/src/ycli/yandex/datalens/schemas/workbook_export.py @@ -1,16 +1,17 @@ # Generated from the DataLens specification by scripts/gen_datalens_models.py; do not edit by hand. -from typing import Any +from typing import Annotated, Any from pydantic import Field from ycli.yandex.models import APIModel, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared class StartWorkbookExportResult(APIModel): - export_id: str | None = Field( + export_id: Annotated[str | None, Identity()] = Field( default=None, alias="exportId", description="ID of the started workbook export." ) @@ -20,7 +21,7 @@ class StartWorkbookExportArgs(RequestBody): class GetWorkbookExportStatusResult(APIModel): - export_id: str | None = Field( + export_id: Annotated[str | None, Identity()] = Field( default=None, alias="exportId", description="ID of the workbook export." ) status: shared.WorkbookTransferProcessStatus | None = None @@ -49,7 +50,7 @@ class GetWorkbookExportResultArgs(RequestBody): class CancelWorkbookExportResult(APIModel): - export_id: str | None = Field( + export_id: Annotated[str | None, Identity()] = Field( default=None, alias="exportId", description="ID of the canceled workbook export.", @@ -72,7 +73,7 @@ class GetWorkbookExportResultResultData(APIModel): class GetWorkbookExportResultResult(APIModel): - export_id: str | None = Field( + export_id: Annotated[str | None, Identity()] = Field( default=None, alias="exportId", description="ID of the workbook export." ) data: GetWorkbookExportResultResultData | None = None diff --git a/src/ycli/yandex/datalens/schemas/workbook_import.py b/src/ycli/yandex/datalens/schemas/workbook_import.py index 296aad85c..a245a28aa 100644 --- a/src/ycli/yandex/datalens/schemas/workbook_import.py +++ b/src/ycli/yandex/datalens/schemas/workbook_import.py @@ -5,12 +5,13 @@ from pydantic import Field from ycli.yandex.models import APIModel, NoDropNull, RequestBody +from ycli.yandex.sync.marks import Identity from . import shared class StartWorkbookImportResult(APIModel): - import_id: str | None = Field( + import_id: Annotated[str | None, Identity()] = Field( default=None, alias="importId", description="ID of the started workbook import." ) workbook_id: str | None = Field( @@ -34,7 +35,7 @@ class StartWorkbookImportArgs(RequestBody): class GetWorkbookImportStatusResult(APIModel): - import_id: str | None = Field( + import_id: Annotated[str | None, Identity()] = Field( default=None, alias="importId", description="ID of the workbook import." ) workbook_id: str | None = Field( diff --git a/tests/architecture/test_names.py b/tests/architecture/test_names.py index f968a95a0..01c27c882 100644 --- a/tests/architecture/test_names.py +++ b/tests/architecture/test_names.py @@ -23,10 +23,21 @@ "ycli.yandex.tracker.entities.models.Link": "a link is told by its two ends", "ycli.yandex.tracker.gaps.models.UserGaps": "the absences of a user, not one object", "ycli.yandex.wiki.resources.models.ResourceItem": "wraps a file or a grid of another kind", + **{ + f"ycli.yandex.datalens.schemas.{name}": ( + "a listing of several kinds: an id alone does not say which command reads it" + ) + for name in ( + "collection.GetStructureItemsResultItemsItemVariant1", + "collection.GetStructureItemsResultItemsItemVariant2", + "collection.StructureItemEntry", + "shared.OtherKind", + ) + }, + "ycli.yandex.datalens.schemas.shared.SubjectWithBindings": ( + "who has access, told by the subject and the role together" + ), } -#: The models generated from the DataLens specification name their identifier per resource, -#: where the generator can read it. Until then no listing of DataLens prints names. -GENERATED = "ycli.yandex.datalens.schemas." def _returns() -> dict[str, Any]: @@ -59,11 +70,10 @@ def unnamed(returns: dict[str, Any]) -> dict[str, list[str]]: def test_the_item_of_every_listing_names_itself_or_says_why_not(): found = unnamed(_returns()) - generated = {name for name in found if name.startswith(GENERATED)} - unexplained = found.keys() - generated - NO_NAME.keys() + # Every class by its own name: none is excused by where it lives. + unexplained = found.keys() - NO_NAME.keys() assert not unexplained, {name: found[name] for name in unexplained} assert not NO_NAME.keys() - found.keys(), "a reason for an item that names itself" - assert generated, "no generated model is left without a name: drop GENERATED" def test_the_check_bites(): diff --git a/tests/contract/test_output_formats.py b/tests/contract/test_output_formats.py index c3571585e..a98c145e9 100644 --- a/tests/contract/test_output_formats.py +++ b/tests/contract/test_output_formats.py @@ -157,6 +157,8 @@ def test_the_header_is_the_same_for_an_empty_listing_as_for_a_full_one( #: Operations with a case whose reply leaves out the field that names the item: ``-o name`` #: says so and prints nothing, so a script does not act on fewer objects than were listed. SPARSE = { + "datalens.datasets.update", + "datalens.datasets.validate", "forms.filling.submit", "tracker.boards.list", "tracker.comments.list", @@ -217,3 +219,27 @@ def test_name_prints_one_identifier_for_each_item_or_refuses_before_any_request( for name, item in zip(names, items, strict=True): own = item.values() if isinstance(item, dict) else [item] assert name in {value if isinstance(value, str) else json.dumps(value) for value in own} + + +def test_what_lies_in_a_workbook_is_named_by_its_own_id_not_by_the_workbook(monkeypatch): + """Under the section's key alone every line was the id of the workbook asked for. + + The same holds for the two other listings whose items are of another kind than their + section: ``collections content-list`` is refused, ``entries revisions-list`` prints + revisions. + """ + case = _first("datalens.workbooks.entries_list") + assert case.cli is not None + workbook = case.cli[3] + result, _ = _named(case, monkeypatch) + names = result.stdout.split() + assert names == ["ent00000000001", "ent00000000002"] + assert workbook not in names and len(set(names)) == len(names) + + refused, api = _named(_first("datalens.collections.content_list"), monkeypatch) + assert refused.exit_code == 2 and api.calls == [] + revisions, _ = _named(_first("datalens.entries.revisions_list"), monkeypatch) + listed = _items( + json.loads(_printed(_first("datalens.entries.revisions_list"), "json", monkeypatch)) + ) + assert revisions.stdout.split() == [item["revId"] for item in listed] diff --git a/tests/tooling/test_gen_datalens_models.py b/tests/tooling/test_gen_datalens_models.py index 68f4b1f65..08ca4bf98 100644 --- a/tests/tooling/test_gen_datalens_models.py +++ b/tests/tooling/test_gen_datalens_models.py @@ -18,6 +18,14 @@ REF = "#/components/schemas/" +_MARK_IDENTIFIERS = gen._mark_identifiers + + +@pytest.fixture(autouse=True) +def _small_documents_declare_no_identifier(monkeypatch): + """The documents of these tests have sections of their own, which the tables do not list.""" + monkeypatch.setattr(gen, "_mark_identifiers", lambda spec: 0) + def _json(schema: dict) -> dict: return {"content": {"application/json": {"schema": schema}}} @@ -955,9 +963,10 @@ def test_the_model_template_is_the_generators_own_but_for_what_ycli_adds(): changes = [line for line in difflib.ndiff(theirs, ours) if line[:1] in "+-"] assert [line[2:] for line in changes if line[0] == "-"] == [" {{ description }}"] added = [line[2:].strip() for line in changes if line[0] == "+"] - assert len(added) == 9 - assert sum(line.startswith("{#- ycli:") for line in added) == 2 + assert len(added) == 14 + assert sum(line.startswith("{#- ycli:") for line in added) == 3 assert sum("Annotated[{{ field.type_hint }}, NoDropNull()]" in line for line in added) == 2 + assert sum("Annotated[{{ field.type_hint }}, Identity()]" in line for line in added) == 2 def test_the_root_model_template_is_the_generators_own_but_for_what_ycli_adds(): @@ -1144,3 +1153,142 @@ def test_the_marked_classes_of_the_layer_are_its_unions_of_request_envelopes(): unions.add(name) assert marked == unions assert {"CreateSparkApplicationArgs", "UpdateHtmlPageArgs"} <= marked + + +def _named_document() -> dict: + """Two sections: things are read by ``thingId``; a part lists parts of a thing.""" + thing = {"type": "object", "properties": {"thingId": _text(), "title": _text()}} + part = {"type": "object", "properties": {"partId": _text(), "thingId": _text()}} + paths = { + "/rpc/getThing": {"post": {"tags": ["Things"], "responses": {"200": _json(thing)}}}, + "/rpc/getThingParts": { + "post": { + "tags": ["Things"], + "responses": { + "200": _json( + { + "type": "object", + "properties": {"parts": {"type": "array", "items": part}}, + } + ) + }, + } + }, + "/rpc/getStatus": { + "post": { + "tags": ["Status"], + "responses": {"200": _json({"type": "object", "properties": {"ok": _text()}})}, + } + }, + } + return {"openapi": "3.1.0", "paths": paths, "components": {"schemas": {}}} + + +def _declare(monkeypatch, identifiers: dict, nothing: dict, another: dict) -> None: + monkeypatch.setattr(gen, "_mark_identifiers", _MARK_IDENTIFIERS) + monkeypatch.setattr(gen, "_IDENTIFIERS", identifiers) + monkeypatch.setattr(gen, "_NO_IDENTIFIER", nothing) + monkeypatch.setattr(gen, "_RETURNS_ANOTHER_KIND", another) + + +def test_the_field_that_names_an_object_is_marked_by_its_section_or_its_operation(monkeypatch): + _declare( + monkeypatch, {"Things": "thingId"}, {"Status": "no object"}, {"getThingParts": "partId"} + ) + schemas = gen.prepare(_named_document())["components"]["schemas"] + named = { + (name, key) + for name, schema in schemas.items() + for key, field in (schema.get("properties") or {}).items() + if isinstance(field, dict) and field.get(gen._NAMES) + } + # A part carries the key of its thing too: the operation says it is named by its own. + assert named == { + ("things.GetThingResponse", "thingId"), + ("things.GetThingPartsResponsePartsItem", "partId"), + } + module = gen.generate(_named_document())["things.py"] + assert "thing_id: Annotated[str | None, Identity()] = Field(" in module + assert "part_id: Annotated[str | None, Identity()] = Field(" in module + assert "x-ycli" not in module and gen.foreign(module) == [] + + +def test_only_a_row_of_a_reply_is_marked_not_what_lies_inside_it(monkeypatch): + """A field of the object that holds the same key is read by no command: it has no mark.""" + document = _named_document() + owner = {"type": "object", "properties": {"thingId": _text(), "name": _text()}} + reply = document["paths"]["/rpc/getThing"]["post"]["responses"]["200"] + reply["content"]["application/json"]["schema"]["properties"]["owner"] = owner + _declare(monkeypatch, {"Things": "thingId"}, {"Status": "no object"}, {"getThingParts": None}) + schemas = gen.prepare(document)["components"]["schemas"] + marked = { + name + for name, schema in schemas.items() + for field in (schema.get("properties") or {}).values() + if isinstance(field, dict) and field.get(gen._NAMES) + } + assert marked == {"things.GetThingResponse"} + assert "thingId" in schemas["things.GetThingResponseOwner"]["properties"] + + +def test_an_operation_that_returns_several_kinds_names_none(monkeypatch): + _declare(monkeypatch, {"Things": "thingId"}, {"Status": "no object"}, {"getThingParts": None}) + schemas = gen.prepare(_named_document())["components"]["schemas"] + part = schemas["things.GetThingPartsResponsePartsItem"]["properties"] + assert not any(field.get(gen._NAMES) for field in part.values()) + + +@pytest.mark.parametrize( + ("identifiers", "nothing", "another", "said"), + [ + ({"Things": "thingId"}, {}, {}, "neither ['Status']"), + ({"Things": "thingId", "Status": "ok"}, {"Status": "no object"}, {}, "both ['Status']"), + ({"Things": "thingId"}, {"Status": "x", "Gone": "x"}, {}, "no such section ['Gone']"), + ( + {"Things": "thingId"}, + {"Status": "x"}, + {"getGone": "id"}, + "no such operation ['getGone']", + ), + ( + {"Things": "noSuchKey"}, + {"Status": "x"}, + {}, + "no reply schema has the key declared for: ['Things']", + ), + ( + {"Things": "thingId"}, + {"Status": "x"}, + {"getThingParts": "noSuchKey"}, + "['getThingParts']", + ), + ], +) +def test_a_declaration_the_specification_does_not_bear_out_stops_the_run( + monkeypatch, identifiers, nothing, another, said +): + _declare(monkeypatch, identifiers, nothing, another) + with pytest.raises(SystemExit) as stopped: + gen.prepare(_named_document()) + assert said in str(stopped.value) + + +def test_a_schema_two_sections_would_name_differently_stops_the_run(monkeypatch): + document = _named_document() + both = {"type": "object", "properties": {"thingId": _text(), "statusId": _text()}} + document["components"]["schemas"]["Shared"] = both + ref = {"$ref": "#/components/schemas/Shared"} + document["paths"]["/rpc/getThing"]["post"]["responses"]["200"] = _json(ref) + document["paths"]["/rpc/getStatus"]["post"]["responses"]["200"] = _json(ref) + _declare(monkeypatch, {"Things": "thingId", "Status": "statusId"}, {}, {}) + with pytest.raises(SystemExit, match="would be named by two keys"): + gen.prepare(document) + + +def test_every_section_of_the_published_names_declares_its_identifier_once(): + """The tables and the snapshot of what DataLens publishes agree, both ways.""" + snapshot = gen.ROOT / "scripts" / "api_snapshot" / "datalens.json" + published = {operation["group"] for operation in json.loads(snapshot.read_text())} + declared = gen._IDENTIFIERS.keys() | gen._NO_IDENTIFIER.keys() + assert declared == published + assert not gen._IDENTIFIERS.keys() & gen._NO_IDENTIFIER.keys() diff --git a/tests/unit/cli/test_output_strategies.py b/tests/unit/cli/test_output_strategies.py index d8b41dafe..79a8b289f 100644 --- a/tests/unit/cli/test_output_strategies.py +++ b/tests/unit/cli/test_output_strategies.py @@ -315,7 +315,8 @@ def test_name_prints_nothing_and_says_which_item_the_reply_left_unnamed(): with pytest.raises(YandexUnexpectedReplyError) as failed: NameStrategy().render(listed, console) assert str(failed.value) == ( - "item 2 of this listing has no issueKey (and 1 more): `-o name` cannot name it" + "item 2 of this listing has no issueKey (and 1 more): `-o name` cannot name it. " + "The request was sent: a command that changes something has changed it" ) assert buf.getvalue() == "" with pytest.raises(YandexUnexpectedReplyError, match="item 1 of this listing has no issueKey:"):