openapi: 3.0.0

info:
  title: TousAntiCovid
  version: 1.0.0
  
servers:
  - url: 'https://api.tousanticovid.gouv.fr/api/{apiVersion}'
    variables:
      apiVersion:
        default: 'v6'
        description: API Version

tags:
  - name: captcha
  - name: registration
  - name: analytics

paths:
  /captcha:
    post:
      operationId: generateCaptcha
      tags:
        - captcha
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CaptchaRequest'
      responses:
        201:
          description: CAPTCHA Generated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CaptchaResponse'
          
  /captcha/{captchaId}/{captchaType}:
    get:
      operationId: getCaptcha
      tags:
        - captcha
      parameters:
        - $ref: '#/components/parameters/captchaId'
        - $ref: '#/components/parameters/captchaType'
      responses:
        200:
          description: CAPTCHA Image / Audio
          content:
            image/png:
              schema:
                type: string
                format: binary
            audio/wave:
              schema:
                type: string
                format: binary
            
  /register:
    post:
      operationId: register
      tags:
        - registration
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RegisterRequest'
      responses:
        201:
          description: Registration successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RegisterResponse'
                
  /unregister:
    post:
      operationId: unregister
      tags:
        - registration
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UnregisterRequest'
      responses:
        200:
          description: Unregister successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CommonResponse'
                
  /status:
    post:
      operationId: status
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StatusRequest'
      responses:
        200:
          description: Status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatusResponse'
                
  /report:
    post:
      operationId: report
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ReportRequest'
      responses:
        200:
          description: 'Report OK'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReportResponse'
        401:
          description: 'Invalid token'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
                
  /analytics:
    post:
      operationId: sendAnalytics
      tags:
        - analytics
      security:
        - bearerAuth: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SendAnalyticsRequest'
      responses:
        200:
          description: Analytics sent successfully
              
    delete:
      operationId: deleteAnalytics
      tags:
        - analytics
      security:
        - bearerAuth: []
      parameters:
        - in: query
          name: installationUuid
          schema:
            type: string
            format: uuid
          required: true
      responses:
        204:
          description: Analytics deleted
  
  /deleteExposureHistory:
    post:
      operationId: deleteExposureHistory
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DeleteExposureHistoryRequest'
      responses:
        200:
          description: Exposure history deleted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CommonResponse'


components:           
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

  parameters:
    captchaId:
      in: path
      name: captchaId
      required: true
      schema:
        type: string
        example: '7c6d7873eeb34ef5909df2a08f6cf7ac'
    
    captchaType:
      in: path
      name: captchaType
      required: true
      schema:
        type: string
        enum:
          - "image"
          - "audio"

                
  schemas:
    ErrorResponse:
      type: object
      properties:
        message:
          type: string
          example: 'Invalid authentication'
          
    CommonResponse:
      properties:
        success:
          type: boolean
        message:
          type: string
  
    CaptchaRequest:
      type: object
      properties:
        type:
          type: string
          example: "IMAGE"
          enum:
            - "IMAGE"
            - "AUDIO"
        locale:
          type: string
          example: "FR"
          enum:
            - "EN"
            - "FR"
        
    CaptchaResponse:
      type: object
      properties:
        id:
          type: string
          example: '7c6d7873eeb34ef5909df2a08f6cf7ac'
          
    RegisterRequest:
      type: object
      properties:
        captcha:
          type: string
          example: 'abcd'
        captchaId:
          type: string
          example: ''
        clientPublicECDHKey:
          type: string
          example: 'MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEzfamcO03njvnZHs4em+FIk5FypBLt4KzpN9o1NIV6A9ouW/SNrgqTQon6wWmfBe/aMN4eFXN7XQSlM3OTaaXZA=='
          
    RegisterResponse:
      type: object
      properties:
        tuples:
          type: string
        message:
          type: string
        timeStart:
          type: number
          example: 3799958400
        config:
          type: array
          items:
            type: string
          
    UnregisterRequest:
      type: object
      properties:
        ebid:
          type: string
          format: base64
          example: 'htRPut7VZug='
        epochId:
          type: number
          example: 42042
        time:
          type: string
          format: base64
          example: '5MAgVx=='
        mac:
          type: string
          example: 'UBVFhDn9cNqfEWojMhjJ6wSpTLE4GgSNa51PGs0uNSQ='
          
    StatusRequest:
      type: object
      properties:
        ebid:
          type: string
          format: base64
          example: 'htRPut7VZug='
        epochId:
          type: number
          example: 42042
        time:
          type: string
          format: base64
          example: '5MAgVx=='
        mac:
          type: string
          example: 'UBVFhDn9cNqfEWojMhjJ6wSpTLE4GgSNa51PGs0uNSQ='
          
    DeleteExposureHistoryRequest:
      type: object
      properties:
        ebid:
          type: string
          format: base64
          example: 'htRPut7VZug='
        epochId:
          type: number
          example: 42042
        time:
          type: string
          format: base64
          example: '5MAgVx=='
        mac:
          type: string
          example: 'UBVFhDn9cNqfEWojMhjJ6wSpTLE4GgSNa51PGs0uNSQ='
          
    StatusResponse:
      type: object
      properties:
        riskLevel:
          type: number
        lastContactDate:
          type: string
          format: datetime
        lastRiskScoringDate:
          type: string
          format: datetime
        message:
          type: string
        tuples:
          type: string
        declarationToken:
          type: string
        analyticsToken:
          type: string
    
    ReportResponse:
      type: object
      properties:
        success:
          type: boolean
        message:
          type: string
        reportValidationToken:
          type: string
    
    ReportRequest:
      type: object
      properties:
        contacts:
          type: array
          items:
            type: string
        token:
          type: string
          example: '123456'
          
    SendAnalyticsRequest:
      type: object
      properties:
        installationUuid:
          type: string
          format: uuid
        infos:
          $ref: '#/components/schemas/AppInfos'
        events:
          type: array
          items:
            $ref: '#/components/schemas/TimestampedEvent'
        errors:
          type: array
          items:
            $ref: '#/components/schemas/TimestampedEvent'
            
    TimestampedEvent:
      type: object
      properties:
        name:
          type: string
          example: 'e3'
        timestamp:
          type: string
        desc:
          type: string
          nullable: true
        
    AppInfos:
      type: object
      properties:
        type:
          type: integer
          example: 0
        os:
          type: string
          example: 'Android'
        deviceModel:
          type: string
          example: 'SM-J330FN'
        osVersion:
          type: string
          example: '28'
        appVersion:
          type: string
          example: '3.7.0'
        appBuild:
          type: integer
          example: 328
        receivedHelloMessagesCount:
          type: integer
        placesCount:
          type: integer
        formsCount:
          type: integer
        certificatesCount:
          type: integer
        statusSuccessCount:
          type: integer
        userHasAZipcode:
          type: boolean
