{
  "openapi": "3.1.0",
  "info": {
    "title": "NWT API Reference",
    "version": "1.0.0",
    "summary": "Same-origin interactive API reference for the NWT public demo.",
    "description": "Public Scalar API demo backed by a same-origin Worker. All records are fictional, authentication is not enforced, and write operations simulate responses without persisting state."
  },
  "servers": [
    {
      "url": "/",
      "description": "Same-origin demo server"
    }
  ],
  "tags": [
    {
      "name": "Companies",
      "description": "Browse and simulate company profile operations."
    },
    {
      "name": "Events",
      "description": "Inspect simulated company activity events."
    },
    {
      "name": "Imports",
      "description": "Simulate batch company imports via JSON, multipart upload, or form data."
    }
  ],
  "security": [
    {},
    {
      "bearerAuth": []
    },
    {
      "apiKeyAuth": []
    }
  ],
  "paths": {
    "/api/companies": {
      "get": {
        "tags": ["Companies"],
        "summary": "List companies",
        "description": "Returns fictional companies filtered by optional sector, country, and search query.",
        "operationId": "listCompanies",
        "security": [
          {},
          {
            "bearerAuth": []
          },
          {
            "apiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of companies to return (1-100).",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "example": 10
          },
          {
            "name": "sector",
            "in": "query",
            "description": "Case-insensitive exact sector filter.",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "Biotechnology"
          },
          {
            "name": "country",
            "in": "query",
            "description": "Case-insensitive 2-letter country code filter.",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 2,
              "maxLength": 2
            },
            "example": "US"
          },
          {
            "name": "q",
            "in": "query",
            "description": "Case-insensitive substring matched against id, name, sector, and description.",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "acme"
          }
        ],
        "responses": {
          "200": {
            "description": "Matching fictional companies.",
            "headers": {
              "Cache-Control": {
                "description": "Caching directive.",
                "schema": {
                  "type": "string",
                  "example": "no-store"
                }
              },
              "X-Content-Type-Options": {
                "description": "MIME-sniffing protection header.",
                "schema": {
                  "type": "string",
                  "example": "nosniff"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CompanyListResponse"
                },
                "examples": {
                  "all": {
                    "summary": "Full demo dataset",
                    "value": {
                      "data": [
                        {
                          "id": "acme-research",
                          "name": "Acme Research",
                          "sector": "Biotechnology",
                          "country": "US",
                          "website": "https://acme-research.example",
                          "employeeCount": 142,
                          "description": "Fictional laboratory automation and assay modeling demo company."
                        },
                        {
                          "id": "atlas-systems",
                          "name": "Atlas Systems",
                          "sector": "Infrastructure",
                          "country": "DE",
                          "website": "https://atlas-systems.example",
                          "employeeCount": 310,
                          "description": "Fictional distributed telemetry and industrial edge software demo company."
                        }
                      ],
                      "total": 2
                    }
                  },
                  "filtered": {
                    "summary": "Filtered by sector=Biotechnology&country=US&q=acme",
                    "value": {
                      "data": [
                        {
                          "id": "acme-research",
                          "name": "Acme Research",
                          "sector": "Biotechnology",
                          "country": "US",
                          "website": "https://acme-research.example",
                          "employeeCount": 142,
                          "description": "Fictional laboratory automation and assay modeling demo company."
                        }
                      ],
                      "total": 1
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        },
        "x-codeSamples": [
          {
            "lang": "curl",
            "label": "cURL",
            "source": "curl -s \"/api/companies?sector=Biotechnology&limit=10\""
          },
          {
            "lang": "javascript",
            "label": "JavaScript",
            "source": "const res = await fetch(\"/api/companies?sector=Biotechnology&limit=10\");\nconst payload = await res.json();"
          }
        ]
      },
      "post": {
        "tags": ["Companies"],
        "summary": "Create a company (simulated)",
        "description": "Validates and simulates creating a company record without persisting state.",
        "operationId": "createCompany",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompanyCreateInput"
              },
              "examples": {
                "nova": {
                  "summary": "Create Nova Biotech",
                  "value": {
                    "name": "Nova Biotech",
                    "sector": "Biotechnology",
                    "country": "US",
                    "website": "https://nova-biotech.example",
                    "employeeCount": 85,
                    "description": "Simulated genomics workflow demo company."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Simulated company created.",
            "headers": {
              "Cache-Control": {
                "description": "Caching directive.",
                "schema": {
                  "type": "string",
                  "example": "no-store"
                }
              },
              "X-Content-Type-Options": {
                "description": "MIME-sniffing protection header.",
                "schema": {
                  "type": "string",
                  "example": "nosniff"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Company"
                },
                "examples": {
                  "created": {
                    "summary": "Simulated created response",
                    "value": {
                      "id": "nova-biotech",
                      "name": "Nova Biotech",
                      "sector": "Biotechnology",
                      "country": "US",
                      "website": "https://nova-biotech.example",
                      "employeeCount": 85,
                      "description": "Simulated genomics workflow demo company."
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "413": {
            "$ref": "#/components/responses/PayloadTooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMediaType"
          }
        },
        "x-codeSamples": [
          {
            "lang": "curl",
            "label": "cURL",
            "source": "curl -s -X POST \"/api/companies\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"name\":\"Nova Biotech\",\"sector\":\"Biotechnology\",\"country\":\"US\"}'"
          },
          {
            "lang": "javascript",
            "label": "JavaScript",
            "source": "const res = await fetch(\"/api/companies\", {\n  method: \"POST\",\n  headers: { \"Content-Type\": \"application/json\" },\n  body: JSON.stringify({ name: \"Nova Biotech\", sector: \"Biotechnology\", country: \"US\" })\n});\nconst created = await res.json();"
          }
        ]
      }
    },
    "/api/companies/{id}": {
      "parameters": [
        {
          "name": "id",
          "in": "path",
          "required": true,
          "description": "Company slug identifier.",
          "schema": {
            "type": "string"
          },
          "examples": {
            "acme": {
              "summary": "Acme Research",
              "value": "acme-research"
            },
            "atlas": {
              "summary": "Atlas Systems",
              "value": "atlas-systems"
            }
          }
        }
      ],
      "get": {
        "tags": ["Companies"],
        "summary": "Get a company",
        "description": "Retrieves a single fictional company by its id.",
        "operationId": "getCompany",
        "responses": {
          "200": {
            "description": "Company found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Company"
                },
                "examples": {
                  "acme": {
                    "summary": "Acme Research",
                    "value": {
                      "id": "acme-research",
                      "name": "Acme Research",
                      "sector": "Biotechnology",
                      "country": "US",
                      "website": "https://acme-research.example",
                      "employeeCount": 142,
                      "description": "Fictional laboratory automation and assay modeling demo company."
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": ["Companies"],
        "summary": "Replace a company (simulated)",
        "description": "Simulates replacing a company record without persisting changes.",
        "operationId": "replaceCompany",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompanyCreateInput"
              },
              "examples": {
                "replaceAcme": {
                  "summary": "Replace Acme Research",
                  "value": {
                    "name": "Acme Research Labs",
                    "sector": "Biotechnology",
                    "country": "US",
                    "website": "https://acme-research.example",
                    "employeeCount": 160,
                    "description": "Replaced simulated company profile."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Simulated company replaced.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Company"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "413": {
            "$ref": "#/components/responses/PayloadTooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMediaType"
          }
        }
      },
      "patch": {
        "tags": ["Companies"],
        "summary": "Update a company (simulated)",
        "description": "Simulates a partial update of a company record without persisting changes.",
        "operationId": "updateCompany",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompanyPatchInput"
              },
              "examples": {
                "updateDetails": {
                  "summary": "Update employeeCount and description",
                  "value": {
                    "employeeCount": 155,
                    "description": "Updated in simulated demo mode."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Simulated company updated.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Company"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "413": {
            "$ref": "#/components/responses/PayloadTooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMediaType"
          }
        }
      },
      "delete": {
        "tags": ["Companies"],
        "summary": "Delete a company (simulated)",
        "description": "Simulates deleting a company record without persisting changes.",
        "operationId": "deleteCompany",
        "responses": {
          "204": {
            "description": "Simulated company deleted.",
            "headers": {
              "Cache-Control": {
                "description": "Caching directive.",
                "schema": {
                  "type": "string",
                  "example": "no-store"
                }
              },
              "X-Content-Type-Options": {
                "description": "MIME-sniffing protection header.",
                "schema": {
                  "type": "string",
                  "example": "nosniff"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/api/events": {
      "get": {
        "tags": ["Events"],
        "summary": "List company events",
        "description": "Returns simulated company events, optionally filtered by companyId and type.",
        "operationId": "listEvents",
        "parameters": [
          {
            "name": "companyId",
            "in": "query",
            "description": "Filter events by exact company id.",
            "required": false,
            "schema": {
              "type": "string"
            },
            "example": "acme-research"
          },
          {
            "name": "type",
            "in": "query",
            "description": "Case-insensitive event type filter.",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/EventType"
            },
            "example": "funding"
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of events to return (1-100).",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            },
            "example": 10
          }
        ],
        "responses": {
          "200": {
            "description": "Matching simulated events.",
            "headers": {
              "Cache-Control": {
                "description": "Caching directive.",
                "schema": {
                  "type": "string",
                  "example": "no-store"
                }
              },
              "X-Content-Type-Options": {
                "description": "MIME-sniffing protection header.",
                "schema": {
                  "type": "string",
                  "example": "nosniff"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventListResponse"
                },
                "examples": {
                  "funding": {
                    "summary": "Filtered by companyId=acme-research&type=funding",
                    "value": {
                      "data": [
                        {
                          "id": "evt-1001",
                          "companyId": "acme-research",
                          "type": "funding",
                          "title": "Simulated Series B milestone recorded",
                          "occurredAt": "2026-09-14T10:30:00Z"
                        }
                      ],
                      "total": 1
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          }
        },
        "x-codeSamples": [
          {
            "lang": "curl",
            "label": "cURL",
            "source": "curl -s \"/api/events?companyId=acme-research&type=funding&limit=10\""
          },
          {
            "lang": "javascript",
            "label": "JavaScript",
            "source": "const res = await fetch(\"/api/events?companyId=acme-research&type=funding&limit=10\");\nconst payload = await res.json();"
          }
        ]
      }
    },
    "/api/imports": {
      "post": {
        "tags": ["Imports"],
        "summary": "Upload company import (simulated)",
        "description": "Simulates a batch import using JSON, multipart/form-data, or application/x-www-form-urlencoded. Maximum payload size is 256 KiB; no data is persisted.",
        "operationId": "importCompanies",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "companies": {
                    "type": "array",
                    "items": {
                      "$ref": "#/components/schemas/CompanyCreateInput"
                    }
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": true
                  }
                }
              },
              "examples": {
                "jsonBatch": {
                  "summary": "JSON batch import",
                  "value": {
                    "companies": [
                      {
                        "name": "Nova Biotech",
                        "sector": "Biotechnology",
                        "country": "US"
                      }
                    ],
                    "dryRun": true
                  }
                }
              }
            },
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": ["file"],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "CSV or JSON dataset file."
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": true,
                    "description": "Validate records without applying changes."
                  }
                }
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": ["source"],
                "properties": {
                  "source": {
                    "type": "string",
                    "example": "https://example.invalid/companies.csv",
                    "description": "Dataset reference or inline payload."
                  },
                  "dryRun": {
                    "type": "boolean",
                    "default": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Simulated import accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ImportResult"
                },
                "examples": {
                  "accepted": {
                    "summary": "Simulated accepted import",
                    "value": {
                      "jobId": "imp-sim-0001",
                      "status": "accepted",
                      "simulated": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "413": {
            "$ref": "#/components/responses/PayloadTooLarge"
          },
          "415": {
            "$ref": "#/components/responses/UnsupportedMediaType"
          }
        },
        "x-codeSamples": [
          {
            "lang": "curl",
            "label": "cURL",
            "source": "curl -s -X POST \"/api/imports\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\"companies\":[{\"name\":\"Nova Biotech\",\"sector\":\"Biotechnology\",\"country\":\"US\"}],\"dryRun\":true}'"
          },
          {
            "lang": "javascript",
            "label": "JavaScript",
            "source": "const res = await fetch(\"/api/imports\", {\n  method: \"POST\",\n  headers: { \"Content-Type\": \"application/json\" },\n  body: JSON.stringify({ companies: [{ name: \"Nova Biotech\", sector: \"Biotechnology\", country: \"US\" }], dryRun: true })\n});\nconst job = await res.json();"
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "Optional pretend bearer token for demo UI controls only. Never enter real credentials (e.g. demo-token-123)."
      },
      "apiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-Demo-Api-Key",
        "description": "Optional pretend API key header for demo UI controls only. Never enter real credentials (e.g. demo-key-456)."
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid query parameter, malformed JSON, or validation error.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "examples": {
              "invalidQuery": {
                "summary": "Invalid limit query parameter",
                "value": {
                  "error": {
                    "code": "INVALID_QUERY",
                    "message": "Query parameter \"limit\" must be between 1 and 100."
                  }
                }
              },
              "validationError": {
                "summary": "Missing required name",
                "value": {
                  "error": {
                    "code": "VALIDATION_ERROR",
                    "message": "Field \"name\" is required and must be a non-empty string."
                  }
                }
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Requested resource was not found.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "error": {
                "code": "NOT_FOUND",
                "message": "Company not found."
              }
            }
          }
        }
      },
      "PayloadTooLarge": {
        "description": "Request body exceeds the endpoint size limit.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "error": {
                "code": "PAYLOAD_TOO_LARGE",
                "message": "Request body exceeds 65536 bytes."
              }
            }
          }
        }
      },
      "UnsupportedMediaType": {
        "description": "Unsupported Content-Type header.",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            },
            "example": {
              "error": {
                "code": "UNSUPPORTED_MEDIA_TYPE",
                "message": "Content-Type must be application/json."
              }
            }
          }
        }
      }
    },
    "schemas": {
      "EventType": {
        "type": "string",
        "enum": ["funding", "product", "partnership", "hiring"]
      },
      "Company": {
        "type": "object",
        "required": ["id", "name", "sector", "country", "website", "employeeCount", "description"],
        "properties": {
          "id": {
            "type": "string",
            "example": "acme-research"
          },
          "name": {
            "type": "string",
            "example": "Acme Research"
          },
          "sector": {
            "type": "string",
            "example": "Biotechnology"
          },
          "country": {
            "type": "string",
            "minLength": 2,
            "maxLength": 2,
            "example": "US"
          },
          "website": {
            "type": "string",
            "format": "uri",
            "example": "https://acme-research.example"
          },
          "employeeCount": {
            "type": "integer",
            "minimum": 0,
            "example": 142
          },
          "description": {
            "type": "string",
            "example": "Fictional laboratory automation and assay modeling demo company."
          }
        }
      },
      "CompanyCreateInput": {
        "type": "object",
        "required": ["name"],
        "properties": {
          "name": {
            "type": "string",
            "example": "Nova Biotech"
          },
          "sector": {
            "type": "string",
            "default": "General",
            "example": "Biotechnology"
          },
          "country": {
            "type": "string",
            "minLength": 2,
            "maxLength": 2,
            "default": "US",
            "example": "US"
          },
          "website": {
            "type": "string",
            "format": "uri",
            "default": "https://example.invalid",
            "example": "https://nova-biotech.example"
          },
          "employeeCount": {
            "type": "integer",
            "minimum": 0,
            "default": 1,
            "example": 85
          },
          "description": {
            "type": "string",
            "default": "Simulated company record (not persisted).",
            "example": "Simulated genomics workflow demo company."
          }
        }
      },
      "CompanyPatchInput": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "sector": {
            "type": "string"
          },
          "country": {
            "type": "string",
            "minLength": 2,
            "maxLength": 2
          },
          "website": {
            "type": "string",
            "format": "uri"
          },
          "employeeCount": {
            "type": "integer",
            "minimum": 0
          },
          "description": {
            "type": "string"
          }
        }
      },
      "CompanyListResponse": {
        "type": "object",
        "required": ["data", "total"],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Company"
            }
          },
          "total": {
            "type": "integer",
            "example": 2
          }
        }
      },
      "Event": {
        "type": "object",
        "required": ["id", "companyId", "type", "title", "occurredAt"],
        "properties": {
          "id": {
            "type": "string",
            "example": "evt-1001"
          },
          "companyId": {
            "type": "string",
            "example": "acme-research"
          },
          "type": {
            "$ref": "#/components/schemas/EventType"
          },
          "title": {
            "type": "string",
            "example": "Simulated Series B milestone recorded"
          },
          "occurredAt": {
            "type": "string",
            "format": "date-time",
            "example": "2026-09-14T10:30:00Z"
          }
        }
      },
      "EventListResponse": {
        "type": "object",
        "required": ["data", "total"],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Event"
            }
          },
          "total": {
            "type": "integer",
            "example": 4
          }
        }
      },
      "ImportResult": {
        "type": "object",
        "required": ["jobId", "status", "simulated"],
        "properties": {
          "jobId": {
            "type": "string",
            "example": "imp-sim-0001"
          },
          "status": {
            "type": "string",
            "enum": ["accepted"],
            "example": "accepted"
          },
          "simulated": {
            "type": "boolean",
            "example": true
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "object",
            "required": ["code", "message"],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
