{
  "openapi": "3.1.0",
  "info": {
    "title": "Fastening Lab API",
    "version": "1.0.0",
    "description": "Parametric CAD and print coupons for 33 fastening mechanisms. Jobs never start a physical print."
  },
  "servers": [
    {
      "url": "https://fastening.home.mivx.ru"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Service health",
        "responses": {
          "200": {
            "description": "Service name and model count"
          }
        }
      }
    },
    "/api/models": {
      "get": {
        "summary": "Search the catalogue",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "group",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Matching mechanisms"
          }
        }
      }
    },
    "/api/models/{model_id}": {
      "get": {
        "summary": "Mechanism, parameter schema, source and files",
        "parameters": [
          {
            "name": "model_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "hook-slider",
                "fork",
                "dovetail",
                "keyhole",
                "bayonet",
                "turn-tab",
                "wedge",
                "toggle",
                "pin-clip",
                "cantilever",
                "torsion",
                "double-clip",
                "split-pin",
                "push-rivet",
                "annular",
                "c-clip",
                "detent",
                "press-fit",
                "collet",
                "printed-thread",
                "captive-nut",
                "heat-insert",
                "plastic-screw",
                "magnets",
                "kinematic",
                "pin-hinge",
                "print-hinge",
                "ball-joint",
                "living-hinge",
                "heat-rivet",
                "glue-lap",
                "weld",
                "y-zipper"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Mechanism metadata"
          },
          "404": {
            "description": "Unknown model"
          }
        }
      }
    },
    "/api/generate/{model_id}": {
      "post": {
        "summary": "Generate native CAD and viewer meshes",
        "parameters": [
          {
            "name": "model_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "hook-slider",
                "fork",
                "dovetail",
                "keyhole",
                "bayonet",
                "turn-tab",
                "wedge",
                "toggle",
                "pin-clip",
                "cantilever",
                "torsion",
                "double-clip",
                "split-pin",
                "push-rivet",
                "annular",
                "c-clip",
                "detent",
                "press-fit",
                "collet",
                "printed-thread",
                "captive-nut",
                "heat-insert",
                "plastic-screw",
                "magnets",
                "kinematic",
                "pin-hinge",
                "print-hinge",
                "ball-joint",
                "living-hinge",
                "heat-rivet",
                "glue-lap",
                "weld",
                "y-zipper"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "parameters"
                ],
                "properties": {
                  "parameters": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 1000
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "completed",
                        "failed"
                      ]
                    },
                    "jobId": {
                      "type": "string"
                    },
                    "statusUrl": {
                      "type": "string"
                    },
                    "assets": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string"
                    },
                    "model": {
                      "type": "object"
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "202": {
            "description": "Queued or running CAD job",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "completed",
                        "failed"
                      ]
                    },
                    "jobId": {
                      "type": "string"
                    },
                    "statusUrl": {
                      "type": "string"
                    },
                    "assets": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string"
                    },
                    "model": {
                      "type": "object"
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "429": {
            "description": "CAD queue full; respect Retry-After"
          }
        }
      }
    },
    "/api/probe/{model_id}": {
      "post": {
        "summary": "Generate an oriented coupon and Bambu Studio 3MF",
        "parameters": [
          {
            "name": "model_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "hook-slider",
                "fork",
                "dovetail",
                "keyhole",
                "bayonet",
                "turn-tab",
                "wedge",
                "toggle",
                "pin-clip",
                "cantilever",
                "torsion",
                "double-clip",
                "split-pin",
                "push-rivet",
                "annular",
                "c-clip",
                "detent",
                "press-fit",
                "collet",
                "printed-thread",
                "captive-nut",
                "heat-insert",
                "plastic-screw",
                "magnets",
                "kinematic",
                "pin-hinge",
                "print-hinge",
                "ball-joint",
                "living-hinge",
                "heat-rivet",
                "glue-lap",
                "weld",
                "y-zipper"
              ]
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "parameters"
                ],
                "properties": {
                  "parameters": {
                    "type": "object",
                    "additionalProperties": {
                      "type": "number",
                      "minimum": 0,
                      "maximum": 1000
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Completed result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "completed",
                        "failed"
                      ]
                    },
                    "jobId": {
                      "type": "string"
                    },
                    "statusUrl": {
                      "type": "string"
                    },
                    "assets": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string"
                    },
                    "model": {
                      "type": "object"
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "202": {
            "description": "Queued or running CAD job",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "completed",
                        "failed"
                      ]
                    },
                    "jobId": {
                      "type": "string"
                    },
                    "statusUrl": {
                      "type": "string"
                    },
                    "assets": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string"
                    },
                    "model": {
                      "type": "object"
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameters"
          },
          "429": {
            "description": "CAD queue full; respect Retry-After"
          }
        }
      }
    },
    "/api/jobs/{job_id}": {
      "get": {
        "summary": "Poll a CAD job",
        "parameters": [
          {
            "name": "job_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Job state and completed result",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "queued",
                        "running",
                        "completed",
                        "failed"
                      ]
                    },
                    "jobId": {
                      "type": "string"
                    },
                    "statusUrl": {
                      "type": "string"
                    },
                    "assets": {
                      "type": "string"
                    },
                    "url": {
                      "type": "string"
                    },
                    "model": {
                      "type": "object"
                    },
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Unknown job; resubmit original request after a restart"
          }
        }
      }
    }
  }
}
