# Copyright 2021 - 2025 PeopleWare n.v.
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

type: object
examples:
  - structureVersion: 2
    toOneAssociations:
      - /some-service/v1/x/123
      - /my-service/v1/y/abc
    exact:
      - '0123456789'
      - '9876543210'
    fuzzy:
      - find me
      - if you can
      - '9876543210'
    content:
      structureVersion: 2
      discriminator: my-service/some-resource
      extraData: extra
      moreInfo:
        aDetail: 2
        anotherDetail: true
      aReference: /my-service/a/canonical/uri
    embedded:
      x: /your-service/v1/x/123
  - structureVersion: 2
    toOneAssociations:
      - /some-service/v1/x/123
    exact: []
    fuzzy: []
    content:
      structureVersion: 2
      discriminator: my-service/some-resource
      extraData: extra
      moreInfo:
        aDetail: 2
        anotherDetail: true
      aReference: /my-service/a/canonical/uri
    embedded:
      x: /your-service/v1/x/123
  - structureVersion: 2
    toOneAssociations: []
    exact:
      - '0123456789'
    fuzzy: []
    content:
      structureVersion: 2
      discriminator: my-service/some-resource
      extraData: extra
      moreInfo:
        aDetail: 2
        anotherDetail: true
      aReference: /my-service/a/canonical/uri
    embedded:
      x: /your-service/v1/x/123
  - structureVersion: 2
    toOneAssociations: []
    exact: []
    fuzzy:
      - find me
    content:
      structureVersion: 2
      discriminator: my-service/some-resource
      extraData: extra
      moreInfo:
        aDetail: 2
        anotherDetail: true
      aReference: /my-service/a/canonical/uri
    embedded:
      x: /your-service/v1/x/123
description: >-
  Returned as `search-document` by a service for a parent resource. A _search index document_ is created in the search
  index based on this information. The search service retrieves the information from the search index.


  It contains strings for which the resource this is a search document for can be found by, and the `content` that is to
  be sent to the client (more or less). The resource this is a search document for can be found with an exact match on
  the strings in `exact` or `toOneAssociations`, and by a fuzzy search on the strings in `fuzzy`. Some strings might
  appear in both.


  `toOneAssociations`, `exact`, and `fuzzy` may be empty, but not all of them.


  Search results can be limited to selected types with an exact match on `content.discriminator`. The found resource can
  be retrieved in the indexed version at `href`.
properties:
  structureVersion:
    examples:
      - 2
    description: Version of the data structure of this resource type
    minimum: 1
    const: 2
  toOneAssociations:
    type: array
    examples:
      - - /some-service/v1/x/123
        - /my-service/v1/y/abc
    description: >-
      Array of canonical URIs of the resources the represented resource has a to-one association to. Used to find the
      represented resource as element of the to-many association of the referenced resource.


      The order is irrelevant. May be empty if `fuzzy` or `exact` is not empty.
    uniqueItems: true
    items:
      type: string
      examples:
        - /my-service/v1/y/abc
      description: 'A _canonical URI_ is the URI where are resource can be interacted with, without the scheme and authority
        (see [RFC 3986 Uniform Resource Identifier (URI): Generic Syntax; 3. Syntax
        Components](https://www.rfc-editor.org/rfc/rfc3986#section-3)), and without the build number. By convention, the
        canonical URI’s first segment is the name of the service in which the URI resides, followed by the relative URI
        of the resource in the API of that service.'
      format: uri-reference
      minLength: 1
  exact:
    type: array
    examples:
      - - '0123456789'
        - '9876543210'
    description: >-
      List of strings on which the resource can be found with exact match.


      The order is irrelevant. May be empty if `fuzzy` or `toOneAssociations` is not empty.
    uniqueItems: true
    items:
      type: string
      examples:
        - Mari
        - Jos
        - '0123456789'
        - '0123456789'
      description: free text on which the resource can be found (trimmed, not empty)
      minLength: 1
  fuzzy:
    type: array
    examples:
      - - find me
        - if you can
    description: >-
      List of strings on which the resource can be found with fuzzy match.


      The order is irrelevant. May be empty if `exact` or `toOneAssociations` is not empty.
    uniqueItems: true
    items:
      type: string
      examples:
        - Mari
        - Jos
        - '0123456789'
        - find me
      description: free text on which the resource can be found (trimmed, not empty)
      minLength: 1
  embedded:
    type: object
    examples:
      - x: /your-service/v1/x/123
        y: /my-service/v1/y/abc
    description: >-
      Map of canonical URIs of the resources this search index document embeds information of. When the search index
      document for the referenced resources is updated, the search index document for the represented resource needs to
      be updated too.


      The `content` of the referenced resources is spliced in the search result `content` of the resource this is the
      search document for. The resource this is the search document for can also be found with the `exact` and `fuzzy`
      entries of the referenced resources.
    properties: {}
    additionalProperties: true
  content:
    type: object
    examples:
      - structureVersion: 2
        discriminator: my-service/some-resource
    description: >-
      The resource's search document with the most up-to-date information, i.e., up-to-date up until, but not including,
      `x-date`.


      This is a contract between this service and clients of the search service. Specific properties are added for
      different `discriminators`. When returned by the search service, the property `href` is added. This is the
      canonical URI of the found resource, including an `at` query parameter, that refers to the precise version of the
      found resource that was indexed.
    properties:
      structureVersion:
        examples:
          - 2
        description: Version of the data structure of this resource type
        minimum: 1
        const: 2
      discriminator:
        type: string
        examples:
          - my-service/some-resource
        description: >-
          Type of the indexed resource.


          This enables users to search only on particular resource type. The type is qualified with the service name, to
          avoid name clashes (slash-separated).
        minLength: 1
        pattern: ^([-a-z0-9]+)\/([-a-z0-9/]+)$
    required:
      - structureVersion
      - discriminator
    additionalProperties: true
required:
  - structureVersion
  - toOneAssociations
  - exact
  - fuzzy
  - embedded
  - content
additionalProperties: true
