openapi: 3.0.1
info:
  title: Debian Code Search
  description: OpenAPI for https://codesearch.debian.net/
  contact:
    email: stapelberg@debian.org
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: 1.4.0
externalDocs:
  description: Get a Debian Code Search API key
  url: https://codesearch.debian.net/apikeys/
servers:
- url: https://codesearch.debian.net/api/v1
tags:
- name: search
  description: Code Search
paths:
  /search:
    get:
      tags:
      - search
      summary: Searches through source code
      description: |-
        Performs a search through the full Debian Code Search corpus, blocking until all results are available (might take a few seconds depending on the search query).

        Search results are ordered by their ranking (best results come first).
      operationId: search
      parameters:
      - name: query
        in: query
        description: The search query, for example `who knows...` (literal) or `who
          knows\.\.\.` (regular expression). See https://codesearch.debian.net/faq
          for more details about which keywords are supported. The regular expression
          flavor is RE2, see https://github.com/google/re2/blob/master/doc/syntax.txt
        required: true
        schema:
          type: string
      - name: match_mode
        in: query
        description: Whether the query is to be interpreted as a literal (`literal`)
          instead of as an RE2 regular expression (`regexp`). Literal searches are
          faster and do not require escaping special characters, regular expression
          searches are more powerful.
        schema:
          type: string
          default: regexp
          enum:
          - literal
          - regexp
      responses:
        200:
          description: All search results
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SearchResult'
        403:
          description: The x-dcs-apikey header was either not set at all, or contained
            an invalid (no longer valid?) API key. Please see https://codesearch.debian.net/apikeys/
            for obtaining a key.
          content: {}
      security:
      - api_key: []
  /searchperpackage:
    get:
      tags:
      - search
      summary: Like /search, but aggregates per package
      description: 'The search results are currently sorted arbitrarily, but we intend
        to sort them by ranking eventually: https://github.com/Debian/dcs/blob/51338e934eb7ee18d00c5c18531c0790a83cb698/cmd/dcs-web/querymanager.go#L719'
      operationId: searchperpackage
      parameters:
      - name: query
        in: query
        description: The search query, for example `who knows...` (literal) or `who
          knows\.\.\.` (regular expression). See https://codesearch.debian.net/faq
          for more details about which keywords are supported. The regular expression
          flavor is RE2, see https://github.com/google/re2/blob/master/doc/syntax.txt
        required: true
        schema:
          type: string
      - name: match_mode
        in: query
        description: Whether the query is to be interpreted as a literal (`literal`)
          instead of as an RE2 regular expression (`regexp`). Literal searches are
          faster and do not require escaping special characters, regular expression
          searches are more powerful.
        schema:
          type: string
          default: regexp
          enum:
          - literal
          - regexp
      responses:
        200:
          description: All search results
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/PackageSearchResult'
        403:
          description: The x-dcs-apikey header was either not set at all, or contained
            an invalid (no longer valid?) API key. Please see https://codesearch.debian.net/apikeys/
            for obtaining a key.
          content: {}
      security:
      - api_key: []
components:
  schemas:
    SearchResult:
      required:
      - context
      - line
      - package
      - path
      type: object
      properties:
        package:
          type: string
          description: The Debian source package containing this search result, including
            the full Debian version number.
          example: i3-wm_4.18-1
        path:
          type: string
          description: Path to the file containing the this search result, starting
            with `package`.
          example: i3bar/src/xcb.c
        line:
          type: integer
          description: Line number containing the search result.
          format: uint32
          example: 1313
        context_before:
          type: array
          description: Up to 2 full lines before the search result (see `context`).
          example:
          - '    } else {'
          - '        cursor = xcb_generate_id(xcb_connection);'
          items:
            type: string
        context:
          type: string
          description: The full line containing the search result.
          example: '        i3Font cursor_font = load_font("cursor", false);'
        context_after:
          type: array
          description: Up to 2 full lines after the search result (see `context`).
          example:
          - '        xcb_create_glyph_cursor('
          - '            xcb_connection,'
          items:
            type: string
      description: A search result matching the specified query. You can use sources.debian.org
        to view the file contents. See https://github.com/Debian/dcs/blob/master/cmd/dcs-web/show/show.go
        for how to construct a sources.debian.org URL from a search result.
    PackageSearchResult:
      required:
      - package
      - results
      type: object
      properties:
        package:
          type: string
          description: The Debian source package for which up to 2 search results
            have been aggregated in `results`.
          example: i3-wm_4.18-1
        results:
          type: array
          items:
            $ref: '#/components/schemas/SearchResult'
  parameters:
    queryParam:
      name: query
      in: query
      description: The search query, for example `who knows...` (literal) or `who
        knows\.\.\.` (regular expression). See https://codesearch.debian.net/faq for
        more details about which keywords are supported. The regular expression flavor
        is RE2, see https://github.com/google/re2/blob/master/doc/syntax.txt
      required: true
      schema:
        type: string
    matchModeParam:
      name: match_mode
      in: query
      description: Whether the query is to be interpreted as a literal (`literal`)
        instead of as an RE2 regular expression (`regexp`). Literal searches are faster
        and do not require escaping special characters, regular expression searches
        are more powerful.
      schema:
        type: string
        default: regexp
        enum:
        - literal
        - regexp
  securitySchemes:
    api_key:
      type: apiKey
      name: x-dcs-apikey
      in: header
