{
  "openapi": "3.1.0",
  "info": {
    "title": "Remove One Star review rule check API",
    "version": "1.0.0",
    "summary": "Check review text against Trustpilot's and Google's published rules.",
    "description": "A transparent keyword heuristic, the same code as the review-rule-check package. It names the rule a review may break and the words that matched. It never predicts a decision: Heuristic from removeonestar.com; the platform makes the decision. Free, no key. Nothing is stored and no review text is logged. Rate limits are per IP: 60 check requests a minute (burst 30; a batch costs 1 plus 1 per 10 reviews) and 120 rule requests a minute.",
    "license": {
      "name": "MIT",
      "identifier": "MIT"
    },
    "contact": {
      "name": "Remove One Star",
      "url": "https://www.removeonestar.com/developers"
    }
  },
  "servers": [
    {
      "url": "https://www.removeonestar.com/api/v1"
    }
  ],
  "externalDocs": {
    "description": "Developer docs",
    "url": "https://www.removeonestar.com/developers"
  },
  "paths": {
    "/check": {
      "post": {
        "operationId": "checkReviews",
        "summary": "Check one review or up to 50",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "oneOf": [
                  {
                    "type": "object",
                    "required": [
                      "platform",
                      "text"
                    ],
                    "properties": {
                      "platform": {
                        "type": "string",
                        "enum": [
                          "trustpilot",
                          "google"
                        ]
                      },
                      "text": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 5000
                      }
                    }
                  },
                  {
                    "type": "object",
                    "required": [
                      "platform",
                      "reviews"
                    ],
                    "properties": {
                      "platform": {
                        "type": "string",
                        "enum": [
                          "trustpilot",
                          "google"
                        ]
                      },
                      "reviews": {
                        "type": "array",
                        "minItems": 1,
                        "maxItems": 50,
                        "items": {
                          "oneOf": [
                            {
                              "type": "string",
                              "maxLength": 5000
                            },
                            {
                              "type": "object",
                              "required": [
                                "text"
                              ],
                              "properties": {
                                "text": {
                                  "type": "string",
                                  "maxLength": 5000
                                },
                                "stars": {
                                  "type": "integer",
                                  "minimum": 1,
                                  "maximum": 5
                                }
                              }
                            }
                          ]
                        }
                      }
                    }
                  }
                ]
              },
              "examples": {
                "one": {
                  "value": {
                    "platform": "trustpilot",
                    "text": "Use code SAVE20 at the other shop."
                  }
                },
                "many": {
                  "value": {
                    "platform": "google",
                    "reviews": [
                      "Call me on 555-0142 for a better deal.",
                      {
                        "text": "Friendly staff.",
                        "stars": 5
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "For text: one result. For reviews: the results and the totals.",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "allOf": [
                        {
                          "$ref": "#/components/schemas/Result"
                        },
                        {
                          "type": "object",
                          "properties": {
                            "note": {
                              "type": "string"
                            }
                          }
                        }
                      ]
                    },
                    {
                      "type": "object",
                      "properties": {
                        "platform": {
                          "type": "string",
                          "enum": [
                            "trustpilot",
                            "google"
                          ]
                        },
                        "results": {
                          "type": "array",
                          "items": {
                            "$ref": "#/components/schemas/Result"
                          }
                        },
                        "totals": {
                          "type": "object",
                          "properties": {
                            "worth-flagging": {
                              "type": "integer"
                            },
                            "needs-human": {
                              "type": "integer"
                            },
                            "likely-stays": {
                              "type": "integer"
                            }
                          }
                        },
                        "note": {
                          "type": "string"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "Too large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Retry-After says when to try again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/rules": {
      "get": {
        "operationId": "listRules",
        "summary": "List the rules",
        "parameters": [
          {
            "name": "platform",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "trustpilot",
                "google"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The rules",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "platform": {
                      "type": "string"
                    },
                    "count": {
                      "type": "integer"
                    },
                    "rules": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Rule"
                      }
                    },
                    "note": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited. Retry-After says when to try again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Rule": {
        "type": "object",
        "required": [
          "id",
          "key",
          "platform",
          "name",
          "policy",
          "quote",
          "sourceTitle",
          "sourceUrl",
          "verified",
          "pageUrl"
        ],
        "properties": {
          "id": {
            "type": "string",
            "examples": [
              "trustpilot-advertising"
            ]
          },
          "key": {
            "type": "string",
            "examples": [
              "advertising"
            ]
          },
          "platform": {
            "type": "string",
            "enum": [
              "trustpilot",
              "google"
            ]
          },
          "name": {
            "type": "string"
          },
          "policy": {
            "type": "string",
            "description": "The rule in plain words."
          },
          "quote": {
            "type": "string",
            "description": "A short quote from the platform's own page."
          },
          "sourceTitle": {
            "type": "string"
          },
          "sourceUrl": {
            "type": "string",
            "format": "uri"
          },
          "verified": {
            "type": "string",
            "format": "date",
            "description": "The day the quote was checked against the live page."
          },
          "pageUrl": {
            "type": "string",
            "format": "uri",
            "description": "The removeonestar.com page that explains the rule."
          }
        }
      },
      "Match": {
        "type": "object",
        "properties": {
          "signal": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "rule": {
            "type": "string"
          },
          "ruleId": {
            "type": "string"
          },
          "strength": {
            "type": "string",
            "enum": [
              "strong",
              "weak"
            ]
          },
          "text": {
            "type": "string",
            "description": "The words in the review that matched."
          }
        }
      },
      "Result": {
        "type": "object",
        "properties": {
          "platform": {
            "type": "string",
            "enum": [
              "trustpilot",
              "google"
            ]
          },
          "verdict": {
            "type": "string",
            "enum": [
              "worth-flagging",
              "needs-human",
              "likely-stays"
            ]
          },
          "matches": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Match"
            }
          },
          "rules": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Rule"
            }
          },
          "stars": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          },
          "note": {
            "type": "string"
          }
        }
      }
    }
  }
}
