openapi: 3.1.0
info:
  title: Nomatron Control Plane API
  description: |
    The Nomatron control plane API used by the Nomatron UI and CLI to manage organisations, applications, environments, and deployments.
  version: v1
servers:
  - url: 'https://{nomatron_addr}/api/v1'
    description: Nomatron API address (NOMATRON_ADDR / --addr)
    variables:
      nomatron_addr:
        default: 'localhost:4649'
security:
  - BearerAuth: []
tags:
  - name: System
    description: 'Health, status and basic service information'
  - name: Authentication
    description: Login and authentication workflows
  - name: Users
    description: User lifecycle and credential operations
  - name: RBAC
    description: 'Roles, permissions, and access control'
  - name: Organisations
    description: 'Organisation lifecycle, membership and ownership'
  - name: Groups
    description: Organisation groups and group membership
  - name: Clusters
    description: Nomad cluster management (global and organisation-scoped)
  - name: Integrations
    description: External integrations (e.g. GitHub)
  - name: Apps
    description: Applications within an organisation
  - name: App Jobs
    description: 'Jobs nested under applications, including job-level configuration'
  - name: Environments
    description: Job environments and ordering
  - name: Operations
    description: 'Plans, applies, releases and operation history'
  - name: Approvals
    description: 'Approval policies, versions, decisions and approval status'
  - name: Variables
    description: Variables and variable values across scopes (global/org/app/job)
  - name: Templates
    description: Template rendering (inline and from Git)
  - name: Drift
    description: Drift actions and reconciliation workflows
  - name: Import
    description: Import and migration of job definitions
  - name: Webhooks
    description: Incoming webhook endpoints (e.g. GitHub)
  - name: Audit
    description: Audit/event history (including Serf events)
  - name: Service Accounts
    description: Service account management
  - name: Network Agents
    description: Nomatron network agents and tokens
  - name: License
    description: License validation and Keygen machine seat management
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
  parameters:
    ClusterName:
      name: clusterName
      in: path
      required: true
      schema:
        type: string
      description: Cluster name (unique within its scope)
    WithServers:
      name: with_servers
      in: query
      required: false
      schema:
        type: boolean
        default: false
    WithNodes:
      name: with_nodes
      in: query
      required: false
      schema:
        type: boolean
        default: false
    Status:
      name: status
      in: query
      required: false
      description: Filter by cluster status (repeatable)
      schema:
        type: array
        items:
          type: string
      style: form
      explode: true
    OrderBy:
      name: order_by
      in: query
      required: false
      schema:
        type: string
        default: updated_at DESC
      description: 'Sort order, e.g. "updated_at DESC"'
    OrgSlug:
      name: orgSlug
      in: path
      required: true
      schema:
        type: string
      description: Organization slug (URL-safe identifier)
    GroupName:
      name: groupName
      in: path
      required: true
      schema:
        type: string
      description: Group name (unique within an organization)
    Username:
      name: username
      in: path
      required: true
      schema:
        type: string
      description: Username
    Limit:
      name: limit
      in: query
      required: false
      schema:
        type: integer
        minimum: 0
        default: 0
      description: 0 means no limit (server default)
    Offset:
      name: offset
      in: query
      required: false
      schema:
        type: integer
        minimum: 0
        default: 0
    Cursor:
      name: cursor
      in: query
      required: false
      schema:
        type: string
      description: Opaque pagination cursor from a previous response.
    IncludeHealth:
      name: include_health
      in: query
      required: false
      schema:
        type: boolean
        default: false
      description: Include release-health enrichment in operation list results. Defaults to false because health enrichment adds additional database work.
    AppSlug:
      name: slug
      in: path
      required: true
      schema:
        type: string
      description: Application slug (unique within an organization)
    AppJobSlug:
      name: jobSlug
      in: path
      required: true
      schema:
        type: string
      description: App job slug (unique within an application)
    VariableID:
      name: variableID
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Variable ID
    ValueID:
      name: valueID
      in: path
      required: true
      schema:
        type: string
        format: uuid
      description: Variable value row ID
    EnvSlug:
      name: envSlug
      in: path
      required: true
      schema:
        type: string
      description: Environment slug (unique within the app)
    EnvironmentSlug:
      name: environmentSlug
      in: path
      required: true
      schema:
        type: string
      description: Environment slug (unique within the app)
    EnvironmentSlugQuery:
      name: environmentSlug
      in: query
      required: false
      schema:
        type: string
      description: Optional environment slug used to select env-scoped variable values during rendering.
    DryRun:
      name: dryRun
      in: query
      required: false
      schema:
        type: boolean
        default: true
      description: 'When true, performs a read-only render (no side effects).'
    ServiceAccountID:
      name: serviceAccountID
      in: path
      required: true
      schema:
        type: string
        format: uuid
    ServiceAccountTokenID:
      name: tokenID
      in: path
      required: true
      schema:
        type: string
        format: uuid
    GitHubConnectionName:
      name: connectionName
      in: path
      required: true
      schema:
        type: string
      description: GitHub integration connection name.
  schemas:
    HostAgentACLTokenSelectionRequest:
      type: object
      required:
        - accessor_ids
      properties:
        accessor_ids:
          type: array
          minItems: 1
          maxItems: 10000
          items:
            type: string
    ApiPagination:
      type: object
      properties:
        limit:
          type: integer
          minimum: 0
          example: 50
        next_cursor:
          type: string
          nullable: true
          example: null
        prev_cursor:
          type: string
          nullable: true
          example: null
        total:
          type: integer
          format: int64
          nullable: true
          example: 123
      required:
        - limit
      additionalProperties: false
    ApiMeta:
      type: object
      properties:
        request_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        request_time:
          type: string
          format: date-time
          example: '2026-01-01T00:00:00Z'
        status:
          type: string
          enum:
            - success
            - error
          example: success
        code:
          type: string
          description: 'Machine-readable response code (e.g. OK, VALIDATION_ERROR, PERMISSION_DENIED)'
          example: OK
        pagination:
          $ref: '#/components/schemas/ApiPagination'
      required:
        - request_id
        - request_time
        - status
        - code
      additionalProperties: false
    ApiWarning:
      type: object
      properties:
        code:
          type: string
          example: DEPRECATED_FIELD
        message:
          type: string
          example: Field 'foo' is deprecated
        field:
          type: string
          nullable: true
          example: foo
      required:
        - code
        - message
      additionalProperties: false
    ApiErrorItem:
      type: object
      properties:
        code:
          type: string
          example: VALIDATION_ERROR
        message:
          type: string
          example: slug is required
        field:
          type: string
          nullable: true
          example: slug
        details:
          type: object
          additionalProperties: true
          description: 'Optional machine-readable diagnostics such as node ID, conflict source, and conflicting range.'
      required:
        - code
        - message
        - field
      additionalProperties: false
    ApiResponseBase:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - warnings
        - errors
      description: Base response envelope for success responses.
    ApiResponseError:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          nullable: true
          description: Null for error responses.
          example: null
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    UnauthenticatedLicenseStatus:
      type: object
      additionalProperties: false
      required:
        - license_state
      description: |
        Coarse licensing state returned on unauthenticated GET /status. Does not include installation identifiers, fingerprints, or validation endpoints.
      properties:
        license_state:
          type: string
          description: |
            Aggregated validation state for load balancers and probes: valid, grace, invalid, or dev_unlicensed when the server runs in dev mode.
        issue_code:
          type: string
          description: |
            Non-identifying blocking issue code when license_state is not valid (for example LICENSE_INVALID or a blocking issue code from the runtime).
    AuthenticatedStatusLicensing:
      type: object
      additionalProperties: false
      description: |
        Licensing block on GET /status when the caller is authenticated. Includes feature entitlements for web UI gates without installation identifiers or validation targets.
      required:
        - license_state
        - runtime_mode
        - validation_status
        - entitlements
      properties:
        license_state:
          type: string
          description: |
            Aggregated validation state for load balancers and probes: valid, grace, invalid, or dev_unlicensed when the server runs in dev mode.
        issue_code:
          type: string
          description: |
            Non-identifying blocking issue code when license_state is not valid.
        runtime_mode:
          type: string
        validation_status:
          type: string
        entitlements:
          type: object
          additionalProperties:
            type: boolean
    LicenseQuotaUsage:
      type: object
      additionalProperties: false
      description: Per-quota usage counters returned under licensing usage maps.
      required:
        - used
        - limit
        - remaining
        - near_limit
        - exhausted
        - at_limit
        - can_add
      properties:
        used:
          type: integer
        limit:
          type: integer
        remaining:
          type: integer
          description: Always present (including 0 at limit); not omitted via omitempty.
        unlimited:
          type: boolean
        not_included:
          type: boolean
          description: True when the licensed quota limit is 0 and current usage is 0 (feature not included in the plan).
        near_limit:
          type: boolean
        exhausted:
          type: boolean
        at_limit:
          type: boolean
          description: True when used >= limit and limit > 0.
        can_add:
          type: boolean
          description: False when RequireQuota for +1 would return LICENSE_QUOTA_EXCEEDED.
    LicenseStatusDetail:
      type: object
      additionalProperties: true
      description: |
        Detailed licensing runtime state for authenticated GET /license/status.
      properties:
        runtime_mode:
          type: string
        license_mode:
          type: string
        tier:
          type: string
        validation_status:
          type: string
        validation_target:
          type: string
        machine_fingerprint:
          type: string
        machine_fingerprint_prefix:
          type: string
        machine_activation_status:
          type: string
        last_activation_error:
          type: string
          description: 'Last Keygen auto-activation error for this server, when recorded.'
        installation_id:
          type: string
          format: uuid
        keygen_license_id:
          type: string
        license_contact_email:
          type: string
        cache_integrity_valid:
          type: boolean
        entitlements:
          type: object
          additionalProperties:
            type: boolean
        quotas:
          type: object
          additionalProperties: true
        usage:
          type: object
          additionalProperties:
            $ref: '#/components/schemas/LicenseQuotaUsage'
        issues:
          type: array
          items:
            type: object
            additionalProperties: true
        summary:
          type: object
          additionalProperties: true
        metrics:
          type: object
          additionalProperties: true
        last_successful_validation_at:
          type: string
          format: date-time
    ApiResponseLicenseStatus:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/LicenseStatusDetail'
    StatusPayload:
      type: object
      additionalProperties: true
      properties:
        dev_unlicensed:
          type: boolean
          description: |
            True when this authenticated response is from a dev-mode server running without a license. Omitted for anonymous callers.
        tunnel_active:
          type: boolean
          description: |
            True when dev mode has an active ngrok tunnel. Omitted for anonymous callers.
        tunnel_public_url:
          type: string
          description: |
            Public HTTPS URL for the dev ngrok API tunnel when tunnel_active is true. Omitted for anonymous callers.
        licensing:
          oneOf:
            - $ref: '#/components/schemas/UnauthenticatedLicenseStatus'
            - $ref: '#/components/schemas/AuthenticatedStatusLicensing'
      example:
        app: nomatron
        version: dev
        licensing:
          license_state: valid
        serf:
          bind_addr: 127.0.0.1
          members:
            - Name: dev-mode-serf-node-1
              Addr: 127.0.0.1
              Port: 7946
              Tags:
                node_id: 00000000-0000-4000-8000-000000000001
              Status: 1
              ProtocolMin: 1
              ProtocolMax: 5
              ProtocolCur: 2
              DelegateMin: 2
              DelegateMax: 5
              DelegateCur: 4
          name: dev-mode-serf-node-1
          num_alive: 1
          num_failed: 0
          num_left: 0
          status: alive
          timestamp: '2026-02-24T10:43:21Z'
    ApiResponseStatus:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/StatusPayload'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T10:43:21.796297Z'
          status: success
          code: OK
        data:
          app: nomatron
          version: dev
          serf:
            bind_addr: 127.0.0.1
            members:
              - Name: dev-mode-serf-node-1
                Addr: 127.0.0.1
                Port: 7946
                Tags:
                  node_id: 00000000-0000-4000-8000-000000000001
                Status: 1
                ProtocolMin: 1
                ProtocolMax: 5
                ProtocolCur: 2
                DelegateMin: 2
                DelegateMax: 5
                DelegateCur: 4
            name: dev-mode-serf-node-1
            num_alive: 1
            num_failed: 0
            num_left: 0
            status: alive
            timestamp: '2026-02-24T10:43:21Z'
        warnings: []
        errors: []
    HealthComponentStatus:
      type: object
      additionalProperties: false
      required:
        - status
      properties:
        status:
          type: string
          example: ok
    HealthComponents:
      type: object
      additionalProperties: true
      example:
        database:
          status: ok
        serf:
          status: ok
    HealthPayload:
      type: object
      additionalProperties: false
      required:
        - ok
        - components
      properties:
        ok:
          type: boolean
          example: true
        components:
          $ref: '#/components/schemas/HealthComponents'
      example:
        ok: true
        components:
          database:
            status: ok
          serf:
            status: ok
    ApiResponseHealth:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/HealthPayload'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T10:45:05.268001Z'
          status: success
          code: OK
        data:
          ok: true
          components:
            database:
              status: ok
            serf:
              status: ok
        warnings: []
        errors: []
    DatabaseStatus:
      type: object
      additionalProperties: false
      required:
        - initialized
        - ready
        - state
      properties:
        initialized:
          type: boolean
        ready:
          type: boolean
        state:
          type: string
          enum:
            - unreachable
            - database_missing
            - uninitialized
            - initialized
        message:
          type: string
    DatabaseInitRequest:
      type: object
      additionalProperties: false
      properties:
        root_username:
          type: string
        root_password:
          type: string
          format: password
    DatabaseInitResult:
      type: object
      additionalProperties: false
      required:
        - username
        - message
      properties:
        username:
          type: string
        message:
          type: string
    ApiResponseDatabaseStatus:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/DatabaseStatus'
    ApiResponseDatabaseInit:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/DatabaseInitResult'
    SerfEvent:
      type: object
      additionalProperties: false
      required:
        - ID
        - Timestamp
        - EventType
        - Source
        - Message
        - Metadata
      properties:
        ID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        Timestamp:
          type: string
          format: date-time
          example: '2026-02-24T00:06:28.575723Z'
        EventType:
          type: string
          example: member-join
        Source:
          type: string
          example: serf
        Message:
          type: string
          example: Node 00000000-0000-4000-8000-000000000001 joined
        Metadata:
          type: string
          description: JSON-encoded metadata payload
          example: '{"addr": "127.0.0.1", "name": "dev-mode-serf-node-1", "port": 7946}'
    ApiResponseSerfEvents:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/SerfEvent'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T10:46:41.073148Z'
          status: success
          code: OK
        data:
          - ID: 00000000-0000-4000-8000-000000000001
            Timestamp: '2026-02-24T00:06:28.575723Z'
            EventType: member-join
            Source: serf
            Message: Node 00000000-0000-4000-8000-000000000001 joined
            Metadata: '{"addr": "127.0.0.1", "name": "dev-mode-serf-node-1", "port": 7946, "tags": {"node_id": "00000000-0000-4000-8000-000000000001"}}'
        warnings: []
        errors: []
    LoginRequest:
      type: object
      required:
        - username
        - password
      properties:
        username:
          type: string
          example: msmith
        password:
          type: string
          format: password
          example: ChangeMe123!
      additionalProperties: false
    LoginResponse:
      type: object
      required:
        - token
      properties:
        token:
          type: string
          example: <access-token>
      additionalProperties: false
    OIDCProvider:
      type: object
      required:
        - id
        - slug
        - display_name
        - enabled
        - is_default
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        slug:
          type: string
          example: okta
        display_name:
          type: string
          example: Okta
        issuer_url:
          type: string
          format: uri
          example: 'https://example.okta.com/oauth2/default'
        client_id:
          type: string
          example: 0oa123example
        scopes:
          type: array
          items:
            type: string
          example:
            - openid
            - profile
            - email
        username_claim:
          type: string
          example: preferred_username
        email_claim:
          type: string
          example: email
        name_claim:
          type: string
          example: name
        groups_claim:
          type: string
          example: groups
        allowed_email_domains:
          type: array
          items:
            type: string
          example:
            - example.com
        enabled:
          type: boolean
          example: true
        is_default:
          type: boolean
          example: false
        auto_provision:
          type: boolean
          example: true
        sync_groups:
          type: boolean
          example: true
        sync_profile:
          type: boolean
          example: true
        updated_at:
          type: string
          format: date-time
          nullable: true
      additionalProperties: false
    OIDCProviderListResponse:
      type: object
      required:
        - providers
      properties:
        providers:
          type: array
          items:
            $ref: '#/components/schemas/OIDCProvider'
      additionalProperties: false
    CreateOIDCProviderRequest:
      type: object
      required:
        - slug
        - display_name
        - issuer_url
        - client_id
        - client_secret
      properties:
        slug:
          type: string
          example: okta
        display_name:
          type: string
          example: Okta
        issuer_url:
          type: string
          format: uri
          example: 'https://example.okta.com/oauth2/default'
        client_id:
          type: string
          example: 0oa123456789
        client_secret:
          type: string
          format: password
          writeOnly: true
        scopes:
          type: array
          items:
            type: string
          example:
            - openid
            - profile
            - email
        username_claim:
          type: string
          example: preferred_username
        email_claim:
          type: string
          example: email
        name_claim:
          type: string
          example: name
        groups_claim:
          type: string
          example: groups
        allowed_email_domains:
          type: array
          items:
            type: string
          example:
            - example.com
        enabled:
          type: boolean
          example: false
        is_default:
          type: boolean
          example: false
        auto_provision:
          type: boolean
          example: true
        sync_profile:
          type: boolean
          example: true
        sync_groups:
          type: boolean
          example: true
        metadata:
          type: object
          additionalProperties: true
          nullable: true
      additionalProperties: false
    UpdateOIDCProviderRequest:
      type: object
      properties:
        display_name:
          type: string
        issuer_url:
          type: string
          format: uri
        migrate_identities:
          type: boolean
          description: Required when changing issuer_url and identities already exist for the provider. Root only.
        client_id:
          type: string
        scopes:
          type: array
          items:
            type: string
        username_claim:
          type: string
        email_claim:
          type: string
        name_claim:
          type: string
        groups_claim:
          type: string
        allowed_email_domains:
          type: array
          items:
            type: string
        enabled:
          type: boolean
        is_default:
          type: boolean
        auto_provision:
          type: boolean
        sync_profile:
          type: boolean
        sync_groups:
          type: boolean
        metadata:
          type: object
          additionalProperties: true
          nullable: true
      additionalProperties: false
    RotateOIDCProviderSecretRequest:
      type: object
      required:
        - client_secret
      properties:
        client_secret:
          type: string
          format: password
          writeOnly: true
      additionalProperties: false
    OIDCCLIStartResponse:
      type: object
      required:
        - authorization_url
        - transaction_id
        - expires_at
      properties:
        authorization_url:
          type: string
          format: uri
        transaction_id:
          type: string
          format: uuid
        expires_at:
          type: string
          format: date-time
      additionalProperties: false
    OIDCCLIPollResponse:
      type: object
      required:
        - status
      properties:
        status:
          type: string
          enum:
            - pending
            - complete
        token:
          type: string
          nullable: true
      additionalProperties: false
    OIDCGroupRoleMapping:
      type: object
      required:
        - id
        - provider_id
        - external_group
        - role
        - domain
        - enabled
        - created_at
      properties:
        id:
          type: string
          format: uuid
        provider_id:
          type: string
          format: uuid
        external_group:
          type: string
          example: platform-admins
        role:
          type: string
          example: platform-admin
        domain:
          type: string
          example: global
        description:
          type: string
        enabled:
          type: boolean
        created_at:
          type: string
          format: date-time
      additionalProperties: false
    CreateOIDCGroupRoleMappingRequest:
      type: object
      required:
        - external_group
        - role
        - domain
      properties:
        external_group:
          type: string
          example: platform-admins
        role:
          type: string
          example: platform-admin
        domain:
          type: string
          example: global
        description:
          type: string
        enabled:
          type: boolean
          example: true
      additionalProperties: false
    PreviewOIDCClaimsRequest:
      type: object
      required:
        - claims
      properties:
        claims:
          type: object
          additionalProperties: true
      additionalProperties: false
    NormalizedOIDCClaims:
      type: object
      required:
        - sub
        - username
        - email
        - name
        - groups
        - raw
      properties:
        sub:
          type: string
        username:
          type: string
        email:
          type: string
        email_verified:
          type: boolean
          nullable: true
        name:
          type: string
        groups:
          type: array
          items:
            type: string
        raw:
          type: object
          additionalProperties: true
      additionalProperties: false
    ApiResponseOIDCProvider:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/OIDCProvider'
          required:
            - data
    ApiResponseOIDCProviders:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/OIDCProvider'
          required:
            - data
    ApiResponseOIDCGroupRoleMappings:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/OIDCGroupRoleMapping'
          required:
            - data
    ApiResponseOIDCGroupRoleMapping:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/OIDCGroupRoleMapping'
          required:
            - data
    ApiResponseNormalizedOIDCClaims:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/NormalizedOIDCClaims'
          required:
            - data
    ApiResponseLogin:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/LoginResponse'
          required:
            - data
    User:
      type: object
      required:
        - id
        - username
        - name
        - auth_provider
        - is_active
        - created_by
        - created_at
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        username:
          type: string
          example: msmith
        name:
          type: string
          example: Morgan Smith
        auth_provider:
          type: string
          example: nomatron
        is_active:
          type: boolean
          example: true
        metadata:
          type: object
          additionalProperties:
            type: string
          nullable: true
          description: Optional user metadata (string key/value map). May be omitted when empty.
        created_by:
          description: |
            Actor that created the user. Usually a user ID (UUID). For bootstrap/system-created
            users this may be a string like "bootstrap".
          oneOf:
            - type: string
              description: User ID of the creator.
              format: uuid
              pattern: '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'
              example: 00000000-0000-4000-8000-000000000001
            - type: string
              description: System/bootstrap marker.
              enum:
                - bootstrap
              example: bootstrap
        created_at:
          type: string
          format: date-time
          example: '2026-02-24T00:06:40.468246Z'
      additionalProperties: false
    CreateUserRequest:
      type: object
      required:
        - username
        - name
        - password
      properties:
        username:
          type: string
          example: msmith
        name:
          type: string
          example: Morgan Smith
        password:
          type: string
          format: password
          example: ChangeMe123!
        metadata:
          description: Optional JSON metadata blob stored for the user.
          oneOf:
            - type: object
              additionalProperties: true
            - type: string
          nullable: true
      additionalProperties: false
    UpdateUserRequest:
      type: object
      properties:
        name:
          type: string
          nullable: true
          example: Morgan Smith
        metadata:
          description: JSON metadata to be merged with existing metadata.
          oneOf:
            - type: object
              additionalProperties: true
            - type: string
          nullable: true
      additionalProperties: false
    ResetPasswordRequest:
      type: object
      required:
        - new_password
      properties:
        new_password:
          type: string
          format: password
          minLength: 8
          example: EvenBetter123!
      additionalProperties: false
    ActionResponse:
      type: object
      required:
        - message
      properties:
        message:
          type: string
          example: ok
      additionalProperties: false
    LicenseMachine:
      type: object
      required:
        - id
        - name
        - fingerprint
        - fingerprint_prefix
        - is_local_server
        - is_live_server
      properties:
        id:
          type: string
        name:
          type: string
        fingerprint:
          type: string
        fingerprint_prefix:
          type: string
        serf_node_name:
          type: string
        server_identity:
          type: string
          description: Stable per-server identity label (not the cluster key).
        last_heartbeat_at:
          type: string
          format: date-time
        is_local_server:
          type: boolean
        is_live_server:
          type: boolean
      additionalProperties: false
    LicenseMachinesList:
      type: object
      required:
        - machines
        - summary
      properties:
        machines:
          type: array
          items:
            $ref: '#/components/schemas/LicenseMachine'
        summary:
          type: object
          required:
            - used
            - limit
          properties:
            used:
              type: integer
            limit:
              type: integer
          additionalProperties: false
      additionalProperties: false
    LicenseMachineRemoved:
      type: object
      required:
        - removed
        - machine
      properties:
        removed:
          type: boolean
        machine:
          $ref: '#/components/schemas/LicenseMachine'
      additionalProperties: false
    ApiResponseLicenseMachinesList:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/LicenseMachinesList'
          required:
            - data
    ApiResponseLicenseMachineRemoved:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/LicenseMachineRemoved'
          required:
            - data
    ApiResponseUser:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/User'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T11:42:13.973437Z'
          status: success
          code: CREATED
        data:
          id: 00000000-0000-4000-8000-000000000001
          username: msmith
          name: Morgan Smith
          auth_provider: nomatron
          is_active: true
          created_by: 00000000-0000-4000-8000-000000000001
          created_at: '2026-02-24T11:42:13.967747Z'
        warnings: []
        errors: []
    ApiResponseUsers:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/User'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T11:24:55.381214Z'
          status: success
          code: OK
        data:
          - id: 00000000-0000-4000-8000-000000000001
            username: root
            name: Root User
            auth_provider: nomatron
            is_active: true
            metadata:
              created_by: bootstrap
              email: root@example.com
              role_description: Server-wide administrator with full access
            created_by: bootstrap
            created_at: '2026-02-24T00:06:28.568395Z'
          - id: 00000000-0000-4000-8000-000000000001
            username: user-23
            name: user-23
            auth_provider: nomatron
            is_active: true
            created_by: 00000000-0000-4000-8000-000000000001
            created_at: '2026-02-24T00:06:40.468246Z'
        warnings: []
        errors: []
    ApiResponseAction:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ActionResponse'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T08:00:35.268586Z'
          status: success
          code: OK
        data:
          message: ok
        warnings: []
        errors: []
    GitHubProviderKind:
      type: string
      enum:
        - github_com
        - enterprise_server
      default: github_com
      description: GitHub.com or self-hosted GitHub Enterprise Server.
    CreateGitHubConnectionRequest:
      type: object
      required:
        - name
        - scope
        - app_id
        - client_id
        - app_slug
        - private_key_pem
        - webhook_secret
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        scope:
          type: string
          enum:
            - global
            - org
          example: global
        org_id:
          type: string
          format: uuid
          nullable: true
          example: null
        name:
          type: string
          example: mynomatron
        provider_kind:
          $ref: '#/components/schemas/GitHubProviderKind'
        web_base_url:
          type: string
          format: uri
          example: 'https://github.example.com'
          description: 'Required for enterprise_server; defaults to https://github.com for github_com.'
        api_base_url:
          type: string
          format: uri
          example: 'https://github.example.com/api/v3'
          description: Optional Enterprise API override.
        upload_base_url:
          type: string
          format: uri
          example: 'https://github.example.com/api/uploads'
          description: Optional Enterprise upload API override.
        app_id:
          type: string
          example: '3100988'
        client_id:
          type: string
          example: Iv1.xxxxx
        app_slug:
          type: string
          example: mynomatron
        private_key_pem:
          type: string
          writeOnly: true
          example: |-
            -----BEGIN EXAMPLE KEY PLACEHOLDER-----
            ...
            -----END EXAMPLE KEY PLACEHOLDER-----
        webhook_secret:
          type: string
          writeOnly: true
          example: '0000000000000000000000000000000000000000000000000000000000000001'
        tls_ca_bundle_pem:
          type: string
          writeOnly: true
          example: |-
            -----BEGIN CERTIFICATE-----
            MIIC...
            -----END CERTIFICATE-----
          description: Optional PEM CA bundle for private Enterprise CAs.
      additionalProperties: false
    UpdateGitHubConnectionRequest:
      type: object
      properties:
        name:
          type: string
          example: mynomatron
        provider_kind:
          $ref: '#/components/schemas/GitHubProviderKind'
        web_base_url:
          type: string
          format: uri
          example: 'https://github.example.com'
        api_base_url:
          type: string
          format: uri
          example: 'https://github.example.com/api/v3'
        upload_base_url:
          type: string
          format: uri
          example: 'https://github.example.com/api/uploads'
        app_id:
          type: string
          example: '3100988'
        client_id:
          type: string
          example: Iv1.xxxxx
        app_slug:
          type: string
          example: mynomatron
        private_key_pem:
          type: string
          writeOnly: true
          example: |-
            -----BEGIN EXAMPLE KEY PLACEHOLDER-----
            ...
            -----END EXAMPLE KEY PLACEHOLDER-----
        webhook_secret:
          type: string
          writeOnly: true
          example: '0000000000000000000000000000000000000000000000000000000000000001'
        tls_ca_bundle_pem:
          type: string
          writeOnly: true
      additionalProperties: false
    GitHubConnection:
      type: object
      required:
        - id
        - scope
        - name
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        scope:
          type: string
          enum:
            - global
            - org
          example: global
        org_id:
          type: string
          format: uuid
          nullable: true
          example: null
        name:
          type: string
          example: mynomatron
        provider_kind:
          $ref: '#/components/schemas/GitHubProviderKind'
        web_base_url:
          type: string
          format: uri
          example: 'https://github.com'
        api_base_url:
          type: string
          format: uri
          example: 'https://api.github.com'
        upload_base_url:
          type: string
          format: uri
          example: 'https://uploads.github.com'
        app_id:
          type: string
          example: '3100988'
        client_id:
          type: string
          example: Iv1.xxxxx
        app_slug:
          type: string
          example: mynomatron
        private_key_pem:
          type: string
          example: ''
          description: Always empty in responses.
        webhook_secret:
          type: string
          example: ''
          description: Always empty in responses.
        tls_ca_bundle_pem:
          type: string
          example: ''
          description: Always empty in responses.
        installation_id:
          type: integer
          format: int64
          nullable: true
          example: 116654423
        installation_account_login:
          type: string
          nullable: true
          example: example-org
        installation_target_type:
          type: string
          nullable: true
          example: User
        installation_target_id:
          type: integer
          format: int64
          nullable: true
          example: 25905997
        installed_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-03-15T22:24:57.075369Z'
        created_at:
          type: string
          format: date-time
          example: '2026-03-15T22:23:37.802491Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-03-15T22:24:57.253624Z'
        status:
          type: string
          enum:
            - not_installed
            - installed
            - invalid
            - error
          nullable: true
          example: installed
        checked_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-03-15T22:25:17.140622Z'
        error:
          type: string
          nullable: true
          example: null
      additionalProperties: false
    GitHubConnectionList:
      type: object
      required:
        - total
        - items
      properties:
        total:
          type: integer
          example: 1
        items:
          type: array
          items:
            $ref: '#/components/schemas/GitHubConnection'
      additionalProperties: false
    GitHubConnectResponse:
      type: object
      required:
        - install_url
        - connection
        - scope
        - post_redirect
      properties:
        install_url:
          type: string
          format: uri
          example: 'https://github.com/apps/mynomatron/installations/new?state=abc123'
        connection:
          type: string
          example: mynomatron
        scope:
          type: string
          enum:
            - global
            - organization
          example: global
        post_redirect:
          type: string
          example: /integrations
      additionalProperties: false
    GitHubAppRegistrationResponse:
      type: object
      required:
        - registration_url
        - app_name
        - description
        - homepage_url
        - callback_url
        - setup_url
        - webhook_url
        - suggested_webhook_secret
        - owner
        - owner_type
        - public
        - setup_on_update
        - permissions
        - events
        - notes
      properties:
        registration_url:
          type: string
          format: uri
          example: 'https://github.com/organizations/nomatronio/settings/apps/new?name=nomatronio-a1b2c3d4'
        provider_kind:
          $ref: '#/components/schemas/GitHubProviderKind'
        web_base_url:
          type: string
          format: uri
          example: 'https://github.com'
        api_base_url:
          type: string
          format: uri
          example: 'https://api.github.com'
        upload_base_url:
          type: string
          format: uri
          example: 'https://uploads.github.com'
        app_name:
          type: string
          example: nomatronio-a1b2c3d4
        description:
          type: string
          example: 'Nomatron GitHub App for repository access, webhook delivery, and pull request automation.'
        homepage_url:
          type: string
          format: uri
          example: 'https://nomatron.example.com'
        callback_url:
          type: string
          format: uri
          example: 'https://nomatron.example.com/api/v1/integrations/github/callback'
        setup_url:
          type: string
          format: uri
          example: 'https://nomatron.example.com/api/v1/integrations/github/callback'
        webhook_url:
          type: string
          format: uri
          example: 'https://nomatron.example.com/api/v1/webhooks/github'
        suggested_webhook_secret:
          type: string
          example: '0000000000000000000000000000000000000000000000000000000000000001'
        owner:
          type: string
          nullable: true
          example: nomatronio
        owner_type:
          type: string
          nullable: true
          enum:
            - org
            - user
            - ''
          example: org
        public:
          type: boolean
          example: false
        setup_on_update:
          type: boolean
          example: false
        permissions:
          type: object
          additionalProperties:
            type: string
          example:
            contents: write
            metadata: read
            pull_requests: write
            issues: write
            administration: write
            webhooks: write
        events:
          type: array
          items:
            type: string
          example:
            - push
            - pull_request
            - issue_comment
        notes:
          type: array
          items:
            type: string
          example:
            - GitHub does not allow webhook secrets to be prefilled from URL parameters.
            - Paste suggested_webhook_secret into both GitHub App registration and the Nomatron GitHub connection.
            - Use owner_type=org only when creating the app inside a GitHub organization; omit it for personal-account apps.
      additionalProperties: false
    ApiResponseGitHubConnection:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/GitHubConnection'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-15T22:25:17.140626Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          scope: global
          org_id: null
          name: mynomatron
          app_id: '3100988'
          client_id: Iv1.xxxxx
          app_slug: mynomatron
          private_key_pem: ''
          webhook_secret: ''
          installation_id: 116654423
          installation_account_login: example-org
          installation_target_type: User
          installation_target_id: 25905997
          installed_at: '2026-03-15T22:24:57.075369Z'
          created_at: '2026-03-15T22:23:37.802491Z'
          updated_at: '2026-03-15T22:24:57.253624Z'
          status: installed
          checked_at: '2026-03-15T22:25:17.140622Z'
        warnings: []
        errors: []
    ApiResponseGitHubConnections:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/GitHubConnectionList'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-15T22:25:17.140626Z'
          status: success
          code: OK
        data:
          total: 1
          items:
            - id: 00000000-0000-4000-8000-000000000001
              scope: global
              org_id: null
              name: mynomatron
              app_id: '3100988'
              client_id: Iv1.xxxxx
              app_slug: mynomatron
              private_key_pem: ''
              webhook_secret: ''
              installation_id: 116654423
              installation_account_login: example-org
              installation_target_type: User
              installation_target_id: 25905997
              installed_at: '2026-03-15T22:24:57.075369Z'
              created_at: '2026-03-15T22:23:37.802491Z'
              updated_at: '2026-03-15T22:24:57.253624Z'
              status: installed
              checked_at: '2026-03-15T22:25:17.140622Z'
        warnings: []
        errors: []
    ApiResponseGitHubConnect:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/GitHubConnectResponse'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-15T22:24:00Z'
          status: success
          code: OK
        data:
          install_url: 'https://github.com/apps/mynomatron/installations/new?state=abc123'
          connection: mynomatron
          scope: global
          post_redirect: /integrations
        warnings: []
        errors: []
    ApiResponseGitHubAppRegistration:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/GitHubAppRegistrationResponse'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-16T08:35:07.392866Z'
          status: success
          code: OK
        data:
          registration_url: 'https://github.com/organizations/nomatronio/settings/apps/new?administration=write&callback_urls%5B%5D=https%3A%2F%2Fnomatron.example.com%2Fapi%2Fv1%2Fintegrations%2Fgithub%2Fcallback&contents=read&description=Nomatron+GitHub+App+for+repository+access%2C+webhook+delivery%2C+and+pull+request+automation.&events%5B%5D=push&events%5B%5D=pull_request&events%5B%5D=issue_comment&integration%5Bdevice_flow_enabled%5D=0&integration%5Bhook_attributes%5D%5Bactive%5D=1&integration%5Brequest_oauth_on_install%5D=0&integration%5Bsetup_on_update%5D=0&integration%5Buser_token_expiration_enabled%5D=0&issues=write&metadata=read&name=nomatronio-a1b2c3d4&public=false&pull_requests=write&setup_url=https%3A%2F%2Fnomatron.example.com%2Fapi%2Fv1%2Fintegrations%2Fgithub%2Fcallback&url=https%3A%2F%2Fnomatron.example.com&webhook_url=https%3A%2F%2Fnomatron.example.com%2Fapi%2Fv1%2Fwebhooks%2Fgithub&webhooks=write'
          app_name: nomatronio-a1b2c3d4
          description: 'Nomatron GitHub App for repository access, webhook delivery, and pull request automation.'
          homepage_url: 'https://nomatron.example.com'
          callback_url: 'https://nomatron.example.com/api/v1/integrations/github/callback'
          setup_url: 'https://nomatron.example.com/api/v1/integrations/github/callback'
          webhook_url: 'https://nomatron.example.com/api/v1/webhooks/github'
          suggested_webhook_secret: '0000000000000000000000000000000000000000000000000000000000000001'
          owner: nomatronio
          owner_type: org
          public: false
          setup_on_update: false
          permissions:
            contents: write
            metadata: read
            pull_requests: write
            issues: write
            administration: write
            webhooks: write
          events:
            - push
            - pull_request
            - issue_comment
          notes:
            - GitHub does not allow webhook secrets to be prefilled from URL parameters.
            - Paste suggested_webhook_secret into both GitHub App registration and the Nomatron GitHub connection.
            - Use owner_type=org only when creating the app inside a GitHub organization; omit it for personal-account apps.
            - 'Repository webhook creation requires the GitHub App repository permission Webhooks: Read and write.'
            - 'Posting plan results back to pull requests requires the GitHub App repository permission Pull requests: Read and write.'
            - 'Accept-drift jobspec write-back requires the GitHub App repository permission Contents: Read and write.'
            - Existing GitHub App installs must approve the Contents permission upgrade before accept-drift can open PRs.
            - 'Nomatron uses the observed GitHub form field names for user_token_expiration_enabled, request_oauth_on_install, device_flow_enabled, setup_on_update, and hook_attributes.active.'
        warnings: []
        errors: []
    AssignRoleRequest:
      type: object
      additionalProperties: false
      required:
        - domain
        - role
        - subject
      properties:
        domain:
          type: string
          description: 'Role domain/scope (e.g. global, organization:<id>, app:<id>).'
          example: global
        role:
          type: string
          description: Role name.
          example: server-admin
        subject:
          type: string
          description: 'Subject identifier (typically user:<uuid>).'
          example: 'user:00000000-0000-4000-8000-000000000001'
    ApiResponseNull:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              nullable: true
              description: No payload is returned for this operation.
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T08:00:35.268586Z'
          status: success
          code: CREATED
        data: null
        warnings: []
        errors: []
    CreateRoleRequest:
      type: object
      additionalProperties: false
      required:
        - name
        - permissions
      properties:
        name:
          type: string
          example: platform-admin
        description:
          type: string
          nullable: true
          example: Platform administrators
        permissions:
          type: array
          minItems: 1
          items:
            type: string
          example:
            - global.users.list
            - global.roles.assign
    UpdateRoleRequest:
      type: object
      properties:
        description:
          type: string
          nullable: true
          example: Updated description
        permissions:
          type: array
          description: Permission strings like "global.roles.assign"
          items:
            type: string
          example:
            - global.users.list
            - global.roles.assign
      additionalProperties: false
    Role:
      type: object
      additionalProperties: false
      required:
        - id
        - name
        - scope
        - builtIn
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          example: server-admin
        description:
          type: string
          nullable: true
          example: Full access at global scope
        scope:
          type: string
          description: |
            Role scope selector. In current API responses this appears as an empty string
            for built-in roles.
          example: ''
        builtIn:
          type: boolean
          description: True if this is a built-in (seeded) role.
          example: true
    ApiResponseRoles:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/Role'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T00:46:31.948136Z'
          status: success
          code: OK
        data:
          - id: 00000000-0000-4000-8000-000000000001
            name: root
            description: Unlimited access across all scopes
            scope: ''
            builtIn: true
          - id: 00000000-0000-4000-8000-000000000001
            name: server-admin
            description: Full access at global scope
            scope: ''
            builtIn: true
        warnings: []
        errors: []
    RoleDetail:
      type: object
      additionalProperties: false
      required:
        - id
        - name
        - scope
        - builtIn
        - permissions
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          example: platform-admin
        description:
          type: string
          nullable: true
          example: Platform administrators
        scope:
          type: string
          example: ''
        builtIn:
          type: boolean
          example: false
        permissions:
          type: array
          items:
            type: string
          example:
            - global.users.list
            - global.roles.assign
    ApiResponseRole:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/Role'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T08:12:09.967763Z'
          status: success
          code: CREATED
        data:
          id: 00000000-0000-4000-8000-000000000001
          name: platform-admin
          description: Platform administrators
          scope: ''
          builtIn: false
        warnings: []
        errors: []
    ApiResponseRoleDetail:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/RoleDetail'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T08:12:09.967763Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          name: platform-admin
          description: Platform administrators
          scope: ''
          builtIn: false
          permissions:
            - global.users.list
            - global.roles.assign
        warnings: []
        errors: []
    Permission:
      type: object
      additionalProperties: false
      required:
        - id
        - scope
        - resource
        - action
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        scope:
          type: string
          description: 'Permission scope (e.g. global, organization)'
          example: global
        resource:
          type: string
          description: Primary resource name
          example: organizations
        subresource:
          type: string
          nullable: true
          description: Optional subresource name (may be omitted)
          example: environments
        action:
          type: string
          description: Action name
          example: read
    ApiResponsePermissions:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/Permission'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T00:39:52.267202Z'
          status: success
          code: OK
        data:
          - id: 00000000-0000-4000-8000-000000000001
            scope: global
            resource: organizations
            action: create
          - id: 00000000-0000-4000-8000-000000000001
            scope: global
            resource: organizations
            action: read
          - id: 00000000-0000-4000-8000-000000000001
            scope: organization
            resource: app_jobs
            subresource: environments
            action: read
        warnings: []
        errors: []
    RoleCreateResponse:
      type: object
      additionalProperties: false
      required:
        - ID
        - Name
        - Scope
        - BuiltIn
      properties:
        ID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        Name:
          type: string
          example: platform-admin
        Description:
          type: string
          nullable: true
          example: Platform administrators
        Scope:
          type: string
          example: ''
        OrgID:
          type: string
          format: uuid
          nullable: true
          example: null
        BuiltIn:
          type: boolean
          example: false
    ApiResponseRoleCreate:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/RoleCreateResponse'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T08:12:09.967763Z'
          status: success
          code: CREATED
        data:
          ID: 00000000-0000-4000-8000-000000000001
          Name: platform-admin
          Description: Platform administrators
          Scope: ''
          OrgID: null
          BuiltIn: false
        warnings: []
        errors: []
    RoleUpsertResponse:
      type: object
      additionalProperties: false
      required:
        - ID
        - Name
        - Scope
        - BuiltIn
      properties:
        ID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        Name:
          type: string
          example: platform-admin
        Description:
          type: string
          nullable: true
          example: Updated description
        Scope:
          type: string
          example: ''
        OrgID:
          type: string
          format: uuid
          nullable: true
          example: null
        BuiltIn:
          type: boolean
          example: false
    ApiResponseRoleUpsert:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/RoleUpsertResponse'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T10:32:31.477175Z'
          status: success
          code: OK
        data:
          ID: 00000000-0000-4000-8000-000000000001
          Name: platform-admin
          Description: Updated description
          Scope: ''
          OrgID: null
          BuiltIn: false
        warnings: []
        errors: []
    Organization:
      type: object
      additionalProperties: false
      required:
        - id
        - name
        - slug
        - owner_user_id
        - description
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          example: Platform Engineering
        slug:
          type: string
          example: platform-engineering
        owner_user_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        description:
          type: string
          nullable: true
          example: A test org for org-1
        metadata:
          type: object
          nullable: true
          additionalProperties: true
          example: null
        created_at:
          type: string
          format: date-time
          example: '2026-02-24T00:06:41.10058Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-02-24T00:06:41.10058Z'
    CreateOrganizationRequest:
      type: object
      additionalProperties: false
      required:
        - name
      properties:
        name:
          type: string
          example: Platform Engineering
        slug:
          type: string
          nullable: true
          description: 'Optional URL-safe organization slug; if omitted, generated from name.'
          example: platform-engineering
        description:
          type: string
          nullable: true
          example: A test org for org-1
        owner_username:
          type: string
          nullable: true
          description: Optional; if omitted server chooses current user (if that’s how your API works)
          example: user-1
        metadata:
          type: object
          nullable: true
          additionalProperties: true
          example: null
    UpdateOrganizationRequest:
      type: object
      properties:
        description:
          type: string
          nullable: true
          example: Updated org description
        metadata:
          description: Optional org metadata blob to store/merge (implementation-defined).
          oneOf:
            - type: object
              additionalProperties: true
            - type: string
          nullable: true
      additionalProperties: false
    OrganizationMemberSummary:
      type: object
      required:
        - user_id
        - username
        - joined_at
      properties:
        user_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        username:
          type: string
          example: msmith
        joined_at:
          type: string
          format: date-time
          example: '2026-01-10T00:00:00Z'
      additionalProperties: false
    AddOrganizationMemberRequest:
      type: object
      required:
        - username
      properties:
        username:
          type: string
          example: msmith
      additionalProperties: false
    TransferOrganizationOwnershipRequest:
      type: object
      required:
        - new_owner
      properties:
        new_owner:
          type: string
          description: Username of the new owner
          example: msmith
      additionalProperties: false
    ApiResponseOrganization:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/Organization'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T00:06:41.101652Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          name: Platform Engineering
          slug: platform-engineering
          owner_user_id: 00000000-0000-4000-8000-000000000001
          description: A test org for org-1
          metadata: null
          created_at: '2026-02-24T00:06:41.10058Z'
          updated_at: '2026-02-24T00:06:41.10058Z'
        warnings: []
        errors: []
    ApiResponseOrganizationMembers:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/OrganizationMembersList'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T00:06:41.556109Z'
          status: success
          code: OK
        data:
          items:
            - user_id: 00000000-0000-4000-8000-000000000001
              username: user-10
              joined_at: '2026-02-24T00:06:41.549816Z'
            - user_id: 00000000-0000-4000-8000-000000000001
              username: user-22
              joined_at: '2026-02-24T00:06:41.51141Z'
            - user_id: 00000000-0000-4000-8000-000000000001
              username: user-7
              joined_at: '2026-02-24T00:06:41.491963Z'
          pagination:
            limit: 0
            offset: 0
            total: 3
        warnings: []
        errors: []
    OrganizationMember:
      type: object
      additionalProperties: false
      required:
        - user_id
        - username
        - joined_at
      properties:
        user_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        username:
          type: string
          example: user-10
        joined_at:
          type: string
          format: date-time
          example: '2026-02-24T00:06:41.549816Z'
    Pagination:
      type: object
      additionalProperties: false
      required:
        - limit
        - offset
        - total
      properties:
        limit:
          type: integer
          example: 0
        offset:
          type: integer
          example: 0
        total:
          type: integer
          example: 3
    OrganizationMembersList:
      type: object
      additionalProperties: false
      required:
        - items
        - pagination
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/OrganizationMember'
        pagination:
          $ref: '#/components/schemas/Pagination'
    OrganizationList:
      type: object
      additionalProperties: false
      required:
        - items
        - pagination
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Organization'
        pagination:
          $ref: '#/components/schemas/Pagination'
    ApiResponseOrganizations:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/OrganizationList'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T00:31:56.443244Z'
          status: success
          code: OK
        data:
          items:
            - id: 00000000-0000-4000-8000-000000000001
              name: org-2
              slug: org-2
              owner_user_id: 00000000-0000-4000-8000-000000000001
              description: A test org for org-2
              metadata: null
              created_at: '2026-02-24T00:06:41.095041Z'
              updated_at: '2026-02-24T00:06:41.095041Z'
            - id: 00000000-0000-4000-8000-000000000001
              name: org-3
              slug: org-3
              owner_user_id: 00000000-0000-4000-8000-000000000001
              description: A test org for org-3
              metadata: null
              created_at: '2026-02-24T00:06:41.095668Z'
              updated_at: '2026-02-24T00:06:41.095668Z'
            - id: 00000000-0000-4000-8000-000000000001
              name: org-1
              slug: org-1
              owner_user_id: 00000000-0000-4000-8000-000000000001
              description: A test org for org-1
              metadata: null
              created_at: '2026-02-24T00:06:41.10058Z'
              updated_at: '2026-02-24T00:06:41.10058Z'
          pagination:
            limit: 0
            offset: 0
            total: 3
        warnings: []
        errors: []
    Group:
      type: object
      required:
        - id
        - name
        - organization_id
        - owner_user_id
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          example: platform-admins
        organization_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        owner_user_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        description:
          type: string
          nullable: true
          example: Admins for platform operations
        metadata:
          type: object
          nullable: true
          additionalProperties: true
          example:
            cost_center: infra
            slack_channel: '#platform'
            managed_by: nomatron
        created_at:
          type: string
          format: date-time
          example: '2026-02-23T11:10:04Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-02-23T11:15:22Z'
      additionalProperties: false
      example:
        id: 00000000-0000-4000-8000-000000000001
        name: platform-admins
        organization_id: 00000000-0000-4000-8000-000000000001
        owner_user_id: 00000000-0000-4000-8000-000000000001
        description: Admins for platform operations
        metadata:
          cost_center: infra
          slack_channel: '#platform'
          managed_by: nomatron
        created_at: '2026-02-23T11:10:04Z'
        updated_at: '2026-02-23T11:15:22Z'
    GroupMember:
      type: object
      required:
        - user_id
        - group_id
        - joined_at
        - updated_at
      properties:
        user_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        group_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        joined_at:
          type: string
          format: date-time
          example: '2026-02-23T11:12:00Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-02-23T11:12:00Z'
      additionalProperties: false
      example:
        user_id: 00000000-0000-4000-8000-000000000001
        group_id: 00000000-0000-4000-8000-000000000001
        joined_at: '2026-02-23T11:12:00Z'
        updated_at: '2026-02-23T11:12:00Z'
    CreateGroupRequest:
      type: object
      required:
        - name
        - owner_username
      properties:
        name:
          type: string
          example: platform-admins
        owner_username:
          type: string
          example: msmith
        description:
          type: string
          nullable: true
          example: Admins for platform operations
        metadata:
          type: object
          nullable: true
          additionalProperties: true
          example:
            slack_channel: '#platform'
            cost_center: infra
      additionalProperties: false
      description: |
        organization slug is taken from the path (orgSlug) and set server-side.
      example:
        name: platform-admins
        owner_username: msmith
        description: Admins for platform operations
        metadata:
          slack_channel: '#platform'
          cost_center: infra
    UpdateGroupRequest:
      type: object
      properties:
        description:
          type: string
          nullable: true
          example: Admins for platform operations (updated)
        metadata:
          type: object
          nullable: true
          additionalProperties: true
          example:
            slack_channel: '#platform-ops'
            managed_by: nomatron
      additionalProperties: false
      example:
        description: Admins for platform operations (updated)
        metadata:
          slack_channel: '#platform-ops'
          managed_by: nomatron
    TransferGroupOwnershipRequest:
      type: object
      required:
        - new_owner
      properties:
        new_owner:
          type: string
          example: jdoe
      additionalProperties: false
      example:
        new_owner: jdoe
    ApiResponseGroup:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/Group'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T15:00:20.522644Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          name: platform-admins
          organization_id: 00000000-0000-4000-8000-000000000001
          owner_user_id: 00000000-0000-4000-8000-000000000001
          description: Admins for platform operations
          metadata:
            slack_channel: '#platform'
            cost_center: infra
          created_at: '2026-02-23T11:10:04Z'
          updated_at: '2026-02-23T11:15:22Z'
        warnings: []
        errors: []
    ApiResponseGroups:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/Group'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T15:05:44.03306Z'
          status: success
          code: OK
        data:
          - id: 00000000-0000-4000-8000-000000000001
            name: platform-admins
            organization_id: 00000000-0000-4000-8000-000000000001
            owner_user_id: 00000000-0000-4000-8000-000000000001
            description: Admins for platform operations
            metadata:
              slack_channel: '#platform'
            created_at: '2026-02-23T11:10:04Z'
            updated_at: '2026-02-23T11:15:22Z'
          - id: 00000000-0000-4000-8000-000000000001
            name: release-approvers
            organization_id: 00000000-0000-4000-8000-000000000001
            owner_user_id: 00000000-0000-4000-8000-000000000001
            description: Approvers for production releases
            metadata: null
            created_at: '2026-02-23T11:20:04Z'
            updated_at: '2026-02-23T11:20:04Z'
        warnings: []
        errors: []
    ApiResponseGroupMembers:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/GroupMember'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T15:10:37.62109Z'
          status: success
          code: OK
        data:
          - user_id: 00000000-0000-4000-8000-000000000001
            group_id: 00000000-0000-4000-8000-000000000001
            joined_at: '2026-02-23T11:12:00Z'
            updated_at: '2026-02-23T11:12:00Z'
          - user_id: 00000000-0000-4000-8000-000000000001
            group_id: 00000000-0000-4000-8000-000000000001
            joined_at: '2026-02-23T11:14:30Z'
            updated_at: '2026-02-23T11:14:30Z'
        warnings: []
        errors: []
    GroupMemberUsernames:
      type: array
      description: List of usernames belonging to the group.
      items:
        type: string
      example:
        - msmith
        - lashel
        - bob
    ApiResponseGroupMemberUsernames:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/GroupMemberUsernames'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T18:56:47.93851Z'
          status: success
          code: OK
        data:
          - msmith
          - alice
        warnings: []
        errors: []
    CreateClusterRequest:
      type: object
      description: |
        Create a Nomad cluster connection.

        Defaults:
        - connectivity_mode defaults to "direct" when omitted or empty.
      additionalProperties: false
      required:
        - name
      properties:
        name:
          type: string
          example: prod-eu
        connectivity_mode:
          type: string
          enum:
            - direct
            - agent
          description: |
            How Nomatron connects to the Nomad cluster.

            - direct: Nomatron connects to the Nomad API address directly (address required).
            - agent: Nomatron routes requests via a network agent (network_agent_id required).
            If omitted or empty, defaults to "direct".
          example: direct
        address:
          type: string
          nullable: true
          description: Nomad API address. Required when connectivity_mode is "direct".
          example: 'https://nomad-prod-eu.example.com:4646'
        network_agent_id:
          type: string
          format: uuid
          nullable: true
          description: Network agent ID to use when connectivity_mode is "agent".
          example: 00000000-0000-4000-8000-000000000001
        description:
          type: string
          nullable: true
        acl_token:
          type: string
          nullable: true
          description: Nomad ACL token used to query the cluster (direct mode only). Accepted on write only; never returned by cluster responses.
        tls_cert:
          type: string
          nullable: true
          description: PEM encoded client cert (direct mode only)
        tls_key:
          type: string
          nullable: true
          description: PEM encoded client key (direct mode only). Accepted on write only; never returned by cluster responses.
        ca_cert:
          type: string
          nullable: true
          description: PEM encoded CA cert (direct mode only)
        skip_verify:
          type: boolean
          default: false
        scope:
          type: string
          nullable: true
          description: |
            If omitted, server sets to "global" for global create,
            or to the resolved org ID for org create.
      example:
        name: prod-eu
        connectivity_mode: direct
        address: 'https://nomad-prod-eu.example.com:4646'
        description: EU Nomad cluster
        acl_token: 00000000-0000-4000-8000-000000000001
        tls_cert: |
          -----BEGIN CERTIFICATE-----
          MIIB...
          -----END CERTIFICATE-----
        tls_key: |
          -----BEGIN EXAMPLE KEY PLACEHOLDER-----
          ...
          -----END PRIVATE KEY-----
        ca_cert: |
          -----BEGIN CERTIFICATE-----
          MIIB...
          -----END CERTIFICATE-----
        skip_verify: false
        scope: global
    UpdateClusterRequest:
      type: object
      description: |
        Patch cluster fields. Only provided fields are updated.

        Rules:
        - connectivity_mode may be set to "direct" or "agent".
        - If switching to "direct", address must be provided (or already exist).
        - If switching to "agent", network_agent_id must be provided (or already exist).
      additionalProperties: false
      properties:
        name:
          type: string
          nullable: true
          example: prod-eu
        connectivity_mode:
          type: string
          enum:
            - direct
            - agent
          nullable: true
          example: agent
        address:
          type: string
          nullable: true
          description: Nomad API address (used when connectivity_mode is "direct").
          example: 'https://nomad-prod-eu.example.com:4646'
        network_agent_id:
          type: string
          format: uuid
          nullable: true
          description: Network agent ID (used when connectivity_mode is "agent").
          example: 00000000-0000-4000-8000-000000000001
        description:
          type: string
          nullable: true
          example: EU Nomad cluster (updated)
        acl_token:
          type: string
          nullable: true
          description: Nomad ACL token used to query the cluster. Accepted on write only; never returned by cluster responses. Omit to leave unchanged. Empty or whitespace-only values are rejected unless clear_acl_token is true.
          example: 00000000-0000-4000-8000-000000000001
        clear_acl_token:
          type: boolean
          description: 'When true, removes the stored Nomad ACL token. Mutually exclusive with a non-empty acl_token.'
          example: false
        tls_cert:
          type: string
          nullable: true
        tls_key:
          type: string
          nullable: true
          description: PEM encoded client key. Accepted on write only; never returned by cluster responses.
        ca_cert:
          type: string
          nullable: true
        skip_verify:
          type: boolean
          nullable: true
          example: false
      example:
        connectivity_mode: agent
        network_agent_id: 00000000-0000-4000-8000-000000000001
        description: Private cluster via agent
    Cluster:
      type: object
      additionalProperties: false
      description: |
        Cluster connection as stored by Nomatron.

        Notes:
        - In direct mode, address is set.
        - In agent mode, network_agent_id is set and address may be null.
        - Credential fields are redacted from API responses.
      required:
        - id
        - name
        - skip_verify
        - scope
        - connectivity_mode
        - servers
        - nodes
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          example: prod-eu
        description:
          type: string
          nullable: true
          example: EU Nomad cluster
        connectivity_mode:
          type: string
          enum:
            - direct
            - agent
          example: direct
        network_agent_id:
          type: string
          format: uuid
          nullable: true
          description: Present when connectivity_mode is "agent"
          example: null
        address:
          type: string
          nullable: true
          description: Nomad API address (present when connectivity_mode is "direct")
          example: 'https://nomad-prod-eu.example.com:4646'
        acl_token:
          type: string
          nullable: true
          description: Redacted in API responses.
          example: null
        tls_cert:
          type: string
          nullable: true
          description: Redacted in API responses.
        tls_key:
          type: string
          nullable: true
          description: Redacted in API responses.
        ca_cert:
          type: string
          nullable: true
          description: Redacted in API responses.
        skip_verify:
          type: boolean
          example: false
        scope:
          type: string
          description: '"global" or an org ID (as string)'
          example: global
        servers:
          type: array
          items:
            $ref: '#/components/schemas/ClusterServer'
          example: []
          default: []
        nodes:
          type: array
          items:
            $ref: '#/components/schemas/ClusterNode'
          example: []
          default: []
        networking_cilium_owner:
          type: string
          enum:
            - none
            - managed
            - customer
          description: Who owns Cilium on eligible clients when Application Networking is or was connected.
          example: none
      example:
        id: 00000000-0000-4000-8000-000000000001
        name: us-cluster
        description: A US Nomad cluster
        connectivity_mode: direct
        network_agent_id: null
        address: 'http://nomad.example.internal:4646'
        acl_token: 00000000-0000-4000-8000-000000000001
        skip_verify: false
        scope: global
        servers: []
        nodes: []
    ClusterServer:
      type: object
      additionalProperties: false
      required:
        - id
        - address
        - cluster_id
        - server_name
        - status
        - datacenter
        - region
        - version
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
        address:
          type: string
        cluster_id:
          type: string
          format: uuid
        server_name:
          type: string
        status:
          type: string
        datacenter:
          type: string
        region:
          type: string
        version:
          type: string
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      example:
        id: 00000000-0000-4000-8000-000000000001
        address: '192.0.2.12:4647'
        cluster_id: 00000000-0000-4000-8000-000000000001
        server_name: nomad-server-1
        status: alive
        datacenter: dc1
        region: global
        version: 1.8.1
        created_at: '2026-03-04T10:12:00Z'
        updated_at: '2026-03-04T10:12:00Z'
    ClusterNode:
      type: object
      additionalProperties: false
      required:
        - id
        - address
        - cluster_id
        - status
        - datacenter
        - version
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
        address:
          type: string
        cluster_id:
          type: string
          format: uuid
        name:
          type: string
          nullable: true
        node_id:
          type: string
          nullable: true
        node_pool:
          type: string
          nullable: true
        node_class:
          type: string
          nullable: true
        status:
          type: string
        datacenter:
          type: string
        version:
          type: string
        attributes:
          type: object
          additionalProperties: true
          nullable: true
        drivers:
          type: object
          additionalProperties: true
          nullable: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      example:
        id: 00000000-0000-4000-8000-000000000001
        address: 192.0.2.25
        cluster_id: 00000000-0000-4000-8000-000000000001
        name: nomad-client-1
        node_id: 00000000-0000-4000-8000-000000000001
        node_pool: default
        node_class: general
        status: ready
        datacenter: dc1
        version: 1.8.1
        attributes:
          arch: amd64
          os: linux
        drivers:
          docker:
            detected: true
            healthy: true
        created_at: '2026-03-04T10:12:00Z'
        updated_at: '2026-03-04T10:12:00Z'
    ApiResponseCluster:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/Cluster'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-04T10:12:00Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          name: us-cluster
          description: A US Nomad cluster
          connectivity_mode: direct
          network_agent_id: null
          address: 'http://nomad.example.internal:4646'
          acl_token: 00000000-0000-4000-8000-000000000001
          skip_verify: false
          scope: global
          servers: []
          nodes: []
        warnings: []
        errors: []
    ApiResponseClusters:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/Cluster'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T15:00:20.522644Z'
          status: success
          code: OK
        data:
          - id: 00000000-0000-4000-8000-000000000001
            name: us-cluster
            description: A US Nomad cluster
            connectivity_mode: direct
            network_agent_id: null
            address: 'http://nomad.example.internal:4646'
            acl_token: 00000000-0000-4000-8000-000000000001
            skip_verify: false
            scope: global
            servers: []
            nodes: []
          - id: 00000000-0000-4000-8000-000000000001
            name: private-prod
            description: Private cluster via agent
            connectivity_mode: agent
            network_agent_id: 00000000-0000-4000-8000-000000000001
            address: null
            acl_token: null
            skip_verify: false
            scope: global
            servers: []
            nodes: []
        warnings: []
        errors: []
    GitProvider:
      type: string
      description: Git provider for the app repository.
      enum:
        - github
        - gitlab
      example: github
    DeploymentTriggerMode:
      type: string
      description: App deployment trigger mode.
      enum:
        - branch_commit
        - tag
      example: branch_commit
    TagPatternType:
      type: string
      description: Tag matching style for tag-based deployment triggers.
      enum:
        - semver
        - prefix
        - suffix
        - custom_regex
      example: semver
    App:
      type: object
      required:
        - id
        - org_id
        - name
        - slug
        - repo_url
        - ref
        - cluster_id
        - git_provider
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
        org_id:
          type: string
          format: uuid
        name:
          type: string
          example: Nomatron API
        slug:
          type: string
          example: nomatron-api
        description:
          type: string
          nullable: true
        repo_url:
          type: string
          example: 'https://github.com/nomatron/nomatron.git'
        repo_host:
          type: string
          example: github.com
          description: Host portion of the GitHub repository URL.
        ref:
          type: string
          nullable: true
          example: main
        trigger_mode:
          $ref: '#/components/schemas/DeploymentTriggerMode'
        tag_pattern_type:
          allOf:
            - $ref: '#/components/schemas/TagPatternType'
          nullable: true
        tag_pattern:
          type: string
          nullable: true
          description: 'Prefix, suffix, or regular expression used by tag-based triggers.'
        cluster_id:
          type: string
          format: uuid
        repo_webhook_id:
          type: string
          format: uuid
          nullable: true
          description: Repo-level webhook linkage (if established).
        vcs_github_id:
          type: string
          format: uuid
          nullable: true
          description: Optional VCS integration ID for GitHub.
        git_provider:
          $ref: '#/components/schemas/GitProvider'
        updated_by:
          type: string
          format: uuid
          nullable: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      additionalProperties: false
    CreateAppRequest:
      type: object
      required:
        - name
        - repo_url
        - cluster_id
      properties:
        name:
          type: string
          example: Nomatron API
        slug:
          type: string
          nullable: true
          example: nomatron-api
        description:
          type: string
          nullable: true
        repo_url:
          type: string
          example: 'https://github.com/nomatron/nomatron.git'
        repo_host:
          type: string
          example: github.com
          description: Host portion of the GitHub repository URL.
        ref:
          type: string
          nullable: true
          description: Branch ref tracked by branch commit triggers. Defaults to "main" when omitted.
          example: main
        trigger_mode:
          $ref: '#/components/schemas/DeploymentTriggerMode'
        tag_pattern_type:
          allOf:
            - $ref: '#/components/schemas/TagPatternType'
          nullable: true
        tag_pattern:
          type: string
          nullable: true
          description: 'Prefix, suffix, or regular expression used by tag-based triggers.'
        cluster_id:
          type: string
          format: uuid
        vcs_github_id:
          type: string
          format: uuid
          nullable: true
        git_provider:
          $ref: '#/components/schemas/GitProvider'
      additionalProperties: false
    UpdateAppRequest:
      type: object
      properties:
        name:
          type: string
          nullable: true
        description:
          type: string
          nullable: true
        ref:
          type: string
          nullable: true
        trigger_mode:
          allOf:
            - $ref: '#/components/schemas/DeploymentTriggerMode'
          nullable: true
        tag_pattern_type:
          allOf:
            - $ref: '#/components/schemas/TagPatternType'
          nullable: true
        tag_pattern:
          type: string
          nullable: true
        cluster_id:
          type: string
          format: uuid
          nullable: true
      additionalProperties: false
    CreateAppJobRequest:
      type: object
      required:
        - name
        - jobspec_type
      properties:
        name:
          type: string
          example: payments-api
        slug:
          type: string
          nullable: true
          example: payments-api
        description:
          type: string
          nullable: true
          example: Payments API job
        repo_url:
          type: string
          nullable: true
          description: 'Optional repository URL override for this job. If unset, the job inherits the app repository.'
          example: 'https://github.com/nomatronio/payments-worker.git'
        jobspec_path:
          type: string
          nullable: true
          description: Required for file source mode. Legacy source path returned for compatibility; directory mode uses source_directory.
          example: deploy/jobs/payments
        jobspec_type:
          type: string
          description: Jobspec source type
          enum:
            - NOMAD
            - TEMPLATE
          example: NOMAD
        source_mode:
          type: string
          enum:
            - file
            - directory
          x-enum-varnames:
            - CreateAppJobRequestSourceModeFile
            - CreateAppJobRequestSourceModeDirectory
          default: file
          description: Source shape for this app job. File mode preserves jobspec_path behavior. Directory mode points at a repository directory containing one Nomad jobspec and optional Nomad jobspec var files.
          example: directory
        source_directory:
          type: string
          nullable: true
          description: Repository-relative directory used when source_mode is directory.
          example: deploy/jobs/payments
        job_file_path:
          type: string
          nullable: true
          description: Optional repository-relative Nomad jobspec file within source_directory. Required later if directory discovery is ambiguous.
          example: deploy/jobs/payments/payments.nomad.hcl
        job_var_file_paths:
          type: array
          nullable: true
          description: Ordered repository-relative Nomad jobspec var files used only with HCL jobspecs. Entries may be HCL assignment files or JSON object files.
          items:
            type: string
          example:
            - deploy/jobs/payments/base.vars.hcl
            - deploy/jobs/payments/generated.json
        default_namespace:
          type: string
          nullable: true
          description: Default Nomad namespace for this job (if used)
          example: default
        cluster_id:
          type: string
          format: uuid
          nullable: true
          description: Optional override cluster for this job; if unset app/other default applies
        priority:
          type: integer
          nullable: true
          description: Deployment group priority within the app. Jobs with the same value deploy together.
          example: 10
        networking_mode:
          type: string
          nullable: true
          description: Application Networking mode for this job. `managed_overlay` injects the configured Cilium CNI network into Docker task groups and requires healthy Host Agent and Cilium coverage before plan/apply; it cannot be combined with an app-scoped Docker network.
          enum:
            - job_spec
            - managed_overlay
          default: job_spec
          example: job_spec
      additionalProperties: false
    UpdateAppJobRequest:
      type: object
      properties:
        name:
          type: string
          nullable: true
        slug:
          type: string
          nullable: true
        description:
          type: string
          nullable: true
        repo_url:
          type: string
          nullable: true
          description: Optional repository URL override for this job. Send null or an empty string to inherit the app repository.
        nomad_job_id:
          type: string
          nullable: true
        jobspec_path:
          type: string
          nullable: true
          description: 'File mode jobspec path. For directory mode, source_directory is the canonical source path.'
          example: deploy/jobs/payments
        jobspec_type:
          type: string
          nullable: true
          enum:
            - NOMAD
            - TEMPLATE
          example: NOMAD
        source_mode:
          type: string
          nullable: true
          enum:
            - file
            - directory
          x-enum-varnames:
            - UpdateAppJobRequestSourceModeFile
            - UpdateAppJobRequestSourceModeDirectory
          description: Source shape for this app job.
          example: directory
        source_directory:
          type: string
          nullable: true
          description: Repository-relative directory used when source_mode is directory. Send null when switching back to file mode.
          example: deploy/jobs/payments
        job_file_path:
          type: string
          nullable: true
          description: Optional repository-relative Nomad jobspec file within source_directory.
          example: deploy/jobs/payments/payments.nomad.hcl
        job_var_file_paths:
          type: array
          nullable: true
          description: Ordered repository-relative Nomad jobspec var files used only with HCL jobspecs.
          items:
            type: string
          example:
            - deploy/jobs/payments/base.vars.hcl
            - deploy/jobs/payments/generated.json
        default_namespace:
          type: string
          nullable: true
        cluster_id:
          type: string
          format: uuid
          nullable: true
        priority:
          type: integer
          nullable: true
          minimum: 1
          description: Deployment group priority. Jobs with the same value deploy together.
        networking_mode:
          type: string
          nullable: true
          description: Application Networking mode for this job. `managed_overlay` injects the configured Cilium CNI network into Docker task groups and requires healthy Host Agent and Cilium coverage before plan/apply; it cannot be combined with an app-scoped Docker network.
          enum:
            - job_spec
            - managed_overlay
          example: job_spec
      additionalProperties: false
    AppJob:
      type: object
      additionalProperties: false
      required:
        - ID
        - AppID
        - Name
        - Slug
        - JobspecPath
        - JobspecType
        - SourceMode
        - JobVarFilePaths
        - ClusterID
        - DefaultNamespace
        - Priority
        - NetworkingMode
        - EffectiveRepoURL
        - EffectiveRepoFullName
        - CreatedAt
        - UpdatedAt
      properties:
        ID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        AppID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        Name:
          type: string
          example: Template Service
        Slug:
          type: string
          example: template
        Description:
          type: string
          nullable: true
          example: template demo entrypoint
        RepoHost:
          type: string
          nullable: true
          description: Repository host for the job-level override. Null means the job inherits the app repository.
          example: github.com
        RepoFullName:
          type: string
          nullable: true
          description: Normalized owner/repository identity for the job-level override. Null means the job inherits the app repository.
          example: nomatronio/platform-worker
        RepoURL:
          type: string
          nullable: true
          description: Job-level repository override. Null means the job inherits the app repository.
          example: 'https://github.com/nomatronio/platform-worker.git'
        JobspecPath:
          type: string
          description: File mode jobspec path. For directory mode this mirrors source_directory for backward compatibility.
          example: nomatron.tpl
        JobspecType:
          type: string
          example: TEMPLATE
        SourceMode:
          type: string
          enum:
            - file
            - directory
          x-enum-varnames:
            - AppJobSourceModeFile
            - AppJobSourceModeDirectory
          example: file
        SourceDirectory:
          type: string
          nullable: true
          description: Repository-relative directory used when SourceMode is directory.
          example: deploy/jobs/payments
        JobFilePath:
          type: string
          nullable: true
          description: Optional repository-relative Nomad jobspec file within SourceDirectory.
          example: deploy/jobs/payments/payments.nomad.hcl
        JobVarFilePaths:
          type: array
          description: Ordered repository-relative Nomad jobspec var files used only with HCL jobspecs. Raw values are not returned.
          items:
            type: string
          example:
            - deploy/jobs/payments/base.vars.hcl
            - deploy/jobs/payments/generated.json
        SourceFiles:
          type: array
          nullable: true
          description: Configured source file provenance inferred from API fields. Operation-time resolution may add commit and hash metadata in later workflows.
          items:
            $ref: '#/components/schemas/AppJobSourceFile'
        ClusterID:
          type: string
          format: uuid
          nullable: true
          example: null
        DefaultNamespace:
          type: string
          example: default
        NetworkingMode:
          type: string
          description: Application Networking mode for this job.
          enum:
            - job_spec
            - managed_overlay
          example: job_spec
        Priority:
          type: integer
          description: Deployment group priority. Jobs with the same value deploy together.
          example: 10
        EffectiveRepoURL:
          type: string
          description: Repository URL Nomatron will use for this job after applying app-level inheritance.
          example: 'https://github.com/nomatronio/platform-worker.git'
        EffectiveRepoFullName:
          type: string
          description: Normalized repository identity Nomatron will use for this job after applying app-level inheritance.
          example: nomatronio/platform-worker
        CreatedAt:
          type: string
          format: date-time
          example: '2026-02-23T11:10:04.678871Z'
        UpdatedAt:
          type: string
          format: date-time
          example: '2026-02-23T11:10:04.678871Z'
    AppJobSourceFile:
      type: object
      additionalProperties: false
      required:
        - path
        - role
        - format
        - order
      properties:
        path:
          type: string
          description: Repository-relative source file path.
          example: deploy/jobs/payments/generated.json
        role:
          type: string
          enum:
            - job_spec
            - job_var_file
          x-enum-varnames:
            - AppJobSourceFileRoleJobSpec
            - AppJobSourceFileRoleJobVarFile
          description: 'Source file role. job_var_file means a Nomad jobspec var file, not a Nomatron Variable.'
        format:
          type: string
          enum:
            - hcl
            - json
          x-enum-varnames:
            - AppJobSourceFileFormatHCL
            - AppJobSourceFileFormatJSON
          description: Detected source file format.
        order:
          type: integer
          description: Deterministic assembly order within the source package.
          example: 1
    ApiResponseApp:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/App'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T11:10:04.68212Z'
          status: success
          code: CREATED
        data:
          id: 00000000-0000-4000-8000-000000000001
          org_id: 00000000-0000-4000-8000-000000000001
          name: Nomatron API
          slug: nomatron-api
          description: null
          repo_url: 'https://github.com/nomatron/nomatron.git'
          ref: main
          cluster_id: 00000000-0000-4000-8000-000000000001
          repo_webhook_id: null
          vcs_github_id: null
          git_provider: github
          updated_by: null
          created_at: '2026-02-23T11:10:04.678871Z'
          updated_at: '2026-02-23T11:10:04.678871Z'
        warnings: []
        errors: []
    ApiResponseApps:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/App'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T13:55:44.03306Z'
          status: success
          code: OK
        data:
          - id: 00000000-0000-4000-8000-000000000001
            org_id: 00000000-0000-4000-8000-000000000001
            name: Nomatron API
            slug: nomatron-api
            description: null
            repo_url: 'https://github.com/nomatron/nomatron.git'
            ref: main
            cluster_id: 00000000-0000-4000-8000-000000000001
            repo_webhook_id: null
            vcs_github_id: null
            git_provider: github
            updated_by: null
            created_at: '2026-02-23T11:10:04.678871Z'
            updated_at: '2026-02-23T11:10:04.678871Z'
        warnings: []
        errors: []
    ApiResponseAppJob:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/AppJob'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T11:10:04.68212Z'
          status: success
          code: CREATED
        data:
          ID: 00000000-0000-4000-8000-000000000001
          AppID: 00000000-0000-4000-8000-000000000001
          Name: Template Service
          Slug: template
          Description: template demo entrypoint
          RepoHost: null
          RepoFullName: null
          RepoURL: null
          JobspecPath: nomatron.tpl
          JobspecType: TEMPLATE
          SourceMode: file
          SourceDirectory: null
          JobFilePath: null
          JobVarFilePaths: []
          SourceFiles: []
          ClusterID: null
          DefaultNamespace: default
          NetworkingMode: job_spec
          Priority: 10
          EffectiveRepoURL: 'https://github.com/nomatronio/platform.git'
          EffectiveRepoFullName: nomatronio/platform
          CreatedAt: '2026-02-23T11:10:04.678871Z'
          UpdatedAt: '2026-02-23T11:10:04.678871Z'
        warnings: []
        errors: []
    ApiResponseAppJobs:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/AppJob'
          required:
            - data
    ApprovalPolicy:
      type: object
      additionalProperties: false
      required:
        - version
        - default_rule
        - environment_rules
      properties:
        version:
          type: integer
          minimum: 1
          example: 3
        default_rule:
          $ref: '#/components/schemas/ApprovalRule'
        environment_rules:
          type: array
          items:
            $ref: '#/components/schemas/EnvironmentApprovalRule'
          example: []
    ApprovalRule:
      type: object
      additionalProperties: false
      required:
        - required_approvals
        - approvers
      properties:
        required_approvals:
          type: integer
          minimum: 0
          example: 1
        approvers:
          $ref: '#/components/schemas/ApprovalApprovers'
    ApprovalApprovers:
      type: object
      additionalProperties: false
      required:
        - users
        - groups
      properties:
        users:
          type: array
          items:
            type: string
            description: Username (not UUID)
          example:
            - msmith
            - jdoe
        groups:
          type: array
          items:
            type: string
            format: uuid
          example: []
    EnvironmentApprovalRule:
      type: object
      additionalProperties: false
      required:
        - environment_id
        - rule
      properties:
        environment_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        rule:
          $ref: '#/components/schemas/ApprovalRule'
    ApprovalPolicyVersion:
      type: object
      additionalProperties: false
      required:
        - version
        - changed_at
      properties:
        version:
          type: integer
          minimum: 1
          example: 2
        changed_at:
          type: string
          format: date-time
          example: '2026-02-23T12:30:46.351815Z'
    UpsertApprovalPolicyRequest:
      type: object
      additionalProperties: false
      required:
        - default_rule
        - environment_rules
      properties:
        default_rule:
          $ref: '#/components/schemas/UpsertApprovalRule'
        environment_rules:
          type: array
          items:
            $ref: '#/components/schemas/UpsertEnvironmentApprovalRule'
          example: []
      example:
        default_rule:
          required_approvals: 1
          approvers:
            users:
              - msmith
              - jdoe
            groups: []
        environment_rules: []
    UpsertApprovalRule:
      type: object
      additionalProperties: false
      required:
        - required_approvals
        - approvers
      properties:
        required_approvals:
          type: integer
          minimum: 0
          example: 1
        approvers:
          $ref: '#/components/schemas/UpsertApprovalApprovers'
    UpsertApprovalApprovers:
      type: object
      additionalProperties: false
      required:
        - users
        - groups
      properties:
        users:
          type: array
          items:
            type: string
            description: Username (not UUID)
          example:
            - msmith
            - jdoe
            - sdoe
        groups:
          type: array
          items:
            type: string
            description: Group name (not UUID)
          example: []
    UpsertEnvironmentApprovalRule:
      type: object
      additionalProperties: false
      required:
        - environment_id
        - rule
      properties:
        environment_id:
          type: string
          format: uuid
        rule:
          $ref: '#/components/schemas/UpsertApprovalRule'
    ApiResponseApprovalPolicy:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ApprovalPolicy'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T12:30:46.368197Z'
          status: success
          code: OK
        data:
          version: 3
          default_rule:
            required_approvals: 1
            approvers:
              users:
                - msmith
                - jdoe
              groups: []
          environment_rules: []
        warnings: []
        errors: []
    ApiResponseApprovalPolicyVersion:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ApprovalPolicyVersion'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T13:55:44.03306Z'
          status: success
          code: OK
        data:
          version: 2
          changed_at: '2026-02-23T12:30:46.351815Z'
        warnings: []
        errors: []
    ApiResponseApprovalPolicyVersions:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ApprovalPolicyVersionList'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T13:55:44.03306Z'
          status: success
          code: OK
        data:
          items:
            - version: 2
              changed_at: '2026-02-23T12:30:46.351815Z'
            - version: 1
              changed_at: '2026-02-23T11:10:04.987433Z'
          limit: 50
          offset: 0
        warnings: []
        errors: []
    ApprovalPolicyVersionList:
      type: object
      additionalProperties: false
      required:
        - items
        - limit
        - offset
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/ApprovalPolicyVersion'
        limit:
          type: integer
          example: 50
        offset:
          type: integer
          example: 0
    ApprovalPolicyVersionListItem:
      type: object
      additionalProperties: false
      required:
        - version
        - changed_at
      properties:
        version:
          type: integer
          minimum: 1
          example: 2
        changed_at:
          type: string
          format: date-time
          example: '2026-02-23T12:30:46.351815Z'
    ApprovalPolicyVersionDetail:
      type: object
      additionalProperties: false
      required:
        - version
        - changed_at
        - snapshot
      properties:
        version:
          type: integer
          minimum: 1
          example: 1
        changed_at:
          type: string
          format: date-time
          example: '2026-02-23T11:10:04.987433Z'
        snapshot:
          $ref: '#/components/schemas/ApprovalPolicySnapshot'
    ApprovalPolicySnapshot:
      type: object
      additionalProperties: false
      required:
        - version
        - default_rule
      properties:
        version:
          type: integer
          minimum: 1
          example: 1
        default_rule:
          $ref: '#/components/schemas/ApprovalRule'
        environment_rules:
          type: array
          items:
            $ref: '#/components/schemas/EnvironmentApprovalRule'
          example: []
    ApiResponseApprovalPolicyVersionList:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ApprovalPolicyVersionList'
          required:
            - data
    ApiResponseApprovalPolicyVersionDetail:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ApprovalPolicyVersionDetail'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T14:06:37.62109Z'
          status: success
          code: OK
        data:
          version: 1
          changed_at: '2026-02-23T11:10:04.987433Z'
          snapshot:
            version: 1
            default_rule:
              approvers:
                users: []
                groups: []
              required_approvals: 1
            environment_rules: []
        warnings: []
        errors: []
    RenderTemplateRequest:
      type: object
      additionalProperties: false
      required:
        - template
      properties:
        template:
          type: string
          description: Raw HCL template text to render.
          example: |
            job "demo" {
              group "web" {
                task "nginx" {
                  config {
                    image = "{{ var \"IMAGE\" }}"
                  }
                }
              }
            }
    TemplateReference:
      type: object
      description: 'A reference discovered during template rendering (variable, placeholder, etc).'
      additionalProperties: true
      properties:
        key:
          type: string
          description: Referenced key/name (if applicable).
        scope:
          type: string
          description: Scope of the reference (if applicable).
        variable_id:
          type: string
          format: uuid
          nullable: true
        environment_id:
          type: string
          format: uuid
          nullable: true
    RenderedTemplate:
      type: object
      additionalProperties: false
      required:
        - rendered_hcl
        - referenced
        - missing
        - masked
      properties:
        rendered_hcl:
          type: string
          description: Rendered Nomad jobspec HCL output.
          example: |
            job "demo" {
              group "web" {
                task "nginx" {
                  config {
                    image = "nginx:latest"
                  }
                }
              }
            }
        environment_id:
          type: string
          format: uuid
          nullable: true
          description: Environment UUID used during rendering (if an environment was selected).
        referenced:
          type: array
          description: References successfully resolved and used during rendering.
          items:
            $ref: '#/components/schemas/TemplateReference'
        missing:
          type: array
          description: References that were required but missing/unresolvable.
          items:
            $ref: '#/components/schemas/TemplateReference'
        masked:
          type: array
          description: References that were resolved but masked due to sensitivity rules.
          items:
            $ref: '#/components/schemas/TemplateReference'
        error:
          type: string
          nullable: true
          description: Rendering error message (if rendering failed but still returned a structured response).
    ApiResponseRenderedTemplate:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/RenderedTemplate'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T14:31:31.030336Z'
          status: success
          code: OK
        data:
          rendered_hcl: |
            job "demo" {
              group "web" {
                task "nginx" {
                  config {
                    image = "nginx:latest"
                  }
                }
              }
            }
          environment_id: 00000000-0000-4000-8000-000000000001
          referenced: []
          missing: []
          masked: []
        warnings: []
        errors: []
    JobPreview:
      type: object
      additionalProperties: false
      required:
        - jobspec_type
        - format
        - content
        - supports_environments
      properties:
        jobspec_type:
          type: string
          description: Jobspec type for the job (`TEMPLATE` or `NOMAD`).
          example: TEMPLATE
        format:
          type: string
          description: Format of the returned content (`hcl` or `json`).
          enum:
            - hcl
            - json
          example: hcl
        content:
          type: string
          description: Preview job file content in the requested format.
        source_path:
          type: string
          description: Git path of the job file used for the preview.
          example: nomad/demo.nomad.hcl
        source_format:
          type: string
          description: Native format of the source job file before conversion.
          enum:
            - hcl
            - json
          example: hcl
        supports_environments:
          type: boolean
          description: True for TEMPLATE jobs that render with environment-scoped variables.
        environment_id:
          type: string
          format: uuid
          nullable: true
          description: Environment UUID used during TEMPLATE rendering.
        environment_slug:
          type: string
          nullable: true
          description: Environment slug used during TEMPLATE rendering.
        referenced:
          type: array
          description: TEMPLATE references successfully resolved during rendering.
          items:
            $ref: '#/components/schemas/TemplateReference'
        missing:
          type: array
          description: TEMPLATE references that were missing/unresolvable.
          items:
            $ref: '#/components/schemas/TemplateReference'
        masked:
          type: array
          description: TEMPLATE references that were masked due to sensitivity rules.
          items:
            $ref: '#/components/schemas/TemplateReference'
        warning:
          type: string
          nullable: true
          description: Non-fatal conversion or preview warning.
        error:
          type: string
          nullable: true
          description: Structured render error when TEMPLATE rendering partially failed.
    ApiResponseJobPreview:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/JobPreview'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T14:31:31.030336Z'
          status: success
          code: OK
        data:
          jobspec_type: TEMPLATE
          format: hcl
          content: |
            job "demo" {
              group "web" {
                task "nginx" {
                  config {
                    image = "nginx:latest"
                  }
                }
              }
            }
          source_path: nomad/demo.nomad.tpl
          source_format: hcl
          supports_environments: true
          environment_slug: staging
          referenced: []
          missing: []
          masked: []
        warnings: []
        errors: []
    Variable:
      type: object
      additionalProperties: false
      required:
        - id
        - scope
        - key
        - value_type
        - sensitivity
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        scope:
          type: string
          description: Variable scope
          example: app
        org_id:
          type: string
          format: uuid
          nullable: true
          example: null
        app_id:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
        app_job_id:
          type: string
          format: uuid
          nullable: true
          example: null
        key:
          type: string
          example: IMAGE
        description:
          type: string
          nullable: true
          example: docker container image
        value_type:
          type: string
          description: Variable value type
          example: string
        sensitivity:
          type: string
          description: Variable sensitivity
          example: normal
        default_value:
          type: string
          nullable: true
          description: Default value. Sensitive variables return a masked value instead of plaintext.
          example: null
        created_at:
          type: string
          format: date-time
          example: '2026-02-24T14:31:30.949383Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-02-24T14:31:30.949383Z'
      example:
        id: 00000000-0000-4000-8000-000000000001
        scope: app
        org_id: null
        app_id: 00000000-0000-4000-8000-000000000001
        app_job_id: null
        key: IMAGE
        description: docker container image
        value_type: string
        sensitivity: normal
        created_at: '2026-02-24T14:31:30.949383Z'
        updated_at: '2026-02-24T14:31:30.949383Z'
    CreateVariableRequest:
      type: object
      additionalProperties: false
      required:
        - key
      properties:
        key:
          type: string
          example: IMAGE
        description:
          type: string
          nullable: true
          example: docker container image
        value_type:
          type: string
          nullable: true
          example: string
        sensitivity:
          type: string
          nullable: true
          example: normal
        default_value:
          type: string
          nullable: true
          example: null
      example:
        key: IMAGE
        description: docker container image
        value_type: string
        sensitivity: normal
    UpdateVariableRequest:
      type: object
      additionalProperties: false
      properties:
        description:
          type: string
          nullable: true
          example: docker container image
        value_type:
          type: string
          nullable: true
          example: string
        sensitivity:
          type: string
          nullable: true
          example: normal
        default_value:
          type: string
          nullable: true
          example: null
      example:
        description: docker container image
    ApiResponseVariable:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/Variable'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T14:31:30.956937Z'
          status: success
          code: CREATED
        data:
          id: 00000000-0000-4000-8000-000000000001
          scope: app
          app_id: 00000000-0000-4000-8000-000000000001
          key: IMAGE
          description: docker container image
          value_type: string
          sensitivity: normal
          created_at: '2026-02-24T14:31:30.949383Z'
          updated_at: '2026-02-24T14:31:30.949383Z'
        warnings: []
        errors: []
    ApiResponseVariables:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/Variable'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T12:32:00Z'
          status: success
          code: OK
        data:
          - id: 00000000-0000-4000-8000-000000000001
            scope: global
            org_id: null
            app_id: null
            app_job_id: null
            key: NOMATRON_VAR_IMAGE_TAG
            description: Docker image tag used for deployments
            value_type: string
            sensitivity: plain
            default_value: latest
            created_at: '2026-02-24T12:30:00Z'
            updated_at: '2026-02-24T12:31:00Z'
          - id: 00000000-0000-4000-8000-000000000001
            scope: global
            org_id: null
            app_id: null
            app_job_id: null
            key: NOMATRON_VAR_API_URL
            description: Base URL for downstream API
            value_type: string
            sensitivity: plain
            default_value: 'https://api.example.com'
            created_at: '2026-02-24T12:30:10Z'
            updated_at: '2026-02-24T12:31:10Z'
        warnings: []
        errors: []
    VariableValue:
      type: object
      additionalProperties: false
      required:
        - id
        - variable_id
        - is_default
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
        variable_id:
          type: string
          format: uuid
        environment_id:
          type: string
          format: uuid
          nullable: true
        value:
          type: string
          nullable: true
          description: Variable value. Sensitive variables return a masked value instead of plaintext.
        is_default:
          type: boolean
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      example:
        id: 00000000-0000-4000-8000-000000000001
        variable_id: 00000000-0000-4000-8000-000000000001
        environment_id: null
        value: v1.2.3
        is_default: true
        created_at: '2026-02-24T12:40:00Z'
        updated_at: '2026-02-24T12:41:00Z'
    UpsertVariableValueRequest:
      type: object
      additionalProperties: false
      required:
        - value
      properties:
        value:
          type: string
          nullable: true
          example: 'nginx:latest'
      example:
        value: 'nginx:latest'
    ApiResponseVariableValue:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/VariableValue'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T14:31:31.030336Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          variable_id: 00000000-0000-4000-8000-000000000001
          environment_id: 00000000-0000-4000-8000-000000000001
          value: 'nginx:latest'
          is_default: false
          created_at: '2026-02-24T14:31:31.026061Z'
          updated_at: '2026-02-24T14:31:31.026061Z'
        warnings: []
        errors: []
    ApiResponseVariableValues:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          required:
            - data
          properties:
            data:
              type: array
              items:
                $ref: '#/components/schemas/VariableValue'
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-24T12:42:00Z'
          status: success
          code: OK
        data:
          - id: 00000000-0000-4000-8000-000000000001
            variable_id: 00000000-0000-4000-8000-000000000001
            environment_id: null
            value: latest
            is_default: true
            created_at: '2026-02-24T12:40:00Z'
            updated_at: '2026-02-24T12:41:00Z'
          - id: 00000000-0000-4000-8000-000000000001
            variable_id: 00000000-0000-4000-8000-000000000001
            environment_id: 00000000-0000-4000-8000-000000000001
            value: v1.2.3
            is_default: false
            created_at: '2026-02-24T12:40:10Z'
            updated_at: '2026-02-24T12:41:10Z'
        warnings: []
        errors: []
    Environment:
      type: object
      additionalProperties: false
      required:
        - id
        - app_id
        - name
        - slug
        - cluster_id
        - namespace
        - priority
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        app_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          example: dev
        slug:
          type: string
          example: dev
        cluster_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        namespace:
          type: string
          example: nginx
        priority:
          type: integer
          example: 1
        created_at:
          type: string
          format: date-time
          example: '2026-02-23T11:10:04Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-02-23T11:10:04Z'
    CreateEnvironmentRequest:
      type: object
      additionalProperties: false
      required:
        - name
        - slug
        - cluster_id
        - namespace
        - priority
      properties:
        name:
          type: string
          example: dev
        slug:
          type: string
          example: dev
        cluster_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        namespace:
          type: string
          example: nginx
        priority:
          type: integer
          example: 1
    UpdateEnvironmentRequest:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
          nullable: true
          example: dev
        slug:
          type: string
          nullable: true
          example: dev
        cluster_id:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
        namespace:
          type: string
          nullable: true
          example: nginx
        priority:
          type: integer
          nullable: true
          example: 1
    ReorderEnvironmentsRequest:
      type: object
      additionalProperties: false
      required:
        - slugs
      properties:
        slugs:
          type: array
          items:
            type: string
          example:
            - dev
            - prod
            - staging
    ReorderAppJobsRequest:
      type: object
      additionalProperties: false
      properties:
        slugs:
          type: array
          description: Explicit flattened order. This assigns unique stepped deployment groups in the supplied order.
          items:
            type: string
          example:
            - api
            - worker
            - scheduler
        items:
          type: array
          description: Explicit deployment group assignments. Use this form when multiple jobs should share the same group.
          items:
            type: object
            additionalProperties: false
            required:
              - slug
              - priority
            properties:
              slug:
                type: string
              priority:
                type: integer
                minimum: 1
          example:
            - slug: api
              priority: 1
            - slug: worker
              priority: 1
            - slug: scheduler
              priority: 2
    ReorderAppJobsResult:
      type: object
      additionalProperties: false
      required:
        - items
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/AppJob'
    ApiResponseReorderAppJobs:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ReorderAppJobsResult'
          required:
            - data
    AppBulkActionRequest:
      type: object
      additionalProperties: false
      properties:
        environment_slug:
          type: string
          description: 'App environment slug to plan or apply. When omitted, Nomatron uses the app''s first environment. Apps must have at least one environment before planning or applying.'
          example: prod
        job_slugs:
          type: array
          items:
            type: string
          description: 'Optional app job slugs to include. When omitted, Nomatron selects all jobs in the app.'
        mode:
          type: string
          enum:
            - changed
            - all
          description: Selection mode for app-level deployment and promotion triggers.
        ref:
          type: string
          nullable: true
        commit_sha:
          type: string
          nullable: true
    AppBulkActionResult:
      type: object
      additionalProperties: false
      properties:
        batch_id:
          type: string
          format: uuid
        batch_type:
          type: string
          enum:
            - plan
            - apply
        state:
          type: string
          enum:
            - pending
            - running
            - succeeded
            - failed
            - cancelled
        source_environment_id:
          type: string
          format: uuid
          nullable: true
          description: Source environment for app promotion batches.
        target_environment_id:
          type: string
          format: uuid
          nullable: true
          description: Target environment for app promotion batches.
        items:
          type: array
          items:
            type: object
            additionalProperties: false
            properties:
              app_job_id:
                type: string
                format: uuid
              priority:
                type: integer
                description: Deployment group priority for this app job.
              deployment_group:
                type: integer
                description: Alias of priority for UI and clients that use deployment group language.
              plan_operation_id:
                type: string
                format: uuid
                nullable: true
              apply_operation_id:
                type: string
                format: uuid
                nullable: true
              state:
                type: string
                enum:
                  - pending
                  - queued
                  - waiting_health
                  - succeeded
                  - failed
                  - cancelled
              error_summary:
                type: string
                nullable: true
    ApiResponseAppBulkAction:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/AppBulkActionResult'
          required:
            - data
    AppStackBatchItem:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        batch_id:
          type: string
          format: uuid
        app_job_id:
          type: string
          format: uuid
        job_slug:
          type: string
        job_name:
          type: string
        priority:
          type: integer
          description: Deployment group priority for this app job.
        position:
          type: integer
        state:
          type: string
          enum:
            - pending
            - queued
            - waiting_health
            - succeeded
            - failed
            - cancelled
        plan_operation_id:
          type: string
          format: uuid
          nullable: true
        apply_operation_id:
          type: string
          format: uuid
          nullable: true
        plan_operation:
          allOf:
            - $ref: '#/components/schemas/Operation'
          nullable: true
        apply_operation:
          allOf:
            - $ref: '#/components/schemas/Operation'
          nullable: true
        error_summary:
          type: string
          nullable: true
    AppStackBatch:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        org_id:
          type: string
          format: uuid
        app_id:
          type: string
          format: uuid
        batch_type:
          type: string
          enum:
            - plan
            - apply
        state:
          type: string
          enum:
            - pending
            - running
            - succeeded
            - failed
            - cancelled
        ref:
          type: string
          nullable: true
        commit_sha:
          type: string
          nullable: true
        error_summary:
          type: string
          nullable: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        items:
          type: array
          items:
            $ref: '#/components/schemas/AppStackBatchItem'
    AppStackBatchList:
      type: object
      additionalProperties: false
      required:
        - items
        - total
        - limit
        - offset
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/AppStackBatch'
        total:
          type: integer
          minimum: 0
        limit:
          type: integer
          minimum: 1
        offset:
          type: integer
          minimum: 0
    ApiResponseAppStackBatches:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/AppStackBatchList'
          required:
            - data
    DestroyPlanBatchItem:
      type: object
      additionalProperties: false
      properties:
        app_job_id:
          type: string
          format: uuid
        priority:
          type: integer
          description: Deployment group priority for this app job.
        deployment_group:
          type: integer
          description: Alias of priority for UI and clients that use deployment group language.
        plan_operation_id:
          type: string
          format: uuid
          nullable: true
        apply_operation_id:
          type: string
          format: uuid
          nullable: true
        state:
          type: string
          enum:
            - pending
            - queued
            - waiting_health
            - succeeded
            - failed
            - cancelled
        error_summary:
          type: string
          nullable: true
    DestroyPlanTarget:
      type: object
      additionalProperties: false
      required:
        - org_id
        - app_id
        - app_slug
        - app_job_id
        - app_job_slug
        - cluster_id
        - cluster_name
        - namespace
        - nomad_job_id
        - source
      properties:
        org_id:
          type: string
          format: uuid
        app_id:
          type: string
          format: uuid
        app_slug:
          type: string
        app_job_id:
          type: string
          format: uuid
        app_job_slug:
          type: string
        environment_id:
          type: string
          format: uuid
          nullable: true
        environment_slug:
          type: string
          nullable: true
        cluster_id:
          type: string
          format: uuid
        cluster_name:
          type: string
        namespace:
          type: string
        region:
          type: string
          nullable: true
        nomad_job_id:
          type: string
        source:
          type: string
          description: Source used to identify the destroy target.
          example: runtime_state
    DestroyPlanResult:
      type: object
      additionalProperties: false
      required:
        - targets
        - ready_for_apply
        - target_count
      properties:
        operation_id:
          type: string
          format: uuid
          nullable: true
        batch_id:
          type: string
          format: uuid
          nullable: true
        batch_state:
          type: string
          nullable: true
          enum:
            - pending
            - running
            - succeeded
            - failed
            - cancelled
        items:
          type: array
          items:
            $ref: '#/components/schemas/DestroyPlanBatchItem'
        targets:
          type: array
          items:
            $ref: '#/components/schemas/DestroyPlanTarget'
        approval_state:
          type: string
          nullable: true
          enum:
            - not_required
            - pending
            - approved
            - rejected
        approval_required_count:
          type: integer
          minimum: 0
        approval_request_id:
          type: string
          format: uuid
          nullable: true
        ready_for_apply:
          type: boolean
        target_count:
          type: integer
          minimum: 0
    ApiResponseDestroyPlan:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/DestroyPlanResult'
          required:
            - data
    DestroyApplyResult:
      type: object
      additionalProperties: false
      required:
        - operation_id
        - plan_operation_id
        - state
        - approval_state
        - target_count
        - targets
      properties:
        operation_id:
          type: string
          format: uuid
        plan_operation_id:
          type: string
          format: uuid
        state:
          type: string
          enum:
            - queued
            - running
            - succeeded
            - failed
            - cancelled
        approval_state:
          type: string
          enum:
            - not_required
            - pending
            - approved
            - rejected
        target_count:
          type: integer
          minimum: 0
        targets:
          type: array
          items:
            $ref: '#/components/schemas/DestroyPlanTarget'
    ApiResponseDestroyApply:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/DestroyApplyResult'
          required:
            - data
    AppStackApprovalResult:
      type: object
      additionalProperties: false
      properties:
        environment_id:
          type: string
          format: uuid
          nullable: true
        items:
          type: array
          items:
            type: object
            additionalProperties: false
            properties:
              app_job_id:
                type: string
                format: uuid
              operation_id:
                type: string
                format: uuid
              outcome:
                type: string
                enum:
                  - approved
                  - pending
                  - rejected
                  - no_pending_plan
    ApiResponseAppStackApproval:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/AppStackApprovalResult'
          required:
            - data
    ReorderEnvironmentResultItem:
      type: object
      additionalProperties: false
      required:
        - ID
        - Slug
        - Priority
      properties:
        ID:
          type: string
          format: uuid
        Slug:
          type: string
        Priority:
          type: integer
          minimum: 1
    ReorderEnvironmentsResult:
      type: object
      additionalProperties: false
      required:
        - app_id
        - environments
      properties:
        app_id:
          type: string
          format: uuid
        environments:
          type: array
          items:
            $ref: '#/components/schemas/ReorderEnvironmentResultItem'
    ApiResponseReorderEnvironments:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ReorderEnvironmentsResult'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T18:24:12.125864Z'
          status: success
          code: OK
        data:
          app_id: 00000000-0000-4000-8000-000000000001
          environments:
            - ID: 00000000-0000-4000-8000-000000000001
              Slug: dev
              Priority: 1
            - ID: 00000000-0000-4000-8000-000000000001
              Slug: prod
              Priority: 2
            - ID: 00000000-0000-4000-8000-000000000001
              Slug: staging
              Priority: 3
        warnings: []
        errors: []
    ApiResponseEnvironment:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/Environment'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T17:38:24.116229Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          app_id: 00000000-0000-4000-8000-000000000001
          name: dev
          slug: dev
          cluster_id: 00000000-0000-4000-8000-000000000001
          namespace: nginx
          priority: 1
          created_at: '2026-02-23T11:10:04Z'
          updated_at: '2026-02-23T11:10:04Z'
        warnings: []
        errors: []
    ApiResponseEnvironments:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/EnvironmentList'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T17:56:46.84646Z'
          status: success
          code: OK
        data:
          items:
            - id: 00000000-0000-4000-8000-000000000001
              app_id: 00000000-0000-4000-8000-000000000001
              name: dev
              slug: dev
              cluster_id: 00000000-0000-4000-8000-000000000001
              namespace: nginx
              priority: 1
              created_at: '2026-02-23T11:10:04Z'
              updated_at: '2026-02-23T11:10:04Z'
        warnings: []
        errors: []
    EnvironmentList:
      type: object
      additionalProperties: false
      required:
        - items
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Environment'
    ApprovalDecision:
      type: object
      additionalProperties: false
      required:
        - decision
        - comment
      properties:
        decision:
          type: string
          enum:
            - approve
            - reject
          example: approve
        comment:
          type: string
          nullable: true
          example: LGTM
      example:
        decision: approve
        comment: LGTM
    RecordApprovalDecisionRequest:
      $ref: '#/components/schemas/ApprovalDecision'
    ApiResponseApprovalDecision:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ApprovalDecisionResult'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    ApprovalDecisionResult:
      type: object
      additionalProperties: false
      required:
        - operation_id
        - environment_id
        - outcome
      properties:
        operation_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        environment_id:
          type: string
          format: uuid
          nullable: true
          example: null
        outcome:
          type: string
          description: Outcome of the approval decision.
          example: approved
      example:
        operation_id: 00000000-0000-4000-8000-000000000001
        environment_id: null
        outcome: approved
    ApiResponseApprovablePlan:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ApprovablePlanPayload'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    QueuePlanAccepted:
      type: object
      required:
        - operation_id
        - status
      properties:
        operation_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        status:
          type: string
          enum:
            - queued
          example: queued
      additionalProperties: false
    QueueJobDeployRequest:
      type: object
      additionalProperties: false
      properties:
        environment_slug:
          type: string
          nullable: true
          description: App environment slug to deploy. New job deployments must target the app's first environment.
          example: prod
        ref:
          type: string
          nullable: true
          description: Optional git ref override for the deployment plan.
          example: refs/heads/main
        commit_sha:
          type: string
          nullable: true
          description: Optional commit SHA override for the deployment plan.
          example: 3a15425de862cc15e17d8282ffb41f71ed2fdc2a
    QueueJobDeployAccepted:
      type: object
      required:
        - operation_id
        - status
      properties:
        operation_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        status:
          type: string
          enum:
            - queued
          example: queued
        environment_id:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
        ref:
          type: string
          nullable: true
          example: refs/heads/main
        commit_sha:
          type: string
          nullable: true
          example: 3a15425de862cc15e17d8282ffb41f71ed2fdc2a
      additionalProperties: false
    ApiResponseJobDeploy:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/QueueJobDeployAccepted'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    PlanApplyAccepted:
      type: object
      required:
        - operation_id
        - plan_operation_id
        - status
      properties:
        operation_id:
          type: string
          format: uuid
          description: Apply operation ID.
          example: 00000000-0000-4000-8000-000000000001
        plan_operation_id:
          type: string
          format: uuid
          description: Plan operation ID used to start the apply.
          example: 00000000-0000-4000-8000-000000000001
        status:
          type: string
          enum:
            - queued
          example: queued
        environment_id:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
      additionalProperties: false
    ApiResponsePlanApply:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/PlanApplyAccepted'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    ApiResponseQueuedPlan:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/QueuePlanAccepted'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    ApprovablePlanPayload:
      type: object
      required:
        - operation
        - artifact
      properties:
        operation:
          $ref: '#/components/schemas/LatestApprovablePlanOperation'
        artifact:
          nullable: true
          allOf:
            - $ref: '#/components/schemas/ApprovablePlanArtifact'
      additionalProperties: false
      example:
        artifact:
          id: 00000000-0000-4000-8000-000000000001
          kind: plan_output
          media_type: text/x-diff
          body: |
            + Job: "nginx-nomatron-template" (forces create)
              + "Name"...
        operation:
          ID: 00000000-0000-4000-8000-000000000001
          OrgID: 00000000-0000-4000-8000-000000000001
          AppID: 00000000-0000-4000-8000-000000000001
          AppJobID: 00000000-0000-4000-8000-000000000001
          EnvironmentID: 00000000-0000-4000-8000-000000000001
          OpType: plan
          State: succeeded
          ApprovalState: pending
          AppliedAt: null
          SupersededAt: null
          SupersededByID: null
          CommitSHA: 3a15425de862cc15e17d8282ffb41f71ed2fdc2a
          Ref: refs/heads/main
          CreatedAt: '2026-02-22T18:47:33.048402Z'
    ApprovablePlanArtifact:
      type: object
      required:
        - id
        - kind
        - media_type
        - body
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        kind:
          type: string
          description: Operation artifact kind
          example: plan_output
        media_type:
          type: string
          description: Media type of the artifact body
          example: text/x-diff
        body:
          description: 'Artifact body. String for text bodies (plan_output), JSON for plan_diff.'
          oneOf:
            - type: string
              example: |
                + Job: "nginx-nomatron-template" (forces create)
                  + "Name"...
            - type: object
              additionalProperties: true
              example:
                ID: nginx-nomatron-template
                Fields:
                  - Name: Name
                    Type: Added
                    Old: ''
                    New: nginx-nomatron-template
      additionalProperties: false
    LatestApprovablePlanOperation:
      type: object
      required:
        - ID
        - OrgID
        - AppID
        - AppJobID
        - OpType
        - State
        - ApprovalState
        - CreatedAt
      properties:
        ID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        OrgID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        AppID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        AppJobID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        EnvironmentID:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
        OpType:
          type: string
          example: plan
        State:
          type: string
          example: succeeded
        ApprovalState:
          type: string
          example: pending
        AppliedAt:
          type: string
          format: date-time
          nullable: true
          example: null
        SupersededAt:
          type: string
          format: date-time
          nullable: true
          example: null
        SupersededByID:
          type: string
          format: uuid
          nullable: true
          example: null
        CommitSHA:
          type: string
          nullable: true
          example: 3a15425de862cc15e17d8282ffb41f71ed2fdc2a
        Ref:
          type: string
          nullable: true
          example: refs/heads/main
        CreatedAt:
          type: string
          format: date-time
          nullable: true
          example: '2026-02-22T18:47:33.048402Z'
      additionalProperties: false
    CreateSpeculativePlanRequest:
      type: object
      additionalProperties: false
      properties:
        ref:
          type: string
          nullable: true
          description: Optional git ref override for the speculative plan.
          example: feature/foo
        commit_sha:
          type: string
          nullable: true
          description: Optional commit SHA override for the speculative plan.
          example: abc1234
        environment_slug:
          type: string
          nullable: true
          description: 'Optional app environment slug to target. When omitted, Nomatron uses the normal default plan target.'
          example: staging
        inputs:
          type: object
          nullable: true
          additionalProperties: true
          description: Optional plan-time inputs (implementation-defined).
          example:
            image_tag: sha-abc123
      example:
        environment_slug: staging
        ref: feature/foo
        commit_sha: abc1234
        inputs:
          image_tag: sha-abc123
    SpeculativePlan:
      type: object
      additionalProperties: false
      required:
        - plan_id
        - status
        - created_at
      properties:
        plan_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        status:
          type: string
          enum:
            - queued
            - running
            - complete
            - failed
          example: complete
        created_at:
          type: string
          format: date-time
          example: '2026-01-01T00:00:00Z'
        summary:
          type: string
          nullable: true
          example: No changes
        environment_id:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
      example:
        plan_id: 00000000-0000-4000-8000-000000000001
        status: complete
        created_at: '2026-01-01T00:00:00Z'
        summary: No changes
        environment_id: 00000000-0000-4000-8000-000000000001
    ApiResponseSpeculativePlan:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/SpeculativePlan'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    AcceptDriftResponse:
      type: object
      additionalProperties: false
      required:
        - operation_id
        - status
      description: |
        Accept-drift is asynchronous. The worker rebases Nomatron desired state onto live Nomad state, then best-effort opens a GitHub PR updating the connected jobspec (JSON or HCL) using a GitHub field mask plus semantic drift diff. TEMPLATE jobs skip git write-back. Successful operations may record the PR URL on the accept-drift release summary and a debug operation artifact.
      properties:
        operation_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        status:
          type: string
          enum:
            - queued
          example: queued
        environment_id:
          type: string
          format: uuid
          nullable: true
          description: Present for environment-scoped accept-drift.
          example: 00000000-0000-4000-8000-000000000001
      example:
        operation_id: 00000000-0000-4000-8000-000000000001
        status: queued
    ApiResponseAcceptDrift:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/AcceptDriftResponse'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    ImportJobRequest:
      type: object
      required:
        - job_id
      properties:
        job_id:
          type: string
          description: Nomad Job ID to import (required)
          example: nginx-nomatron-template
      additionalProperties: false
    ImportJobAccepted:
      type: object
      required:
        - operation_id
        - status
      properties:
        operation_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        status:
          type: string
          enum:
            - queued
          example: queued
      additionalProperties: false
    ApiResponseImportJob:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ImportJobAccepted'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    CreatePromotionPlanRequest:
      type: object
      additionalProperties: false
      properties:
        to_environment:
          type: string
          nullable: true
          description: Optional override of the next environment slug.
          example: staging
      example:
        to_environment: staging
    PromotionPlan:
      type: object
      additionalProperties: false
      required:
        - operation_id
        - source_environment_id
        - target_environment_id
      properties:
        operation_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        source_environment_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        target_environment_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
      example:
        operation_id: 00000000-0000-4000-8000-000000000001
        source_environment_id: 00000000-0000-4000-8000-000000000001
        target_environment_id: 00000000-0000-4000-8000-000000000001
    ApiResponsePromotionPlan:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/PromotionPlan'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    CreateRollbackPlanRequest:
      type: object
      additionalProperties: false
      properties:
        environment_slug:
          type: string
          description: Target environment slug (same environment to roll back within). Required unless environment_id is set.
          example: staging
        environment_id:
          type: string
          format: uuid
          description: Target environment UUID. Required unless environment_slug is set.
        source_release_id:
          type: string
          format: uuid
          nullable: true
          description: Optional prior healthy release to restore. Defaults to the previous healthy release before the current head.
      example:
        environment_slug: staging
        source_release_id: 00000000-0000-4000-8000-000000000001
    RollbackPlan:
      type: object
      additionalProperties: false
      required:
        - operation_id
        - environment_id
      properties:
        operation_id:
          type: string
          format: uuid
        environment_id:
          type: string
          format: uuid
        ref:
          type: string
          nullable: true
          description: 'Synthetic provenance ref of the form rollback:<environment_id>:<source_release_id>'
        commit_sha:
          type: string
          nullable: true
          description: Historical commit SHA from the source release
    ApiResponseRollbackPlan:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/RollbackPlan'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    RollbackCandidate:
      type: object
      additionalProperties: false
      required:
        - release_id
        - health_status
        - created_at
        - is_default
      properties:
        release_id:
          type: string
          format: uuid
        commit_sha:
          type: string
          nullable: true
        ref:
          type: string
          nullable: true
        git_tag:
          type: string
          nullable: true
        summary:
          type: string
          nullable: true
        health_status:
          type: string
          example: healthy
        created_at:
          type: string
          format: date-time
        is_default:
          type: boolean
          description: True for the newest healthy candidate (default rollback target)
        plan_operation_id:
          type: string
          format: uuid
          nullable: true
    ApiResponseRollbackCandidates:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          type: array
          items:
            $ref: '#/components/schemas/RollbackCandidate'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      additionalProperties: false
    Operation:
      type: object
      additionalProperties: false
      required:
        - id
        - org_id
        - app_id
        - app_job_id
        - cluster_id
        - namespace
        - jobspec_type
        - op_type
        - state
        - approval_state
        - approval_required_count
        - ref
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        org_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        app_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        app_job_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        cluster_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        namespace:
          type: string
          example: default
        jobspec_type:
          type: string
          description: Jobspec source type for the operation.
          enum:
            - NOMAD
            - TEMPLATE
          example: NOMAD
        op_type:
          type: string
          description: Operation type.
          example: plan
        state:
          type: string
          description: Execution state of the operation.
          example: succeeded
        approval_state:
          type: string
          description: Approval state for the operation.
          example: not_required
        approval_required_count:
          type: integer
          minimum: 0
          example: 0
        ref:
          type: string
          description: Git ref associated with the operation.
          example: main
        commit_sha:
          type: string
          nullable: true
          description: Commit SHA associated with the operation.
          example: abc1234
        git_tag:
          type: string
          nullable: true
          description: Git tag that triggered the operation when tag-based deployment is used.
          example: 12.33.4456
        created_at:
          type: string
          format: date-time
          example: '2026-02-23T22:55:43.791645Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-02-23T22:55:47.461254Z'
        started_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-02-23T22:55:47.108513Z'
        finished_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-02-23T22:55:47.461506Z'
    OperationList:
      type: object
      additionalProperties: false
      required:
        - items
        - total
        - limit
        - offset
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/Operation'
        total:
          type: integer
          minimum: 0
          example: 2
        limit:
          type: integer
          minimum: 1
          example: 50
        offset:
          type: integer
          minimum: 0
          example: 0
        next_cursor:
          type: string
          nullable: true
          description: Cursor to fetch the next page. Omitted when there is no next page.
          example: '2026-03-01T12:00:00.123456789Z|00000000-0000-4000-8000-000000000001'
    ApiResponseOperations:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/OperationList'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T22:55:51.999309Z'
          status: success
          code: OK
        data:
          items:
            - id: 00000000-0000-4000-8000-000000000001
              org_id: 00000000-0000-4000-8000-000000000001
              app_id: 00000000-0000-4000-8000-000000000001
              app_job_id: 00000000-0000-4000-8000-000000000001
              cluster_id: 00000000-0000-4000-8000-000000000001
              namespace: default
              jobspec_type: NOMAD
              op_type: import
              state: succeeded
              approval_state: not_required
              approval_required_count: 0
              ref: main
              created_at: '2026-02-23T22:55:43.791645Z'
              updated_at: '2026-02-23T22:55:45.209589Z'
              started_at: '2026-02-23T22:55:45.123798Z'
              finished_at: '2026-02-23T22:55:45.209969Z'
            - id: 00000000-0000-4000-8000-000000000001
              org_id: 00000000-0000-4000-8000-000000000001
              app_id: 00000000-0000-4000-8000-000000000001
              app_job_id: 00000000-0000-4000-8000-000000000001
              cluster_id: 00000000-0000-4000-8000-000000000001
              namespace: default
              jobspec_type: NOMAD
              op_type: plan
              state: succeeded
              approval_state: not_required
              approval_required_count: 0
              ref: main
              created_at: '2026-02-23T22:55:43.791645Z'
              updated_at: '2026-02-23T22:55:47.461254Z'
              started_at: '2026-02-23T22:55:47.108513Z'
              finished_at: '2026-02-23T22:55:47.461506Z'
          total: 2
          limit: 50
          offset: 0
        warnings: []
        errors: []
    OperationDetail:
      type: object
      additionalProperties: false
      required:
        - ID
        - OrgID
        - AppID
        - AppJobID
        - JobspecType
        - ClusterID
        - Namespace
        - IsSpeculative
        - ApprovalState
        - ApprovalRequiredCount
        - ApprovalVersion
        - ApplyAttemptCount
        - OpType
        - State
        - Ref
        - CreatedAt
        - UpdatedAt
      properties:
        ID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        OrgID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        AppID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        AppJobID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        JobspecType:
          type: string
          enum:
            - NOMAD
            - TEMPLATE
          example: NOMAD
        EnvironmentID:
          type: string
          format: uuid
          nullable: true
          example: null
        ClusterID:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        Namespace:
          type: string
          example: default
        IsSpeculative:
          type: boolean
          example: false
        ApprovalState:
          type: string
          example: not_required
        ApprovalRequiredCount:
          type: integer
          minimum: 0
          example: 0
        ApprovalPolicyID:
          type: string
          format: uuid
          nullable: true
          example: null
        ApprovalPolicyVersion:
          type: integer
          nullable: true
          minimum: 1
          example: null
        ApprovalRequestID:
          type: string
          format: uuid
          nullable: true
          example: null
        ApprovalVersion:
          type: integer
          minimum: 0
          example: 1
        ApprovedAt:
          type: string
          format: date-time
          nullable: true
          example: null
        RejectedAt:
          type: string
          format: date-time
          nullable: true
          example: null
        PlanOperationID:
          type: string
          format: uuid
          nullable: true
          example: null
        AppliedAt:
          type: string
          format: date-time
          nullable: true
          example: null
        ApplyError:
          type: string
          nullable: true
          example: null
        ApplyAttemptCount:
          type: integer
          minimum: 0
          example: 0
        OpType:
          type: string
          example: import
        State:
          type: string
          example: succeeded
        Ref:
          type: string
          example: main
        CommitSHA:
          type: string
          nullable: true
          example: null
        LeaseOwner:
          type: string
          nullable: true
          example: null
        LeaseExpiresAt:
          type: string
          format: date-time
          nullable: true
          example: null
        LeaseHeartbeatAt:
          type: string
          format: date-time
          nullable: true
          example: null
        ErrorSummary:
          type: string
          nullable: true
          example: null
        CreatedAt:
          type: string
          format: date-time
          example: '2026-02-23T22:55:43.791645Z'
        UpdatedAt:
          type: string
          format: date-time
          example: '2026-02-23T22:55:45.209589Z'
        StartedAt:
          type: string
          format: date-time
          nullable: true
          example: '2026-02-23T22:55:45.123798Z'
        FinishedAt:
          type: string
          format: date-time
          nullable: true
          example: '2026-02-23T22:55:45.209969Z'
        SupersededAt:
          type: string
          format: date-time
          nullable: true
          example: null
        SupersededById:
          type: string
          format: uuid
          nullable: true
          example: null
    ApiResponseOperation:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/OperationDetail'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-23T23:05:21.404181Z'
          status: success
          code: OK
        data:
          ID: 00000000-0000-4000-8000-000000000001
          OrgID: 00000000-0000-4000-8000-000000000001
          AppID: 00000000-0000-4000-8000-000000000001
          AppJobID: 00000000-0000-4000-8000-000000000001
          JobspecType: NOMAD
          EnvironmentID: null
          ClusterID: 00000000-0000-4000-8000-000000000001
          Namespace: default
          IsSpeculative: false
          ApprovalState: not_required
          ApprovalRequiredCount: 0
          ApprovalPolicyID: null
          ApprovalPolicyVersion: null
          ApprovalRequestID: null
          ApprovalVersion: 1
          ApprovedAt: null
          RejectedAt: null
          PlanOperationID: null
          AppliedAt: null
          ApplyError: null
          ApplyAttemptCount: 0
          OpType: import
          State: succeeded
          Ref: main
          CommitSHA: null
          LeaseOwner: null
          LeaseExpiresAt: null
          LeaseHeartbeatAt: null
          ErrorSummary: null
          CreatedAt: '2026-02-23T22:55:43.791645Z'
          UpdatedAt: '2026-02-23T22:55:45.209589Z'
          StartedAt: '2026-02-23T22:55:45.123798Z'
          FinishedAt: '2026-02-23T22:55:45.209969Z'
          SupersededAt: null
          SupersededById: null
        warnings: []
        errors: []
    AuditLogListResponse:
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/AuditLog'
        has_more:
          type: boolean
      required:
        - items
        - has_more
    AuditLog:
      type: object
      properties:
        id:
          type: string
          format: uuid
        timestamp:
          type: string
          format: date-time
        event_type:
          type: string
        request_id:
          type: string
          format: uuid
        actor_type:
          type: string
          description: Actor type (user or service account)
        actor_user_id:
          type: string
          format: uuid
          nullable: true
        actor_service_account_id:
          type: string
          format: uuid
          nullable: true
        org_id:
          type: string
          format: uuid
          nullable: true
        app_id:
          type: string
          format: uuid
          nullable: true
        app_job_id:
          type: string
          format: uuid
          nullable: true
        resource_type:
          type: string
          nullable: true
        resource_id:
          type: string
          format: uuid
          nullable: true
        resource_name:
          type: string
          nullable: true
        origin:
          type: string
          nullable: true
          description: 'Request origin/channel (ui, cli, api, mcp)'
        client_id:
          type: string
          nullable: true
          description: OAuth client id when origin is mcp
        mcp_tool:
          type: string
          nullable: true
          description: Optional MCP tool name when forwarded by the MCP server
        metadata:
          type: object
          additionalProperties: true
          nullable: true
        cursor:
          type: string
          description: Cursor to fetch the next page (pass as `cursor` query param)
      required:
        - id
        - timestamp
        - event_type
        - actor_type
        - cursor
    ApiResponseAuditLogListResponse:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/AuditLogListResponse'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-02-28T18:16:57.734492Z'
          status: success
          code: OK
        data:
          has_more: false
          items:
            - id: 00000000-0000-4000-8000-000000000001
              timestamp: '2026-02-28T18:15:34.276476Z'
              event_type: variable_value.upsert
              request_id: 00000000-0000-4000-8000-000000000001
              actor_type: user
              actor_user_id: 00000000-0000-4000-8000-000000000001
              org_id: 00000000-0000-4000-8000-000000000001
              app_id: 00000000-0000-4000-8000-000000000001
              app_job_id: null
              resource_type: variable_value
              resource_id: 00000000-0000-4000-8000-000000000001
              metadata:
                bytes: 455
                duration_ms: 2
                http_method: PUT
                http_path: /api/v1/organizations/org-1/apps/my-template-app/jobs/template/variables/00000000-0000-4000-8000-000000000001/values/environments/prod
                ip: '::1'
                query: ''
                request_id: ''
                route_name: ''
                route_tpl: '/api/v1/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/variables/{variableID}/values/environments/{envSlug}'
                scope: app_job
                status_code: 200
                user_agent: Go-http-client/1.1
              cursor: '2026-02-28T18:15:34.276476Z|00000000-0000-4000-8000-000000000001'
            - id: 00000000-0000-4000-8000-000000000001
              timestamp: '2026-02-28T18:15:34.233783Z'
              event_type: approval_policy.upsert
              request_id: 00000000-0000-4000-8000-000000000001
              actor_type: user
              actor_user_id: 00000000-0000-4000-8000-000000000001
              org_id: 00000000-0000-4000-8000-000000000001
              app_id: 00000000-0000-4000-8000-000000000001
              app_job_id: 00000000-0000-4000-8000-000000000001
              resource_type: approval_policy
              metadata:
                bytes: 301
                duration_ms: 42
                http_method: PUT
                http_path: /api/v1/organizations/org-1/apps/my-template-app/approval-policy
                ip: '::1'
                query: ''
                request_id: ''
                route_name: ''
                route_tpl: '/api/v1/organizations/{orgSlug}/apps/{slug}/approval-policy'
                status_code: 200
                user_agent: Go-http-client/1.1
              cursor: '2026-02-28T18:15:34.233783Z|00000000-0000-4000-8000-000000000001'
        warnings: []
        errors: []
    CreateServiceAccountRequest:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
          minLength: 1
          example: terraform
        description:
          type: string
          nullable: true
          example: Service account used by Terraform automation
      required:
        - name
      example:
        name: terraform
        description: Service account used by Terraform automation
    UpdateServiceAccountRequest:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
          nullable: true
          example: terraform-prod
        description:
          type: string
          nullable: true
          example: Terraform service account for production
      description: Fields are optional; only provided fields are updated.
      example:
        name: terraform-prod
        description: Terraform service account for production
    CreateServiceAccountTokenRequest:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
          nullable: true
          description: Optional friendly label for UI
          example: terraform-prod
        expires_at:
          type: string
          format: date-time
          nullable: true
          description: Null means never expires
          example: '2026-12-31T23:59:59Z'
      required: []
      example:
        name: terraform-prod
        expires_at: '2026-12-31T23:59:59Z'
    ServiceAccount:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          example: terraform
        description:
          type: string
          nullable: true
          example: service account for terraform
        is_active:
          type: boolean
          example: true
        created_by:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        created_at:
          type: string
          format: date-time
          example: '2026-03-02T11:18:13.493934Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-03-02T11:18:13.493934Z'
        cursor:
          type: string
          nullable: true
          description: Optional cursor value for pagination (if you expose it)
          example: eyJjcmVhdGVkX2F0IjoiMjAyNi0wMy0wMlQxMToxODoxMy40OTM5MzRaIiwiaWQiOiJjYzZhNzNlNy1kODNiLTQxNTQtOTE0Yy02ZmI3ZGVmZjdkMTAifQ==
      required:
        - id
        - name
        - is_active
        - created_by
        - created_at
        - updated_at
      example:
        id: 00000000-0000-4000-8000-000000000001
        name: terraform
        description: service account for terraform
        is_active: true
        created_by: 00000000-0000-4000-8000-000000000001
        created_at: '2026-03-02T11:18:13.493934Z'
        updated_at: '2026-03-02T11:18:13.493934Z'
    ServiceAccountListResponse:
      type: object
      additionalProperties: false
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/ServiceAccount'
        has_more:
          type: boolean
          example: false
        cursor:
          type: string
          nullable: true
          description: Optional next cursor (if you decide to expose a top-level cursor)
          example: eyJjcmVhdGVkX2F0IjoiMjAyNi0wMy0wMlQxMToxODoxMy40OTM5MzRaIiwiaWQiOiJjYzZhNzNlNy1kODNiLTQxNTQtOTE0Yy02ZmI3ZGVmZjdkMTAifQ==
      required:
        - items
        - has_more
      example:
        items:
          - id: 00000000-0000-4000-8000-000000000001
            name: terraform
            description: service account for terraform
            is_active: true
            created_by: 00000000-0000-4000-8000-000000000001
            created_at: '2026-03-02T11:18:13.493934Z'
            updated_at: '2026-03-02T11:18:13.493934Z'
        has_more: false
    ServiceAccountTokenListItem:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          nullable: true
          example: terraform-prod
        token_prefix:
          type: string
          description: Non-secret prefix for identifying the token
          example: examplePrefix
        created_by:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        created_at:
          type: string
          format: date-time
          example: '2026-03-02T11:18:20.123739Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-03-02T11:25:06.123739Z'
        expires_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
        revoked_at:
          type: string
          format: date-time
          nullable: true
          example: null
        last_used_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-03-02T11:39:33.980638Z'
      required:
        - id
        - token_prefix
        - created_by
        - created_at
        - updated_at
      example:
        id: 00000000-0000-4000-8000-000000000001
        name: terraform-prod
        token_prefix: examplePrefix
        created_by: 00000000-0000-4000-8000-000000000001
        created_at: '2026-03-02T11:18:20.123739Z'
        updated_at: '2026-03-02T11:25:06.123739Z'
        expires_at: '2026-12-31T23:59:59Z'
        revoked_at: null
        last_used_at: '2026-03-02T11:39:33.980638Z'
    ServiceAccountTokenDetail:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        service_account_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          nullable: true
          example: terraform-prod
        token_prefix:
          type: string
          description: Non-secret prefix for identifying the token
          example: examplePrefix
        created_by:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        created_at:
          type: string
          format: date-time
          example: '2026-03-02T11:18:20.123739Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-03-02T11:25:06.123739Z'
        expires_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
        revoked_at:
          type: string
          format: date-time
          nullable: true
          example: null
        last_used_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-03-02T11:39:33.980638Z'
      required:
        - id
        - service_account_id
        - token_prefix
        - created_by
        - created_at
        - updated_at
      example:
        id: 00000000-0000-4000-8000-000000000001
        service_account_id: 00000000-0000-4000-8000-000000000001
        name: terraform-prod
        token_prefix: examplePrefix
        created_by: 00000000-0000-4000-8000-000000000001
        created_at: '2026-03-02T11:18:20.123739Z'
        updated_at: '2026-03-02T11:25:06.123739Z'
        expires_at: '2026-12-31T23:59:59Z'
        revoked_at: null
        last_used_at: '2026-03-02T11:39:33.980638Z'
    ServiceAccountTokenListResponse:
      type: object
      additionalProperties: false
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/ServiceAccountTokenListItem'
        has_more:
          type: boolean
          example: true
        cursor:
          type: string
          format: date-time
          nullable: true
          description: Next cursor (created_at of last item)
          example: '2026-03-02T11:18:20.123739Z'
      required:
        - items
        - has_more
      example:
        items:
          - id: 00000000-0000-4000-8000-000000000001
            name: terraform-prod
            token_prefix: examplePrefix
            created_by: 00000000-0000-4000-8000-000000000001
            created_at: '2026-03-02T11:18:20.123739Z'
            updated_at: '2026-03-02T11:25:06.123739Z'
            expires_at: '2026-12-31T23:59:59Z'
            revoked_at: null
            last_used_at: '2026-03-02T11:39:33.980638Z'
        has_more: true
        cursor: '2026-03-02T11:18:20.123739Z'
    CreateServiceAccountTokenResponse:
      type: object
      additionalProperties: false
      properties:
        token:
          type: string
          description: Raw token (returned exactly once)
          example: nsa_000000000000_00000000000000000000000000000000000000001
        token_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        service_account_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        token_prefix:
          type: string
          example: examplePrefix
        expires_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
      required:
        - token
        - token_id
        - service_account_id
        - token_prefix
      example:
        token: nsa_000000000000_00000000000000000000000000000000000000001
        token_id: 00000000-0000-4000-8000-000000000001
        service_account_id: 00000000-0000-4000-8000-000000000001
        token_prefix: examplePrefix
        expires_at: '2026-12-31T23:59:59Z'
    ApiResponseServiceAccount:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ServiceAccount'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-02T11:25:06.123739Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          name: terraform
          description: service account for terraform
          is_active: true
          created_by: 00000000-0000-4000-8000-000000000001
          created_at: '2026-03-02T11:18:13.493934Z'
          updated_at: '2026-03-02T11:18:13.493934Z'
        warnings: []
        errors: []
    ApiResponseServiceAccountList:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ServiceAccountListResponse'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-02T11:25:06.123739Z'
          status: success
          code: OK
        data:
          items:
            - id: 00000000-0000-4000-8000-000000000001
              name: terraform
              description: service account for terraform
              is_active: true
              created_by: 00000000-0000-4000-8000-000000000001
              created_at: '2026-03-02T11:18:13.493934Z'
              updated_at: '2026-03-02T11:18:13.493934Z'
          has_more: false
        warnings: []
        errors: []
    ApiResponseServiceAccountToken:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ServiceAccountTokenDetail'
              example:
                id: 00000000-0000-4000-8000-000000000001
                service_account_id: 00000000-0000-4000-8000-000000000001
                name: terraform-prod
                token_prefix: examplePrefix
                created_by: 00000000-0000-4000-8000-000000000001
                created_at: '2026-03-02T11:18:20.123739Z'
                updated_at: '2026-03-02T11:25:06.123739Z'
                expires_at: '2026-12-31T23:59:59Z'
                revoked_at: null
                last_used_at: '2026-03-02T11:39:33.980638Z'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-02T11:40:00Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          service_account_id: 00000000-0000-4000-8000-000000000001
          name: terraform-prod
          token_prefix: examplePrefix
          created_by: 00000000-0000-4000-8000-000000000001
          created_at: '2026-03-02T11:18:20.123739Z'
          updated_at: '2026-03-02T11:25:06.123739Z'
          expires_at: '2026-12-31T23:59:59Z'
          revoked_at: null
          last_used_at: '2026-03-02T11:39:33.980638Z'
        warnings: []
        errors: []
    ApiResponseServiceAccountTokenList:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/ServiceAccountTokenListResponse'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-02T11:40:00Z'
          status: success
          code: OK
        data:
          items:
            - id: 00000000-0000-4000-8000-000000000001
              name: terraform-prod
              token_prefix: examplePrefix
              created_by: 00000000-0000-4000-8000-000000000001
              created_at: '2026-03-02T11:18:20.123739Z'
              updated_at: '2026-03-02T11:25:06.123739Z'
              expires_at: '2026-12-31T23:59:59Z'
              revoked_at: null
              last_used_at: '2026-03-02T11:39:33.980638Z'
          has_more: true
          cursor: '2026-03-02T11:18:20.123739Z'
        warnings: []
        errors: []
    ApiResponseCreateServiceAccountToken:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/CreateServiceAccountTokenResponse'
          required:
            - data
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-02T11:18:20.123739Z'
          status: success
          code: CREATED
        data:
          token: nsa_000000000000_00000000000000000000000000000000000000001
          token_id: 00000000-0000-4000-8000-000000000001
          service_account_id: 00000000-0000-4000-8000-000000000001
          token_prefix: examplePrefix
          expires_at: '2026-12-31T23:59:59Z'
        warnings: []
        errors: []
    NetworkAgent:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          example: private-cluster-agent-1
        description:
          type: string
          nullable: true
          example: Network agent running inside private VPC
        is_active:
          type: boolean
          example: true
        last_seen_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-03-06T17:40:22Z'
        created_by_type:
          type: string
          enum:
            - user
            - service_account
          example: user
        created_by_user_id:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
        created_by_service_account_id:
          type: string
          format: uuid
          nullable: true
          example: null
        created_at:
          type: string
          format: date-time
          example: '2026-03-06T17:12:10Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-03-06T17:12:10Z'
      required:
        - id
        - name
        - is_active
        - created_by_type
        - created_at
        - updated_at
    NetworkAgentToken:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        network_agent_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          nullable: true
          example: initial-token
        token_prefix:
          type: string
          example: Yg6m9iX1vWgK
        expires_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
        revoked_at:
          type: string
          format: date-time
          nullable: true
          example: null
        last_used_at:
          type: string
          format: date-time
          nullable: true
          example: null
        created_by_type:
          type: string
          enum:
            - user
            - service_account
          example: user
        created_by_user_id:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
        created_by_service_account_id:
          type: string
          format: uuid
          nullable: true
          example: null
        created_at:
          type: string
          format: date-time
          example: '2026-03-06T17:12:10Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-03-06T17:12:10Z'
      required:
        - id
        - network_agent_id
        - token_prefix
        - created_by_type
        - created_at
        - updated_at
    NetworkAgentTokenWithRawToken:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        network_agent_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        name:
          type: string
          nullable: true
          example: initial-token
        token_prefix:
          type: string
          example: Yg6m9iX1vWgK
        expires_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
        revoked_at:
          type: string
          format: date-time
          nullable: true
          example: null
        last_used_at:
          type: string
          format: date-time
          nullable: true
          example: null
        created_by_type:
          type: string
          enum:
            - user
            - service_account
          example: user
        created_by_user_id:
          type: string
          format: uuid
          nullable: true
          example: 00000000-0000-4000-8000-000000000001
        created_by_service_account_id:
          type: string
          format: uuid
          nullable: true
          example: null
        created_at:
          type: string
          format: date-time
          example: '2026-03-06T17:12:10Z'
        updated_at:
          type: string
          format: date-time
          example: '2026-03-06T17:12:10Z'
        raw_token:
          type: string
          example: nomatron_agent_EXAMPLE0000.EXAMPLE000000000000000000000000000000000000
      required:
        - id
        - network_agent_id
        - token_prefix
        - created_by_type
        - created_at
        - updated_at
        - raw_token
    MintedNetworkAgentToken:
      type: object
      additionalProperties: false
      properties:
        token_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        network_agent_id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        token_prefix:
          type: string
          example: Yg6m9iX1vWgK
        token:
          type: string
          example: nomatron_agent_EXAMPLE0000.EXAMPLE000000000000000000000000000000000000
      required:
        - token_id
        - network_agent_id
        - token_prefix
        - token
    CreateNetworkAgentRequest:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
          example: private-cluster-agent-1
        description:
          type: string
          nullable: true
          example: Network agent running inside private VPC
        token_name:
          type: string
          nullable: true
          example: initial-token
        expires_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
      required:
        - name
      example:
        name: private-cluster-agent-1
        description: Network agent running inside private VPC
        token_name: initial-token
        expires_at: '2026-12-31T23:59:59Z'
    UpdateNetworkAgentRequest:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
          nullable: true
          example: build-agent-eu-west-1
        description:
          type: string
          nullable: true
          example: Updated network agent description
      example:
        name: build-agent-eu-west-1
        description: Updated network agent description
    ActivateNetworkAgentRequest:
      type: object
      additionalProperties: false
      properties:
        token_name:
          type: string
          nullable: true
          example: reactivated-token
        expires_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
      example:
        token_name: reactivated-token
        expires_at: '2026-12-31T23:59:59Z'
    RotateNetworkAgentTokensRequest:
      type: object
      additionalProperties: false
      properties:
        name:
          type: string
          nullable: true
          example: rotation-2026-03-06
        expires_at:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-31T23:59:59Z'
        revoke_existing:
          type: boolean
          nullable: true
          example: true
      example:
        name: rotation-2026-03-06
        expires_at: '2026-12-31T23:59:59Z'
        revoke_existing: true
    ListNetworkAgentsResponseData:
      type: object
      additionalProperties: false
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/NetworkAgent'
        total:
          type: integer
          format: int64
          example: 1
        limit:
          type: integer
          example: 50
        offset:
          type: integer
          example: 0
      required:
        - items
        - total
        - limit
        - offset
    CreateNetworkAgentResponseData:
      type: object
      additionalProperties: false
      properties:
        network_agent:
          $ref: '#/components/schemas/NetworkAgent'
        token:
          $ref: '#/components/schemas/NetworkAgentTokenWithRawToken'
      required:
        - network_agent
        - token
    ReadNetworkAgentResponseData:
      type: object
      additionalProperties: false
      properties:
        network_agent:
          $ref: '#/components/schemas/NetworkAgent'
        latest_token:
          $ref: '#/components/schemas/NetworkAgentToken'
      required:
        - network_agent
    UpdateNetworkAgentResponseData:
      type: object
      additionalProperties: false
      properties:
        network_agent:
          $ref: '#/components/schemas/NetworkAgent'
      required:
        - network_agent
    ActivateNetworkAgentResponseData:
      type: object
      additionalProperties: false
      properties:
        network_agent:
          $ref: '#/components/schemas/NetworkAgent'
        token:
          $ref: '#/components/schemas/NetworkAgentToken'
        minted:
          $ref: '#/components/schemas/MintedNetworkAgentToken'
      required:
        - network_agent
        - token
        - minted
    DeactivateNetworkAgentResponseData:
      type: object
      additionalProperties: false
      properties:
        network_agent:
          $ref: '#/components/schemas/NetworkAgent'
        revoked_tokens:
          type: integer
          format: int64
          example: 1
        deactivated_at:
          type: string
          format: date-time
          example: '2026-03-06T18:10:00Z'
      required:
        - network_agent
        - revoked_tokens
        - deactivated_at
    RotateNetworkAgentTokensResponseData:
      type: object
      additionalProperties: false
      properties:
        network_agent:
          $ref: '#/components/schemas/NetworkAgent'
        revoked_tokens:
          type: integer
          format: int64
          example: 1
        rotated_at:
          type: string
          format: date-time
          example: '2026-03-06T18:15:00Z'
        minted:
          $ref: '#/components/schemas/MintedNetworkAgentToken'
      required:
        - network_agent
        - revoked_tokens
        - rotated_at
        - minted
    DeleteNetworkAgentResponseData:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
          example: 00000000-0000-4000-8000-000000000001
        deleted:
          type: boolean
          example: true
      required:
        - id
        - deleted
    NetworkAgentCreateEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/CreateNetworkAgentResponseData'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T18:20:00Z'
          status: success
          code: CREATED
        data:
          network_agent:
            id: 00000000-0000-4000-8000-000000000001
            name: private-cluster-agent-1
            description: Network agent running inside private VPC
            is_active: true
            last_seen_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:20:00Z'
            updated_at: '2026-03-06T18:20:00Z'
          token:
            id: 00000000-0000-4000-8000-000000000001
            network_agent_id: 00000000-0000-4000-8000-000000000001
            name: initial-token
            token_prefix: Yg6m9iX1vWgK
            expires_at: '2026-12-31T23:59:59Z'
            revoked_at: null
            last_used_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:20:00Z'
            updated_at: '2026-03-06T18:20:00Z'
            raw_token: nomatron_agent_EXAMPLE0000.EXAMPLE000000000000000000000000000000000000
        warnings: []
        errors: []
    NetworkAgentReadEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ReadNetworkAgentResponseData'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T18:22:00Z'
          status: success
          code: OK
        data:
          network_agent:
            id: 00000000-0000-4000-8000-000000000001
            name: private-cluster-agent-1
            description: Network agent running inside private VPC
            is_active: true
            last_seen_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:20:00Z'
            updated_at: '2026-03-06T18:20:00Z'
          latest_token:
            id: 00000000-0000-4000-8000-000000000001
            network_agent_id: 00000000-0000-4000-8000-000000000001
            name: initial-token
            token_prefix: Yg6m9iX1vWgK
            expires_at: '2026-12-31T23:59:59Z'
            revoked_at: null
            last_used_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:20:00Z'
            updated_at: '2026-03-06T18:20:00Z'
        warnings: []
        errors: []
    NetworkAgentListEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ListNetworkAgentsResponseData'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T18:24:00Z'
          status: success
          code: OK
        data:
          items:
            - id: 00000000-0000-4000-8000-000000000001
              name: private-cluster-agent-1
              description: Network agent running inside private VPC
              is_active: true
              last_seen_at: null
              created_by_type: user
              created_by_user_id: 00000000-0000-4000-8000-000000000001
              created_by_service_account_id: null
              created_at: '2026-03-06T18:20:00Z'
              updated_at: '2026-03-06T18:20:00Z'
          total: 1
          limit: 50
          offset: 0
        warnings: []
        errors: []
    NetworkAgentUpdateEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/UpdateNetworkAgentResponseData'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T18:25:00Z'
          status: success
          code: OK
        data:
          network_agent:
            id: 00000000-0000-4000-8000-000000000001
            name: build-agent-eu-west-1
            description: Updated network agent description
            is_active: true
            last_seen_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:20:00Z'
            updated_at: '2026-03-06T18:25:00Z'
        warnings: []
        errors: []
    NetworkAgentActivateEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ActivateNetworkAgentResponseData'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T18:27:00Z'
          status: success
          code: CREATED
        data:
          network_agent:
            id: 00000000-0000-4000-8000-000000000001
            name: private-cluster-agent-1
            description: Network agent running inside private VPC
            is_active: true
            last_seen_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:20:00Z'
            updated_at: '2026-03-06T18:27:00Z'
          token:
            id: 00000000-0000-4000-8000-000000000001
            network_agent_id: 00000000-0000-4000-8000-000000000001
            name: reactivated-token
            token_prefix: examplePrefix
            expires_at: '2026-12-31T23:59:59Z'
            revoked_at: null
            last_used_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:27:00Z'
            updated_at: '2026-03-06T18:27:00Z'
          minted:
            token_id: 00000000-0000-4000-8000-000000000001
            network_agent_id: 00000000-0000-4000-8000-000000000001
            token_prefix: examplePrefix
            token: nomatron_agent_EXAMPLE0000.EXAMPLE000000000000000000000000000000000000
        warnings: []
        errors: []
    NetworkAgentDeactivateEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/DeactivateNetworkAgentResponseData'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T18:28:00Z'
          status: success
          code: OK
        data:
          network_agent:
            id: 00000000-0000-4000-8000-000000000001
            name: private-cluster-agent-1
            description: Network agent running inside private VPC
            is_active: false
            last_seen_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:20:00Z'
            updated_at: '2026-03-06T18:28:00Z'
          revoked_tokens: 1
          deactivated_at: '2026-03-06T18:28:00Z'
        warnings: []
        errors: []
    NetworkAgentRotateTokenEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/RotateNetworkAgentTokensResponseData'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T18:29:00Z'
          status: success
          code: OK
        data:
          network_agent:
            id: 00000000-0000-4000-8000-000000000001
            name: private-cluster-agent-1
            description: Network agent running inside private VPC
            is_active: true
            last_seen_at: null
            created_by_type: user
            created_by_user_id: 00000000-0000-4000-8000-000000000001
            created_by_service_account_id: null
            created_at: '2026-03-06T18:20:00Z'
            updated_at: '2026-03-06T18:29:00Z'
          revoked_tokens: 1
          rotated_at: '2026-03-06T18:29:00Z'
          minted:
            token_id: 00000000-0000-4000-8000-000000000001
            network_agent_id: 00000000-0000-4000-8000-000000000001
            token_prefix: examplePrefix
            token: nomatron_agent_EXAMPLE0000.EXAMPLE000000000000000000000000000000000000
        warnings: []
        errors: []
    NetworkAgentDeleteEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/DeleteNetworkAgentResponseData'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T18:30:00Z'
          status: success
          code: OK
        data:
          id: 00000000-0000-4000-8000-000000000001
          deleted: true
        warnings: []
        errors: []
    ClusterNetworkingStatus:
      type: object
      additionalProperties: false
      properties:
        networking_mode:
          type: string
          enum:
            - disabled
            - connected_docker
            - connected_byo
            - connected_managed
        networking_status:
          type: string
          enum:
            - disabled
            - installing
            - connecting
            - healthy
            - degraded
            - unavailable
            - error
        networking_cni_name:
          type: string
          nullable: true
        networking_kvstore_mode:
          type: string
          enum:
            - none
            - customer
            - nomatron_managed
        networking_cilium_owner:
          type: string
          enum:
            - none
            - managed
            - customer
          description: Who owns Cilium on eligible clients for teardown safety.
        networking_ready_node_count:
          type: integer
        networking_eligible_node_count:
          type: integer
        networking_error:
          type: string
          nullable: true
        networking_connectivity_warnings:
          type: array
          items:
            type: string
        networking_policy_source:
          type: string
          enum:
            - none
            - git
            - inline
        networking_active_policy_snapshot_id:
          type: string
          format: uuid
          nullable: true
        networking_nomad_namespace:
          type: string
        networking_policy_git_connection_id:
          type: string
          format: uuid
          nullable: true
        networking_policy_git_repo:
          type: string
          nullable: true
        networking_policy_git_ref:
          type: string
          nullable: true
        networking_policy_git_path:
          type: string
          nullable: true
        networking_policy_agents_acked:
          type: integer
        networking_policy_agents_expected:
          type: integer
        host_agents_retained:
          type: boolean
          description: True when Application Networking disconnect completed without disabling or removing Host Agents.
        host_agent_deployment:
          allOf:
            - $ref: '#/components/schemas/HostAgentDeploymentDesire'
          nullable: true
          description: Current host-agent deployment desire snapshot when included in the response.
        networking_kvstore_tls_cert_expiry:
          allOf:
            - $ref: '#/components/schemas/KvstoreTLSCertExpiry'
          nullable: true
          description: Managed kvstore TLS certificate expiry summary for authenticated status callers.
        networking_kvstore_tls_upgrade:
          allOf:
            - $ref: '#/components/schemas/KvstoreTLSUpgradeStatus'
          nullable: true
          description: Managed kvstore TLS upgrade progress for authenticated status callers.
    KvstoreTLSUpgradeStatus:
      type: object
      additionalProperties: false
      properties:
        phase:
          type: string
        member_index:
          type: integer
        wait_started_at:
          type: string
          format: date-time
          nullable: true
        stalled:
          type: boolean
        timed_out:
          type: boolean
    KvstoreTLSCertExpiry:
      type: object
      additionalProperties: false
      properties:
        ca_expires_at:
          type: string
          format: date-time
        client_expires_at:
          type: string
          format: date-time
    ClusterNetworkingStatusEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ClusterNetworkingStatus'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    ControllerPolicyImport:
      type: object
      additionalProperties: false
      properties:
        cluster_id:
          type: string
        revision:
          type: integer
          format: int64
        content_hash:
          type: string
        body:
          type: string
        source_mode:
          type: string
          enum:
            - git
            - inline
    ControllerPolicyImportEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          nullable: true
          allOf:
            - $ref: '#/components/schemas/ControllerPolicyImport'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    HostAgentEnrollRequest:
      type: object
      additionalProperties: false
      required:
        - cluster_id
        - enrollment_secret
        - nomad_node_id
        - deployment_mode
        - csr_pem
      properties:
        cluster_id:
          type: string
        enrollment_secret:
          type: string
        nomad_node_id:
          type: string
        hostname:
          type: string
        agent_version:
          type: string
        deployment_mode:
          type: string
          enum:
            - nomad_system_job
            - external_service
        csr_pem:
          type: string
    HostAgent:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        cluster_id:
          type: string
        nomad_node_id:
          type: string
        hostname:
          type: string
          nullable: true
        status:
          type: string
        deployment_mode:
          type: string
          enum:
            - nomad_system_job
            - external_service
        protocol_version:
          type: string
        capabilities:
          type: array
          items:
            type: string
        agent_version:
          type: string
          nullable: true
        nomad_version:
          type: string
        nomad_eligible:
          type: boolean
        certificate_serial:
          type: string
          nullable: true
        certificate_fingerprint:
          type: string
          nullable: true
        certificate_expires_at:
          type: string
          format: date-time
          nullable: true
        last_heartbeat_at:
          type: string
          format: date-time
          nullable: true
        last_inventory_at:
          type: string
          format: date-time
          nullable: true
        last_error:
          type: string
          nullable: true
        inventory_summary:
          $ref: '#/components/schemas/HostAgentInventorySummary'
          nullable: true
    HostAgentInventorySummary:
      type: object
      additionalProperties: false
      required:
        - version
        - received_at
        - docker_network_count
        - cni_binaries
        - cni_configs
        - cilium_available
      properties:
        version:
          type: integer
          format: int64
        received_at:
          type: string
          format: date-time
        docker_network_count:
          type: integer
        cni_binaries:
          type: array
          items:
            type: string
        cni_configs:
          type: array
          items:
            type: string
        cilium_available:
          type: boolean
        cilium_cli_version:
          type: string
        cilium_daemon_version:
          type: string
        cilium_cni_version:
          type: string
    HostAgentEnrollResult:
      type: object
      additionalProperties: false
      properties:
        host:
          $ref: '#/components/schemas/HostAgent'
        certificate_pem:
          type: string
        ca_pem:
          type: string
        expires_at:
          type: string
          format: date-time
    HostAgentEnrollEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/HostAgentEnrollResult'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    HostAgentEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/HostAgent'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    HostAgentListResult:
      type: object
      additionalProperties: false
      required:
        - host_agents
      properties:
        host_agents:
          type: array
          items:
            $ref: '#/components/schemas/HostAgent'
    HostAgentListEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/HostAgentListResult'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    HostNetworkingRuntimeMetrics:
      type: object
      required:
        - captured_at
        - agents
        - commands
        - networks
        - system_jobs
        - cilium
      properties:
        captured_at:
          type: string
          format: date-time
        agents:
          type: object
          properties:
            total:
              type: integer
              format: int64
            connected:
              type: integer
              format: int64
            stale_inventories:
              type: integer
              format: int64
            oldest_inventory_age_seconds:
              type: number
              format: double
        commands:
          type: object
          properties:
            total:
              type: integer
              format: int64
            pending:
              type: integer
              format: int64
            running:
              type: integer
              format: int64
            succeeded:
              type: integer
              format: int64
            failed:
              type: integer
              format: int64
            average_duration_seconds:
              type: number
              format: double
        networks:
          type: object
          properties:
            observed_instances:
              type: integer
              format: int64
            conflicts:
              type: integer
              format: int64
            provisioning_failures:
              type: integer
              format: int64
        system_jobs:
          type: object
          properties:
            desired:
              type: integer
              format: int64
            reconcile_failures:
              type: integer
              format: int64
            last_reconciled_at:
              type: string
              format: date-time
        cilium:
          type: object
          properties:
            healthy:
              type: integer
              format: int64
            degraded:
              type: integer
              format: int64
    HostNetworkingRuntimeMetricsEnvelope:
      allOf:
        - $ref: '#/components/schemas/ApiResponseBase'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/HostNetworkingRuntimeMetrics'
    HostAgentDeploymentDesire:
      type: object
      additionalProperties: false
      required:
        - cluster_id
        - mode
        - desired
        - revision
        - agent_version
        - nomad_namespace
        - job_id
      properties:
        cluster_id:
          type: string
          format: uuid
        mode:
          type: string
          enum:
            - nomad_system_job
            - external_service
            - disabled
        desired:
          type: boolean
        revision:
          type: integer
          format: int64
        agent_version:
          type: string
        nomad_namespace:
          type: string
        job_id:
          type: string
        bootstrap_variable_path:
          type: string
          nullable: true
        bootstrap_expires_at:
          type: string
          format: date-time
          nullable: true
        last_reconciled_at:
          type: string
          format: date-time
          nullable: true
        last_nomad_event_at:
          type: string
          format: date-time
          nullable: true
        desired_spec_hash:
          type: string
        observed_spec_hash:
          type: string
          nullable: true
        eligible_node_ids:
          type: array
          items:
            type: string
        eligible_node_set_hash:
          type: string
        placement_state:
          type: string
          enum:
            - unknown
            - in_sync
            - drift
        placement_reason:
          type: string
          nullable: true
        placement_changed_at:
          type: string
          format: date-time
          nullable: true
        drift_state:
          type: string
          enum:
            - unknown
            - in_sync
            - repairable
            - manual_review
            - permission_denied
        drift_reason:
          type: string
          nullable: true
        teardown_state:
          type: string
          enum:
            - idle
            - tearing_down
            - complete
            - blocked
        workload_identity_desired:
          type: boolean
        workload_identity_state:
          type: string
          enum:
            - unknown
            - attached
            - missing
            - unsupported
            - permission_denied
        last_error:
          type: string
          nullable: true
        privileged_access_acknowledged_at:
          type: string
          format: date-time
          nullable: true
        privileged_access_acknowledged_by:
          type: string
          nullable: true
        privileged_access_acknowledged_mode:
          type: string
          enum:
            - nomad_system_job
            - external_service
          nullable: true
    HostAgentACLTokenBinding:
      type: object
      additionalProperties: false
      required:
        - id
        - cluster_id
        - accessor_id
        - desired
        - attachment_state
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
        cluster_id:
          type: string
          format: uuid
        accessor_id:
          type: string
        desired:
          type: boolean
        expiration_time:
          type: string
          format: date-time
          nullable: true
        last_validated_at:
          type: string
          format: date-time
          nullable: true
        attachment_state:
          type: string
          enum:
            - unknown
            - attached
            - missing
            - expired
            - revoked
            - permission_denied
        last_error:
          type: string
          nullable: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    HostAgentDeploymentStatus:
      type: object
      additionalProperties: false
      required:
        - state
        - expected
        - connected
        - healthy
        - stale
        - missing
        - deployed_agent_versions
        - cilium_versions
        - cilium_version_skew
        - nomad_versions
        - nomad_version_skew
        - managed_install_blocked
        - managed_install_conflicting_nodes
        - docker_plugin_blocked
        - docker_plugin_blocked_nodes
        - docker_plugin_guidance
      properties:
        desire:
          allOf:
            - $ref: '#/components/schemas/HostAgentDeploymentDesire'
          nullable: true
        state:
          type: string
          enum:
            - disabled
            - external_service
            - deploying
            - waiting_for_agents
            - healthy
            - degraded
            - restoring
            - crash_looping
            - permission_denied
            - failed
        expected:
          type: integer
        connected:
          type: integer
        healthy:
          type: integer
        stale:
          type: integer
        missing:
          type: integer
        target_agent_version:
          type: string
          description: 'Version this Nomatron server deploys for managed Host Agents. Follows the running server version after a pack or binary upgrade, even when host_agent_deployment_desire still stores a previous release.'
        target_host_agent_image:
          type: string
          description: 'Container image reference (registry, tag, or digest) this server uses for the managed Host Agent system job with current configuration.'
        target_networking_controller_image:
          type: string
          description: Container image reference this server uses for the managed Application Networking controller with current configuration.
        deployed_agent_versions:
          type: array
          items:
            type: string
        cilium_versions:
          type: array
          description: Distinct reported Cilium daemon versions across eligible clients.
          items:
            type: string
        cilium_version_skew:
          type: boolean
        nomad_versions:
          type: array
          description: Distinct Nomad versions across eligible clients with enrolled Host Agents.
          items:
            type: string
        nomad_version_skew:
          type: boolean
        managed_install_blocked:
          type: boolean
          description: True when existing Cilium is detected on at least one eligible client and managed installation cannot be selected.
        managed_install_conflicting_nodes:
          type: array
          description: Sorted display names and Nomad node IDs for eligible clients that already report Cilium.
          items:
            type: string
        docker_plugin_blocked:
          type: boolean
          description: True when at least one eligible client has not published Nomad Docker plugin fingerprints required for automatic Host Agent deployment (privileged tasks and host volume binds).
        docker_plugin_blocked_nodes:
          type: array
          description: Sorted display names and Nomad node IDs for eligible clients missing driver.docker.privileged.enabled or driver.docker.volumes.enabled.
          items:
            type: string
        docker_plugin_guidance:
          type: string
          description: 'Operator instructions naming the failing clients and the Nomad Docker plugin settings to enable, then restart Nomad.'
        eligible_node_ids:
          type: array
          items:
            type: string
        placement_drift:
          type: boolean
        acl_token_bindings:
          type: array
          items:
            $ref: '#/components/schemas/HostAgentACLTokenBinding'
        manual_install:
          $ref: '#/components/schemas/HostAgentManualInstallConfig'
    HostAgentManualInstallConfig:
      type: object
      additionalProperties: false
      required:
        - control_plane_url
        - grpc_address
        - cluster_id
        - deployment_mode
        - state_directory
        - server_ca_required
        - documentation_url
        - nomad_node_ids
      properties:
        control_plane_url:
          type: string
          format: uri
        grpc_address:
          type: string
        cluster_id:
          type: string
          format: uuid
        deployment_mode:
          type: string
          enum:
            - external_service
        state_directory:
          type: string
        server_ca_path:
          type: string
        server_ca_required:
          type: boolean
        documentation_url:
          type: string
          format: uri
        nomad_node_ids:
          type: array
          items:
            type: string
    UpdateHostAgentDeploymentRequest:
      type: object
      additionalProperties: false
      required:
        - mode
        - privileged_access_acknowledged
      properties:
        mode:
          type: string
          enum:
            - nomad_system_job
            - external_service
            - disabled
        agent_version:
          type: string
        privileged_access_acknowledged:
          type: boolean
    ClusterNetworkingDatastoreConfigInput:
      type: object
      additionalProperties: false
      required:
        - mode
      properties:
        mode:
          type: string
          enum:
            - none
            - customer
            - nomatron_managed
        storage_type:
          type: string
          enum:
            - dynamic_host
            - csi
        placement_node_pool:
          type: string
          maxLength: 128
          description: Optional dedicated Nomad node pool for managed infrastructure placement.
        topology_attribute:
          type: string
          maxLength: 128
          description: Optional Nomad node attribute whose distinct values are used to spread the three managed etcd members. Use datacenter for the Nomad datacenter field.
        endpoints:
          type: array
          items:
            type: string
            format: uri
        volume_ids:
          type: array
          minItems: 3
          maxItems: 3
          items:
            type: string
        ca_pem:
          type: string
          writeOnly: true
        client_cert_pem:
          type: string
          writeOnly: true
        client_key_pem:
          type: string
          writeOnly: true
    ClusterNetworkingDatastoreConfig:
      type: object
      additionalProperties: false
      required:
        - mode
        - endpoints
        - volume_ids
        - selected_node_ids
        - tls_configured
        - updated_at
      properties:
        mode:
          type: string
          enum:
            - none
            - customer
            - nomatron_managed
        storage_type:
          type: string
          enum:
            - dynamic_host
            - csi
          nullable: true
        placement_node_pool:
          type: string
          nullable: true
        topology_attribute:
          type: string
          nullable: true
        selected_node_ids:
          type: array
          description: Persisted Nomad clients selected for managed etcd placement.
          items:
            type: string
        endpoints:
          type: array
          items:
            type: string
            format: uri
        volume_ids:
          type: array
          items:
            type: string
        tls_configured:
          type: boolean
        updated_at:
          type: string
          format: date-time
    ClusterNetworkingDatastoreConfigEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          allOf:
            - $ref: '#/components/schemas/ClusterNetworkingDatastoreConfig'
          nullable: true
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    HostAgentDeploymentStatusEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/HostAgentDeploymentStatus'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    HostAgentEnrollmentSecretEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          type: object
          additionalProperties: false
          required:
            - enrollment
            - enrollment_secret
          properties:
            enrollment:
              type: object
              additionalProperties: true
              description: 'Redacted enrollment metadata, including expiry.'
            enrollment_secret:
              type: string
              writeOnly: true
              description: Short-lived secret returned only by this response.
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    UploadClusterNetworkingPolicyRequest:
      type: object
      additionalProperties: false
      properties:
        body:
          type: string
          description: Cilium NetworkPolicy document body (JSON or YAML text). Required for inline uploads; omitted when fetching from Git.
        source_mode:
          type: string
          enum:
            - inline
            - git
          description: 'Policy source mode. Defaults to inline when body is set, otherwise git.'
        git_ref:
          type: string
          nullable: true
        git_commit:
          type: string
          nullable: true
        git_repo:
          type: string
          description: owner/name repository. Uses the saved Git source when omitted.
        git_path:
          type: string
          description: File or directory path in the repository.
        git_connection_id:
          type: string
          format: uuid
          description: GitHub App connection id in global or cluster-matching org scope.
    ClusterNetworkingPolicySource:
      type: object
      additionalProperties: false
      properties:
        git_connection_id:
          type: string
          format: uuid
        git_repo:
          type: string
        git_ref:
          type: string
        git_path:
          type: string
    ClusterNetworkingPolicySourceEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ClusterNetworkingPolicySource'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    ClusterNetworkingPolicyGitIntegration:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        scope:
          type: string
          enum:
            - global
            - org
        status:
          type: string
    ClusterNetworkingPolicyGitIntegrationsResult:
      type: object
      additionalProperties: false
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/ClusterNetworkingPolicyGitIntegration'
    ClusterNetworkingPolicyGitIntegrationsEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ClusterNetworkingPolicyGitIntegrationsResult'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    ClusterNetworkingPolicyDocumentResult:
      type: object
      additionalProperties: false
      properties:
        index:
          type: integer
        path:
          type: string
        name:
          type: string
        kind:
          type: string
        error:
          type: string
        valid:
          type: boolean
    ClusterNetworkingPolicyValidationResult:
      type: object
      additionalProperties: false
      properties:
        valid:
          type: boolean
        documents:
          type: array
          items:
            $ref: '#/components/schemas/ClusterNetworkingPolicyDocumentResult'
        error:
          type: string
        git_ref:
          type: string
        git_commit:
          type: string
        git_path:
          type: string
        git_repo:
          type: string
    ClusterNetworkingPolicyValidationEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ClusterNetworkingPolicyValidationResult'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    ValidateClusterNetworkingPolicyRequest:
      type: object
      additionalProperties: false
      properties:
        body:
          type: string
        source_mode:
          type: string
          enum:
            - inline
            - git
        git_ref:
          type: string
        git_repo:
          type: string
        git_path:
          type: string
        git_connection_id:
          type: string
          format: uuid
    RollbackClusterNetworkingPolicyRequest:
      type: object
      additionalProperties: false
      required:
        - snapshot_id
      properties:
        snapshot_id:
          type: string
          format: uuid
    ClusterNetworkingPolicySnapshot:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        cluster_id:
          type: string
        revision:
          type: integer
          format: int64
        source_mode:
          type: string
        content_hash:
          type: string
        body:
          type: string
        git_ref:
          type: string
          nullable: true
        git_commit:
          type: string
          nullable: true
        created_by:
          type: string
          nullable: true
        created_at:
          type: string
          format: date-time
    ClusterNetworkingPolicySnapshotEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ClusterNetworkingPolicySnapshot'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    ClusterNetworkingPolicyHistoryResult:
      type: object
      additionalProperties: false
      properties:
        snapshots:
          type: array
          items:
            $ref: '#/components/schemas/ClusterNetworkingPolicySnapshot'
    ClusterNetworkingPolicyHistoryEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ClusterNetworkingPolicyHistoryResult'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    ApplicationNetworkAddressing:
      type: object
      additionalProperties: false
      required:
        - mode
      properties:
        mode:
          type: string
          enum:
            - automatic
            - custom
        cidr:
          type: string
          nullable: true
    ApplicationNetworkRequest:
      type: object
      additionalProperties: false
      required:
        - name
        - mode
        - addressing
      properties:
        name:
          type: string
        slug:
          type: string
        backend:
          type: string
          enum:
            - docker
          default: docker
        mode:
          type: string
          enum:
            - private
            - internal
            - existing
        addressing:
          $ref: '#/components/schemas/ApplicationNetworkAddressing'
        existing_network_name:
          type: string
          nullable: true
        job_slugs:
          type: array
          items:
            type: string
    ApplicationNetworkPatchRequest:
      type: object
      additionalProperties: false
      minProperties: 1
      properties:
        name:
          type: string
        slug:
          type: string
        backend:
          type: string
          enum:
            - docker
        mode:
          type: string
          enum:
            - private
            - internal
            - existing
        addressing:
          $ref: '#/components/schemas/ApplicationNetworkAddressing'
        existing_network_name:
          type: string
          nullable: true
        job_slugs:
          type: array
          items:
            type: string
    ApplicationNetwork:
      type: object
      additionalProperties: true
      required:
        - id
        - name
        - slug
        - backend
        - mode
        - addressing_mode
        - docker_identity
        - job_slugs
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        slug:
          type: string
        backend:
          type: string
          enum:
            - docker
        mode:
          type: string
          enum:
            - private
            - internal
            - existing
        addressing_mode:
          type: string
          enum:
            - automatic
            - custom
        custom_cidr:
          type: string
          nullable: true
        existing_network_name:
          type: string
          nullable: true
        docker_identity:
          type: string
        job_slugs:
          type: array
          items:
            type: string
        cluster_bindings:
          type: array
          items:
            type: object
            additionalProperties: true
        instances:
          type: array
          items:
            type: object
            additionalProperties: true
    ApplicationNetworkEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ApplicationNetwork'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    ApplicationNetworkListResult:
      type: object
      required:
        - networks
      properties:
        networks:
          type: array
          items:
            $ref: '#/components/schemas/ApplicationNetwork'
    ApplicationNetworkListEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          $ref: '#/components/schemas/ApplicationNetworkListResult'
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
    ErrorEnvelope:
      type: object
      additionalProperties: false
      properties:
        meta:
          $ref: '#/components/schemas/ApiMeta'
        data:
          nullable: true
          example: null
        warnings:
          type: array
          items:
            $ref: '#/components/schemas/ApiWarning'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ApiErrorItem'
      required:
        - meta
        - data
        - warnings
        - errors
      example:
        meta:
          request_id: 00000000-0000-4000-8000-000000000001
          request_time: '2026-03-06T17:38:01.760556Z'
          status: error
          code: VALIDATION_FAILED
        data: null
        warnings: []
        errors:
          - code: VALIDATION_FAILED
            message: invalid network_agent_id
            field: network_agent_id
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseError'
    Unauthorized:
      description: Missing or invalid token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseError'
    Forbidden:
      description: Permission denied
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseError'
    NotFound:
      description: Not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseError'
    Conflict:
      description: Conflict
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseError'
    UnprocessableEntity:
      description: Validation failed (semantic errors such as missing template variables)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseError'
    InternalServerError:
      description: Server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseError'
    App:
      x-go-name: AppResponse
      description: App
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseApp'
    Apps:
      description: Apps
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseApps'
    AppJob:
      x-go-name: AppJobResponse
      description: App job
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseAppJob'
          example:
            meta:
              request_id: 00000000-0000-4000-8000-000000000001
              request_time: '2026-02-23T11:10:04.68212Z'
              status: success
              code: CREATED
            data:
              ID: 00000000-0000-4000-8000-000000000001
              AppID: 00000000-0000-4000-8000-000000000001
              Name: Template Service
              Slug: template
              Description: template demo entrypoint
              RepoHost: null
              RepoFullName: null
              RepoURL: null
              JobspecPath: nomatron.tpl
              JobspecType: TEMPLATE
              SourceMode: file
              SourceDirectory: null
              JobFilePath: null
              JobVarFilePaths: []
              SourceFiles: []
              ClusterID: null
              DefaultNamespace: default
              NetworkingMode: job_spec
              Priority: 10
              EffectiveRepoURL: 'https://github.com/nomatronio/platform.git'
              EffectiveRepoFullName: nomatronio/platform
              CreatedAt: '2026-02-23T11:10:04.678871Z'
              UpdatedAt: '2026-02-23T11:10:04.678871Z'
            warnings: []
            errors: []
    AppJobs:
      description: App jobs
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseAppJobs'
          example:
            meta:
              request_id: 00000000-0000-4000-8000-000000000001
              request_time: '2026-02-23T11:10:04.68212Z'
              status: success
              code: OK
            data:
              - ID: 00000000-0000-4000-8000-000000000001
                AppID: 00000000-0000-4000-8000-000000000001
                Name: Template Service
                Slug: template
                Description: template demo entrypoint
                RepoHost: null
                RepoFullName: null
                RepoURL: null
                JobspecPath: nomatron.tpl
                JobspecType: TEMPLATE
                SourceMode: file
                SourceDirectory: null
                JobFilePath: null
                JobVarFilePaths: []
                SourceFiles: []
                ClusterID: null
                DefaultNamespace: default
                NetworkingMode: job_spec
                Priority: 10
                EffectiveRepoURL: 'https://github.com/nomatronio/platform.git'
                EffectiveRepoFullName: nomatronio/platform
                CreatedAt: '2026-02-23T11:10:04.678871Z'
                UpdatedAt: '2026-02-23T11:10:04.678871Z'
              - ID: 00000000-0000-4000-8000-000000000001
                AppID: 00000000-0000-4000-8000-000000000001
                Name: API
                Slug: api
                Description: main service
                RepoHost: github.com
                RepoFullName: nomatronio/platform-api
                RepoURL: 'https://github.com/nomatronio/platform-api.git'
                JobspecPath: jobs/api.nomad.hcl
                JobspecType: NOMAD
                SourceMode: file
                SourceDirectory: null
                JobFilePath: null
                JobVarFilePaths: []
                SourceFiles:
                  - path: jobs/api.nomad.hcl
                    role: job_spec
                    format: hcl
                    order: 0
                ClusterID: 00000000-0000-4000-8000-000000000001
                DefaultNamespace: default
                NetworkingMode: job_spec
                Priority: 20
                EffectiveRepoURL: 'https://github.com/nomatronio/platform-api.git'
                EffectiveRepoFullName: nomatronio/platform-api
                CreatedAt: '2026-02-23T11:12:04.678871Z'
                UpdatedAt: '2026-02-23T11:12:04.678871Z'
            warnings: []
            errors: []
    ApprovalPolicy:
      x-go-name: ApprovalPolicyResponse
      description: Approval policy for an app job
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiResponseApprovalPolicy'
paths:
  /status:
    get:
      tags:
        - System
      summary: Service status
      description: |
        Service snapshot. Optional authentication via session cookie or bearer token. The optional `licensing` block is coarse for unauthenticated callers (`license_state`: valid, grace, invalid, or dev_unlicensed, plus a non-identifying `issue_code` when applicable). Anonymous callers receive that coarse `license_state` and `issue_code` only: `warnings` includes no licensing codes or messages, and the `X-Nomatron-License` header is omitted. Authenticated callers additionally receive `runtime_mode`, `validation_status`, and `entitlements` (feature booleans only), plus the same licensing warnings. Authenticated dev-mode responses also include `dev_unlicensed`, `tunnel_active`, and `tunnel_public_url`, and the response header `X-Nomatron-License: dev-unlicensed`. Identifiers, quotas, usage, and tier details require `GET /license/status` with `global.license.read`.
      operationId: getStatus
      security: []
      responses:
        '200':
          description: Status response
          headers:
            X-Nomatron-License:
              description: |
                Present as `dev-unlicensed` for authenticated callers when the server runs in dev mode. Omitted for anonymous callers and production installs.
              schema:
                type: string
                enum:
                  - dev-unlicensed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseStatus'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /health:
    get:
      tags:
        - System
      summary: Health check
      operationId: getHealth
      security: []
      parameters:
        - name: bootstrap
          in: query
          required: false
          description: |
            When set to `ok` during database bootstrap mode, returns HTTP 200 while Postgres is reachable but the database is not yet initialized. Intended for load-balancer liveness probes.
          schema:
            type: string
            enum:
              - ok
      responses:
        '200':
          description: Healthy
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseHealth'
        '500':
          description: Unhealthy
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseHealth'
        '503':
          description: Unhealthy or Postgres unreachable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseHealth'
  /database/status:
    get:
      tags:
        - System
      summary: Database bootstrap status
      operationId: getDatabaseStatus
      security: []
      responses:
        '200':
          description: Database bootstrap status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseDatabaseStatus'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /database/init:
    post:
      tags:
        - System
      summary: Initialize database
      operationId: initializeDatabase
      security: []
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DatabaseInitRequest'
      responses:
        '201':
          description: Database initialized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseDatabaseInit'
        '409':
          description: Database already initialized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '503':
          description: Postgres unreachable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /system/metrics/host-networking:
    get:
      tags:
        - System
        - Application Networking
      summary: Get Host Networking runtime metrics
      description: 'Requires the global `system.metrics.read` permission. Sensitive inventories, credentials, keys, and command payloads are never returned.'
      operationId: getHostNetworkingRuntimeMetrics
      responses:
        '200':
          description: Host Networking runtime aggregates
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostNetworkingRuntimeMetricsEnvelope'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /auth/login:
    post:
      tags:
        - Authentication
      summary: Login with username and password
      description: Authenticate and receive a JWT access token
      operationId: login
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LoginRequest'
      responses:
        '200':
          description: Login successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LoginResponse'
        '401':
          description: Invalid credentials
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: User disabled or not permitted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /auth/logout:
    post:
      tags:
        - Authentication
      summary: Log out the current session
      description: |
        Revokes the current session JWT server-side and clears browser session cookies when used from the UI.

        Session JWTs issued after the session-revocation upgrade include a server-tracked session id (`jti`).
        Logout revokes only that session. **Legacy session JWTs without `jti` set the user's `sessions_valid_after`
        cutoff and invalidate all of that user's session JWTs on every device** until they sign in again.
      operationId: logout
      responses:
        '200':
          description: Logged out
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseNull'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /auth/providers:
    get:
      tags:
        - Authentication
      summary: List OIDC providers
      description: Public discovery endpoint for enabled login providers. Authenticated callers receive the admin list on the secured route.
      operationId: listAuthProviders
      security: []
      responses:
        '200':
          description: Enabled OIDC providers
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/OIDCProviderListResponse'
        '500':
          description: Failed to list providers
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    post:
      tags:
        - Authentication
      summary: Create an OIDC provider
      operationId: createOIDCProvider
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOIDCProviderRequest'
      responses:
        '201':
          description: Provider created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOIDCProvider'
        '400':
          description: Invalid provider
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/auth/providers/{provider}':
    get:
      tags:
        - Authentication
      summary: Get an OIDC provider
      operationId: getOIDCProvider
      parameters:
        - name: provider
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Provider details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOIDCProvider'
        '404':
          description: Provider not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Authentication
      summary: Update an OIDC provider
      operationId: updateOIDCProvider
      parameters:
        - name: provider
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateOIDCProviderRequest'
      responses:
        '200':
          description: Provider updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOIDCProvider'
        '404':
          description: Provider not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Authentication
      summary: Delete an OIDC provider
      operationId: deleteOIDCProvider
      parameters:
        - name: provider
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: Provider deleted
        '404':
          description: Provider not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/auth/providers/{provider}/test':
    post:
      tags:
        - Authentication
      summary: Test OIDC provider discovery
      operationId: testOIDCProvider
      parameters:
        - name: provider
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Provider discovery succeeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAction'
        '502':
          description: Provider test failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/auth/providers/{provider}/secret':
    post:
      tags:
        - Authentication
      summary: Rotate OIDC provider client secret
      operationId: rotateOIDCProviderSecret
      parameters:
        - name: provider
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RotateOIDCProviderSecretRequest'
      responses:
        '200':
          description: Secret rotated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAction'
        '400':
          description: Secret rotation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/auth/providers/{provider}/group-mappings':
    get:
      tags:
        - Authentication
      summary: List OIDC group role mappings
      operationId: listOIDCGroupMappings
      parameters:
        - name: provider
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Group role mappings
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOIDCGroupRoleMappings'
    post:
      tags:
        - Authentication
      summary: Create OIDC group role mapping
      operationId: createOIDCGroupMapping
      parameters:
        - name: provider
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOIDCGroupRoleMappingRequest'
      responses:
        '201':
          description: Mapping created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOIDCGroupRoleMapping'
        '400':
          description: Mapping could not be created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/auth/providers/group-mappings/{mappingID}':
    delete:
      tags:
        - Authentication
      summary: Delete OIDC group role mapping
      operationId: deleteOIDCGroupMapping
      parameters:
        - name: mappingID
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '204':
          description: Mapping deleted
        '404':
          description: Mapping not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /oauth/register:
    post:
      tags:
        - OAuth
      summary: Dynamic client registration
      description: Register a public OAuth client (MCP host) per RFC 7591.
      operationId: oauthRegisterClient
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - redirect_uris
              properties:
                client_name:
                  type: string
                redirect_uris:
                  type: array
                  items:
                    type: string
                token_endpoint_auth_method:
                  type: string
                  default: none
                grant_types:
                  type: array
                  items:
                    type: string
                response_types:
                  type: array
                  items:
                    type: string
                scope:
                  type: string
      responses:
        '201':
          description: Client registered
          content:
            application/json:
              schema:
                type: object
                properties:
                  client_id:
                    type: string
                  client_id_issued_at:
                    type: integer
                  redirect_uris:
                    type: array
                    items:
                      type: string
                  client_name:
                    type: string
                  token_endpoint_auth_method:
                    type: string
                  grant_types:
                    type: array
                    items:
                      type: string
                  response_types:
                    type: array
                    items:
                      type: string
                  scope:
                    type: string
        '400':
          description: Invalid client metadata
        '429':
          description: Rate limited
  /oauth/authorize:
    get:
      tags:
        - OAuth
      summary: OAuth authorization endpoint
      description: Authorization Code + PKCE (S256). Redirects to login/consent when needed.
      operationId: oauthAuthorize
      security: []
      parameters:
        - name: response_type
          in: query
          required: true
          schema:
            type: string
            enum:
              - code
        - name: client_id
          in: query
          required: true
          schema:
            type: string
        - name: redirect_uri
          in: query
          required: true
          schema:
            type: string
        - name: scope
          in: query
          schema:
            type: string
        - name: state
          in: query
          schema:
            type: string
        - name: code_challenge
          in: query
          required: true
          schema:
            type: string
        - name: code_challenge_method
          in: query
          required: true
          schema:
            type: string
            enum:
              - S256
        - name: resource
          in: query
          required: true
          schema:
            type: string
            description: MCP resource URL (RFC 8707)
      responses:
        '200':
          description: Consent page HTML
        '302':
          description: Redirect with code or to login
        '400':
          description: Invalid request
        '429':
          description: Rate limited
    post:
      tags:
        - OAuth
      summary: OAuth authorization consent submit
      operationId: oauthAuthorizeConsent
      security: []
      responses:
        '302':
          description: Redirect with code or access_denied
        '429':
          description: Rate limited
  /oauth/token:
    post:
      tags:
        - OAuth
      summary: OAuth token endpoint
      description: 'Supports authorization_code, refresh_token, and RFC 8693 token-exchange.'
      operationId: oauthToken
      security: []
      requestBody:
        required: true
        content:
          application/x-www-form-urlencoded:
            schema:
              type: object
              required:
                - grant_type
              properties:
                grant_type:
                  type: string
                code:
                  type: string
                redirect_uri:
                  type: string
                client_id:
                  type: string
                client_secret:
                  type: string
                code_verifier:
                  type: string
                refresh_token:
                  type: string
                subject_token:
                  type: string
                subject_token_type:
                  type: string
                audience:
                  type: string
                resource:
                  type: string
                scope:
                  type: string
      responses:
        '200':
          description: Token response
          content:
            application/json:
              schema:
                type: object
                properties:
                  access_token:
                    type: string
                  token_type:
                    type: string
                  expires_in:
                    type: integer
                  refresh_token:
                    type: string
                  scope:
                    type: string
                  issued_token_type:
                    type: string
        '400':
          description: Invalid grant/request
        '401':
          description: Invalid client
        '429':
          description: Rate limited
  /oauth/signing-keys/rotate:
    post:
      tags:
        - OAuth
      summary: Rotate OAuth AS signing key
      description: Creates a new active signing key and retires the previous key. JWKS serves overlapping keys.
      operationId: rotateOAuthSigningKey
      responses:
        '200':
          description: New key created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAction'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /users:
    post:
      tags:
        - Users
      summary: Create user
      operationId: createUser
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateUserRequest'
            examples:
              withoutMetadata:
                summary: Create user without metadata
                value:
                  username: msmith
                  name: Morgan Smith
                  password: ChangeMe123!
      responses:
        '201':
          description: User created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseUser'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Username already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - Users
      summary: List users
      operationId: listUsers
      parameters:
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 200
          example: 50
        - name: offset
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
          example: 0
      responses:
        '200':
          description: Users list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseUsers'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/users/{username}':
    parameters:
      - name: username
        in: path
        required: true
        schema:
          type: string
        example: msmith
    get:
      tags:
        - Users
      summary: Get user
      operationId: getUser
      responses:
        '200':
          description: User
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseUser'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Users
      summary: Update user
      operationId: updateUser
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateUserRequest'
            examples:
              updateNameOnly:
                summary: Update name only
                value:
                  name: Morgan Smith
              mergeMetadata:
                summary: Merge metadata
                value:
                  metadata:
                    email: morgan.smith@example.com
      responses:
        '200':
          description: Updated user
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseUser'
              examples:
                updatedNameOnly:
                  summary: Updated user (name only)
                  value:
                    meta:
                      request_id: 00000000-0000-0000-0000-000000000000
                      request_time: '2026-02-24T11:24:55.381214Z'
                      status: success
                      code: OK
                    data:
                      id: 02a5d1e4-43bf-45f8-a39c-b76f4c45b9ad
                      username: msmith
                      name: Morgan Smith
                      auth_provider: nomatron
                      is_active: true
                      created_by: 22935710-cd15-415a-9dee-f5398274e21c
                      created_at: '2026-02-24T11:42:13.967747Z'
                    warnings: []
                    errors: []
                mergedMetadata:
                  summary: Updated user (merged metadata)
                  value:
                    meta:
                      request_id: 00000000-0000-0000-0000-000000000000
                      request_time: '2026-02-24T11:24:55.381214Z'
                      status: success
                      code: OK
                    data:
                      id: 02a5d1e4-43bf-45f8-a39c-b76f4c45b9ad
                      username: msmith
                      name: Morgan Smith
                      auth_provider: nomatron
                      is_active: true
                      metadata:
                        email: morgan.smith@example.com
                      created_by: 22935710-cd15-415a-9dee-f5398274e21c
                      created_at: '2026-02-24T11:42:13.967747Z'
                    warnings: []
                    errors: []
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Users
      summary: Delete user
      operationId: deleteUser
      parameters:
        - name: revoke_created_tokens
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/users/{username}/delete-preview':
    get:
      tags:
        - Users
      summary: Preview user delete impact
      operationId: getUserDeletePreview
      parameters:
        - name: username
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Delete impact preview
        '404':
          description: User not found
  /users/erasures:
    post:
      tags:
        - Users
      summary: Pseudonymise audit data for a deleted user (root only)
      operationId: createUserErasure
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - user_id
                - request_ref
              properties:
                user_id:
                  type: string
                  format: uuid
                request_ref:
                  type: string
                  maxLength: 128
                  description: Ticket or case reference only; must not contain PII.
      responses:
        '200':
          description: Audit pseudonymisation applied
        '403':
          description: Audit pseudonymisation requires the root role
  '/users/{username}/activate':
    post:
      tags:
        - Users
      summary: Activate user
      operationId: activateUser
      parameters:
        - name: username
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Activated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseUser'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/users/{username}/deactivate':
    post:
      tags:
        - Users
      summary: Deactivate user
      operationId: deactivateUser
      parameters:
        - name: username
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Deactivated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseUser'
              example:
                meta:
                  request_id: 602d2a62-9245-419e-b9f1-2698e15dde42
                  request_time: '2026-02-24T11:53:39.011336Z'
                  status: success
                  code: OK
                data:
                  id: 22935710-cd15-415a-9dee-f5398274e21c
                  username: user-25
                  name: Morgan Smith
                  auth_provider: nomatron
                  is_active: false
                  created_by: 756d0b37-bd41-400c-b0a1-c846a56cd4ff
                  created_at: '2026-02-24T00:06:40.974168Z'
                warnings: []
                errors: []
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/users/{username}/reset-password':
    post:
      tags:
        - Users
      summary: Reset user password
      operationId: resetUserPassword
      parameters:
        - name: username
          in: path
          required: true
          schema:
            type: string
          example: msmith
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ResetPasswordRequest'
      responses:
        '200':
          description: Password reset
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseNull'
              example:
                meta:
                  request_id: bec2af2b-e57d-404e-af81-ec477342883b
                  request_time: '2026-02-24T12:07:01.506684Z'
                  status: success
                  code: OK
                data: null
                warnings: []
                errors: []
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/users/{username}/revoke-sessions':
    post:
      tags:
        - Users
      summary: Revoke all sessions for a user
      description: |
        Invalidates every session JWT for the user by bumping `sessions_valid_after` and revoking active `user_sessions` rows.

        Requires the `global.users.update` permission (held by built-in **root**, **platform-admin**, and **access-admin**).
        Only a **root** actor may revoke sessions for a protected (root) user; other holders of `global.users.update` receive 403.
      operationId: revokeUserSessions
      parameters:
        - name: username
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Sessions revoked
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseNull'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: User not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /rbac/roles/assign:
    post:
      tags:
        - RBAC
      summary: Assign role
      operationId: assignRole
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AssignRoleRequest'
      responses:
        '201':
          description: Role assigned
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseNull'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /rbac/roles/remove:
    post:
      tags:
        - RBAC
      summary: Remove role assignment
      operationId: removeRole
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AssignRoleRequest'
      responses:
        '200':
          description: Removed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseNull'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /rbac/roles:
    post:
      tags:
        - RBAC
      summary: Create custom role
      operationId: createRole
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRoleRequest'
      responses:
        '201':
          description: Role created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseRoleUpsert'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - RBAC
      summary: List roles
      operationId: listRoles
      responses:
        '200':
          description: Roles
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseRoles'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/rbac/roles/{name}':
    get:
      tags:
        - RBAC
      summary: Get role details
      operationId: getRole
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: string
          example: 'role:server-admin'
      responses:
        '200':
          description: Role detail
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseRoleDetail'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Role not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    put:
      tags:
        - RBAC
      summary: Update role
      operationId: updateRole
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: string
          example: 'role:platform-admin'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateRoleRequest'
      responses:
        '200':
          description: Updated role
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseRoleUpsert'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Role not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - RBAC
      summary: Delete role
      operationId: deleteRole
      parameters:
        - name: name
          in: path
          required: true
          schema:
            type: string
          example: 'role:platform-admin'
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseNull'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Role not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /permissions:
    get:
      tags:
        - RBAC
      summary: List permissions
      operationId: listPermissions
      responses:
        '200':
          description: Permissions
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponsePermissions'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /organizations:
    post:
      tags:
        - Organisations
      summary: Create organization
      operationId: createOrganization
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateOrganizationRequest'
      responses:
        '201':
          description: Organization created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOrganization'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Owner user not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Organization already exists
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - Organisations
      summary: List organizations
      operationId: listOrganizations
      parameters:
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
        - name: offset
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
      responses:
        '200':
          description: Organizations list
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOrganizations'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}':
    get:
      tags:
        - Organisations
      summary: Get organization
      operationId: getOrganization
      parameters:
        - name: orgSlug
          in: path
          required: true
          schema:
            type: string
          example: nomatronio
      responses:
        '200':
          description: Organization
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOrganization'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Organisations
      summary: Update organization
      operationId: updateOrganization
      parameters:
        - name: orgSlug
          in: path
          required: true
          schema:
            type: string
          example: nomatronio
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateOrganizationRequest'
      responses:
        '200':
          description: Updated organization
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOrganization'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Organisations
      summary: Delete organization
      operationId: deleteOrganization
      parameters:
        - name: orgSlug
          in: path
          required: true
          schema:
            type: string
          example: nomatronio
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/members':
    get:
      parameters:
        - name: orgSlug
          in: path
          required: true
          schema:
            type: string
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
        - name: offset
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
      tags:
        - Organisations
      summary: List organization members
      operationId: listOrganizationMembers
      responses:
        '200':
          description: Members
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOrganizationMembers'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    post:
      tags:
        - Organisations
      summary: Add organization member
      operationId: addOrganizationMember
      parameters:
        - name: orgSlug
          in: path
          required: true
          schema:
            type: string
          example: nomatronio
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddOrganizationMemberRequest'
      responses:
        '200':
          description: Member added (updated member list returned)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOrganizationMembers'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or user not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Already a member
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/members/{username}':
    delete:
      tags:
        - Organisations
      summary: Remove organization member
      operationId: removeOrganizationMember
      parameters:
        - name: orgSlug
          in: path
          required: true
          schema:
            type: string
          example: nomatronio
        - name: username
          in: path
          required: true
          schema:
            type: string
          example: msmith
      responses:
        '200':
          description: Member removed (updated member list returned)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOrganizationMembers'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or membership not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/transfer':
    post:
      tags:
        - Organisations
      summary: Transfer organization ownership
      operationId: transferOrganizationOwnership
      parameters:
        - name: orgSlug
          in: path
          required: true
          schema:
            type: string
          example: nomatronio
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TransferOrganizationOwnershipRequest'
      responses:
        '200':
          description: Ownership transferred
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Organization'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or user not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/groups':
    post:
      tags:
        - Groups
      summary: Create group
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateGroupRequest'
      responses:
        '201':
          description: Group created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGroup'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
    get:
      tags:
        - Groups
      summary: List groups
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
      responses:
        '200':
          description: List of groups
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGroups'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/groups/{groupName}':
    get:
      tags:
        - Groups
      summary: Get group
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GroupName'
      responses:
        '200':
          description: Group
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGroup'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    patch:
      tags:
        - Groups
      summary: Update group
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GroupName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateGroupRequest'
      responses:
        '200':
          description: Updated group
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGroup'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - Groups
      summary: Delete group
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GroupName'
      responses:
        '204':
          description: Deleted
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/groups/{groupName}/members':
    get:
      tags:
        - Groups
      summary: List group members
      description: Returns usernames of users in the group.
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GroupName'
      responses:
        '200':
          description: Group member usernames
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGroupMemberUsernames'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or group not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Failed to list group members
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/groups/{groupName}/members/{username}':
    put:
      tags:
        - Groups
      summary: Add member to group
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GroupName'
        - $ref: '#/components/parameters/Username'
      responses:
        '200':
          description: Updated group members
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGroupMemberUsernames'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - Groups
      summary: Remove member from group
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GroupName'
        - $ref: '#/components/parameters/Username'
      responses:
        '200':
          description: Updated group members
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGroupMemberUsernames'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/groups/{groupName}/owner':
    post:
      tags:
        - Groups
      summary: Transfer group ownership
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GroupName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TransferGroupOwnershipRequest'
      responses:
        '200':
          description: Updated group
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGroup'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /clusters:
    post:
      tags:
        - Clusters
      summary: Create global cluster
      operationId: createGlobalCluster
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateClusterRequest'
      responses:
        '201':
          description: Cluster created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCluster'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
    get:
      tags:
        - Clusters
      summary: List global clusters
      operationId: listGlobalClusters
      parameters:
        - $ref: '#/components/parameters/WithServers'
        - $ref: '#/components/parameters/WithNodes'
        - $ref: '#/components/parameters/Status'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/OrderBy'
      responses:
        '200':
          description: Clusters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseClusters'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/clusters/{clusterName}':
    get:
      tags:
        - Clusters
      summary: Get global cluster
      operationId: getGlobalCluster
      parameters:
        - $ref: '#/components/parameters/ClusterName'
      responses:
        '200':
          description: Cluster
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCluster'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    patch:
      tags:
        - Clusters
      summary: Update global cluster
      operationId: updateGlobalCluster
      parameters:
        - $ref: '#/components/parameters/ClusterName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateClusterRequest'
      responses:
        '200':
          description: Updated cluster
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCluster'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - Clusters
      summary: Delete global cluster
      description: |
        Removes the cluster from Nomatron after Application Networking teardown. Managed Nomad jobs, Variables, and the `nomatron-networking` namespace are deleted first so they are not left orphaned. Host Agents are removed on delete (undo-scope teardown). The first delete without `force` starts teardown and returns **409 Conflict** with a teardown-in-progress message. Retrying delete while teardown runs reports progress and does not queue additional Cilium removals. When teardown finishes, the next delete succeeds with **204**. Clusters with networking disabled and no managed Host Agents delete in one call. Customer-owned Nomad jobs and ACL bindings are not removed. Returns 409 if applications still reference the cluster.
      operationId: deleteGlobalCluster
      parameters:
        - $ref: '#/components/parameters/ClusterName'
        - name: force
          in: query
          required: false
          description: |
            When true, allows deleting an agent-owned cluster whose connectivity agent has no active session. Nomatron revokes the bound agent credentials and skips Nomad teardown that requires a live session.
          schema:
            type: boolean
            default: false
      responses:
        '204':
          description: Deleted
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/clusters/{clusterName}/poll':
    post:
      tags:
        - Clusters
      summary: Poll global cluster now
      operationId: pollGlobalClusterNow
      parameters:
        - $ref: '#/components/parameters/ClusterName'
      responses:
        '200':
          description: Polled cluster (updated)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCluster'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          description: Agent connectivity unavailable (no connected agent session or peer forwarding path)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/clusters':
    post:
      tags:
        - Clusters
      summary: Create organization cluster
      operationId: createOrganizationCluster
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateClusterRequest'
      responses:
        '201':
          description: Cluster created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCluster'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
    get:
      tags:
        - Clusters
      summary: List organization clusters
      operationId: listOrganizationClusters
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/WithServers'
        - $ref: '#/components/parameters/WithNodes'
        - $ref: '#/components/parameters/Status'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/OrderBy'
      responses:
        '200':
          description: Clusters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseClusters'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/clusters/{clusterName}':
    get:
      tags:
        - Clusters
      summary: Get organization cluster
      operationId: getOrganizationCluster
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/ClusterName'
      responses:
        '200':
          description: Cluster
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCluster'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    patch:
      tags:
        - Clusters
      summary: Update organization cluster
      operationId: updateOrganizationCluster
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/ClusterName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateClusterRequest'
      responses:
        '200':
          description: Updated cluster
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCluster'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - Clusters
      summary: Delete organization cluster
      description: |
        Removes the cluster from Nomatron after Application Networking teardown. Same teardown semantics as the global delete route (409 while teardown is in progress; 204 when teardown is complete or nothing managed remains).
      operationId: deleteOrganizationCluster
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/ClusterName'
        - name: force
          in: query
          required: false
          description: |
            When true, allows deleting an agent-owned cluster whose connectivity agent has no active session. Nomatron revokes the bound agent credentials and skips Nomad teardown that requires a live session.
          schema:
            type: boolean
            default: false
      responses:
        '204':
          description: Deleted
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/clusters/{clusterName}/poll':
    post:
      tags:
        - Clusters
      summary: Poll organization cluster now
      operationId: pollOrganizationClusterNow
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/ClusterName'
      responses:
        '200':
          description: Polled cluster (updated)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCluster'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
        '503':
          description: Agent connectivity unavailable (no connected agent session or peer forwarding path)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps':
    post:
      tags:
        - Apps
      summary: Create app
      operationId: createApp
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - name: validate
          in: query
          required: false
          schema:
            type: boolean
            default: true
          description: Skip GitHub repository/install validation for automation or bootstrap flows when set to false.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAppRequest'
      responses:
        '201':
          $ref: '#/components/responses/App'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: App already exists (name or slug conflict)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - Apps
      summary: List apps
      operationId: listApps
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
      responses:
        '200':
          $ref: '#/components/responses/Apps'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}':
    parameters:
      - $ref: '#/components/parameters/OrgSlug'
      - name: slug
        in: path
        required: true
        schema:
          type: string
        description: App slug (unique within the organization)
    get:
      tags:
        - Apps
      summary: Get app
      operationId: getApp
      responses:
        '200':
          $ref: '#/components/responses/App'
        '400':
          description: Bad request (missing/invalid slug)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or app not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Apps
      summary: Update app
      operationId: updateApp
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateAppRequest'
      responses:
        '200':
          $ref: '#/components/responses/App'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or app not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Apps
      summary: Delete app
      operationId: deleteApp
      parameters:
        - name: force
          in: query
          required: false
          description: |
            When true, abandons runtimes in destroy_failed state without verifying Nomad removal, then deletes the app. Requires app_jobs.destroy permission. Deployed or destroy_pending runtimes still block delete until a destroy apply succeeds.
          schema:
            type: boolean
            default: false
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or app not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs':
    get:
      tags:
        - App Jobs
      summary: List app jobs
      operationId: listAppJobs
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      responses:
        '200':
          $ref: '#/components/responses/AppJobs'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: Organization or application not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          $ref: '#/components/responses/InternalServerError'
    post:
      tags:
        - App Jobs
      summary: Create app job
      operationId: createAppJob
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAppJobRequest'
      responses:
        '201':
          $ref: '#/components/responses/AppJob'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: Organization or application not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}':
    get:
      tags:
        - App Jobs
      summary: Get app job
      operationId: getAppJob
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      responses:
        '200':
          $ref: '#/components/responses/AppJob'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: 'Organization, application, or app job not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          $ref: '#/components/responses/InternalServerError'
    patch:
      tags:
        - App Jobs
      summary: Update app job
      operationId: updateAppJob
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateAppJobRequest'
      responses:
        '200':
          $ref: '#/components/responses/AppJob'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: 'Organization, application, or app job not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - App Jobs
      summary: Delete app job
      operationId: deleteAppJob
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - name: force
          in: query
          required: false
          description: |
            When true, abandons a destroy_failed runtime without verifying Nomad removal, then deletes the app job. Requires app_jobs.destroy permission. Deployed or destroy_pending runtimes still block delete until a destroy apply succeeds.
          schema:
            type: boolean
            default: false
      responses:
        '204':
          description: Deleted
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/reorder':
    post:
      tags:
        - App Jobs
      summary: Reorder app jobs or assign deployment groups
      operationId: reorderAppJobs
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReorderAppJobsRequest'
      responses:
        '200':
          description: App jobs reordered
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseReorderAppJobs'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/plans':
    post:
      tags:
        - Apps
      summary: Queue app-level plan batch
      operationId: queueAppPlanBatch
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AppBulkActionRequest'
      responses:
        '202':
          description: App plan batch queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAppBulkAction'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/deploys':
    post:
      tags:
        - Apps
      summary: Queue app-level deploy batch
      description: Alias for the app-level plan batch endpoint used by deployment-oriented clients.
      operationId: queueAppDeployBatch
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AppBulkActionRequest'
      responses:
        '202':
          description: App deploy batch queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAppBulkAction'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/destroy-plans':
    post:
      tags:
        - Apps
      summary: Create app-level destroy plan batch
      operationId: createAppDestroyPlan
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - name: environment_slug
          in: query
          required: false
          schema:
            type: string
          description: Optional environment slug when multiple deployed targets exist.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                environment_slug:
                  type: string
                  description: Optional environment slug when multiple deployed targets exist.
      responses:
        '202':
          description: App destroy plan batch created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseDestroyPlan'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/applies':
    post:
      tags:
        - Apps
      summary: Queue app-level apply batch
      operationId: queueAppApplyBatch
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AppBulkActionRequest'
      responses:
        '202':
          description: App apply batch queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAppBulkAction'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/promote':
    post:
      tags:
        - Apps
      summary: Queue app-level promotion batch
      description: Creates promotion plans for selected app jobs that share the same next environment path.
      operationId: queueAppPromotionBatch
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AppBulkActionRequest'
      responses:
        '202':
          description: App promotion batch queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAppBulkAction'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/batches':
    get:
      tags:
        - Apps
      summary: List app stack deployment batches
      description: Lists app-level stack plan and apply batches with per-job operations for deployment history and review.
      operationId: listAppStackBatches
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 200
            default: 50
        - name: offset
          in: query
          required: false
          schema:
            type: integer
            minimum: 0
            default: 0
      responses:
        '200':
          description: App stack deployment batches
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAppStackBatches'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/approval-decisions':
    post:
      tags:
        - Apps
      summary: Record app stack approval decision
      operationId: recordAppStackApprovalDecision
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - name: environment_slug
          in: query
          required: false
          schema:
            type: string
          description: 'App environment slug. When omitted, Nomatron uses the app''s first environment. Apps must have at least one environment before planning or applying.'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApprovalDecision'
      responses:
        '200':
          description: App stack approval decision recorded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAppStackApproval'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/approval-policy':
    get:
      tags:
        - Apps
      summary: Get approval policy
      operationId: getApprovalPolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      responses:
        '200':
          $ref: '#/components/responses/ApprovalPolicy'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, or approval policy not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    put:
      tags:
        - Apps
      summary: Upsert approval policy
      operationId: upsertApprovalPolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertApprovalPolicyRequest'
      responses:
        '200':
          $ref: '#/components/responses/ApprovalPolicy'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or application not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/approval-policy/versions':
    get:
      tags:
        - Apps
      summary: List approval policy versions
      operationId: listApprovalPolicyVersions
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      responses:
        '200':
          description: Approval policy versions
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ApiResponseApprovalPolicyVersions'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, or approval policy not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/approval-policy/versions/{version}':
    get:
      tags:
        - Apps
      summary: Get approval policy version
      operationId: getApprovalPolicyVersion
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - name: version
          in: path
          required: true
          schema:
            type: integer
            minimum: 1
          description: Approval policy version number
      responses:
        '200':
          description: Approval policy version
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseApprovalPolicyVersionDetail'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Version not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/approval-decisions':
    post:
      tags:
        - App Jobs
      summary: Record approval decision for latest approvable plan
      operationId: recordLatestApprovalDecision
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApprovalDecision'
      responses:
        '200':
          description: Approval decision recorded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseApprovalDecision'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/approval-decisions/latest':
    get:
      tags:
        - App Jobs
      summary: Get latest approvable plan
      operationId: getLatestApprovablePlan
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      responses:
        '200':
          description: Latest approvable plan
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseApprovablePlan'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/plans':
    post:
      tags:
        - App Jobs
      summary: Queue approvable plan
      operationId: queueApprovablePlan
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      responses:
        '202':
          description: Approvable plan queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseQueuedPlan'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/deploys':
    post:
      tags:
        - App Jobs
      summary: Queue job deployment
      description: Creates an approval-gated plan for deploying one app job to the app's first environment.
      operationId: queueJobDeploy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/QueueJobDeployRequest'
      responses:
        '202':
          description: Job deployment queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseJobDeploy'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/destroy-plans':
    post:
      tags:
        - App Jobs
      summary: Create job destroy plan
      operationId: createJobDestroyPlan
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - name: environment_slug
          in: query
          required: false
          schema:
            type: string
          description: Optional environment slug when multiple deployed targets exist.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                environment_slug:
                  type: string
                  description: Optional environment slug when multiple deployed targets exist.
      responses:
        '202':
          description: Destroy plan created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseDestroyPlan'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/operations/{operationID}/applies':
    post:
      tags:
        - App Jobs
      summary: Create apply from plan
      description: Starts an apply operation for an approved or approval-free plan operation.
      operationId: createPlanApply
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - name: operationID
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: Plan operation ID.
      responses:
        '202':
          description: Apply queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponsePlanApply'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/plans/speculative':
    post:
      tags:
        - App Jobs
      summary: Create speculative plan
      operationId: createSpeculativePlan
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSpeculativePlanRequest'
      responses:
        '202':
          description: Speculative plan created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseSpeculativePlan'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/drift/accept':
    post:
      tags:
        - App Jobs
      summary: Accept drift for job
      description: |
        Queues an accept_drift operation that rebases Nomatron desired state onto the live Nomad job. After a successful rebase, Nomatron best-effort opens a GitHub PR updating the connected jobspec file in its stored format (JSON or HCL), using the GitHub job as a field mask so Nomad default noise is omitted. Requires GitHub App Contents: Read and write.
      operationId: acceptDriftForJob
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      responses:
        '202':
          description: Accept-drift operation queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAcceptDrift'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/environments/{environmentSlug}/drift/accept':
    post:
      tags:
        - App Jobs
      summary: Accept drift for job environment
      description: |
        Environment-scoped accept-drift. Same async rebase + best-effort GitHub PR write-back behavior as the job-scoped endpoint.
      operationId: acceptDriftForJobEnvironment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/EnvironmentSlug'
      responses:
        '202':
          description: Accept-drift operation queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAcceptDrift'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/import':
    post:
      tags:
        - App Jobs
      summary: Import job
      operationId: importJob
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImportJobRequest'
      responses:
        '202':
          description: Import operation queued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseImportJob'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/preview':
    get:
      tags:
        - App Jobs
      summary: Preview job file
      description: |
        Returns a reviewable job file preview for TEMPLATE and NOMAD jobs.
        TEMPLATE jobs require an environment and render with sensitive values masked.
        NOMAD jobs return the connected Git job file. Use `format` to request HCL or JSON.
      operationId: previewAppJob
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/EnvironmentSlugQuery'
        - name: format
          in: query
          required: false
          schema:
            type: string
            enum:
              - hcl
              - json
            default: hcl
          description: Output format for the preview content.
        - name: ref
          in: query
          required: false
          schema:
            type: string
          description: Optional Git ref override. Defaults to the app ref.
      responses:
        '200':
          description: Job file preview
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseJobPreview'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          description: Template render validation failed during job preview
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/promote':
    post:
      tags:
        - App Jobs
      summary: Create promotion plan (next environment)
      operationId: createPromotionPlanNext
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreatePromotionPlanRequest'
      responses:
        '200':
          description: Promotion plan created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponsePromotionPlan'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/rollback':
    post:
      tags:
        - App Jobs
      summary: Create rollback plan (same environment)
      description: |
        Creates an approval-gated plan that replays a prior healthy release's
        rendered_template into the same environment. Without source_release_id,
        selects the previous healthy release before the current head.
      operationId: createRollbackPlan
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateRollbackPlanRequest'
      responses:
        '200':
          description: Rollback plan created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseRollbackPlan'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/rollback-candidates':
    get:
      tags:
        - App Jobs
      summary: List healthy rollback candidate releases
      description: |
        Returns prior healthy releases for the environment (excluding the current
        head), newest first. The first item is the default rollback target.
      operationId: listRollbackCandidates
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - name: environment_slug
          in: query
          required: false
          schema:
            type: string
          description: Environment slug (required unless environment_id is provided)
        - name: environment_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Environment UUID (required unless environment_slug is provided)
      responses:
        '200':
          description: Rollback candidates
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseRollbackCandidates'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/operations':
    get:
      tags:
        - Operations
      summary: List operations by organization
      operationId: listOperationsByOrg
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/Cursor'
        - $ref: '#/components/parameters/OrderBy'
        - $ref: '#/components/parameters/IncludeHealth'
      responses:
        '200':
          description: Operations
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOperations'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/operations':
    get:
      tags:
        - Operations
      summary: List operations by app
      operationId: listOperationsByApp
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/Cursor'
        - $ref: '#/components/parameters/OrderBy'
        - $ref: '#/components/parameters/IncludeHealth'
      responses:
        '200':
          description: Operations
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOperations'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or application not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/operations':
    get:
      tags:
        - Operations
      summary: List operations by app job
      operationId: listOperationsByAppJob
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/Cursor'
        - $ref: '#/components/parameters/OrderBy'
        - $ref: '#/components/parameters/IncludeHealth'
      responses:
        '200':
          description: Operations
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOperations'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, or app job not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/operations/{operationID}':
    get:
      tags:
        - Operations
      summary: Get operation
      operationId: getOperation
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - name: operationID
          in: path
          required: true
          schema:
            type: string
          description: Operation identifier (UUID or opaque ID)
      responses:
        '200':
          description: Operations
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseOperation'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Operation not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/operations/{operationID}/destroy-applies':
    post:
      tags:
        - Operations
      summary: Create destroy apply from destroy plan
      operationId: createDestroyApply
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - name: operationID
          in: path
          required: true
          schema:
            type: string
            format: uuid
          description: Destroy plan operation ID.
      responses:
        '202':
          description: Destroy apply created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseDestroyApply'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /variables:
    post:
      tags:
        - Variables
      summary: Create global variable
      operationId: createGlobalVariable
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateVariableRequest'
      responses:
        '201':
          description: Variable created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - Variables
      summary: List global variables
      operationId: listGlobalVariables
      parameters:
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/OrderBy'
      responses:
        '200':
          description: Variables
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariables'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/variables/{variableID}':
    parameters:
      - $ref: '#/components/parameters/VariableID'
    get:
      tags:
        - Variables
      summary: Get global variable
      operationId: getGlobalVariable
      responses:
        '200':
          description: Variable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Variables
      summary: Update global variable
      operationId: updateGlobalVariable
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateVariableRequest'
      responses:
        '200':
          description: Updated variable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Variables
      summary: Delete global variable
      operationId: deleteGlobalVariable
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/variables':
    post:
      tags:
        - Variables
      summary: Create organization variable
      operationId: createOrganizationVariable
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateVariableRequest'
      responses:
        '201':
          description: Variable created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - Variables
      summary: List organization variables
      operationId: listOrganizationVariables
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/OrderBy'
      responses:
        '200':
          description: Variables
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariables'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/variables/{variableID}':
    parameters:
      - $ref: '#/components/parameters/OrgSlug'
      - $ref: '#/components/parameters/VariableID'
    get:
      tags:
        - Variables
      summary: Get organization variable
      operationId: getOrganizationVariable
      responses:
        '200':
          description: Variable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Variables
      summary: Update organization variable
      operationId: updateOrganizationVariable
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateVariableRequest'
      responses:
        '200':
          description: Updated variable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Variables
      summary: Delete organization variable
      operationId: deleteOrganizationVariable
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/variables':
    post:
      tags:
        - Variables
      summary: Create app variable
      operationId: createAppVariable
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateVariableRequest'
      responses:
        '201':
          description: Variable created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or application not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - Variables
      summary: List app variables
      operationId: listAppVariables
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/OrderBy'
      responses:
        '200':
          description: Variables
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariables'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or application not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/variables/{variableID}':
    parameters:
      - $ref: '#/components/parameters/OrgSlug'
      - $ref: '#/components/parameters/AppSlug'
      - $ref: '#/components/parameters/VariableID'
    get:
      tags:
        - Variables
      summary: Get app variable
      operationId: getAppVariable
      responses:
        '200':
          description: Variable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Variables
      summary: Update app variable
      operationId: updateAppVariable
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateVariableRequest'
      responses:
        '200':
          description: Updated variable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Variables
      summary: Delete app variable
      operationId: deleteAppVariable
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/variables':
    post:
      tags:
        - Variables
      summary: Create app job variable
      operationId: createAppJobVariable
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateVariableRequest'
      responses:
        '201':
          description: Variable created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, or app job not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - Variables
      summary: List app job variables
      operationId: listAppJobVariables
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - $ref: '#/components/parameters/OrderBy'
      responses:
        '200':
          description: Variables
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariables'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, or app job not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/variables/{variableID}':
    parameters:
      - $ref: '#/components/parameters/OrgSlug'
      - $ref: '#/components/parameters/AppSlug'
      - $ref: '#/components/parameters/AppJobSlug'
      - $ref: '#/components/parameters/VariableID'
    get:
      tags:
        - Variables
      summary: Get app job variable
      operationId: getAppJobVariable
      responses:
        '200':
          description: Variable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, app job, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Variables
      summary: Update app job variable
      operationId: updateAppJobVariable
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateVariableRequest'
      responses:
        '200':
          description: Updated variable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariable'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, app job, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Variables
      summary: Delete app job variable
      operationId: deleteAppJobVariable
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, application, app job, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/variables/{variableID}/values':
    get:
      tags:
        - Variables
      summary: List variable values (default + any env-specific rows)
      operationId: listGlobalVariableValues
      parameters:
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
      responses:
        '200':
          description: Variable values
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValues'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/variables/{variableID}/values/default':
    get:
      tags:
        - Variables
      summary: Get default value for a variable
      operationId: getGlobalVariableDefaultValue
      parameters:
        - $ref: '#/components/parameters/VariableID'
      responses:
        '200':
          description: Default value row (environment_id is null)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Variable or default value not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    put:
      tags:
        - Variables
      summary: Upsert default value for a variable
      operationId: upsertGlobalVariableDefaultValue
      parameters:
        - $ref: '#/components/parameters/VariableID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertVariableValueRequest'
      responses:
        '200':
          description: Default value upserted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/variables/{variableID}/values/{valueID}':
    delete:
      tags:
        - Variables
      summary: Delete a variable value row by ID
      operationId: deleteGlobalVariableValue
      parameters:
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/ValueID'
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Variable or value not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/variables/{variableID}/values':
    get:
      tags:
        - Variables
      summary: List organization variable values
      operationId: listOrganizationVariableValues
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
      responses:
        '200':
          description: Variable Values
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValues'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/variables/{variableID}/values/default':
    get:
      tags:
        - Variables
      summary: Get organization variable default value
      operationId: getOrganizationVariableDefaultValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/VariableID'
      responses:
        '200':
          description: Default value
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, variable, or default value not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    put:
      tags:
        - Variables
      summary: Upsert organization variable default value
      operationId: upsertOrganizationVariableDefaultValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/VariableID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertVariableValueRequest'
      responses:
        '200':
          description: Default value upserted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or variable not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/variables/{variableID}/values/{valueID}':
    delete:
      tags:
        - Variables
      summary: Delete organization variable value by ID
      operationId: deleteOrganizationVariableValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/ValueID'
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, variable, or value not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/variables/{variableID}/values':
    get:
      tags:
        - Variables
      summary: List app variable values
      operationId: listAppVariableValues
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
      responses:
        '200':
          description: Variable values
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValues'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/variables/{variableID}/values/default':
    get:
      tags:
        - Variables
      summary: Get app variable default value
      operationId: getAppVariableDefaultValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/VariableID'
      responses:
        '200':
          description: Default value
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, variable, or default value not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    put:
      tags:
        - Variables
      summary: Upsert app variable default value
      operationId: upsertAppVariableDefaultValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/VariableID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertVariableValueRequest'
      responses:
        '200':
          description: Default value upserted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/variables/{variableID}/values/environments/{envSlug}':
    get:
      tags:
        - Variables
      summary: Get environment-specific value for an app variable
      operationId: getAppVariableEnvValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/EnvSlug'
      responses:
        '200':
          description: Environment-specific value row
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Environment or value not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    put:
      tags:
        - Variables
      summary: Upsert environment-specific value for an app variable
      operationId: upsertAppVariableEnvValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/EnvSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertVariableValueRequest'
      responses:
        '200':
          description: Environment-specific value upserted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Environment, variable, or app not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/variables/{variableID}/values/{valueID}':
    delete:
      tags:
        - Variables
      summary: Delete app variable value by ID
      operationId: deleteAppVariableValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/ValueID'
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, variable, or value not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/variables/{variableID}/values':
    get:
      tags:
        - Variables
      summary: List app job variable values (default + env-specific)
      operationId: listAppJobVariableValues
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
      responses:
        '200':
          description: Variable values
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValues'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, job, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/variables/{variableID}/values/default':
    get:
      tags:
        - Variables
      summary: Get app job variable default value
      operationId: getAppJobVariableDefaultValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/VariableID'
      responses:
        '200':
          description: Default value
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, job, variable, or default value not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    put:
      tags:
        - Variables
      summary: Upsert app job variable default value
      operationId: upsertAppJobVariableDefaultValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/VariableID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertVariableValueRequest'
      responses:
        '200':
          description: Default value upserted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, job, or variable not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/variables/{variableID}/values/environments/{envSlug}':
    get:
      tags:
        - Variables
      summary: Get environment-specific value for an app job variable
      operationId: getAppJobVariableEnvValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/EnvSlug'
      responses:
        '200':
          description: Environment-specific value row
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Environment or value not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    put:
      tags:
        - Variables
      summary: Upsert environment-specific value for an app job variable
      operationId: upsertAppJobVariableEnvValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/EnvSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpsertVariableValueRequest'
      responses:
        '200':
          description: Environment-specific value upserted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseVariableValue'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Environment, variable, or app job not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/variables/{variableID}/values/{valueID}':
    delete:
      tags:
        - Variables
      summary: Delete app job variable value by ID
      operationId: deleteAppJobVariableValue
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/VariableID'
        - $ref: '#/components/parameters/ValueID'
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Value not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/environments':
    post:
      tags:
        - Environments
      summary: Create environment
      operationId: createEnvironment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateEnvironmentRequest'
      responses:
        '201':
          description: Environment created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseEnvironment'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or app not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Environment already exists (slug conflict)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      tags:
        - Environments
      summary: List environments
      operationId: listEnvironments
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      responses:
        '200':
          description: Environments
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseEnvironments'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization or app not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/environments/{environmentSlug}':
    get:
      tags:
        - Environments
      summary: Get environment
      operationId: getEnvironment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/EnvironmentSlug'
      responses:
        '200':
          description: Environment
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseEnvironment'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Environment not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      tags:
        - Environments
      summary: Update environment
      operationId: updateEnvironment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/EnvironmentSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateEnvironmentRequest'
      responses:
        '200':
          description: Updated environment
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseEnvironment'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Environment not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      tags:
        - Environments
      summary: Delete environment
      operationId: deleteEnvironment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/EnvironmentSlug'
      responses:
        '204':
          description: Deleted
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Environment not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/environments/reorder':
    post:
      tags:
        - Environments
      summary: Reorder environments
      operationId: reorderEnvironments
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReorderEnvironmentsRequest'
      responses:
        '200':
          description: Environments reordered
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseReorderEnvironments'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: App not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/template':
    post:
      tags:
        - Templates
      summary: Render template
      description: 'Renders an app job template using provided inputs (e.g., variables / env selection) and returns rendered output + metadata.'
      operationId: renderTemplate
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RenderTemplateRequest'
      responses:
        '200':
          description: Rendered template
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseRenderedTemplate'
        '400':
          description: Invalid JSON payload / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, or job not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '422':
          description: Template render validation failed (for example missing variables)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/apps/{slug}/jobs/{jobSlug}/template/render':
    get:
      tags:
        - Templates
      summary: Render template from Git
      description: Renders the template using the job's configured Git source (no request body).
      operationId: renderTemplateFromGit
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/AppSlug'
        - $ref: '#/components/parameters/AppJobSlug'
        - $ref: '#/components/parameters/EnvironmentSlugQuery'
        - $ref: '#/components/parameters/DryRun'
      responses:
        '200':
          description: Rendered template
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseRenderedTemplate'
        '400':
          description: Invalid query / validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: 'Organization, app, job, or template source not found'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '422':
          description: Template render validation failed (for example missing variables)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /audit-logs:
    get:
      summary: List audit logs across all organizations
      description: |
        Returns audit log entries across all organizations.
        Default behaviour: low-level per-request entries (event_type = `http.request`) are excluded unless `include_requests=true` is provided (must be exactly the string `"true"`).
        Server administrator access only.
      operationId: listGlobalAuditLogs
      tags:
        - Audit
      parameters:
        - name: event_type
          in: query
          required: false
          schema:
            type: string
          description: Filter by exact event type (e.g. `variable_value.upsert`).
        - name: actor_type
          in: query
          required: false
          schema:
            type: string
            enum:
              - user
              - service_account
          description: Filter by actor type.
        - name: actor_user_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by actor user ID.
        - name: actor_service_account_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by actor service account ID.
        - name: app_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by application ID.
        - name: app_job_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by application job ID.
        - name: resource_type
          in: query
          required: false
          schema:
            type: string
          description: Filter by resource type.
        - name: resource_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by resource ID.
        - name: resource_name
          in: query
          required: false
          schema:
            type: string
          description: Filter by exact resource name.
        - name: resource_name_like
          in: query
          required: false
          schema:
            type: string
          description: Case-insensitive substring match on resource_name.
        - name: from
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: RFC3339 timestamp (inclusive). Filters event_timestamp >= from.
        - name: to
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: RFC3339 timestamp (inclusive). Filters event_timestamp <= to.
        - name: origin
          in: query
          required: false
          schema:
            type: string
            enum:
              - ui
              - cli
              - api
              - mcp
          description: Filter by request origin/channel (from audit_log_channels).
        - name: include_requests
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: |
            Include low-level `http.request` audit entries. Enabled only when the query value is exactly `"true"`.
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 200
            default: 50
          description: Max number of items to return (clamped to 200).
        - name: cursor
          in: query
          required: false
          schema:
            type: string
          description: Opaque pagination cursor from a previous response.
      responses:
        '200':
          description: Audit log entries
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAuditLogListResponse'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/organizations/{orgSlug}/audit-logs':
    get:
      summary: List audit logs for an organization
      description: |
        Returns audit log entries scoped to the specified organization.
        Default behaviour: low-level per-request entries (event_type = `http.request`) are excluded unless `include_requests=true` is provided (must be exactly the string `"true"`).
      operationId: listOrgAuditLogs
      tags:
        - Audit
      parameters:
        - name: orgSlug
          in: path
          required: true
          schema:
            type: string
          description: Organization name / slug.
        - name: event_type
          in: query
          required: false
          schema:
            type: string
          description: Filter by exact event type (e.g. `variable_value.upsert`).
        - name: actor_type
          in: query
          required: false
          schema:
            type: string
            enum:
              - user
              - service_account
          description: Filter by actor type.
        - name: actor_user_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by actor user ID.
        - name: actor_service_account_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by actor service account ID.
        - name: app_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by application ID.
        - name: app_job_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by application job ID.
        - name: resource_type
          in: query
          required: false
          schema:
            type: string
          description: Filter by resource type.
        - name: resource_id
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by resource ID.
        - name: resource_name
          in: query
          required: false
          schema:
            type: string
          description: Filter by exact resource name.
        - name: resource_name_like
          in: query
          required: false
          schema:
            type: string
          description: Case-insensitive substring match on resource_name.
        - name: from
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: RFC3339 timestamp (inclusive). Filters event_timestamp >= from.
        - name: to
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: RFC3339 timestamp (inclusive). Filters event_timestamp <= to.
        - name: origin
          in: query
          required: false
          schema:
            type: string
            enum:
              - ui
              - cli
              - api
              - mcp
          description: Filter by request origin/channel (from audit_log_channels).
        - name: include_requests
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: |
            Include low-level `http.request` audit entries. Enabled only when the query value is exactly `"true"`.
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 200
            default: 50
          description: Max number of items to return (clamped to 200).
        - name: cursor
          in: query
          required: false
          schema:
            type: string
          description: Opaque pagination cursor from a previous response.
      responses:
        '200':
          description: Audit log entries
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseAuditLogListResponse'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Organization not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /integrations/github:
    post:
      tags:
        - GitHub Integrations
      summary: Create global GitHub integration
      operationId: createGlobalGitHubIntegration
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateGitHubConnectionRequest'
      responses:
        '201':
          description: GitHub integration created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnection'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
    get:
      tags:
        - GitHub Integrations
      summary: List global GitHub integrations
      operationId: listGlobalGitHubIntegrations
      security:
        - BearerAuth: []
      parameters:
        - name: q
          in: query
          required: false
          schema:
            type: string
          description: Case-insensitive substring filter on integration name.
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - name: sort
          in: query
          required: false
          schema:
            type: string
            enum:
              - asc
              - desc
            default: desc
        - name: check
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: 'When true, performs a live install health check.'
      responses:
        '200':
          description: GitHub integrations
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnections'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/integrations/github/{connectionName}':
    get:
      tags:
        - GitHub Integrations
      summary: Read global GitHub integration
      operationId: getGlobalGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/GitHubConnectionName'
        - name: check
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: 'When true, performs a live install health check.'
      responses:
        '200':
          description: GitHub integration
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnection'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    patch:
      tags:
        - GitHub Integrations
      summary: Update global GitHub integration
      operationId: updateGlobalGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/GitHubConnectionName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateGitHubConnectionRequest'
      responses:
        '200':
          description: GitHub integration updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnection'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - GitHub Integrations
      summary: Delete global GitHub integration
      operationId: deleteGlobalGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/GitHubConnectionName'
      responses:
        '204':
          description: Deleted
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/integrations/github/{connectionName}/connect':
    get:
      tags:
        - GitHub Integrations
      summary: Generate GitHub App install URL for global integration
      operationId: connectGlobalGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/GitHubConnectionName'
        - name: post_redirect
          in: query
          required: false
          schema:
            type: string
          description: Path to redirect the browser to after install completes.
        - name: mode
          in: query
          required: false
          schema:
            type: string
            enum:
              - json
            x-enum-varnames:
              - ConnectGlobalGitHubIntegrationParamsModeJson
          description: 'When set to json, returns the install URL instead of redirecting.'
      responses:
        '200':
          description: GitHub App install URL
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnect'
        '302':
          description: Redirects the browser to the GitHub App install URL.
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /integrations/github/callback:
    get:
      tags:
        - GitHub Integrations
      summary: Complete GitHub App installation callback
      operationId: githubIntegrationCallback
      parameters:
        - name: state
          in: query
          required: true
          schema:
            type: string
        - name: installation_id
          in: query
          required: true
          schema:
            type: integer
            format: int64
      responses:
        '302':
          description: Redirects to the original post-install destination.
        '400':
          $ref: '#/components/responses/BadRequest'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /integrations/github/app-registration-url:
    get:
      tags:
        - GitHub Integrations
      summary: Generate a prefilled GitHub App registration URL for global setup
      operationId: getGlobalGitHubAppRegistrationURL
      security:
        - BearerAuth: []
      parameters:
        - name: mode
          in: query
          required: false
          schema:
            type: string
            enum:
              - json
            x-enum-varnames:
              - GetGlobalGitHubAppRegistrationURLParamsModeJson
          description: 'When set to `json`, returns the registration payload instead of redirecting to GitHub.'
        - name: name
          in: query
          required: false
          schema:
            type: string
          description: 'Optional GitHub App name override. When omitted, Nomatron generates a globally unique default name.'
        - name: description
          in: query
          required: false
          schema:
            type: string
          description: Optional GitHub App description override.
        - name: owner
          in: query
          required: false
          schema:
            type: string
          description: Optional target owner login. Use with `owner_type=org` to create the app inside a GitHub organization.
        - name: owner_type
          in: query
          required: false
          schema:
            type: string
            enum:
              - org
              - user
          description: Optional GitHub owner type for app creation.
        - name: provider_kind
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/GitHubProviderKind'
          description: Target GitHub provider kind. Defaults to GitHub.com.
        - name: web_base_url
          in: query
          required: false
          schema:
            type: string
            format: uri
          description: 'GitHub Enterprise Server web URL, required when provider_kind is enterprise_server.'
        - name: api_base_url
          in: query
          required: false
          schema:
            type: string
            format: uri
          description: Optional GitHub Enterprise REST API URL override.
        - name: upload_base_url
          in: query
          required: false
          schema:
            type: string
            format: uri
          description: Optional GitHub Enterprise uploads API URL override.
        - name: public
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Whether the GitHub App should be publicly installable.
        - name: setup_on_update
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Whether GitHub should call the setup URL after app updates.
      responses:
        '200':
          description: Prefilled GitHub App registration payload
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubAppRegistration'
        '302':
          description: Redirects the browser to GitHub's GitHub App registration form.
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/integrations/github':
    post:
      tags:
        - GitHub Integrations
      summary: Create organization GitHub integration
      operationId: createOrganizationGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateGitHubConnectionRequest'
      responses:
        '201':
          description: GitHub integration created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnection'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '500':
          $ref: '#/components/responses/InternalServerError'
    get:
      tags:
        - GitHub Integrations
      summary: List organization GitHub integrations
      operationId: listOrganizationGitHubIntegrations
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - name: q
          in: query
          required: false
          schema:
            type: string
        - $ref: '#/components/parameters/Limit'
        - $ref: '#/components/parameters/Offset'
        - name: sort
          in: query
          required: false
          schema:
            type: string
            enum:
              - asc
              - desc
            default: desc
        - name: check
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: GitHub integrations
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnections'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/integrations/github/{connectionName}':
    get:
      tags:
        - GitHub Integrations
      summary: Read organization GitHub integration
      operationId: getOrganizationGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GitHubConnectionName'
        - name: check
          in: query
          required: false
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: GitHub integration
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnection'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    patch:
      tags:
        - GitHub Integrations
      summary: Update organization GitHub integration
      operationId: updateOrganizationGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GitHubConnectionName'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateGitHubConnectionRequest'
      responses:
        '200':
          description: GitHub integration updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnection'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
    delete:
      tags:
        - GitHub Integrations
      summary: Delete organization GitHub integration
      operationId: deleteOrganizationGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GitHubConnectionName'
      responses:
        '204':
          description: Deleted
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/integrations/github/{connectionName}/connect':
    get:
      tags:
        - GitHub Integrations
      summary: Generate GitHub App install URL for organization integration
      operationId: connectOrganizationGitHubIntegration
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - $ref: '#/components/parameters/GitHubConnectionName'
        - name: post_redirect
          in: query
          required: false
          schema:
            type: string
        - name: mode
          in: query
          required: false
          schema:
            type: string
            enum:
              - json
            x-enum-varnames:
              - ConnectOrganizationGitHubIntegrationParamsModeJson
      responses:
        '200':
          description: GitHub App install URL
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubConnect'
        '302':
          description: Redirects the browser to the GitHub App install URL.
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/integrations/github/app-registration-url':
    get:
      tags:
        - GitHub Integrations
      summary: Generate a prefilled GitHub App registration URL for organization setup
      operationId: getOrganizationGitHubAppRegistrationURL
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - name: mode
          in: query
          required: false
          schema:
            type: string
            enum:
              - json
            x-enum-varnames:
              - GetOrganizationGitHubAppRegistrationURLParamsModeJson
          description: 'When set to `json`, returns the registration payload instead of redirecting to GitHub.'
        - name: name
          in: query
          required: false
          schema:
            type: string
          description: 'Optional GitHub App name override. When omitted, Nomatron generates a globally unique default name.'
        - name: description
          in: query
          required: false
          schema:
            type: string
          description: Optional GitHub App description override.
        - name: owner
          in: query
          required: false
          schema:
            type: string
          description: Optional target owner login. Use with `owner_type=org` to create the app inside a GitHub organization.
        - name: owner_type
          in: query
          required: false
          schema:
            type: string
            enum:
              - org
              - user
          description: Optional GitHub owner type for app creation.
        - name: provider_kind
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/GitHubProviderKind'
          description: Target GitHub provider kind. Defaults to GitHub.com.
        - name: web_base_url
          in: query
          required: false
          schema:
            type: string
            format: uri
          description: 'GitHub Enterprise Server web URL, required when provider_kind is enterprise_server.'
        - name: api_base_url
          in: query
          required: false
          schema:
            type: string
            format: uri
          description: Optional GitHub Enterprise REST API URL override.
        - name: upload_base_url
          in: query
          required: false
          schema:
            type: string
            format: uri
          description: Optional GitHub Enterprise uploads API URL override.
        - name: public
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Whether the GitHub App should be publicly installable.
        - name: setup_on_update
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Whether GitHub should call the setup URL after app updates.
      responses:
        '200':
          description: Prefilled GitHub App registration payload
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGitHubAppRegistration'
        '302':
          description: Redirects the browser to GitHub's GitHub App registration form.
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/InternalServerError'
  /service-accounts:
    post:
      summary: Create a service account
      description: Creates a new service account.
      operationId: createServiceAccount
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateServiceAccountRequest'
      responses:
        '201':
          description: Service account created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccount'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      summary: List service accounts
      description: Returns service accounts with optional filters and pagination.
      operationId: listServiceAccounts
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - name: name
          in: query
          required: false
          schema:
            type: string
          description: Exact match on name
        - name: name_like
          in: query
          required: false
          schema:
            type: string
          description: Case-insensitive substring match on name
        - name: created_by
          in: query
          required: false
          schema:
            type: string
            format: uuid
          description: Filter by creator user UUID
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 200
            default: 50
        - name: cursor
          in: query
          required: false
          schema:
            type: string
          description: Opaque cursor from a previous response
      responses:
        '200':
          description: Service accounts
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccountList'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/service-accounts/{serviceAccountID}':
    get:
      summary: Read a service account
      operationId: readServiceAccount
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
      responses:
        '200':
          description: Service account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccount'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Service account not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    patch:
      summary: Update a service account
      description: 'Updates mutable fields (name, description) only.'
      operationId: updateServiceAccount
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateServiceAccountRequest'
      responses:
        '200':
          description: Service account updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccount'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Service account not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      summary: Delete a service account
      description: Permanently deletes a service account. Tokens are deleted via ON DELETE CASCADE.
      operationId: deleteServiceAccount
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseNull'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Service account not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/service-accounts/{serviceAccountID}/activate':
    post:
      summary: Activate a service account
      operationId: activateServiceAccount
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
      responses:
        '200':
          description: Service account activated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccount'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Service account not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/service-accounts/{serviceAccountID}/deactivate':
    post:
      summary: Deactivate a service account
      operationId: deactivateServiceAccount
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
      responses:
        '200':
          description: Service account deactivated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccount'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Service account not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/service-accounts/{serviceAccountID}/tokens':
    post:
      summary: Create a service account token
      description: |
        Mints a new service account token. The raw token is returned exactly once.
      operationId: createServiceAccountToken
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateServiceAccountTokenRequest'
      responses:
        '201':
          description: Token created (raw token returned once)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseCreateServiceAccountToken'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Service account not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    get:
      summary: List service account tokens
      operationId: listServiceAccountTokens
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
        - name: include_revoked
          in: query
          required: false
          schema:
            type: boolean
            default: false
          description: Include revoked tokens
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 200
            default: 50
        - name: cursor
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: Cursor for pagination (created_at before this timestamp)
      responses:
        '200':
          description: Tokens
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccountTokenList'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Service account not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/service-accounts/{serviceAccountID}/tokens/{tokenID}':
    get:
      summary: Read a service account token
      operationId: readServiceAccountToken
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
        - $ref: '#/components/parameters/ServiceAccountTokenID'
      responses:
        '200':
          description: Token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccountToken'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Token not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
    delete:
      summary: Delete a service account token
      description: Permanently deletes a token row.
      operationId: deleteServiceAccountToken
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
        - $ref: '#/components/parameters/ServiceAccountTokenID'
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseNull'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Token not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/service-accounts/{serviceAccountID}/tokens/{tokenID}/revoke':
    post:
      summary: Revoke a service account token
      description: Revokes a token (idempotent).
      operationId: revokeServiceAccountToken
      tags:
        - Service Accounts
      security:
        - BearerAuth: []
      parameters:
        - $ref: '#/components/parameters/ServiceAccountID'
        - $ref: '#/components/parameters/ServiceAccountTokenID'
      responses:
        '200':
          description: Token revoked
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseServiceAccountToken'
        '400':
          description: Validation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Token not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Internal server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /network-agents:
    get:
      tags:
        - Network Agents
      summary: List network agents
      operationId: listNetworkAgents
      parameters:
        - in: query
          name: active
          required: false
          schema:
            type: boolean
          description: Filter by active state.
          example: true
        - in: query
          name: q
          required: false
          schema:
            type: string
          description: Case-insensitive search against network agent name and description.
          example: private
        - in: query
          name: limit
          required: false
          schema:
            type: integer
            minimum: 0
            maximum: 200
            default: 50
          example: 50
        - in: query
          name: offset
          required: false
          schema:
            type: integer
            minimum: 0
            default: 0
          example: 0
      responses:
        '200':
          description: Network agents listed successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentListEnvelope'
        '400':
          description: Invalid query parameters.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
    post:
      tags:
        - Network Agents
      summary: Create network agent
      operationId: createNetworkAgent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateNetworkAgentRequest'
            examples:
              default:
                value:
                  name: private-cluster-agent-1
                  description: Network agent running inside private VPC
                  token_name: initial-token
                  expires_at: '2026-12-31T23:59:59Z'
      responses:
        '201':
          description: Network agent created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentCreateEnvelope'
        '400':
          description: Invalid request payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '409':
          description: Conflict.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/network-agents/{network_agent_id}':
    get:
      tags:
        - Network Agents
      summary: Read network agent
      operationId: readNetworkAgent
      parameters:
        - in: path
          name: network_agent_id
          required: true
          schema:
            type: string
            format: uuid
          example: aec1dbdc-bdd2-4615-9997-023ab143b0b2
      responses:
        '200':
          description: Network agent read successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentReadEnvelope'
        '400':
          description: Invalid network agent ID.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Network agent not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
    patch:
      tags:
        - Network Agents
      summary: Update network agent
      operationId: updateNetworkAgent
      parameters:
        - in: path
          name: network_agent_id
          required: true
          schema:
            type: string
            format: uuid
          example: aec1dbdc-bdd2-4615-9997-023ab143b0b2
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateNetworkAgentRequest'
            examples:
              rename:
                value:
                  name: build-agent-eu-west-1
                  description: Updated network agent description
      responses:
        '200':
          description: Network agent updated successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentUpdateEnvelope'
        '400':
          description: Invalid request payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Network agent not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
    delete:
      tags:
        - Network Agents
      summary: Delete network agent
      operationId: deleteNetworkAgent
      parameters:
        - in: path
          name: network_agent_id
          required: true
          schema:
            type: string
            format: uuid
          example: aec1dbdc-bdd2-4615-9997-023ab143b0b2
      responses:
        '200':
          description: Network agent deleted successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentDeleteEnvelope'
        '400':
          description: Invalid network agent ID.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Network agent not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/network-agents/{network_agent_id}/activate':
    post:
      tags:
        - Network Agents
      summary: Activate network agent
      operationId: activateNetworkAgent
      parameters:
        - in: path
          name: network_agent_id
          required: true
          schema:
            type: string
            format: uuid
          example: aec1dbdc-bdd2-4615-9997-023ab143b0b2
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ActivateNetworkAgentRequest'
            examples:
              with_expiry:
                value:
                  token_name: reactivated-token
                  expires_at: '2026-12-31T23:59:59Z'
      responses:
        '201':
          description: Network agent activated and token minted successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentActivateEnvelope'
        '400':
          description: Invalid request payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Network agent not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '409':
          description: Conflict.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/network-agents/{network_agent_id}/deactivate':
    post:
      tags:
        - Network Agents
      summary: Deactivate network agent
      operationId: deactivateNetworkAgent
      parameters:
        - in: path
          name: network_agent_id
          required: true
          schema:
            type: string
            format: uuid
          example: aec1dbdc-bdd2-4615-9997-023ab143b0b2
      responses:
        '200':
          description: Network agent deactivated and active tokens revoked successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentDeactivateEnvelope'
        '400':
          description: Invalid network agent ID.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Network agent not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/network-agents/{network_agent_id}/tokens/rotate':
    post:
      tags:
        - Network Agents
      summary: Rotate network agent token
      operationId: rotateNetworkAgentToken
      parameters:
        - in: path
          name: network_agent_id
          required: true
          schema:
            type: string
            format: uuid
          example: aec1dbdc-bdd2-4615-9997-023ab143b0b2
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RotateNetworkAgentTokensRequest'
            examples:
              default:
                value:
                  name: rotation-2026-03-06
                  expires_at: '2026-12-31T23:59:59Z'
                  revoke_existing: true
      responses:
        '200':
          description: Network agent token rotated successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentRotateTokenEnvelope'
        '400':
          description: Invalid request payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Network agent not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '409':
          description: Conflict.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  /connectivity-agents:
    get:
      tags:
        - Connectivity Agents
      summary: List connectivity agents
      description: |
        Preferred public name for network agents (proxy Nomad/API into private networks).
        `/network-agents` remains a deprecated alias for one release.
      operationId: listConnectivityAgents
      responses:
        '200':
          description: Connectivity agents listed successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentListEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
    post:
      tags:
        - Connectivity Agents
      summary: Create connectivity agent
      operationId: createConnectivityAgent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateNetworkAgentRequest'
      responses:
        '201':
          description: Created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NetworkAgentCreateEnvelope'
        '401':
          description: Unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/organizations/{orgName}/apps/{app}/networks':
    parameters:
      - name: orgName
        in: path
        required: true
        schema:
          type: string
      - name: app
        in: path
        required: true
        schema:
          type: string
    get:
      tags:
        - Application Networking
      summary: List an application's logical networks
      operationId: listApplicationNetworks
      responses:
        '200':
          description: Logical networks
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApplicationNetworkListEnvelope'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
        - Application Networking
      summary: Create and atomically bind a logical network
      operationId: createApplicationNetwork
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApplicationNetworkRequest'
      responses:
        '201':
          description: Logical network created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApplicationNetworkEnvelope'
        '400':
          $ref: '#/components/responses/BadRequest'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
  '/organizations/{orgName}/apps/{app}/networks/{networkID}':
    parameters:
      - name: orgName
        in: path
        required: true
        schema:
          type: string
      - name: app
        in: path
        required: true
        schema:
          type: string
      - name: networkID
        in: path
        required: true
        schema:
          type: string
          format: uuid
    get:
      tags:
        - Application Networking
      summary: Get a logical network and node-local state
      operationId: getApplicationNetwork
      responses:
        '200':
          description: Logical network
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApplicationNetworkEnvelope'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    patch:
      tags:
        - Application Networking
      summary: Update and atomically bind a logical network
      operationId: updateApplicationNetwork
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApplicationNetworkPatchRequest'
      responses:
        '200':
          description: Logical network updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApplicationNetworkEnvelope'
        '400':
          $ref: '#/components/responses/BadRequest'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
    delete:
      tags:
        - Application Networking
      summary: Delete an unused logical network
      operationId: deleteApplicationNetwork
      responses:
        '204':
          description: Logical network deleted
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
  '/clusters/{clusterName}/networking':
    get:
      tags:
        - Application Networking
      summary: Get cluster Application Networking status
      operationId: getClusterNetworking
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingStatusEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/connect':
    post:
      tags:
        - Application Networking
      summary: Connect Application Networking (BYO or managed)
      operationId: connectClusterNetworking
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                method:
                  type: string
                  enum:
                    - docker
                    - byo
                    - managed
                cni_name:
                  type: string
      responses:
        '200':
          description: Connected (reconciling)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingStatusEnvelope'
        '404':
          description: Cluster not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '409':
          description: |
            Connect is rejected when the cluster is already connected in a different mode,
            managed Cilium teardown is incomplete (BYO requested while owner is still managed),
            managed installation is blocked because eligible clients already run Cilium,
            or a required networking prerequisite is not configured.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/disconnect':
    post:
      tags:
        - Application Networking
      summary: Disconnect Application Networking without removing Host Agents
      description: |
        Disables Application Networking and tears down managed kvstore/controller jobs.
        Host Agent deployment, credentials, and the managed system job are left intact so
        the cluster can reconnect without redeploying agents. Use `POST .../networking/undo-setup`
        to remove Host Agents. Retry cleanup reuses the pending teardown scope and never
        escalates a networking-only disconnect into host-agent removal.
      operationId: disconnectClusterNetworking
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Disconnected
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingStatusEnvelope'
  '/clusters/{clusterName}/networking/undo-setup':
    post:
      tags:
        - Application Networking
      summary: Undo Application Networking setup and remove Host Agents
      description: |
        Disables Application Networking and removes the managed Host Agent system job,
        revokes agent credentials, and deletes the networking namespace after cleanup completes.
        This is the explicit alternative to `POST .../networking/disconnect`, which always
        leaves Host Agents registered.
      operationId: undoClusterNetworkingSetup
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Undo setup started
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingStatusEnvelope'
  '/clusters/{clusterName}/networking/host-agents':
    get:
      tags:
        - Application Networking
      summary: List Host Agents for a cluster
      operationId: listClusterHostAgents
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Host Agents
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentListEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/host-agents/{agentID}/revoke':
    post:
      tags:
        - Application Networking
      summary: Revoke a Host Agent certificate
      operationId: revokeClusterHostAgent
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
        - in: path
          name: agentID
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '204':
          description: Certificate revoked
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  '/clusters/{clusterName}/networking/host-agents/enrollment':
    post:
      tags:
        - Application Networking
      summary: Mint a short-lived Host Agent enrollment secret
      operationId: mintClusterHostAgentEnrollment
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Enrollment secret (returned once)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentEnrollmentSecretEnvelope'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  '/clusters/{clusterName}/networking/host-agent-deployment':
    get:
      tags:
        - Application Networking
      summary: Get Host Agent deployment desire and coverage
      operationId: getClusterHostAgentDeployment
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Host Agent deployment status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentDeploymentStatusEnvelope'
    put:
      tags:
        - Application Networking
      summary: Set the Host Agent installation method
      operationId: updateClusterHostAgentDeployment
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateHostAgentDeploymentRequest'
      responses:
        '200':
          description: Updated Host Agent deployment status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentDeploymentStatusEnvelope'
        '409':
          $ref: '#/components/responses/Conflict'
  '/clusters/{clusterName}/networking/host-agent-deployment/repair':
    post:
      tags:
        - Application Networking
      summary: Repair the desired managed Host Agent system job
      description: Reconciles existing automatic-deployment desire without changing the installation method or target version. Requires `cluster_networking.host_agents.repair`.
      operationId: repairClusterHostAgentDeployment
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Reconciled Host Agent deployment status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentDeploymentStatusEnvelope'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
  '/clusters/{clusterName}/networking/host-agent-acl-policy/remove':
    post:
      tags:
        - Application Networking
      summary: Remove the Nomatron-managed Host Agent ACL policy
      description: Explicitly removes the managed bootstrap ACL policy after Application Networking is disabled. Removal fails if the policy is customer-owned or still referenced by a token or role.
      operationId: removeClusterHostAgentACLPolicy
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '204':
          description: ACL policy removed
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
  '/clusters/{clusterName}/networking/host-agent-acl-policy/tokens':
    get:
      tags:
        - Application Networking
      summary: List client ACL token metadata for Host Agent policy attachment
      operationId: listClusterHostAgentACLTokenCandidates
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Client token metadata
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  '/clusters/{clusterName}/networking/host-agent-acl-policy/tokens/preview':
    post:
      tags:
        - Application Networking
      summary: Preview Host Agent policy attachment to client tokens
      operationId: previewClusterHostAgentACLTokenPolicy
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HostAgentACLTokenSelectionRequest'
      responses:
        '200':
          description: Proposed token policy changes
        '400':
          $ref: '#/components/responses/BadRequest'
        '403':
          $ref: '#/components/responses/Forbidden'
  '/clusters/{clusterName}/networking/host-agent-acl-policy/tokens/apply':
    post:
      tags:
        - Application Networking
      summary: Apply Host Agent policy attachment to client tokens
      operationId: applyClusterHostAgentACLTokenPolicy
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HostAgentACLTokenSelectionRequest'
      responses:
        '200':
          description: Applied token policy changes
        '400':
          $ref: '#/components/responses/BadRequest'
        '403':
          $ref: '#/components/responses/Forbidden'
        '502':
          $ref: '#/components/responses/InternalServerError'
  '/clusters/{clusterName}/networking/policy/active':
    get:
      tags:
        - Application Networking
      summary: Get active NetworkPolicy import payload for the controller
      operationId: getClusterNetworkingActivePolicy
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Active policy import (data may be null when none)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ControllerPolicyImportEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/policy':
    post:
      tags:
        - Application Networking
      summary: Upload NetworkPolicy and create an immutable snapshot
      operationId: uploadClusterNetworkingPolicy
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UploadClusterNetworkingPolicyRequest'
      responses:
        '201':
          description: Snapshot created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicySnapshotEnvelope'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/policy/validate':
    post:
      tags:
        - Application Networking
      summary: Validate Cilium policy documents without creating a snapshot
      operationId: validateClusterNetworkingPolicy
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ValidateClusterNetworkingPolicyRequest'
      responses:
        '200':
          description: Validation result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicyValidationEnvelope'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/policy/source':
    put:
      tags:
        - Application Networking
      summary: Save Git source configuration for cluster Cilium policies
      operationId: putClusterNetworkingPolicySource
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClusterNetworkingPolicySource'
      responses:
        '200':
          description: Saved Git source
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicySourceEnvelope'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/policy/git-integrations':
    get:
      tags:
        - Application Networking
      summary: List GitHub App integrations in scope for cluster Cilium policies
      operationId: listClusterNetworkingPolicyGitIntegrations
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Integrations
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicyGitIntegrationsEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/policy/history':
    get:
      tags:
        - Application Networking
      summary: List NetworkPolicy snapshots for a cluster
      operationId: listClusterNetworkingPolicyHistory
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Snapshot history
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicyHistoryEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/clusters/{clusterName}/networking/policy/rollback':
    post:
      tags:
        - Application Networking
      summary: Rollback NetworkPolicy to a prior snapshot
      operationId: rollbackClusterNetworkingPolicy
      parameters:
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RollbackClusterNetworkingPolicyRequest'
      responses:
        '200':
          description: Rolled back
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicySnapshotEnvelope'
        '404':
          description: Cluster or snapshot not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking':
    get:
      tags:
        - Application Networking
      summary: Get organization cluster Application Networking status
      operationId: getOrganizationClusterNetworking
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingStatusEnvelope'
        '404':
          description: Cluster not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/connect':
    post:
      tags:
        - Application Networking
      summary: Connect Application Networking on an organization cluster
      operationId: connectOrganizationClusterNetworking
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                method:
                  type: string
                  enum:
                    - docker
                    - byo
                    - managed
                cni_name:
                  type: string
      responses:
        '200':
          description: Connected (reconciling)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingStatusEnvelope'
        '404':
          description: Cluster not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '409':
          description: |
            Connect is rejected when the cluster is already connected in a different mode,
            managed Cilium teardown is incomplete (BYO requested while owner is still managed),
            managed installation is blocked because eligible clients already run Cilium,
            or a required networking prerequisite is not configured.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/disconnect':
    post:
      tags:
        - Application Networking
      summary: Disconnect Application Networking without removing Host Agents
      description: Same behavior as the global disconnect route; Host Agents are retained.
      operationId: disconnectOrganizationClusterNetworking
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Disconnected
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingStatusEnvelope'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/undo-setup':
    post:
      tags:
        - Application Networking
      summary: Undo Application Networking setup on an organization cluster
      operationId: undoOrganizationClusterNetworkingSetup
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Undo setup started
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingStatusEnvelope'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agents':
    get:
      tags:
        - Application Networking
      summary: List Host Agents for an organization cluster
      operationId: listOrganizationClusterHostAgents
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Host Agents
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentListEnvelope'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agents/{agentID}/revoke':
    post:
      tags:
        - Application Networking
      summary: Revoke a Host Agent certificate for an organization cluster
      operationId: revokeOrganizationClusterHostAgent
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
        - in: path
          name: agentID
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '204':
          description: Certificate revoked
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agents/enrollment':
    post:
      tags:
        - Application Networking
      summary: Mint a Host Agent enrollment secret for an organization cluster
      operationId: mintOrganizationClusterHostAgentEnrollment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '201':
          description: Enrollment secret (returned once)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentEnrollmentSecretEnvelope'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agent-deployment':
    get:
      tags:
        - Application Networking
      summary: Get Host Agent deployment for an organization cluster
      operationId: getOrganizationClusterHostAgentDeployment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Deployment status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentDeploymentStatusEnvelope'
    put:
      tags:
        - Application Networking
      summary: Set Host Agent installation for an organization cluster
      operationId: updateOrganizationClusterHostAgentDeployment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateHostAgentDeploymentRequest'
      responses:
        '200':
          description: Deployment status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentDeploymentStatusEnvelope'
        '409':
          $ref: '#/components/responses/Conflict'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agent-deployment/repair':
    post:
      tags:
        - Application Networking
      summary: Repair Host Agent deployment for an organization cluster
      operationId: repairOrganizationClusterHostAgentDeployment
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Deployment status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentDeploymentStatusEnvelope'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agent-acl-policy/remove':
    post:
      tags:
        - Application Networking
      summary: Remove the Nomatron-managed Host Agent ACL policy
      description: Explicitly removes the managed bootstrap ACL policy after Application Networking is disabled. Removal fails if the policy is customer-owned or still referenced by a token or role.
      operationId: removeOrganizationClusterHostAgentACLPolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '204':
          description: ACL policy removed
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agent-acl-policy/tokens':
    get:
      tags:
        - Application Networking
      summary: List client ACL token metadata for Host Agent policy attachment
      operationId: listOrganizationClusterHostAgentACLTokenCandidates
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Client token metadata
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agent-acl-policy/tokens/preview':
    post:
      tags:
        - Application Networking
      summary: Preview Host Agent policy attachment to client tokens
      operationId: previewOrganizationClusterHostAgentACLTokenPolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HostAgentACLTokenSelectionRequest'
      responses:
        '200':
          description: Proposed token policy changes
        '400':
          $ref: '#/components/responses/BadRequest'
        '403':
          $ref: '#/components/responses/Forbidden'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/host-agent-acl-policy/tokens/apply':
    post:
      tags:
        - Application Networking
      summary: Apply Host Agent policy attachment to client tokens
      operationId: applyOrganizationClusterHostAgentACLTokenPolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HostAgentACLTokenSelectionRequest'
      responses:
        '200':
          description: Applied token policy changes
        '400':
          $ref: '#/components/responses/BadRequest'
        '403':
          $ref: '#/components/responses/Forbidden'
        '502':
          $ref: '#/components/responses/InternalServerError'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/policy':
    post:
      tags:
        - Application Networking
      summary: Upload NetworkPolicy for an organization cluster
      operationId: uploadOrganizationClusterNetworkingPolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UploadClusterNetworkingPolicyRequest'
      responses:
        '201':
          description: Snapshot created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicySnapshotEnvelope'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/policy/validate':
    post:
      tags:
        - Application Networking
      summary: Validate Cilium policy documents for an organization cluster
      operationId: validateOrganizationClusterNetworkingPolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ValidateClusterNetworkingPolicyRequest'
      responses:
        '200':
          description: Validation result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicyValidationEnvelope'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/policy/source':
    put:
      tags:
        - Application Networking
      summary: Save Git source configuration for an organization cluster
      operationId: putOrganizationClusterNetworkingPolicySource
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClusterNetworkingPolicySource'
      responses:
        '200':
          description: Saved Git source
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicySourceEnvelope'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/policy/git-integrations':
    get:
      tags:
        - Application Networking
      summary: List GitHub App integrations in scope for an organization cluster
      operationId: listOrganizationClusterNetworkingPolicyGitIntegrations
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Integrations
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicyGitIntegrationsEnvelope'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/policy/active':
    get:
      tags:
        - Application Networking
      summary: Get the active policy for an organization cluster
      operationId: getOrganizationClusterNetworkingActivePolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Active policy
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ControllerPolicyImportEnvelope'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/policy/history':
    get:
      tags:
        - Application Networking
      summary: List policy snapshots for an organization cluster
      operationId: listOrganizationClusterNetworkingPolicyHistory
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Snapshot history
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicyHistoryEnvelope'
        '404':
          $ref: '#/components/responses/NotFound'
  '/organizations/{orgSlug}/clusters/{clusterName}/networking/policy/rollback':
    post:
      tags:
        - Application Networking
      summary: Roll back policy for an organization cluster
      operationId: rollbackOrganizationClusterNetworkingPolicy
      parameters:
        - $ref: '#/components/parameters/OrgSlug'
        - in: path
          name: clusterName
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RollbackClusterNetworkingPolicyRequest'
      responses:
        '200':
          description: Rollback snapshot created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClusterNetworkingPolicySnapshotEnvelope'
        '404':
          $ref: '#/components/responses/NotFound'
  /host-agents/enroll:
    post:
      tags:
        - Application Networking
      summary: Enroll a Host Agent with a cluster enrollment secret
      description: |
        Authenticated by cluster enrollment secret (not a user JWT).
        Signs the locally generated CSR with the dedicated Host Agent CA.
      operationId: enrollHostAgent
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/HostAgentEnrollRequest'
      responses:
        '201':
          description: Enrolled
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HostAgentEnrollEnvelope'
        '401':
          description: Invalid enrollment secret
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
  /license/status:
    get:
      tags:
        - License
      summary: License status
      description: |
        Detailed licensing runtime state for authenticated operators, including entitlements, quotas, usage, issues, and non-secret installation hints. Unauthenticated clients should use the coarse `licensing` block on `GET /status` instead.
      operationId: getLicenseStatus
      responses:
        '200':
          description: License status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseLicenseStatus'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  /license/machines:
    get:
      tags:
        - License
      summary: List license machines
      description: |
        Lists Keygen machines bound to the configured license key, including server seat usage and whether each machine corresponds to a live control-plane server.
      operationId: listLicenseMachines
      responses:
        '200':
          description: License machines
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseLicenseMachinesList'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Not available in dev mode
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '502':
          description: Keygen unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
  '/license/machines/{machineRef}':
    delete:
      tags:
        - License
      summary: Remove license machine
      description: |
        Deletes a Keygen machine seat for the configured license. Removing a live control-plane server requires `force=true`.
      operationId: deleteLicenseMachine
      parameters:
        - name: machineRef
          in: path
          required: true
          description: 'Keygen machine id, display name, serf node name, or fingerprint prefix'
          schema:
            type: string
        - name: force
          in: query
          required: false
          description: Allow removing a live control-plane server seat
          schema:
            type: boolean
            default: false
      responses:
        '200':
          description: Machine removed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseLicenseMachineRemoved'
        '401':
          description: Missing or invalid token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '403':
          description: Permission denied
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '404':
          description: Machine not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '409':
          description: Live server removal blocked or dev mode
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
        '502':
          description: Keygen unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseError'
