openapi: "3.0.0"
info:
  version: "1.0.0"
  title: "Varkes Application Connector Client"
  description: "Client for connecting an application to a Kyma cluster"
paths:
  /connection:
    post:
      tags:
        - "connection"
      summary: "Connects the mock to a Kyma cluster"
      requestBody:
        description: "Connection details of the Kyma cluster"
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ConnectionDetails"
      responses:
        "200":
          description: "Successful connection to Kyma"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ConnectionResponse"
        "400":
          description: "Missing required attributes"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "401":
          description: "Connection is not authorized, usually the provided token is not valid"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
    get:
      tags:
        - "connection"
      summary: Returns active connection info
      responses:
        "200":
          description: "Currently connected application and cluster"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ConnectionResponse"
        "404":
          description: "Not connected to Kyma cluster"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
    delete:
      tags:
        - "connection"
      summary: Disconnects the mock from current kyma cluster
      responses:
        204:
          description: Disconnection was successful

  /connection/key:
    get:
      tags:
        - "connection"
      summary: "Gets the private key used by the mock"
      responses:
        "200":
          description: Private key of the mock
          content:
            application/file:
              schema:
                $ref: "#/components/schemas/KeyFile"
        "400":
          description: "Not connected to kyma cluster"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /connection/cert:
    get:
      tags:
        - "connection"
      summary: Get the client certificate for connected Kyma cluster
      responses:
        "200":
          description: client certificate for connected Kyma cluster
          content:
            application/file:
              schema:
                $ref: "#/components/schemas/KeyFile"
        "400":
          description: "Not connected to kyma cluster"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /events:
    post:
      tags:
        - "event"
      summary: "Sends a new event to the connected Kyma cluster"
      requestBody:
        description: "Event payload"
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/EventDetails"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/EventId"
        "400":
          description: "Not connected to kyma cluster or missing required attributes"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /remote/apis:
    post:
      tags:
        - "api"
      summary: "Registers a new API on the connected Kyma cluster"
      requestBody:
        description: "API to be registered"
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ServiceDetails"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ServiceId"
        "400":
          description: "Not connected to Kyma cluster or missing required attributes"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
    get:
      tags:
        - "api"
      summary: "Gets all registered apis on connected Kyma cluster"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: "array"
                items:
                  $ref: "#/components/schemas/Service"
        "400":
          description: "Not connected to Kyma"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /remote/apis/{Id}:
    get:
      tags:
        - "api"
      summary: "Gets a API by ID from connected Kyma cluster"
      parameters:
        - in: "path"
          name: "Id"
          description: "ID of a API"
          required: true
          schema:
            type: "string"
            format: "uuid"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ServiceDetails"
        "404":
          description: "API with the requested Id could not be found"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "400":
          description: "Not connected to Kyma"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
    put:
      tags:
        - "api"
      summary: "Updates a API by ID on connected Kyma cluster"
      requestBody:
        description: "API to be stored"
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ServiceDetails"
      parameters:
        - in: "path"
          name: "Id"
          description: "ID of a service"
          required: true
          schema:
            type: "string"
            format: "uuid"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ServiceDetails"
        "404":
          description: "API with the requested Id could not be found"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "400":
          description: "You are not connected to a Kyma instance."
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
    delete:
      tags:
        - "api"
      summary: "Deletes a API by ID on connected Kyma cluster"
      parameters:
        - in: "path"
          name: "Id"
          description: "ID of a API"
          required: true
          schema:
            type: "string"
            format: "uuid"
      responses:
        "204":
          description: "Successful operation"
        "404":
          description: "API not found"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /local/registration:
    get:
      tags:
        - "api"
      summary: "Gets the status of the batch registration"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Status"
    post:
      tags:
        - "api"
      summary: "Batch registration action"
      requestBody:
        description: "Registration data"
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RegistrationDetails"
      responses:
        "200":
          description: "Currently connected application and cluster"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ConnectionResponse"
        "400":
          description: "Not connected to Kyma"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /local/apis:
    get:
      tags:
        - "api"
      summary: "Gets all local apis bundled from the config file"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: "array"
                items:
                  $ref: "#/components/schemas/Service"
  /local/apis/{apiname}:
    get:
      tags:
        - "api"
      summary: "Gets a specific local api bundled from the config file"
      parameters:
        - in: "path"
          name: "apiname"
          description: "Name of the API"
          required: true
          schema:
            type: "string"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                type: "array"
                items:
                  $ref: "#/components/schemas/Service"
        "404":
          description: "no Api with that name"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /local/apis/{apiname}/register:
    post:
      tags:
        - "api"
      summary: "Registers a specific local API at the connected Kyma cluster"
      requestBody:
        description: "Registration data"
        required: false
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RegistrationDetails"
      parameters:
        - in: "path"
          name: "apiname"
          description: "Name of a API"
          required: true
          schema:
            type: "string"
      responses:
        "200":
          description: "Successful operation"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ServiceDetails"
        "404":
          description: "API with the requested name could not be found"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "400":
          description: "Not connected to Kyma"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /metadata:
    get:
      tags:
        - "misc"
      summary: "Returns this OpenAPI definition"
      responses:
        "200":
          description: "Successful"
          
  /info:
    get:
      tags:
        - "misc"
      summary: "Returns general information of the application"
      responses:
        "200":
          description: "Successful"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Info"
  /console:
    get:
      tags:
        - "misc"
      summary: Returns openapi console for testing
      responses:
        "200":
          description: "Successful"

