{
  "openapi": "3.1.0",
  "info": {
    "title": "РСНМО — поиск по ИНН",
    "version": "1.0.0",
    "description": "Local, potentially incomplete company data. Authentication is not required in this release. Existing /api_inn.php is unchanged. GET may enqueue background enrichment."
  },
  "servers": [
    {
      "url": "https://www.rsnmo.ru"
    }
  ],
  "paths": {
    "/api/v1/company": {
      "get": {
        "operationId": "getCompanyByInn",
        "summary": "Сведения по ИНН",
        "parameters": [
          {
            "in": "query",
            "name": "inn",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^(?:[0-9]{10}|[0-9]{12})$"
            },
            "description": "INN checksum must be valid; retain leading zeros.",
            "example": "7707329152"
          }
        ],
        "responses": {
          "200": {
            "description": "Local query succeeded; found=false is not proof of official absence.",
            "headers": {
              "X-Request-ID": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Success"
                }
              }
            }
          },
          "400": {
            "description": "Invalid INN",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Failure"
                }
              }
            }
          },
          "405": {
            "description": "GET only",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Failure"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited; Retry-After: 1",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Failure"
                }
              }
            }
          },
          "500": {
            "description": "Internal error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Failure"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Source": {
        "type": "object",
        "required": [
          "source_key",
          "title",
          "lookup_status",
          "returned_records",
          "data_loaded_at",
          "last_successful_import_at",
          "update_status",
          "freshness_threshold_days",
          "coverage_scope"
        ],
        "properties": {
          "source_key": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "lookup_status": {
            "type": "string",
            "enum": [
              "found",
              "no_local_data",
              "not_checked",
              "unavailable"
            ]
          },
          "returned_records": {
            "type": "integer",
            "minimum": 0
          },
          "data_loaded_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "last_successful_import_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "update_status": {
            "type": "string",
            "enum": [
              "fresh",
              "stale",
              "unavailable",
              "unknown"
            ]
          },
          "freshness_threshold_days": {
            "type": [
              "integer",
              "null"
            ]
          },
          "coverage_scope": {
            "type": "string",
            "enum": [
              "per_inn",
              "not_asserted"
            ]
          }
        }
      },
      "Success": {
        "type": "object",
        "required": [
          "api_version",
          "request_id",
          "generated_at",
          "data",
          "meta",
          "error"
        ],
        "properties": {
          "api_version": {
            "const": "1"
          },
          "request_id": {
            "type": "string"
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "error": {
            "type": "null"
          },
          "data": {
            "type": "object",
            "required": [
              "inn",
              "found",
              "identity",
              "finance",
              "procurement",
              "registries"
            ],
            "properties": {
              "inn": {
                "type": "string"
              },
              "found": {
                "type": "boolean"
              },
              "identity": {
                "type": "object",
                "additionalProperties": true
              },
              "finance": {
                "type": "object",
                "additionalProperties": true
              },
              "procurement": {
                "type": "object",
                "additionalProperties": true
              },
              "registries": {
                "type": "object",
                "required": [
                  "items",
                  "groups"
                ],
                "properties": {
                  "items": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "additionalProperties": true
                    }
                  },
                  "groups": {
                    "type": [
                      "object",
                      "array"
                    ]
                  }
                }
              }
            },
            "additionalProperties": true
          },
          "meta": {
            "type": "object",
            "required": [
              "completeness",
              "scope",
              "monitor_generated_at",
              "monitor_status",
              "limitations",
              "list_limits",
              "sources"
            ],
            "properties": {
              "completeness": {
                "const": "partial"
              },
              "scope": {
                "const": "loaded_local_data"
              },
              "monitor_generated_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              },
              "monitor_status": {
                "type": "string",
                "enum": [
                  "current",
                  "unknown"
                ]
              },
              "limitations": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "list_limits": {
                "type": "object",
                "additionalProperties": {
                  "type": "integer"
                }
              },
              "sources": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/Source"
                }
              }
            }
          }
        }
      },
      "Failure": {
        "type": "object",
        "required": [
          "api_version",
          "request_id",
          "data",
          "error"
        ],
        "properties": {
          "api_version": {
            "const": "1"
          },
          "request_id": {
            "type": "string"
          },
          "data": {
            "type": "null"
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}
