openapi: "3.0.3"
info:
  title: "Subscription billing API"
  version: "1.0.0"
  description: "The plan code is a natural primary key, so the generator has to reuse the same code across subscriptions and invoices. A subscription in the past_due state still has a renews_at timestamp in the future, which surprises people. The invoice amount is constrained to be non-negative and the paid flag is an integer. This three-table shape is the smallest one where a single-schema generator starts producing dangling references."
paths: {}
x-domain-id: "alt_billing"
x-dialect: "postgres"
components:
  schemas:
    plans:
      type: "object"
      x-primary-key: "code"
      required: ["code", "price_cents", "interval"]
      properties:
        code:
          type: "string"
        price_cents:
          type: "integer"
          minimum: 0
        interval:
          type: "string"
          enum: ["month", "year"]
    subscriptions:
      type: "object"
      x-primary-key: "id"
      required: ["id", "plan_code", "status", "renews_at"]
      properties:
        id:
          type: "string"
          format: "uuid"
        plan_code:
          $ref: "#/components/schemas/plans"
        status:
          type: "string"
          enum: ["trialing", "active", "past_due", "canceled"]
        renews_at:
          type: "string"
          format: "date-time"
    invoices:
      type: "object"
      x-primary-key: "id"
      required: ["id", "subscription_id", "amount_cents", "paid"]
      properties:
        id:
          type: "string"
          format: "uuid"
        subscription_id:
          $ref: "#/components/schemas/subscriptions"
        amount_cents:
          type: "integer"
          minimum: 0
        paid:
          type: "integer"
          minimum: 0
          maximum: 1
