{
  "openapi": "3.1.0",
  "info": {
    "title": "Billing Resource Exporter API",
    "description": "This API is **not** exposed by your OSIE installation.  You should build and deploy an external HTTP service that implements this API for exposing additional billing resources to be ingested into the OSIE billing engine.  The APIs must require authentication with the AWS SigV4 algorithm using the access key secret key pair that were generated by OSIE.",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://billing-exporter.example.com",
      "description": "Your billing resource exporter"
    }
  ],
  "paths": {
    "/billing_resources": {
      "post": {
        "tags": [
          "Billing Resources"
        ],
        "description": "OSIE fetches billing resources from this endpoint for each interval type (month, hour, minute), depending on whether the admin has defined pricing rule for that interval.",
        "operationId": "Billing Resources",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BillingResourcesRequestContext"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/BillingResource"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/billing_resources/types": {
      "post": {
        "tags": [
          "Billing Resources"
        ],
        "description": "Describe a billing resource with its attributes.",
        "operationId": "Billing Resource Types",
        "parameters": [
          {
            "name": "include_values",
            "in": "query",
            "description": "If this parameter is sent to true, the possible values of an attribute should be populated, if any.",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BillingResourceTypesRequestContext"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/BillingResourceType"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "BillingProfile": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "email": {
            "type": "string",
            "minLength": 1
          }
        },
        "required": [
          "email",
          "id"
        ]
      },
      "BillingResourcesRequestContext": {
        "type": "object",
        "description": "The context (project, billing profile for which it fetches the resources.",
        "properties": {
          "project": {
            "$ref": "#/components/schemas/Project"
          },
          "billing_profile": {
            "$ref": "#/components/schemas/BillingProfile"
          },
          "service_provider": {
            "$ref": "#/components/schemas/ServiceProvider",
            "description": "OSIE Service provider information."
          }
        },
        "required": [
          "billing_profile",
          "project",
          "service_provider"
        ]
      },
      "Project": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          }
        }
      },
      "ServiceProvider": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "name": {
            "type": "string",
            "minLength": 1
          },
          "region": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name"
        ]
      },
      "BillingResource": {
        "type": "object",
        "description": "Billing resources are ingested by the OSIE rating engine to calculate the prices.The billing resources will eventually be added as items to the Bill.",
        "properties": {
          "resource_id": {
            "type": "string",
            "description": "The unique identifier of the resource."
          },
          "display_name": {
            "type": "string",
            "description": "The friendly name of the resource, as it will appear on the Bill."
          },
          "resource_type": {
            "type": "string",
            "description": "The type of the resource, as defined in the BillingResourceType."
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "(optional) creation date of the resource."
          },
          "attributes": {
            "type": "object",
            "additionalProperties": {},
            "description": "The resource attributes with their values, where the values can be either string, numeric or boolean, as described earlier in the BillingResourceType."
          },
          "not_eligible_for_billing": {
            "type": "boolean",
            "description": "The resource is in a state that must not be billed (i.e: servers in error state)"
          }
        },
        "required": [
          "attributes"
        ]
      },
      "BillingResourceTypesRequestContext": {
        "type": "object",
        "description": "The service provider for which it fetches the resource types.",
        "properties": {
          "service_provider": {
            "$ref": "#/components/schemas/ServiceProvider",
            "description": "OSIE Service provider information."
          }
        },
        "required": [
          "service_provider"
        ]
      },
      "BillingResourceType": {
        "type": "object",
        "description": "Describes a resource type and its attributes. Allows admins to create new pricing rules for this type of resource.",
        "properties": {
          "resource_type": {
            "type": "string",
            "description": "Define a type for the resource (for example: instance, storage_account, etc)."
          },
          "attributes": {
            "type": "array",
            "description": "Attributes exposed by the resource. They will be used when defining pricing rules for the resource. For example, an instance might expose attributes such as: vcpus, flavor_name, memory_mb.",
            "items": {
              "$ref": "#/components/schemas/ResourceAttribute"
            }
          }
        }
      },
      "ResourceAttribute": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "description": "The data type of the attribute. Possible types are: string, number, boolean."
          },
          "name": {
            "type": "string",
            "description": "The name of the attribute. This name will be displayed in the price rule editor page as well. Usually, the attributes are named using snake_case strategy."
          },
          "is_usage": {
            "type": "boolean",
            "description": "(optional) A `true` value means the attribute is a counter metric (i.e: traffic_mb) that always grows.On every iteration (hour/minute), the price for this attribute will always be re-calculated based on its new value, instead of being added to the last price like in the usual pay-as-you-grow pricing."
          },
          "values": {
            "type": "array",
            "description": "(optional) A list of possible values for this attribute. The values will be rendered as suggestions to the admins when they add a filter for this attribute in the pricing rule. Example use case: allowing admins to select from a list of existing images when creating an image based pricing rule.",
            "items": {
              "$ref": "#/components/schemas/ResourceAttributeValue"
            }
          }
        }
      },
      "ResourceAttributeValue": {
        "type": "object",
        "properties": {
          "value": {
            "type": "string"
          },
          "display_name": {
            "type": "string"
          }
        }
      }
    },
    "securitySchemes": {
      "SigV4": {
        "type": "apiKey",
        "description": "AWS Signature Version 4 Authentication",
        "name": "Authorization",
        "in": "header",
        "x-amazon-apigateway-authtype": "awsSigv4"
      }
    }
  }
}