components:
  schemas:
    Info:
      type: "object"
      properties:
        name:
          type: "string"
          example: "varkes"
          description: "The name of the application"
        links:
          type: "object"
          properties:
            logo:
              type: "string"
              example: "/logo"
              description: "url for getting the application logo"
            localApis:
              type: "string"
              example: "/local/apis"
              description: "url for getting local apis"
            remoteApis:
              type: "string"
              example: "/remote/apis"
              description: "url for getting remote apis"
            connection:
              type: "string"
              example: "/connection"
              description: "url for getting kyma connection info"
            registration:
              type: "string"
              example: "/local/registration"
              description: "url for batch registration"
            events:
              type: "string"
              example: "/events"
              description: "url for sending events"
    Status:
      type: "object"
      properties:
        successCount:
          type: "integer"
          example: 0
          description: "The number of apis successfully registered"
        failedCount:
          type: "integer"
          example: 0
          description: "The number of apis failed to register"
        apisCount:
          type: "integer"
          example: 0
          description: "The number of apis"
        inProgress:
          type: "boolean"
          example: true
          description: "shows wheather the registration is still in progress or not"
        errorMessage:
          type: "string"
          example: "Failed to register api <apiname>: "
          description: "error messages of the failed apis"
    RegistrationDetails:
      type: "object"
      properties:
        baseUrl:
          type: "string"
          description: "Base url under which the API will be served"
          example: "https://myMock.kyma-cluster.io"
    ConnectionDetails:
      type: "object"
      properties:
        url:
          type: "string"
          example: "https://kyma-cluster/v1/applications/sampleApp/info?token=xxx"
          description: "The token url provided by the Kyma cluster to connect to"
        insecure:
          type: "boolean"
          description: "Connected Kyma cluster is running in minikube?"
          example: false
      required:
        - url
    ServiceId:
      type: "object"
      properties:
        id:
          type: "string"
          format: "uuid"
          description: ID of the newly created application
          example: "83a01131-69be-4e52-8a98-2ffa69f7575c"
    ConnectionResponse:
      type: "object"
      properties:
        infoUrl:
          type: "string"
          description: "URL on connected Kyma cluster to retrieve the infos returned here"
          example: https://gateway.mycluster.kyma.cx/v1/applications/management/info
        metadataUrl:
          type: "string"
          description: "URL on connected Kyma cluster to manage APIs"
          example: https://gateway.mycluster.kyma.cx/event-trial/v1/metadata/services
        eventsUrl:
          type: "string"
          description: "URL on connected Kyma cluster to send events"
          example: https://gateway.mycluster.kyma.cx/event-trial/v1/events
        consoleUrl:
          type: "string"
          description: "URL to open application in kyma console"
          example: https://console.mycluster.kyma.cx/home/cmf-apps/details/event-trial
        revocationCertUrl:
          type: "string"
          description: "URL on connected Kyma cluster to revoke client certifactes"
          example: https://gateway.mycluster.kyma.cx/v1/applications/certificates/revocations
        renewCertUrl:
          type: "string"
          description: "URL on connected Kyma cluster to renew client certifactes"
          example: https://gateway.mycluster.kyma.cx/v1/applications/certificates/renewals
        domain:
          type: "string"
          description: "Domain of the connected Kyma cluster"
          example: prod-cluster
        application:
          type: "string"
          description: "Application name on connected Kyma cluster"
          example: myapp
        insecure:
          type: "boolean"
          description: "The connection to the Kyma cluster is insecure"
          example: true

    ServiceDetails:
      allOf:
        - $ref: "#/components/schemas/Service"
        - type: "object"
          properties:
            api:
              $ref: "#/components/schemas/Api"
            events:
              $ref: "#/components/schemas/Events"
            documentation:
              $ref: "#/components/schemas/Documentation"
          required:
            - provider
            - name
            - description
    Api:
      description: "The apis that are being registered with the application"
      type: "object"
      properties:
        targetUrl:
          type: "string"
          format: "uri"
          description: "The full URL to the base path of the API including host and protocol"
          example: "http://localhost:10000/entity"
        credentials:
          $ref: "#/components/schemas/ApiCredentials"
        spec:
          type: "object"
          description: "OpenApi v2 swagger file: https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json"
          example:
            $ref: https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

      required:
        - targetUrl
    Events:
      type: "object"
      description: "Events that are being registered with the application"
      properties:
        spec:
          description: "AsynApi file v1: https://github.com/asyncapi/asyncapi/blob/develop/schema/asyncapi.json"
          type: "object"
          example:
            $ref: https://raw.githubusercontent.com/asyncapi/asyncapi/master/examples/1.1.0/anyof.yml
    EventDetails:
      type: "object"
      properties:
        event-type:
          description: "Type of event"
          type: "string"
          example: "customer.created"
        event-type-version:
          description: "version of event type"
          type: "string"
          example: "v1"
        event-time:
          description: "time when event was send"
          type: string
          example: "2019-03-04T14:19:29.450Z"
        data:
          description: "event payload"
          type: "object"
          example:
            mykey: myvalue
            somekey: somevalue
      required:
        - event-type
        - event-type-version
        - event-time
        - data
    Documentation:
      type: "object"
      description: "Documentation of the Application"
      properties:
        displayName:
          type: "string"
          description: Name of the Documentation
          example: "Schools"
        description:
          type: "string"
          description: Summary of the documentation
          example: "Schools webservices"
        type:
          type: "string"
          description: Type of the documentation
          example: "Overview"
        tags:
          type: "array"
          description: Tags of the application
          example:
            - tag1
            - tag2
          items:
            type: "string"
        docs:
          type: "array"
          description: Docs of the application
          items:
            $ref: "#/components/schemas/Document"
      required:
        - displayName
        - description
        - type
    Document:
      type: "object"
      description: "Documentation document"
      properties:
        title:
          type: "string"
          description: Title of the document
          example: Service Overview Documentation
        type:
          type: "string"
          description: Type of the document
          example: "Overview"
        source:
          type: "string"
          description: Source of the document
          example: This service does this and that...
      required:
        - title
        - type
        - source
    ApiCredentials:
      type: "object"
      description: Credential endpoint of the API
      properties:
        oauth:
          $ref: "#/components/schemas/OAuth"
      required:
        - oauth
    OAuth:
      type: "object"
      description: OAuth endpoint of the API
      properties:
        url:
          type: "string"
          format: "uri"
          example: "http://localhost:10000/entity/authorizationserver/oauth/token"
        clientId:
          type: "string"
          example: "*********"
        clientSecret:
          type: "string"
          example: "*********"
      required:
        - url
        - clientId
        - clientSecret
    ErrorResponse:
      type: "object"
      description: Error returned from the server
      properties:
        error:
          type: "string"
          example: You are not connected. Please try to reconnect
    KeyFile:
      type: "string"
      format: binary
    EventId:
      type: "object"
      description: "Id of the sent event"
      properties:
        event-id:
          type: string
          description: Id of the sent event
          example: f64fc421-2759-4685-a184-752208570615
    Service:
      type: "object"
      description: "Info"
      allOf:
        - $ref: "#/components/schemas/ServiceId"
        - properties:
            provider:
              type: "string"
              description: provider of the api
              example: "Texas Education Board"
            name:
              type: "string"
              description: name of the api
              example: "schools"
            type:
              type: "string"
              description: type of the api
              example: "OpenAPI"
            description:
              type: "string"
              description: description of the api
              example: "API to manage schools in Texas"
            labels:
              type: "object"
              example:
                connected-app: event-trial
                label1: value1
