openapi: 3.1.0
info:
  title: 1C Connector API
  version: 0.1.0
  description: Read-first connector API for safe interaction with 1C metadata, BSL modules, and read-only queries.
servers:
  - url: http://localhost:8011
security:
  - serviceToken: []
paths:
  /health:
    get:
      operationId: health
      parameters:
        - $ref: "#/components/parameters/BaseId"
      responses:
        "200":
          description: Connector health.
  /methods:
    get:
      operationId: listAdapterMethods
      summary: Runtime adapter method registry
      description: Returns every supported RPC method, transport, description, selector capabilities, and input schema known by the running adapter.
      parameters:
        - name: method
          in: query
          required: false
          schema:
            type: string
          description: Optional exact method name.
      responses:
        "200":
          description: Runtime registry generated from the adapter method definitions.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdapterMethodsResponse"
  /rpc:
    post:
      operationId: callAdapterMethod
      summary: Universal adapter RPC
      description: Calls any method advertised by GET /methods. The selected method's input_schema from /methods defines payload.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AdapterRpcRequest"
      responses:
        "200":
          description: Method-specific adapter response. Application errors are returned as structured JSON statuses.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
  /extensions:
    get:
      operationId: listExtensions
      parameters:
        - $ref: "#/components/parameters/BaseId"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /metadata/object/templates:
    post:
      operationId: listObjectTemplates
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /metadata/object/template-details:
    post:
      operationId: getObjectTemplateDetails
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /metadata/object/form-details:
    post:
      operationId: getObjectFormDetails
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /metadata/object/commands:
    post:
      operationId: listObjectCommands
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /metadata/object/special-details:
    post:
      operationId: getObjectSpecialDetails
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /metadata/module-owner-cache/prune:
    post:
      operationId: pruneModuleOwnerCache
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /code/search:
    post:
      operationId: searchCode
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /code/read:
    post:
      operationId: readCode
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /templates/bindings:
    post:
      operationId: getTemplateBindings
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /diagnostics/call-chain:
    post:
      operationId: diagnoseCallChain
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /access/users/search:
    post:
      operationId: searchAccessUsers
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /access/object/roles:
    post:
      operationId: getAccessObjectRoles
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /access/object/subjects:
    post:
      operationId: getAccessObjectSubjects
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /access/rls/discover:
    post:
      operationId: discoverAccessRls
      requestBody:
        $ref: "#/components/requestBodies/AdapterMethodPayload"
      responses:
        "200":
          $ref: "#/components/responses/AdapterMethodResponse"
  /metadata/kinds:
    get:
      operationId: getMetadataKinds
      parameters:
        - $ref: "#/components/parameters/BaseId"
      responses:
        "200":
          description: Available metadata kinds.
  /metadata/objects:
    get:
      operationId: listMetadataObjects
      parameters:
        - $ref: "#/components/parameters/BaseId"
        - name: kind
          in: query
          required: true
          schema:
            $ref: "#/components/schemas/MetadataKind"
        - name: name_filter
          in: query
          required: false
          schema:
            type: string
          description: Optional substring filter over object name, synonym, or GUID. Use this instead of query.
        - name: include_storage
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Include physical DBNames/storage traces. Intended for low-level diagnostics, not normal user-facing metadata responses.
      responses:
        "200":
          description: 1C metadata objects for the requested kind. Physical storage traces are hidden unless include_storage=true.
  /metadata/object:
    get:
      operationId: getMetadataObject
      parameters:
        - $ref: "#/components/parameters/BaseId"
        - name: table
          in: query
          required: false
          schema:
            type: string
            enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
            default: Config
          description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
        - name: kind
          in: query
          required: true
          schema:
            $ref: "#/components/schemas/MetadataKind"
        - name: name
          in: query
          required: true
          schema:
            type: string
        - name: include_storage
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Include physical DBNames/storage traces. Intended for low-level diagnostics, not normal user-facing metadata responses.
      responses:
        "200":
          description: 1C metadata object card with decoded semantic sections. Physical storage traces are hidden unless include_storage=true.
  /metadata/object/decode:
    post:
      operationId: decodeMetadataObject
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                  default: Config
                  description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
                guid:
                  type: string
                  description: Config object GUID. If omitted, kind and name are used.
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                name:
                  type: string
                include_tree:
                  type: boolean
                  default: false
                include_text:
                  type: boolean
                  default: false
                max_depth:
                  type: integer
                  default: 3
                  maximum: 8
      responses:
        "200":
          description: Live decoded Config object profile with semantic sections and DBNames routes.
  /metadata/object/full:
    post:
      operationId: getFullMetadataObjectProfile
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                  default: Config
                  description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
                guid:
                  type: string
                  description: Config object GUID. If omitted, kind and name are used.
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                name:
                  type: string
                ordinal:
                  type: integer
                  minimum: 1
                  description: Optional 1-based object ordinal within metadata.objects.list for the selected kind.
                include_storage:
                  type: boolean
                  default: false
                  description: Include physical DBNames/storage traces for adapter diagnostics.
                sections:
                  type: array
                  description: Optional filter to run only selected sections of the full profile.
                  items:
                    type: string
                    enum:
                      - all
                      - card
                      - semantic
                      - forms
                      - templates
                      - commands
                      - modules
                      - parts_summary
                timeout_seconds:
                  type: integer
                  minimum: 1
                  description: Total job timeout in seconds.
                section_timeout_seconds:
                  type: integer
                  minimum: 1
                  description: Per-section timeout in seconds.
                include_parts_summary:
                  type: boolean
                  default: false
                include_form_module_text:
                  type: boolean
                  default: false
                include_module_text:
                  type: boolean
                  default: false
                  description: Include full object/module BSL text. By default only previews, routine lists, and validation are returned.
                max_forms:
                  type: integer
                  minimum: 1
                  maximum: 100
                limit:
                  type: integer
                  minimum: 1
                max_form_items:
                  type: integer
                  default: 1000
                max_items:
                  type: integer
                  minimum: 1
                  maximum: 5000
      responses:
        "200":
          description: High-level 1C object profile with card, semantic sections, decoded forms, BSL module profiles, and counts.
  /metadata/object/attributes:
    post:
      operationId: getMetadataObjectAttributes
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                  default: Config
                  description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
                guid:
                  type: string
                  description: Config object GUID. If omitted, kind and name are used.
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                name:
                  type: string
                ordinal:
                  type: integer
                  minimum: 1
                  description: Optional 1-based object ordinal within metadata.objects.list for the selected kind.
                include_storage:
                  type: boolean
                  default: false
                  description: Include physical DBNames/storage traces for adapter diagnostics.
      responses:
        "200":
          description: High-level 1C object attributes/requisites and tabular sections. Physical SQL/storage traces are hidden unless include_storage=true.
  /metadata/object/parts:
    post:
      operationId: listMetadataObjectParts
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                guid:
                  type: string
                  description: Config object GUID. If omitted, kind and name are used.
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                name:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                  default: Config
                  description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
                include_text:
                  type: boolean
                  default: false
                include_tree:
                  type: boolean
                  default: false
                part_limit:
                  type: integer
                  default: 200
      responses:
        "200":
          description: Live object Config parts classified by payload evidence.
  /metadata/object/modules:
    post:
      operationId: listMetadataObjectModules
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                  default: Config
                  description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
                guid:
                  type: string
                  description: Config object GUID. If omitted, kind and name are used.
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                name:
                  type: string
      responses:
        "200":
          description: Live BSL module stream ids for a metadata object.
  /metadata/object/related:
    post:
      operationId: listMetadataObjectRelated
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                  default: Config
                  description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
                guid:
                  type: string
                  description: Config object GUID. If omitted, kind and name are used.
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                name:
                  type: string
                include_text:
                  type: boolean
                  default: false
                guids_per_record:
                  type: integer
                  default: 5
      responses:
        "200":
          description: Related live Config records referenced by the object.
  /metadata/object/forms:
    post:
      operationId: listMetadataObjectForms
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                  default: Config
                  description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
                guid:
                  type: string
                  description: Config object GUID. If omitted, kind and name are used.
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                form:
                  type: string
                  description: Optional form name or synonym filter.
                include_text:
                  type: boolean
                  default: false
                include_tree:
                  type: boolean
                  default: false
      responses:
        "200":
          description: Live forms for the metadata object with decoded form payload part summaries.
  /metadata/form/decode:
    post:
      operationId: decodeMetadataForm
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                  default: Config
                  description: Storage table to read from. Use Config for active config, ConfigSave for saved config.
                form_guid:
                  type: string
                  description: Form GUID. The adapter will select the form payload part automatically.
                file_name:
                  type: string
                  description: Exact Config/FileName form payload, for example <form_guid>.0.
                max_items:
                  type: integer
                  default: 500
                include_module_text:
                  type: boolean
                  default: false
      responses:
        "200":
          description: Decoded live form payload profile.
  /metadata/saved-state/forms/search:
    post:
      operationId: searchSavedStateForms
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                tables:
                  type: array
                  items:
                    type: string
                    enum: [ConfigSave, ConfigCASSave]
                prefix:
                  type: string
                form:
                  type: string
                element:
                  type: string
                command:
                  type: string
                query:
                  type: string
                limit:
                  type: integer
                  default: 50
                scan_limit:
                  type: integer
                  default: 1000
      responses:
        "200":
          description: Saved-state form search/index result with matching writable targets.
  /metadata/form/write-target/resolve:
    post:
      operationId: resolveMetadataFormWriteTarget
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [ConfigSave, ConfigCASSave]
                  default: ConfigCASSave
                file_name:
                  type: string
                form_guid:
                  type: string
                form:
                  type: string
                element:
                  type: string
                command:
                  type: string
                element_id:
                  type: string
                element_path:
                  type: string
                property:
                  type: string
                value: {}
                source:
                  type: string
                  enum: [local, local_override, element, override]
                  description: Optional write source selector. Use local_override to intentionally write an element caption even when display text is inherited.
                search_limit:
                  type: integer
                  default: 10
                scan_limit:
                  type: integer
                  default: 1000
      responses:
        "200":
          description: Resolved saved-state form write target with source file, section, writable paths, and semantic diff.
  /metadata/form/element-write:
    post:
      operationId: planMetadataFormElementSavedStateWrite
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, allow_saved_state_write, edits]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [ConfigSave, ConfigCASSave]
                  default: ConfigSave
                  description: Saved-state table to target. Active Config/ConfigCAS writes are rejected.
                form_guid:
                  type: string
                  description: Form GUID. The adapter resolves the saved-state form payload automatically.
                file_name:
                  type: string
                  description: Exact saved-state FileName form payload, for example <form_guid>.0.
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                name:
                  type: string
                form:
                  type: string
                element:
                  type: string
                  description: Form element name or title.
                element_id:
                  type: string
                element_path:
                  type: string
                  description: Internal decoded element path, when available from diagnostic reads.
                allow_saved_state_write:
                  type: boolean
                  description: Required explicit opt-in. The method still returns a proposal and does not update SQL.
                edits:
                  type: array
                  minItems: 1
                  items:
                    type: object
                    required: [property, value]
                    properties:
                      property:
                        type: string
                        description: Decoded form element property, for example title, name, id, or Видимость.
                      value: {}
                      expected_old: {}
                      source:
                        type: string
                        enum: [local, local_override, element, override]
                        description: Optional write source selector. Use local_override to intentionally write the local form element caption.
                expected_sha1:
                  type: string
                include_payload:
                  type: boolean
                  default: false
      responses:
        "200":
          description: Reviewable saved-state form element change proposal. Does not apply SQL changes.
  /metadata/form/element-write-apply:
    post:
      operationId: runMetadataFormElementSavedStateWrite
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, edits]
              properties:
                base_id:
                  type: string
                execution_mode:
                  type: string
                  enum: [plan, apply, apply_and_verify, apply_and_rollback]
                  default: plan
                  description: plan returns a proposal; apply writes it; apply_and_verify writes and keeps the verified change; apply_and_rollback performs a smoke write and restores from backup.
                table:
                  type: string
                  enum: [ConfigSave, ConfigCASSave]
                  default: ConfigSave
                form_guid:
                  type: string
                file_name:
                  type: string
                kind:
                  $ref: "#/components/schemas/MetadataKind"
                name:
                  type: string
                form:
                  type: string
                element:
                  type: string
                element_id:
                  type: string
                element_path:
                  type: string
                allow_sql_saved_state_apply:
                  type: boolean
                  description: Required for execution_mode apply, apply_and_verify, and apply_and_rollback.
                allow_sql_saved_state_rollback:
                  type: boolean
                  description: Required for execution_mode apply_and_rollback.
                edits:
                  type: array
                  minItems: 1
                  items:
                    type: object
                    required: [property, value]
                    properties:
                      property:
                        type: string
                      value: {}
                      expected_old: {}
                      source:
                        type: string
                        enum: [local, local_override, element, override]
                expected_sha1:
                  type: string
      responses:
        "200":
          description: Orchestrated saved-state form element write plan/apply result with semantic verification and optional rollback.
  /metadata/write-plan:
    post:
      operationId: planMetadataWrite
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                target:
                  type: object
                  additionalProperties: true
                  properties:
                    canonical_path:
                      type: string
                      description: Full semantic 1C path, for example Справочник.Контрагенты.Наименование.
                    kind:
                      type: string
                      description: Target surface such as metadata, form, or module.
                    module_ref:
                      type: string
                      description: Concrete saved-state module stream reference.
                    module_id:
                      type: string
                      description: Alias for a concrete saved-state module stream reference.
                    file_name:
                      type: string
                      description: Concrete saved-state file name.
                    form_guid:
                      type: string
                      description: Concrete saved-state form GUID.
                    origin:
                      type: object
                      additionalProperties: true
                      description: Public origin evidence from code.search, code.read, modules.search, or modules.read. Used for layer recommendation without repeating metadata.definition.find.
                    extension_action:
                      type: object
                      additionalProperties: true
                      description: Public routine action evidence from metadata.resolve_overrides. Known actions can infer or validate operation_class; unknown actions block write planning.
                intent:
                  type: object
                  additionalProperties: true
                  properties:
                    operation:
                      type: string
                      description: add, property_change, insert_before, insert_after, replace, replace_with_control, append_routine, upsert_routine, or move_form_item.
                    property:
                      type: string
                    value: {}
                preferred_layer:
                  type: string
                  default: auto
                  description: auto, base, extension, or generated_extension_source.
                preferred_extension:
                  type: string
                  description: Optional expected extension name or GUID. Returned as preferred_extension_conflict when it disagrees with origin evidence.
                extension_actions:
                  type: array
                  items:
                    type: object
                    additionalProperties: true
                  description: Extension action evidence list from metadata.resolve_overrides. A single item can be used as evidence; multiple items block planning as ambiguous until narrowed.
                resolve_origin:
                  type: boolean
                  default: true
                  description: When true, call metadata.definition.find and return compact origin_lookup evidence for canonical_path targets.
                origin_max_matches:
                  type: integer
                  minimum: 1
                  maximum: 100
                  default: 20
      responses:
        "200":
          description: Read-only write plan with canonical-path validation, route proposal, required guards, and problems. Never applies changes.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplateReadResponse"
                properties:
                  schema:
                    type: string
                    enum: [onec_metadata_write_plan.v1]
                  status:
                    type: string
                    enum: [planned, blocked, needs_route, needs_origin]
                  allowed:
                    type: boolean
                  target:
                    type: object
                    additionalProperties: true
                    properties:
                      canonical_path:
                        type: string
                      input_path:
                        type: string
                        nullable: true
                      path_kind:
                        type: string
                      target_kind:
                        type: string
                        enum: [metadata, form, module]
                      concrete_reference:
                        type: string
                        nullable: true
                      concrete_reference_field:
                        type: string
                        nullable: true
                        enum: [module_ref, module_id, file_name, form_guid, null]
                      concrete_reference_source:
                        type: string
                        nullable: true
                        enum: [target, payload, null]
                  route:
                    type: object
                    additionalProperties: true
                    properties:
                      target_kind:
                        type: string
                      operation:
                        type: string
                      operation_class:
                        type: string
                      write_surface:
                        type: string
                      apply_method:
                        type: string
                        nullable: true
                      apply_payload_hint:
                        type: object
                        additionalProperties: true
                        properties:
                          method:
                            type: string
                          ready_for_apply_method:
                            type: boolean
                          next_resolution:
                            type: object
                            additionalProperties: true
                          payload:
                            type: object
                            additionalProperties: true
                  required_guards:
                    type: array
                    items:
                      type: string
                  problems:
                    type: array
                    items:
                      type: object
                      additionalProperties: true
  /metadata/resolve-overrides:
    post:
      operationId: resolveMetadataOverrides
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, method_name]
              properties:
                base_id:
                  type: string
                method_name:
                  type: string
                  description: Procedure or function name to resolve inside the selected object modules.
                object_type:
                  type: string
                  description: 1C metadata kind, for example Catalog, Document, CommonModule.
                object_name:
                  type: string
                  description: 1C metadata object name.
                object_guid:
                  type: string
                  description: 1C metadata object GUID when known.
                ref:
                  type: string
                  description: Public object reference such as Справочник.Номенклатура.
      responses:
        "200":
          description: Read-only routine override/action chain across base and extension modules.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplateReadResponse"
                properties:
                  schema:
                    type: string
                    enum: [onec_metadata_resolve_overrides.v1]
                  status:
                    type: string
                    enum: [ok, not_found]
                  target_method:
                    type: string
                  chain:
                    type: array
                    items:
                      type: object
                      additionalProperties: true
                      properties:
                        source:
                          type: string
                          enum: [configuration, extension]
                        method:
                          type: string
                        line_start:
                          type: integer
                        line_end:
                          type: integer
                        extension_action:
                          type: object
                          additionalProperties: true
                          properties:
                            status:
                              type: string
                              enum: [ok, unknown]
                            operation_class:
                              type: string
                              description: base_definition, insert_before, insert_after, replace, replace_with_control, or unknown_extension_action.
                            requires_control_fragment:
                              type: boolean
                  extension_actions:
                    type: array
                    items:
                      type: object
                      additionalProperties: true
                  write_plan_evidence:
                    type: object
                    additionalProperties: true
                    description: "Ready fragment for metadata.write.plan: target.kind=module, routine_name, object selector fields, extension_action when available, and next_resolution.params for metadata.saved_state.modules.search. It is not a concrete write route."
  /metadata/write-capabilities:
    post:
      operationId: getMetadataWriteCapabilities
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                base_id:
                  type: string
                include_storage:
                  type: boolean
                  default: false
      responses:
        "200":
          description: Agent-facing matrix of what can be read, planned, and written to the saved-state layer.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                properties:
                  schema:
                    type: string
                    enum: [onec_metadata_write_capabilities.v1]
                  status:
                    type: string
                    enum: [ok]
                  default_write_layer:
                    type: string
                    enum: [save]
                  agent_rule:
                    type: string
                    description: Human-readable rule that agent-facing writes target saved-state and not active-applied layers.
                  code_carriers:
                    type: object
                    additionalProperties: true
                  write_capabilities:
                    type: object
                    additionalProperties: true
  /metadata/write:
    post:
      operationId: writeMetadata
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, target]
              properties:
                base_id:
                  type: string
                target:
                  type: object
                  required: [kind]
                  additionalProperties: true
                  properties:
                    kind:
                      type: string
                      enum: [form, module]
                      description: Saved-state form or module write route.
                    canonical_path:
                      type: string
                      description: Full semantic 1C path used for planning and selector hints.
                    table:
                      type: string
                      enum: [ConfigSave, ConfigCASSave]
                    file_name:
                      type: string
                    module_ref:
                      type: string
                    module_id:
                      type: string
                    form_guid:
                      type: string
                    form:
                      type: string
                    element:
                      type: string
                    element_id:
                      type: string
                    element_path:
                      type: string
                mode:
                  type: string
                  enum: [plan, apply, apply_and_verify, apply_and_rollback]
                  default: plan
                allow_sql_saved_state_apply:
                  type: boolean
                  description: Required for apply/apply_and_verify/apply_and_rollback.
                allow_sql_saved_state_rollback:
                  type: boolean
                  description: Required for apply_and_rollback.
                edits:
                  type: array
                  minItems: 1
                  items:
                    type: object
                    required: [property, value]
                    properties:
                      property:
                        type: string
                      value: {}
                      expected_old: {}
                      source:
                        type: string
                        enum: [local, local_override, element, override]
                expected_sha1:
                  type: string
                old:
                  type: string
                new:
                  type: string
                text:
                  type: string
                routine_name:
                  type: string
                routine_text:
                  type: string
                timeout_seconds:
                  type: integer
                  minimum: 1
      responses:
        "200":
          description: High-level metadata write route result. Wraps form/module saved-state write planning/apply or returns a blocked write plan.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplateReadResponse"
                properties:
                  schema:
                    type: string
                    enum: [onec_metadata_write.v1]
                  status:
                    type: string
                  error:
                    type: string
                    nullable: true
                    enum: [write_plan_required, write_plan_blocked, module_target_not_resolved, null]
                  target_kind:
                    type: string
                    enum: [form, module]
                  routed_method:
                    type: string
                  plan:
                    type: object
                    additionalProperties: true
                  apply_payload_hint:
                    type: object
                    additionalProperties: true
                  next_resolution:
                    type: object
                    additionalProperties: true
                  problems:
                    type: array
                    items:
                      type: object
                      additionalProperties: true
                  result:
                    type: object
                    additionalProperties: true
                  resolution:
                    type: object
                    additionalProperties: true
  /code/write:
    post:
      operationId: writeCode
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                object_type:
                  type: string
                  description: 1C metadata kind such as Catalog, Document, CommonForm, or CommonModule.
                object_name:
                  type: string
                object_guid:
                  type: string
                extension:
                  type: string
                  description: Optional extension name/GUID. Extension-first public paths such as test2.t_Форма.ЗаменаДомена are normalized by the adapter.
                path:
                  type: string
                  description: Public 1C path such as CommonForm.t_Форма.ЗаменаДомена or test2.t_Форма.ЗаменаДомена.
                canonical_path:
                  type: string
                module_ref:
                  type: string
                  description: Opaque module_ref from code.search/modules.search read_selector when already known.
                routine_name:
                  type: string
                routine_text:
                  type: string
                  description: Full procedure/function text for routine replacement.
                module_text:
                  type: string
                  description: Full module text replacement.
                full_text:
                  type: string
                  description: Alias for module_text.
                code:
                  type: string
                  description: Alias for module_text.
                old:
                  type: string
                  description: Unique old fragment for fragment replacement.
                new:
                  type: string
                  description: New fragment for fragment replacement.
                mode:
                  type: string
                  enum: [plan, apply]
                  default: apply
                include_storage:
                  type: boolean
                  default: false
      responses:
        "200":
          description: Agent-facing BSL code write facade. Defaults to saved-state/not-activated writes and hides SQL/storage details unless include_storage=true.
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
                properties:
                  schema:
                    type: string
                    enum: [onec_code_write.v1]
                  status:
                    type: string
                    enum: [planned, applied, blocked, ambiguous, not_found, error]
                  operation:
                    type: string
                    enum: [module_replace, routine_replace, fragment_replace]
                  applied:
                    type: boolean
                  write_mode:
                    type: object
                    properties:
                      target:
                        type: string
                        enum: [saved_state]
                      activation_state:
                        type: string
                        enum: [not_activated]
                      production_apply:
                        type: boolean
                  target:
                    type: object
                    additionalProperties: true
                  route:
                    type: object
                    additionalProperties: true
  /metadata/write-learning/capture-before:
    post:
      operationId: captureMetadataWriteLearningBefore
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/MetadataWriteLearningCaptureRequest"
      responses:
        "200":
          description: Saved-state form learning baseline capture without payload hex.
  /metadata/write-learning/capture-after:
    post:
      operationId: captureMetadataWriteLearningAfter
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/MetadataWriteLearningCaptureRequest"
      responses:
        "200":
          description: Saved-state form learning after-capture without payload hex.
  /metadata/write-learning/diff:
    post:
      operationId: diffMetadataWriteLearningCaptures
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                learning_id:
                  type: string
                before_snapshot_id:
                  type: string
                after_snapshot_id:
                  type: string
                before_path:
                  type: string
                after_path:
                  type: string
      responses:
        "200":
          description: Diff of decoded writable properties between before and after captures.
  /metadata/write-learning/infer-rule:
    post:
      operationId: inferMetadataWriteLearningRule
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                learning_id:
                  type: string
                before_snapshot_id:
                  type: string
                after_snapshot_id:
                  type: string
                before_path:
                  type: string
                after_path:
                  type: string
                allow_multiple:
                  type: boolean
                  default: false
                mode:
                  type: string
                  enum: [plan, apply, apply_and_verify, apply_and_rollback]
                  default: plan
                diff:
                  type: object
      responses:
        "200":
          description: Inferred metadata.write payload for replaying the learned form property edit.
  /extension/objects/find:
    post:
      operationId: findExtensionObjects
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ExtensionObjectsFindRequest"
      responses:
        "200":
          description: Extension object/template search result with routes and safe read selectors.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplateReadResponse"
  /metadata/route/resolve:
    post:
      operationId: resolveMetadataRoute
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/MetadataRouteResolveRequest"
      responses:
        "200":
          description: Live storage route resolution for metadata objects or extension child objects.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplateReadResponse"
  /templates/read:
    post:
      operationId: readTemplates
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TemplatesReadRequest"
      responses:
        "200":
          description: Public template structure including decoded MXL/MOXCEL named areas, cells, parameters, column widths, and diagnostics.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplateReadResponse"
  /templates/analyze:
    post:
      operationId: analyzeTemplates
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TemplatesReadRequest"
      responses:
        "200":
          description: Template analysis with named-area widths/intersections, cell parameters, cell text identifiers, coverage, and MOXCEL capability diagnostics.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplateReadResponse"
  /templates/map:
    post:
      operationId: mapTemplates
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TemplatesReadRequest"
      responses:
        "200":
          description: Compact agent-facing template map. Defaults to summary view and returns counts, capabilities, samples, checks, and issues.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TemplateReadResponse"
  /metadata/snapshot:
    post:
      operationId: exportMetadataSnapshot
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                base_id:
                  type: string
                  description: Required 1C database identifier. The adapter does not infer a default database.
                include_modules:
                  type: boolean
                  default: false
      responses:
        "200":
          description: Metadata snapshot v2.
  /modules/search:
    post:
      operationId: searchBslModules
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [query]
              properties:
                query:
                  type: string
                limit:
                  type: integer
                  default: 20
                  maximum: 100
                prefix:
                  type: string
                  description: Optional live storage FileName prefix for targeted Config/ConfigCAS scans.
      responses:
        "200":
          description: Matching BSL modules and snippets.
  /modules/read:
    get:
      operationId: readBslModule
      parameters:
        - $ref: "#/components/parameters/BaseId"
        - name: module_id
          in: query
          required: true
          schema:
            type: string
      responses:
        "200":
          description: BSL module content.
  /code/symbol/resolve:
    post:
      operationId: resolveBslSymbol
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, expression]
              properties:
                base_id:
                  type: string
                expression:
                  type: string
                  description: BSL expression, full 1C path, or dotted symbol chain.
                module_ref:
                  type: string
                  description: Opaque module reference from code.search/modules.search.
                module_id:
                  type: string
                ref:
                  type: string
                  description: Public object selector such as Catalog.Номенклатура.
                kind:
                  type: string
                name:
                  type: string
                routine_name:
                  type: string
                module_ordinal:
                  type: integer
                  default: 1
      responses:
        "200":
          description: Conservative BSL symbol classification.
          content:
            application/json:
              schema:
                type: object
                properties:
                  schema:
                    type: string
                    enum: [onec_bsl_symbol_resolution.v1]
                  status:
                    type: string
                    enum: [resolved, unresolved, invalid_argument, error]
                  resolution_kind:
                    type: string
                    enum: [metadata_path, context_metadata_member, parameter, local_variable]
                  path_kind:
                    type: string
                  canonical_path:
                    type: string
                  context_path:
                    type: string
                  safe_as_metadata_path:
                    type: boolean
                  candidates:
                    type: array
                    items:
                      type: object
  /query/validate:
    post:
      operationId: validateReadonlyQuery
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ReadonlyQueryRequest"
      responses:
        "200":
          description: Query validation result.
  /query/run:
    post:
      operationId: runReadonlyQuery
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ReadonlyQueryRequest"
      responses:
        "200":
          description: Query rows with masking applied.
  /codec/decode:
    post:
      operationId: decodeStoragePayload
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, table, file_name]
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                file_name:
                  type: string
                include_text:
                  type: boolean
                  default: true
                include_tree:
                  type: boolean
                  default: false
      responses:
        "200":
          description: Decoded live storage payload.
  /codec/encode:
    post:
      operationId: encodeStoragePayload
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                source:
                  type: object
                  required: [base_id, table, file_name]
                  properties:
                    base_id:
                      type: string
                    table:
                      type: string
                      enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
                    file_name:
                      type: string
                decoded:
                  type: object
                  additionalProperties: true
                text:
                  type: string
                tree:
                  type: object
                  additionalProperties: true
      responses:
        "200":
          description: Re-encoded storage payload metadata. Does not write to SQL.
  /changes/propose:
    post:
      operationId: proposeChange
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ChangeProposal"
      responses:
        "200":
          description: Reviewable change proposal. Does not apply changes.
  /storage/saved-state/apply-proposal:
    post:
      operationId: applySavedStateProposal
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, allow_sql_saved_state_apply, proposal]
              properties:
                base_id:
                  type: string
                allow_sql_saved_state_apply:
                  type: boolean
                  description: Required explicit write confirmation.
                proposal:
                  type: object
                  description: Proposal returned by changes.propose or metadata.form.element.write with encoded.payload_hex.
                  additionalProperties: true
                timeout_seconds:
                  type: integer
                  minimum: 1
      responses:
        "200":
          description: Saved-state SQL apply result with backup, readback verification, and semantic verification when available.
  /storage/saved-state/rollback:
    post:
      operationId: rollbackSavedStateApply
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, allow_sql_saved_state_rollback]
              properties:
                base_id:
                  type: string
                allow_sql_saved_state_rollback:
                  type: boolean
                  description: Required explicit rollback confirmation.
                backup_id:
                  type: string
                  description: Backup id returned by storage.saved_state.apply_proposal.
                backup_path:
                  type: string
                  description: Backup evidence path inside the adapter backup directory.
                timeout_seconds:
                  type: integer
                  minimum: 1
      responses:
        "200":
          description: Saved-state rollback result. Internally applies the rollback proposal from backup evidence.
  /storage/saved-state/backups:
    post:
      operationId: listSavedStateBackups
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                base_id:
                  type: string
                table:
                  type: string
                  enum: [ConfigSave, ConfigCASSave]
                file_name:
                  type: string
                limit:
                  type: integer
                  minimum: 1
                  maximum: 500
                  default: 50
                diagnostic:
                  type: boolean
                  description: Required by MCP policy because this is a low-level diagnostic method.
      responses:
        "200":
          description: Saved-state apply backups list with source metadata and sha1/byte counts. Payload hex is not returned.
  /access/graph:
    post:
      operationId: buildAccessGraph
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                base_id:
                  type: string
                max_effective_permissions_per_user:
                  type: integer
                  minimum: 0
                  maximum: 200000
                  description: Maximum expanded effective permission entries returned per user. Counts still report total and truncation.
                resolve_identifiers:
                  type: boolean
                  default: true
                  description: Resolve BSP role and metadata object identifiers through the adapter metadata GUID index when base_id is provided.
                access:
                  type: object
                  additionalProperties: true
                  description: Normalized access snapshot with users, groups, profiles, roles, permissions, and data restrictions.
                snapshot:
                  type: object
                  additionalProperties: true
                  description: Metadata snapshot containing snapshot.access.
      responses:
        "200":
          description: Normalized access graph with effective permissions and source chains.
  /access/snapshot/extract:
    post:
      operationId: extractAccessSnapshot
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 1000
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 30
                preset:
                  type: string
                  enum: [bsp]
                  description: Optional built-in extractor profile. bsp resolves standard BSP access metadata and builds extractor queries automatically.
                max_effective_permissions_per_user:
                  type: integer
                  minimum: 0
                  maximum: 200000
                  default: 5000
                  description: Maximum expanded effective permission entries returned per user in graph.effective_users. Counts still report total and truncation.
                resolve_identifiers:
                  type: boolean
                  default: true
                  description: Resolve BSP role and metadata object identifiers through the adapter metadata GUID index and include identifier_resolution diagnostics.
                queries:
                  type: object
                  additionalProperties:
                    type: string
                  description: Optional explicit read-only SQL extractor queries keyed by area, for example users, groups, profiles, roles, group_users, group_profiles, profile_roles, role_permissions, access_group_keys, access_user_keys, access_object_keys, access_set_keys, and data_restrictions. If omitted, the adapter returns schema discovery candidates.
                mappings:
                  type: object
                  additionalProperties:
                    type: object
                    additionalProperties:
                      type: string
                  description: Optional per-area column mapping from normalized field names to SQL column aliases.
      responses:
        "200":
          description: Discovery candidates or a normalized access snapshot with computed graph.
  /access/user/explain:
    post:
      operationId: explainUserAccess
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [user]
              properties:
                base_id:
                  type: string
                user:
                  type: string
                  description: User id or name from the access snapshot.
                object:
                  type: string
                  description: Optional metadata object filter such as Document.ЗаказКлиента.
                action:
                  type: string
                  description: Optional action/right filter such as read, create, update, post, or delete.
                preset:
                  type: string
                  enum: [bsp]
                  description: Optional live extraction profile. If access/snapshot is omitted and preset=bsp is provided, the adapter extracts BSP access data from base_id before explaining the user.
                limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 20000
                  description: Live extraction row limit per area when preset=bsp is used without a provided snapshot.
                max_effective_permissions_per_user:
                  type: integer
                  minimum: 0
                  maximum: 200000
                  description: Maximum expanded effective permission entries returned per user before applying object/action filters.
                resolve_identifiers:
                  type: boolean
                  default: true
                  description: Resolve BSP role and metadata object identifiers through the adapter metadata GUID index when base_id is provided.
                access:
                  type: object
                  additionalProperties: true
                snapshot:
                  type: object
                  additionalProperties: true
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 120
                  description: Live extraction timeout when preset=bsp is used without a provided snapshot.
                resolve_records:
                  type: boolean
                  default: false
                  description: Resolve sampled object access keys to readable data-record presentations where possible.
                max_resolved_records:
                  type: integer
                  minimum: 0
                  maximum: 5000
                  default: 200
                  description: Maximum sampled object-key records to resolve when resolve_records=true.
      responses:
        "200":
          description: User effective access explanation with summary, roles, permissions, access keys, data restrictions, and source chains.
  /access/keys/query:
    post:
      operationId: queryAccessKeys
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                kind:
                  type: string
                  enum: [group, user_set, object, set, all]
                  default: all
                  description: BSP access key area to page through; this is not a 1C metadata kind.
                area:
                  type: string
                  enum: [group, user_set, object, set, all]
                  description: Alias of kind.
                group:
                  type: string
                  description: Filter group access keys by normalized group id.
                user:
                  type: string
                  description: Filter user-set access keys by normalized user ref from access_user_keys.user.
                user_set:
                  type: string
                  description: Filter user-set access keys by normalized user set id.
                object_ref:
                  type: string
                  description: Public 1C metadata object ref, for example Справочники.Номенклатура.
                record_ref:
                  type: string
                  description: Concrete 1C application-data record reference.
                object:
                  type: string
                  description: Legacy raw BSP object filter; prefer object_ref plus record_ref.
                object_id:
                  type: string
                  description: Legacy raw BSP record id; prefer record_ref.
                object_sql_number:
                  type: integer
                  description: Legacy physical DBNames number; prefer object_ref.
                access_set:
                  type: string
                  description: Filter access-set keys by normalized access set id.
                access_key:
                  type: string
                  description: Filter by access key id.
                query:
                  type: string
                  description: Text filter over available name columns for the selected key area.
                limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 1000
                offset:
                  type: integer
                  minimum: 0
                  default: 0
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 60
                resolve_records:
                  type: boolean
                  default: false
                  description: For kind=object, resolve object_sql_number/object_id to readable data-record presentations where possible.
                max_resolved_records:
                  type: integer
                  minimum: 0
                  maximum: 5000
                  default: 200
      responses:
        "200":
          description: Paged BSP access key rows for RLS/key-access investigation.
  /access/object-keys/resolve:
    post:
      operationId: resolveAccessObjectKeys
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                object_ref:
                  type: string
                  description: Public 1C metadata object ref, for example Справочники.Номенклатура.
                record_ref:
                  type: string
                  description: Concrete 1C application-data record reference.
                object:
                  type: string
                  description: Legacy raw BSP object filter; prefer object_ref plus record_ref.
                object_id:
                  type: string
                  description: Legacy raw BSP record id; prefer record_ref.
                object_sql_number:
                  type: integer
                  description: Legacy physical DBNames number; prefer object_ref.
                access_key:
                  type: string
                  description: Optional access key filter.
                limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 1000
                offset:
                  type: integer
                  minimum: 0
                  default: 0
                max_resolved_records:
                  type: integer
                  minimum: 0
                  maximum: 5000
                  default: 200
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 60
      responses:
        "200":
          description: Paged BSP object access keys with readable data-record presentation when resolvable.
  /access/object/explain:
    post:
      operationId: explainAccessObject
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id]
              properties:
                base_id:
                  type: string
                object_ref:
                  type: string
                  description: Public 1C metadata object ref, for example Справочники.Номенклатура.
                record_ref:
                  type: string
                  description: Concrete 1C application-data record reference.
                object:
                  type: string
                  description: Legacy raw BSP object filter; prefer object_ref plus record_ref.
                object_id:
                  type: string
                  description: Legacy raw BSP record id; prefer record_ref.
                object_sql_number:
                  type: integer
                  description: Legacy physical DBNames number; prefer object_ref.
                access_key:
                  type: string
                  description: Access key id to explain directly.
                limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 1000
                offset:
                  type: integer
                  minimum: 0
                  default: 0
                subject_limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 1000
                max_resolved_records:
                  type: integer
                  minimum: 0
                  maximum: 5000
                  default: 200
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 120
      responses:
        "200":
          description: Reverse BSP access-key explanation showing groups, user sets, and users that can receive access to the selected object or key.
  /access/role/profiles:
    post:
      operationId: findAccessRoleProfiles
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, role]
              properties:
                base_id:
                  type: string
                role:
                  type: string
                  description: Role id, role ref tail, exact name, or name substring.
                role_id:
                  type: string
                role_name:
                  type: string
                query:
                  type: string
                limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 1000
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 120
      responses:
        "200":
          description: BSP profiles that include the selected role, plus access groups that use those profiles.
  /access/role/users:
    post:
      operationId: findAccessRoleUsers
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, role]
              properties:
                base_id:
                  type: string
                role:
                  type: string
                  description: Role id, role ref tail, exact name, name substring, or fuzzy role phrase.
                role_id:
                  type: string
                role_name:
                  type: string
                query:
                  type: string
                limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 20000
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 120
      responses:
        "200":
          description: Users that receive the selected BSP role through access profiles and groups, with matched role alternatives.
  /access/role/audit-export:
    post:
      operationId: exportAccessRoleAudit
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, role]
              properties:
                base_id:
                  type: string
                role:
                  type: string
                  description: Role id, exact role name, substring, or fuzzy natural-language role phrase.
                role_id:
                  type: string
                role_name:
                  type: string
                query:
                  type: string
                format:
                  type: string
                  enum: [json, csv]
                  default: json
                limit:
                  type: integer
                  minimum: 1
                  maximum: 20000
                  default: 20000
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 120
      responses:
        "200":
          description: Flat audit export rows for role -> profile -> access group -> user, with optional CSV text in the response.
  /access/role/audit-analyze:
    post:
      operationId: analyzeAccessRoleAudit
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [base_id, role]
              properties:
                base_id:
                  type: string
                role:
                  type: string
                  description: Role id, exact role name, substring, or fuzzy natural-language role phrase.
                role_id:
                  type: string
                role_name:
                  type: string
                query:
                  type: string
                user_threshold:
                  type: integer
                  minimum: 1
                  maximum: 100000
                  default: 50
                timeout_seconds:
                  type: integer
                  minimum: 1
                  maximum: 120
                  default: 120
      responses:
        "200":
          description: Risk findings for role -> profile -> access group -> user audit chains.
