openapi: 3.0.3
info:
  title: Metadata Governance Provider API
  version: 0.2.0
  x-contract-level: L2
servers:
  - url: /
tags:
  - name: MetadataSchemas
  - name: DecompositionTemplates
paths:
  /admin/metadata-schemas:
    get:
      tags: [MetadataSchemas]
      summary: List metadata schemas
      operationId: listMetadataSchemas
      x-requirements: [AC-IDSMETA-13]
      parameters:
        - name: status
          in: query
          required: false
          schema:
            type: string
            enum: [draft, active, deprecated]
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [items]
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/MetadataSchema'
        '400':
          $ref: '#/components/responses/BadRequest'
    post:
      tags: [MetadataSchemas]
      summary: Create metadata schema
      operationId: createMetadataSchema
      x-requirements: [AC-IDSMETA-13]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MetadataSchemaCreateRequest'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetadataSchema'
        '400':
          $ref: '#/components/responses/BadRequest'
  /admin/metadata-schemas/{id}:
    put:
      tags: [MetadataSchemas]
      summary: Update metadata schema
      operationId: updateMetadataSchema
      x-requirements: [AC-IDSMETA-14]
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            minLength: 1
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MetadataSchemaUpdateRequest'
      responses:
        '200':
          description: Updated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MetadataSchema'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
  /admin/data-decomposition/templates:
    get:
      tags: [DecompositionTemplates]
      summary: List decomposition templates
      operationId: listDecompositionTemplates
      x-requirements: [AC-IDSMETA-22]
      parameters:
        - name: status
          in: query
          required: false
          schema:
            type: string
            enum: [draft, active, deprecated]
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                required: [items]
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/DecompositionTemplate'
        '400':
          $ref: '#/components/responses/BadRequest'
    post:
      tags: [DecompositionTemplates]
      summary: Create decomposition template
      operationId: createDecompositionTemplate
      x-requirements: [AC-IDSMETA-21, AC-IDSMETA-22]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DecompositionTemplateCreateRequest'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DecompositionTemplate'
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  schemas:
    MetadataSchema:
      type: object
      required:
        - id
        - field_key
        - label
        - type
        - required
        - scope
        - status
      properties:
        id:
          type: string
        field_key:
          type: string
          pattern: '^[a-z0-9_]+$'
          minLength: 1
          maxLength: 64
        label:
          type: string
          minLength: 1
          maxLength: 64
        type:
          type: string
          enum: [string, number, boolean, enum, array_enum]
        required:
          type: boolean
        options:
          type: array
          items:
            type: string
          uniqueItems: true
        default:
          oneOf:
            - type: string
            - type: number
            - type: boolean
        scope:
          type: array
          minItems: 1
          items:
            type: string
            enum: [kb_document, intent_rule, script_flow, prompt_template]
          uniqueItems: true
        is_filterable:
          type: boolean
          default: true
        is_rank_feature:
          type: boolean
          default: false
        status:
          type: string
          enum: [draft, active, deprecated]
    MetadataSchemaCreateRequest:
      type: object
      required: [field_key, label, type, required, scope, status]
      properties:
        field_key:
          type: string
          pattern: '^[a-z0-9_]+$'
          minLength: 1
          maxLength: 64
        label:
          type: string
          minLength: 1
          maxLength: 64
        type:
          type: string
          enum: [string, number, boolean, enum, array_enum]
        required:
          type: boolean
        options:
          type: array
          items:
            type: string
          uniqueItems: true
        default:
          oneOf:
            - type: string
            - type: number
            - type: boolean
        scope:
          type: array
          minItems: 1
          items:
            type: string
            enum: [kb_document, intent_rule, script_flow, prompt_template]
          uniqueItems: true
        is_filterable:
          type: boolean
          default: true
        is_rank_feature:
          type: boolean
          default: false
        status:
          type: string
          enum: [draft, active, deprecated]
    MetadataSchemaUpdateRequest:
      type: object
      properties:
        label:
          type: string
          minLength: 1
          maxLength: 64
        required:
          type: boolean
        options:
          type: array
          items:
            type: string
          uniqueItems: true
        default:
          oneOf:
            - type: string
            - type: number
            - type: boolean
        scope:
          type: array
          minItems: 1
          items:
            type: string
            enum: [kb_document, intent_rule, script_flow, prompt_template]
          uniqueItems: true
        is_filterable:
          type: boolean
        is_rank_feature:
          type: boolean
        status:
          type: string
          enum: [draft, active, deprecated]
    DecompositionTemplate:
      type: object
      required: [id, name, template_content, version, status]
      properties:
        id:
          type: string
        name:
          type: string
          minLength: 1
          maxLength: 100
        template_content:
          type: string
          minLength: 20
        version:
          type: string
          pattern: '^v?[0-9]+\.[0-9]+\.[0-9]+$'
        status:
          type: string
          enum: [draft, active, deprecated]
    DecompositionTemplateCreateRequest:
      type: object
      required: [name, template_content, version, status]
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
        template_content:
          type: string
          minLength: 20
        version:
          type: string
          pattern: '^v?[0-9]+\.[0-9]+\.[0-9]+$'
        status:
          type: string
          enum: [draft, active, deprecated]
    ErrorResponse:
      type: object
      required: [code, message]
      properties:
        code:
          type: string
        message:
          type: string
        details:
          type: object
          additionalProperties: true
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
