Skip to content

Commit

Permalink
API spec
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Sep 16, 2024
1 parent aa9ab18 commit 5d012bc
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 211 deletions.
49 changes: 31 additions & 18 deletions batch/apispec.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,18 @@ private function resolve_common_schema($name) {
"description" => "Submission ID",
"minimum" => 1
];
$this->setj_schemas->$name = true;
} else if ($name === "rid") {
$this->schemas->$name = (object) [
"type" => "integer",
"description" => "Review ID"
];
} else if ($name === "ok") {
return (object) ["type" => "boolean"];
} else if ($name === "message_list") {
$this->schemas->$name = (object) [
"type" => "list",
"items" => $this->resolve_common_schema("message")
];
$this->setj_schemas->$name = true;
} else if ($name === "message") {
$this->schemas->$name = (object) [
"type" => "object",
Expand All @@ -309,7 +312,6 @@ private function resolve_common_schema($name) {
"pos2" => (object) ["type" => "integer"]
]
];
$this->setj_schemas->$name = true;
} else if ($name === "minimal_response") {
$this->schemas->$name = (object) [
"type" => "object",
Expand All @@ -319,7 +321,6 @@ private function resolve_common_schema($name) {
"message_list" => $this->resolve_common_schema("message_list")
]
];
$this->setj_schemas->$name = true;
} else if ($name === "error_response") {
$this->schemas->$name = (object) [
"type" => "object",
Expand All @@ -330,10 +331,10 @@ private function resolve_common_schema($name) {
"status_code" => (object) ["type" => "integer"]
]
];
$this->setj_schemas->$name = true;
} else {
assert(false);
}
$this->setj_schemas->$name = true;
}
return (object) ["\$ref" => "#/components/schemas/{$name}"];
}
Expand All @@ -345,34 +346,40 @@ private function resolve_common_param($name) {
$compj = $this->j->components = $this->j->components ?? (object) [];
$this->parameters = $compj->parameters = $compj->parameters ?? (object) [];
}
if (!isset($this->parameters->$name)) {
if (!isset($this->parameters->$name)
|| ($this->override_schema && !isset($this->setj_parameters->$name))) {
if ($name === "p.path") {
$this->parameters->{"p.path"} = (object) [
$this->parameters->$name = (object) [
"name" => "p",
"in" => "path",
"required" => true,
"schema" => $this->resolve_common_schema("pid")
];
$this->setj_parameters->{"p.path"} = true;
} else if ($name === "p") {
$this->parameters->p = (object) [
} else if ($name === "p" || $name === "p.opt") {
$this->parameters->$name = (object) [
"name" => "p",
"in" => "query",
"required" => false,
"required" => $name === "p",
"schema" => $this->resolve_common_schema("pid")
];
$this->setj_parameters->p = true;
} else if ($name === "r" || $name === "r.opt") {
$this->parameters->$name = (object) [
"name" => "r",
"in" => "query",
"required" => $name === "r",
"schema" => $this->resolve_common_schema("rid")
];
} else if ($name === "redirect") {
$this->parameters->redirect = (object) [
$this->parameters->$name = (object) [
"name" => "redirect",
"in" => "query",
"required" => false,
"schema" => (object) ["type" => "string"]
];
$this->setj_parameters->redirect = true;
} else {
assert(false);
}
$this->setj_parameters->$name = true;
}
return (object) ["\$ref" => "#/components/parameters/{$name}"];
}
Expand All @@ -387,10 +394,16 @@ private function expand_request($x, $known, $uf, $path) {
foreach ($known as $name => $f) {
if ($name === "*") {
// skip
} else if ($name === "p" && $f === (self::F_REQUIRED | self::F_PATH)) {
$params["p"] = $this->resolve_common_param("p.path");
} else if ($name === "p") {
$params["p"] = $this->resolve_common_param("p");
if ($f === (self::F_REQUIRED | self::F_PATH)) {
$pn = "p.path";
} else {
$pn = $f & self::F_REQUIRED ? "p" : "p.opt";
}
$params["p"] = $this->resolve_common_param($pn);
} else if ($name === "r") {
$pn = $f & self::F_REQUIRED ? "r" : "r.opt";
$params["r"] = $this->resolve_common_param($pn);
} else if ($name === "redirect" && $f === 0) {
$params["redirect"] = $this->resolve_common_param("redirect");
} else if (($f & (self::F_BODY | self::F_FILE)) === 0) {
Expand Down Expand Up @@ -419,7 +432,7 @@ private function expand_request($x, $known, $uf, $path) {
if (isset($pj->name) && is_string($pj->name)) {
$xparams[$pj->name] = $i;
} else if (isset($pj->{"\$ref"}) && is_string($pj->{"\$ref"})
&& preg_match('/\A\#\/components\/parameters\/([^+]*)/', $pj->{"\$ref"}, $m)) {
&& preg_match('/\A\#\/components\/parameters\/([^.]*)/', $pj->{"\$ref"}, $m)) {
$xparams[$m[1]] = $i;
}
}
Expand Down
Loading

0 comments on commit 5d012bc

Please sign in to comment.