components:
  requestBodies:
    AdapterMethodPayload:
      required: true
      content:
        application/json:
          schema:
            type: object
            additionalProperties: true
          examples:
            selectorByName:
              value:
                base_id: <base_id>
                ref: Документы.<ИмяОбъекта>
  responses:
    AdapterMethodResponse:
      description: Method-specific adapter response with a structured status.
      content:
        application/json:
          schema:
            type: object
            additionalProperties: true
  parameters:
    BaseId:
      name: base_id
      in: query
      required: false
      schema:
        type: string
      description: Required for database-specific operations. The adapter does not infer a default database.
  securitySchemes:
    serviceToken:
      type: http
      scheme: bearer
  schemas:
    AdapterRpcRequest:
      type: object
      required: [method]
      additionalProperties: false
      properties:
        method:
          type: string
          minLength: 1
          description: Exact method name advertised by GET /methods.
        payload:
          type: object
          default: {}
          additionalProperties: true
          description: Method-specific input. Use the matching input_schema returned by GET /methods.
    AdapterMethod:
      type: object
      required: [name, transport, description]
      additionalProperties: true
      properties:
        name:
          type: string
        transport:
          type: string
        description:
          type: string
        selector_capabilities:
          type: object
          additionalProperties: true
        input_schema:
          type: object
          additionalProperties: true
    AdapterMethodsResponse:
      type: object
      required: [schema, contract_version, methods, count]
      properties:
        schema:
          type: string
          const: onec_adapter_methods.v1
        contract_version:
          type: string
        methods:
          type: array
          items:
            $ref: "#/components/schemas/AdapterMethod"
        count:
          type: integer
          minimum: 0
    MetadataKind:
      type: string
      enum:
        - catalog
        - document
        - register
        - common_module
        - enum
        - report
        - processing
        - other
    PublicObjectSelector:
      type: object
      properties:
        ref:
          type: string
          description: Public object reference such as Document.АвансовыйОтчет or Отчет.Имя.
        kind:
          type: string
          description: Metadata kind, Russian kind, or Template for direct template route reads.
        name:
          type: string
        guid:
          type: string
        object_type:
          type: string
        object_name:
          type: string
        object_guid:
          type: string
        ordinal:
          type: integer
          minimum: 1
    ExtensionObjectsFindRequest:
      allOf:
        - $ref: "#/components/schemas/PublicObjectSelector"
        - type: object
          required: [base_id]
          properties:
            base_id:
              type: string
            extension:
              type: string
              description: Extension name or GUID. Optional when searching all extension manifests.
            query:
              type: string
              description: Name/GUID fragment to search in DBNames-Ext, extension manifests, and ConfigCAS payload evidence.
            kind:
              type: string
              description: Optional object kind filter, for example Report, Template, Form, or Module.
            limit:
              type: integer
              minimum: 1
              maximum: 500
              default: 50
            scan_limit:
              type: integer
              minimum: 1
            include_storage:
              type: boolean
              default: false
            timeout_seconds:
              type: integer
              minimum: 1
    MetadataRouteResolveRequest:
      allOf:
        - $ref: "#/components/schemas/PublicObjectSelector"
        - type: object
          required: [base_id]
          properties:
            base_id:
              type: string
            extension:
              type: string
            query:
              type: string
            kind:
              type: string
            table:
              type: string
              enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
            file_name:
              type: string
            include_storage:
              type: boolean
              default: false
            timeout_seconds:
              type: integer
              minimum: 1
    TemplatesReadRequest:
      allOf:
        - $ref: "#/components/schemas/PublicObjectSelector"
        - type: object
          required: [base_id]
          properties:
            base_id:
              type: string
            extension:
              type: string
              description: Optional expected extension name/GUID. Owner mismatches are returned as diagnostics.
            owner_ref:
              type: string
              description: Optional template owner selector.
            template:
              type: string
              description: Template/maket name filter.
            name_filter:
              type: string
            table:
              type: string
              enum: [Config, ConfigSave, ConfigCAS, ConfigCASSave]
            file_name:
              type: string
              description: Direct ConfigCAS route key for route-based template reads.
            part_id:
              type: string
            include_storage:
              type: boolean
              default: false
            timeout_seconds:
              type: integer
              minimum: 1
            view:
              type: string
              enum: [summary, structure, full]
              description: Controls response size. templates.map defaults to summary; read/analyze default to full for compatibility.
            sections:
              description: Comma-separated string or array of sections to return, for example named_areas,cells,cell_parameters,widths,coverage,issues,moxel_records.
              oneOf:
                - type: string
                - type: array
                  items:
                    type: string
            max_areas:
              type: integer
              minimum: 0
            max_cells:
              type: integer
              minimum: 0
            max_parameters:
              type: integer
              minimum: 0
            max_coverage:
              type: integer
              minimum: 0
            max_widths:
              type: integer
              minimum: 0
            max_merged:
              type: integer
              minimum: 0
            max_intersections:
              type: integer
              minimum: 0
            max_strings:
              type: integer
              minimum: 0
            max_moxel_records:
              type: integer
              minimum: 0
            moxel_record_start:
              type: integer
              minimum: 0
              description: Optional top-level MOXCEL record index window start for top_level_records, for example 431 for tree_position $.431.
            moxel_record_end:
              type: integer
              minimum: 0
              description: Optional top-level MOXCEL record index window end for top_level_records.
            moxel_record_heads:
              description: Optional comma-separated string or array of MOXCEL top-level record head codes to include in top_level_records.
              oneOf:
                - type: string
                - type: array
                  items:
                    type: integer
            moxel_record_context:
              type: integer
              minimum: 0
              description: Optional neighbor radius around matched top-level records. Returned context records include match=false; matched records include match=true.
            moxel_candidate_rank:
              type: integer
              minimum: 1
              description: Optional 1-based rank from top_level_shape_candidates. Uses the candidate suggested window to focus top_level_records unless explicit record filters override it.
            moxel_candidate_window_index:
              type: integer
              minimum: 1
              description: Optional 1-based suggested window index within the selected moxel_candidate_rank.
            moxel_candidate_reasons:
              description: Optional comma-separated string or array of candidate reason codes. Returned top_level_shape_candidates must contain all requested reasons.
              oneOf:
                - type: string
                - type: array
                  items:
                    type: string
            moxel_candidate_heads:
              description: Optional comma-separated string or array of candidate head codes. Filters returned top_level_shape_candidates by their head value.
              oneOf:
                - type: string
                - type: array
                  items:
                    type: integer
            moxel_candidate_start:
              type: integer
              minimum: 0
              description: Optional top-level MOXCEL position window start for returned top_level_shape_candidates.
            moxel_candidate_end:
              type: integer
              minimum: 0
              description: Optional top-level MOXCEL position window end for returned top_level_shape_candidates.
            moxel_candidate_min_score:
              type: integer
              minimum: 0
              description: Optional minimum heuristic score for returned top_level_shape_candidates.
    MoxelRange:
      type: object
      additionalProperties: true
      properties:
        zero_based:
          type: object
          additionalProperties: true
        one_based:
          type: object
          additionalProperties: true
        width:
          type: integer
        height:
          type: integer
    MoxelNamedArea:
      type: object
      additionalProperties: true
      properties:
        name:
          type: string
        occurrence:
          type: integer
        source:
          type: string
        range:
          $ref: "#/components/schemas/MoxelRange"
    MoxelCell:
      type: object
      additionalProperties: true
      properties:
        row:
          type: integer
        column:
          type: integer
        text:
          type: string
        parameter:
          type: string
        type_code:
          type: integer
    MoxelStructure:
      type: object
      additionalProperties: true
      properties:
        format:
          type: string
        capabilities:
          type: object
          additionalProperties: true
        dimensions:
          type: object
          properties:
            rows:
              type: integer
            columns:
              type: integer
        counts:
          type: object
          additionalProperties:
            type: integer
        named_areas:
          type: array
          items:
            $ref: "#/components/schemas/MoxelNamedArea"
        cells:
          type: array
          items:
            $ref: "#/components/schemas/MoxelCell"
        cell_parameters:
          type: array
          items:
            type: object
            additionalProperties: true
        cell_text_identifiers:
          type: array
          items:
            type: object
            additionalProperties: true
        column_widths:
          type: array
          items:
            type: object
            additionalProperties: true
        merged_ranges:
          type: array
          items:
            $ref: "#/components/schemas/MoxelRange"
        merged_range_candidates:
          type: array
          items:
            type: object
            additionalProperties: true
        merge_record_block_candidates:
          type: array
          items:
            type: object
            additionalProperties: true
        merge_count_hints:
          type: array
          items:
            type: object
            additionalProperties: true
        moxel_record_diagnostics:
          type: array
          items:
            type: object
            additionalProperties: true
    TemplateAnalysis:
      type: object
      additionalProperties: true
      properties:
        status:
          type: string
        checks:
          type: object
          additionalProperties: true
        counts:
          type: object
          additionalProperties:
            type: integer
        issues:
          type: array
          items:
            type: object
            additionalProperties: true
    TemplateReadResponse:
      type: object
      additionalProperties: true
      properties:
        schema:
          type: string
          enum: [onec_templates_read.v1, onec_templates_analyze.v1, onec_templates_map.v1]
        status:
          type: string
        view:
          type: string
          enum: [summary, structure, full]
        templates:
          type: array
          items:
            type: object
            additionalProperties: true
            properties:
              structure:
                $ref: "#/components/schemas/MoxelStructure"
              analysis:
                $ref: "#/components/schemas/TemplateAnalysis"
    MetadataWriteLearningCaptureRequest:
      type: object
      required: [base_id]
      properties:
        base_id:
          type: string
        learning_id:
          type: string
          description: Optional stable id for pairing before/after captures. Generated when omitted.
        table:
          type: string
          enum: [ConfigSave, ConfigCASSave]
          default: ConfigCASSave
        file_name:
          type: string
        form_guid:
          type: string
        form:
          type: string
        element:
          type: string
        command:
          type: string
        element_id:
          type: string
        element_path:
          type: string
        property:
          type: string
        timeout_seconds:
          type: integer
          minimum: 1
    ReadonlyQueryRequest:
      type: object
      required: [base_id, query]
      properties:
        base_id:
          type: string
        query:
          type: string
        params:
          type: object
          additionalProperties: true
        limit:
          type: integer
          default: 100
          maximum: 1000
        timeout_seconds:
          type: integer
          default: 30
          maximum: 120
    ChangeProposal:
      type: object
      required: [source, edits]
      properties:
        source:
          type: object
          required: [base_id]
          properties:
            base_id:
              type: string
            module_id:
              type: string
              description: Optional module id such as Config:<FileName>#stream:<index>. If present, table/file_name and default stream_index are derived from it.
            table:
              type: string
              enum: [Params, Config, ConfigSave, ConfigCAS, ConfigCASSave]
            file_name:
              type: string
            expected_sha1:
              type: string
              description: Optional precondition against the current live payload.
        edits:
          type: array
          minItems: 1
          items:
            type: object
            properties:
              path:
                type: string
                description: Dot-separated numeric path in the decoded brace tree.
              value: {}
              node_type:
                type: string
                enum: [auto, atom, string]
                default: auto
              expected_old:
                type: string
                description: Optional scalar precondition at path.
              stream_index:
                type: integer
                description: Zero-based stream block index for stream payload edits.
              text:
                type: string
                description: Full replacement text for a stream block.
              replace:
                type: object
                required: [old, new]
                properties:
                  old:
                    type: string
                  new:
                    type: string
                  count:
                    type: integer
                    default: 1
              routine:
                type: object
                required: [text]
                properties:
                  operation:
                    type: string
                    enum: [replace, append, upsert]
                    default: replace
                  name:
                    type: string
                    description: Optional target routine name. Defaults to the name parsed from text.
                  text:
                    type: string
                    description: Full BSL procedure/function text.
                  expected_old_sha1:
                    type: string
                    description: Optional SHA1 precondition against the current target routine text.
                  expected_old_contains:
                    type: string
                    description: Optional substring precondition against the current target routine text.
              expected_contains:
                type: string
                description: Optional stream text precondition.
        include_payload:
          type: boolean
          default: false
        include_text:
          type: boolean
          default: false
