{
  "openapi": "3.1.0",
  "info": {
    "title": "GearProfile CAD Export API",
    "version": "1.0.0",
    "description": "Programmatic 2D CAD generator for external involute spur gears (Theoretical & ISO 53:1998 A–D basic racks), DIN 1829 Fellow shaper external gears, and internal ring gears. Exports true analytical NURBS SPLINE curves (`type: \"hq\"`) or polygonal geometric-subtraction paths (`type: \"raw\"`) in DXF and SVG formats. Core gear exports allow 20 requests/day per IP without authentication.",
    "contact": {
      "name": "GearProfile",
      "url": "https://gearprofile.app/",
      "email": "info@gearprofile.app"
    }
  },
  "servers": [
    {
      "url": "https://gearprofile.app",
      "description": "Production server"
    }
  ],
  "paths": {
    "/api/export": {
      "post": {
        "operationId": "exportGearProfile",
        "summary": "Generate and export a 2D involute gear CAD profile (SVG or DXF)",
        "description": "Generates a precision 2D gear tooth profile. `external`, `external_fellow`, and `internal` gears using `type=\"raw\"` or `type=\"hq\"` are free up to 20 exports/day per IP (no authentication required). `spline_external`, `spline_internal`, and `type=\"cutter\"` require an authenticated Pro session.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GearExportRequest"
              },
              "examples": {
                "iso53ExternalDxf": {
                  "summary": "24-tooth module 2 ISO 53 Profile A external spur gear (HQ NURBS DXF)",
                  "value": {
                    "gear_type": "external",
                    "rack_profile": "iso53_a",
                    "m": 2.0,
                    "z": 24,
                    "x": 0.0,
                    "type": "hq",
                    "format": "dxf"
                  }
                },
                "internalRingSvg": {
                  "summary": "48-tooth module 1.5 internal ring gear cut by 16-tooth Fellow pinion (HQ SVG)",
                  "value": {
                    "gear_type": "internal",
                    "m": 1.5,
                    "z": 48,
                    "z1": 16,
                    "alpha_deg": 20.0,
                    "type": "hq",
                    "format": "svg"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Generated SVG XML or DXF ASCII text with point count and remaining daily quota",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GearExportResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid parameter format or geometric constraint error (e.g. z1 >= z for internal ring gear)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "403": {
            "description": "Requested feature requires an authenticated Pro membership (ISO 4156 splines or cutter geometry)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "429": {
            "description": "Daily free export quota (20/day) or per-minute rate limit (60/min) exceeded",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "GearExportRequest": {
        "type": "object",
        "properties": {
          "gear_type": {
            "type": "string",
            "enum": ["external", "external_fellow", "internal", "spline_external", "spline_internal"],
            "default": "external",
            "description": "Gear generation method. `external`, `external_fellow`, and `internal` are free; `spline_external` and `spline_internal` require Pro."
          },
          "m": {
            "type": "number",
            "minimum": 0.5,
            "maximum": 10.0,
            "default": 1.0,
            "description": "Metric module in mm (`m = 25.4 / DP` for AGMA Diametral Pitch)."
          },
          "z": {
            "type": "integer",
            "minimum": 5,
            "maximum": 100,
            "default": 15,
            "description": "Number of teeth on the target gear (`z > z1` required for `internal`)."
          },
          "alpha_deg": {
            "type": "number",
            "minimum": 10.0,
            "maximum": 30.0,
            "default": 20.0,
            "description": "Pressure angle in degrees. Locked to 20.0 when `rack_profile` is an ISO 53 A–D standard."
          },
          "ha_coeff": {
            "type": "number",
            "minimum": 0.5,
            "maximum": 1.5,
            "default": 1.0,
            "description": "Addendum height coefficient `ha*` (dimensionless multiple of module)."
          },
          "hf_coeff": {
            "type": "number",
            "minimum": 0.5,
            "maximum": 1.5,
            "default": 1.25,
            "description": "Dedendum depth coefficient `hf*` (dimensionless multiple of module)."
          },
          "x": {
            "type": "number",
            "minimum": -1.5,
            "maximum": 1.5,
            "default": 0.0,
            "description": "Profile shift coefficient `x` (positive prevents undercut on low-tooth pinions)."
          },
          "rack_profile": {
            "type": "string",
            "enum": ["theoretical", "iso53_a", "iso53_b", "iso53_c", "iso53_d"],
            "default": "theoretical",
            "description": "Basic rack cutter standard for `gear_type=\"external\"`."
          },
          "z1": {
            "type": "integer",
            "minimum": 5,
            "maximum": 100,
            "default": 10,
            "description": "Fellow shaper pinion cutter tooth count (used when `gear_type` is `external_fellow` or `internal`)."
          },
          "type": {
            "type": "string",
            "enum": ["raw", "hq", "cutter"],
            "default": "raw",
            "description": "`raw` (boolean subtraction polyline), `hq` (exact NURBS SPLINE / cubic Bezier), or `cutter` (Pro only)."
          },
          "format": {
            "type": "string",
            "enum": ["svg", "dxf"],
            "default": "svg",
            "description": "Output CAD file format."
          }
        }
      },
      "GearExportResponse": {
        "type": "object",
        "required": ["content", "format", "points_raw", "quota_remaining"],
        "properties": {
          "content": {
            "type": "string",
            "description": "Full SVG document or ASCII DXF file content ready to save directly to `.svg` or `.dxf`."
          },
          "format": {
            "type": "string",
            "enum": ["svg", "dxf"]
          },
          "points_raw": {
            "type": "integer",
            "description": "Vertex / control point count in the exported geometry."
          },
          "quota_remaining": {
            "type": "integer",
            "description": "Remaining exports in the current 24-hour window."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string"
          },
          "pro_required": {
            "type": "boolean"
          },
          "quota_exceeded": {
            "type": "boolean"
          },
          "resets_in": {
            "type": "integer",
            "description": "Seconds until quota resets (when `quota_exceeded` is true)."
          }
        }
      }
    }
  }
}
