add(codegen): docs codegen for all
This commit is contained in:
@@ -52,6 +52,7 @@ if (getenv("DEBUG") === "true") {
|
||||
$api_files = glob($project . "/docs/src/spec/*.json");
|
||||
$apis = array_map(function($filename) {
|
||||
$api = array_change_key_case_recursive(json_decode(file_get_contents($filename), true));
|
||||
$api['entrypoint'] = strtolower($api['interface']);
|
||||
if (empty($api['parameters'])) {
|
||||
$api['parameters'] = array();
|
||||
}
|
||||
@@ -71,7 +72,7 @@ $apis = array_map(function($filename) {
|
||||
}, $api_files);
|
||||
|
||||
usort($apis, function($a, $b) {
|
||||
return strcmp($a['interface'], $b['interface']);
|
||||
return strcmp($a['entrypoint'], $b['entrypoint']);
|
||||
});
|
||||
|
||||
$parsers = array(
|
||||
|
||||
43
codegen/crm/docs/index.php
Normal file
43
codegen/crm/docs/index.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
$cleanUp = function($contents) {
|
||||
$lines = array_map("trim", explode("\n", $contents));
|
||||
$empty = true;
|
||||
foreach ($lines as $k => $v) {
|
||||
if ($v === "") {
|
||||
if ($empty) {
|
||||
unset($lines[$k]);
|
||||
}
|
||||
$empty = true;
|
||||
continue;
|
||||
}
|
||||
$empty = false;
|
||||
}
|
||||
$contents = implode("\n", $lines);
|
||||
$contents = str_replace("`\n|", "` |", $contents);
|
||||
$contents = preg_replace("/^# /sm", "\n\n\n# ", $contents);
|
||||
return trim($contents);
|
||||
};
|
||||
|
||||
foreach ($apis as $k => $api) {
|
||||
$entrypoint = $api['entrypoint'];
|
||||
$filename_md = $dirname . "/src/" . $entrypoint . "/index.md";
|
||||
if (file_exists($filename_md)) {
|
||||
$api['description'] = file_get_contents($filename_md);
|
||||
}
|
||||
|
||||
foreach ($api['apis'] as $key => $call) {
|
||||
$name = $call['name'];
|
||||
$filename_md = $dirname . "/src/" . $entrypoint . "/" . $name . ".md";
|
||||
if (file_exists($filename_md)) {
|
||||
$call['description'] = file_get_contents($filename_md);
|
||||
}
|
||||
$api['apis'][$key] = $call;
|
||||
}
|
||||
|
||||
$apis[$k] = $api;
|
||||
}
|
||||
|
||||
$tpl->load("README.tpl");
|
||||
$tpl->assign("apis", $apis);
|
||||
file_put_contents($dirname . "/README.md", $cleanUp($tpl->get()));
|
||||
43
codegen/sam/docs/index.php
Normal file
43
codegen/sam/docs/index.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
$cleanUp = function($contents) {
|
||||
$lines = array_map("trim", explode("\n", $contents));
|
||||
$empty = true;
|
||||
foreach ($lines as $k => $v) {
|
||||
if ($v === "") {
|
||||
if ($empty) {
|
||||
unset($lines[$k]);
|
||||
}
|
||||
$empty = true;
|
||||
continue;
|
||||
}
|
||||
$empty = false;
|
||||
}
|
||||
$contents = implode("\n", $lines);
|
||||
$contents = str_replace("`\n|", "` |", $contents);
|
||||
$contents = preg_replace("/^# /sm", "\n\n\n# ", $contents);
|
||||
return trim($contents);
|
||||
};
|
||||
|
||||
foreach ($apis as $k => $api) {
|
||||
$entrypoint = $api['entrypoint'];
|
||||
$filename_md = $dirname . "/src/" . $entrypoint . "/index.md";
|
||||
if (file_exists($filename_md)) {
|
||||
$api['description'] = file_get_contents($filename_md);
|
||||
}
|
||||
|
||||
foreach ($api['apis'] as $key => $call) {
|
||||
$name = $call['name'];
|
||||
$filename_md = $dirname . "/src/" . $entrypoint . "/" . $name . ".md";
|
||||
if (file_exists($filename_md)) {
|
||||
$call['description'] = file_get_contents($filename_md);
|
||||
}
|
||||
$api['apis'][$key] = $call;
|
||||
}
|
||||
|
||||
$apis[$k] = $api;
|
||||
}
|
||||
|
||||
$tpl->load("README.tpl");
|
||||
$tpl->assign("apis", $apis);
|
||||
file_put_contents($dirname . "/README.md", $cleanUp($tpl->get()));
|
||||
43
codegen/system/docs/index.php
Normal file
43
codegen/system/docs/index.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
$cleanUp = function($contents) {
|
||||
$lines = array_map("trim", explode("\n", $contents));
|
||||
$empty = true;
|
||||
foreach ($lines as $k => $v) {
|
||||
if ($v === "") {
|
||||
if ($empty) {
|
||||
unset($lines[$k]);
|
||||
}
|
||||
$empty = true;
|
||||
continue;
|
||||
}
|
||||
$empty = false;
|
||||
}
|
||||
$contents = implode("\n", $lines);
|
||||
$contents = str_replace("`\n|", "` |", $contents);
|
||||
$contents = preg_replace("/^# /sm", "\n\n\n# ", $contents);
|
||||
return trim($contents);
|
||||
};
|
||||
|
||||
foreach ($apis as $k => $api) {
|
||||
$entrypoint = $api['entrypoint'];
|
||||
$filename_md = $dirname . "/src/" . $entrypoint . "/index.md";
|
||||
if (file_exists($filename_md)) {
|
||||
$api['description'] = file_get_contents($filename_md);
|
||||
}
|
||||
|
||||
foreach ($api['apis'] as $key => $call) {
|
||||
$name = $call['name'];
|
||||
$filename_md = $dirname . "/src/" . $entrypoint . "/" . $name . ".md";
|
||||
if (file_exists($filename_md)) {
|
||||
$call['description'] = file_get_contents($filename_md);
|
||||
}
|
||||
$api['apis'][$key] = $call;
|
||||
}
|
||||
|
||||
$apis[$k] = $api;
|
||||
}
|
||||
|
||||
$tpl->load("README.tpl");
|
||||
$tpl->assign("apis", $apis);
|
||||
file_put_contents($dirname . "/README.md", $cleanUp($tpl->get()));
|
||||
31
codegen/templates/README.tpl
Normal file
31
codegen/templates/README.tpl
Normal file
@@ -0,0 +1,31 @@
|
||||
{foreach $apis as $api}
|
||||
# {api.title}
|
||||
|
||||
{api.description}
|
||||
|
||||
{foreach $api.apis as $name => $call}
|
||||
## {call.title}
|
||||
|
||||
{call.description}
|
||||
|
||||
#### Method
|
||||
|
||||
| URI | Protocol | Method | Authentication |
|
||||
| --- | -------- | ------ | -------------- |
|
||||
| `{api.path}{call.path}` | {if $api.protocol}{api.protocol}{else}HTTP/S{/if} | {call.method} | {eval echo implode(", ", $api.authentication)} |
|
||||
|
||||
#### Request parameters
|
||||
|
||||
| Parameter | Type | Method | Description | Default | Required? |
|
||||
| --------- | ---- | ------ | ----------- | ------- | --------- |
|
||||
{foreach $call.parameters as $method => $params}
|
||||
{foreach $params as $param}
|
||||
| {param.name} | {param.type} | {method|toupper} | {param.title} | {if empty($param.default)}N/A{else}{param.default}{/if}
|
||||
{if $param.values}<br><br>Values:<br><br><ul>{foreach $param.values as $value}<li>`{value}`</li>{/foreach}{/if} | {if $param.required}YES{else}NO{/if} |
|
||||
{/foreach}
|
||||
{/foreach}
|
||||
|
||||
|
||||
{/foreach}
|
||||
|
||||
{/foreach}
|
||||
Reference in New Issue
Block a user