{
  "components": {
    "schemas": {
      "Error": {
        "properties": {
          "error": {
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "type": "object"
          }
        },
        "type": "object"
      },
      "ShortenResult": {
        "properties": {
          "code": {
            "description": "7-character short code",
            "pattern": "^[0-9A-Za-z]{7}$",
            "type": "string"
          },
          "created": {
            "description": "false if this URL had already been shortened",
            "type": "boolean"
          },
          "short_url": {
            "description": "The short URL to give to the user",
            "format": "uri",
            "type": "string"
          },
          "url": {
            "description": "Normalized destination URL",
            "format": "uri",
            "type": "string"
          }
        },
        "required": [
          "code",
          "short_url",
          "url",
          "created"
        ],
        "type": "object"
      }
    }
  },
  "info": {
    "description": "Create 7-character short URLs. No authentication. The same URL always returns the same short URL. Dangerous URLs (Google Safe Browsing), private addresses and other shorteners are refused.",
    "title": "yk.gy URL shortener",
    "version": "1.0.0"
  },
  "openapi": "3.1.0",
  "paths": {
    "/api/shorten": {
      "get": {
        "description": "Returns a short URL for the given http(s) URL. Call this when the user asks to shorten a link.",
        "operationId": "shortenUrl",
        "parameters": [
          {
            "description": "The http(s) URL to shorten",
            "in": "query",
            "name": "url",
            "required": true,
            "schema": {
              "maxLength": 2048,
              "type": "string"
            }
          },
          {
            "description": "Response format",
            "in": "query",
            "name": "format",
            "required": false,
            "schema": {
              "default": "json",
              "enum": [
                "json",
                "text"
              ],
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShortenResult"
                }
              }
            },
            "description": "Existing short URL for this URL"
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShortenResult"
                }
              }
            },
            "description": "New short URL created"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Invalid or disallowed URL"
          },
          "422": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Flagged as unsafe by Google Safe Browsing"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Rate limited; retry after the Retry-After header"
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Temporarily unavailable (safety check or storage)"
          }
        },
        "summary": "Shorten a URL"
      },
      "post": {
        "operationId": "shortenUrlPost",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "additionalProperties": false,
                "properties": {
                  "url": {
                    "maxLength": 2048,
                    "type": "string"
                  }
                },
                "required": [
                  "url"
                ],
                "type": "object"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShortenResult"
                }
              }
            },
            "description": "Existing short URL for this URL"
          },
          "201": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ShortenResult"
                }
              }
            },
            "description": "New short URL created"
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Invalid or disallowed URL"
          },
          "422": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Flagged as unsafe by Google Safe Browsing"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Rate limited; retry after the Retry-After header"
          },
          "503": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "description": "Temporarily unavailable (safety check or storage)"
          }
        },
        "summary": "Shorten a URL (JSON body)"
      }
    }
  },
  "servers": [
    {
      "url": "https://dev.yk.gy"
    }
  ]
}