openapi: 3.0.0
info:
  title: 'Link Example'
  description: ''
  contact:
    name: 'Contact Name'
    email: support@example.com
  version: 1.0.0
paths:
  '/2.0/repositories/{username}':
    get:
      operationId: getRepositoriesByOwner
      parameters:
        -
          name: username
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: 'Repositories owned by the supplied user'
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/repository'
          links:
            userRepository:
              $ref: '#/components/links/UserRepository'
  '/2.0/repositories/{username}/{slug}':
    get:
      operationId: getRepository
      parameters:
        -
          name: username
          in: path
          required: true
          schema:
            type: string
        -
          name: slug
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: 'The repository'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/repository'
          links:
            repositoryPullRequests:
              $ref: '#/components/links/RepositoryPullRequests'
  '/2.0/repositories/{username}/{slug}/{state}/pullrequests':
    get:
      operationId: getPullRequestsByRepository
      parameters:
        -
          name: username
          in: path
          required: true
          schema:
            type: string
        -
          name: slug
          in: path
          required: true
          schema:
            type: string
        -
          name: state
          in: path
          required: true
          schema:
            $ref: '#/components/schemas/State'
        -
          name: label
          in: query
          required: false
          schema:
            type: string
      responses:
        '200':
          description: 'An array of pull request objects'
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/pullrequest'
  '/2.0/repositories/{username}/{slug}/pullrequests/{pid}':
    get:
      operationId: getPullRequestsById
      parameters:
        -
          name: username
          in: path
          required: true
          schema:
            type: string
        -
          name: slug
          in: path
          required: true
          schema:
            type: string
        -
          name: pid
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: 'A pull request object'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/pullrequest'
          links:
            pullRequestMerge:
              $ref: '#/components/links/PullRequestMerge'
  '/2.0/repositories/{username}/{slug}/pullrequests/{pid}/merge':
    post:
      operationId: mergePullRequest
      parameters:
        -
          name: username
          in: path
          required: true
          schema:
            type: string
        -
          name: slug
          in: path
          required: true
          schema:
            type: string
        -
          name: pid
          in: path
          required: true
          schema:
            type: string
        -
          name: X-NONCE-ID
          in: header
          required: true
          schema:
            type: string
        -
          name: User-Bind-Session
          in: cookie
          required: false
          schema:
            type: string
      responses:
        '204':
          description: 'The PR was successfully merged'
  '/2.0/users/{username}':
    get:
      tags:
        - Users
      summary: 'Get user details by username'
      operationId: getUserByName
      parameters:
        -
          name: username
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: 'The User'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/user'
          links:
            userRepositories:
              $ref: '#/components/links/UserRepositories'
components:
  schemas:
    pullrequest:
      properties:
        state:
          $ref: '#/components/schemas/State'
        id:
          type: integer
        title:
          type: string
        repository:
          $ref: '#/components/schemas/repository'
        author:
          $ref: '#/components/schemas/user'
      type: object
    repository:
      properties:
        slug:
          type: string
        owner:
          $ref: '#/components/schemas/user'
      type: object
    State:
      type: string
      enum:
        - OPEN
        - MERGED
        - DECLINED
    user:
      properties:
        username:
          type: string
        uuid:
          type: string
      type: object
  links:
    UserRepositories:
      operationId: getRepositoriesByOwner
      parameters:
        username: '$response.body#/username'
    UserRepository:
      operationId: getRepository
      parameters:
        username: '$response.body#/owner/username'
        slug: '$response.body#/slug'
    RepositoryPullRequests:
      operationId: getPullRequestsByRepository
      parameters:
        username: '$response.body#/owner/username'
        slug: '$response.body#/slug'
    PullRequestMerge:
      operationId: mergePullRequest
      parameters:
        username: '$response.body#/author/username'
        slug: '$response.body#/repository/slug'
        pid: '$response.body#/id'
