Mercurial > hg > orthanc
changeset 7049:4f42a9f8e078
refactoring
| author | Sebastien Jodogne <s.jodogne@gmail.com> |
|---|---|
| date | Tue, 11 Aug 2026 17:15:23 +0200 |
| parents | e1cce5515153 |
| children | 61055f1ee946 f9e92fe0c493 |
| files | OrthancServer/Sources/main.cpp |
| diffstat | 1 files changed, 70 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancServer/Sources/main.cpp Tue Aug 11 17:01:21 2026 +0200 +++ b/OrthancServer/Sources/main.cpp Tue Aug 11 17:15:23 2026 +0200 @@ -1998,6 +1998,73 @@ } +static void ExportOpenApi(const std::string& target) +{ + Json::Value openapi; + + { + SQLiteDatabaseWrapper inMemoryDatabase; + inMemoryDatabase.Open(); + PluginStorageAreaAdapter inMemoryStorage(new MemoryStorageArea); + ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */); + OrthancRestApi restApi(context, false /* no Orthanc Explorer */); + restApi.GenerateOpenApiDocumentation(openapi); + context.Stop(); + } + + openapi["info"]["version"] = ORTHANC_VERSION; + openapi["info"]["title"] = "Orthanc API"; + openapi["info"]["description"] = + "This is the full documentation of the [REST API](https://orthanc.uclouvain.be/book/users/rest.html) " + "of Orthanc.<p>This reference is automatically generated from the source code of Orthanc. A " + "[shorter cheat sheet](https://orthanc.uclouvain.be/book/users/rest-cheatsheet.html) is part of " + "the Orthanc Book.<p>An earlier, manually crafted version from August 2019, is [still available]" + "(2019-08-orthanc-openapi.html), but is not up-to-date anymore ([source]" + "(https://groups.google.com/g/orthanc-users/c/NUiJTEICSl8/m/xKeqMrbqAAAJ))."; + + Json::Value server = Json::objectValue; + server["url"] = "https://orthanc.uclouvain.be/demo/"; + openapi["servers"].append(server); + + std::string s; + Toolbox::WriteStyledJson(s, openapi); + + if (target == "-") + { + std::cout << s; // Print to stdout + } + else + { + SystemToolbox::WriteFile(s, SystemToolbox::PathFromUtf8(target)); + } +} + + +static void ExportCheatSheet(const std::string& target) +{ + std::string cheatsheet; + + { + SQLiteDatabaseWrapper inMemoryDatabase; + inMemoryDatabase.Open(); + PluginStorageAreaAdapter inMemoryStorage(new MemoryStorageArea); + ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */); + OrthancRestApi restApi(context, false /* no Orthanc Explorer */); + restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html"); + context.Stop(); + } + + if (target == "-") + { + std::cout << cheatsheet; // Print to stdout + } + else + { + SystemToolbox::WriteFile(cheatsheet, SystemToolbox::PathFromUtf8(target)); + } +} + + #if defined(_WIN32) && !defined(__MINGW32__) // arguments are passed as UTF-16 on Windows int wmain(int argc, wchar_t *argv[]) @@ -2171,47 +2238,11 @@ } else if (boost::starts_with(argument, "--openapi=")) { - std::string target = argument.substr(10); + const std::string target = argument.substr(argument.find('=') + 1); try { - Json::Value openapi; - - { - SQLiteDatabaseWrapper inMemoryDatabase; - inMemoryDatabase.Open(); - PluginStorageAreaAdapter inMemoryStorage(new MemoryStorageArea); - ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */); - OrthancRestApi restApi(context, false /* no Orthanc Explorer */); - restApi.GenerateOpenApiDocumentation(openapi); - context.Stop(); - } - - openapi["info"]["version"] = ORTHANC_VERSION; - openapi["info"]["title"] = "Orthanc API"; - openapi["info"]["description"] = - "This is the full documentation of the [REST API](https://orthanc.uclouvain.be/book/users/rest.html) " - "of Orthanc.<p>This reference is automatically generated from the source code of Orthanc. A " - "[shorter cheat sheet](https://orthanc.uclouvain.be/book/users/rest-cheatsheet.html) is part of " - "the Orthanc Book.<p>An earlier, manually crafted version from August 2019, is [still available]" - "(2019-08-orthanc-openapi.html), but is not up-to-date anymore ([source]" - "(https://groups.google.com/g/orthanc-users/c/NUiJTEICSl8/m/xKeqMrbqAAAJ))."; - - Json::Value server = Json::objectValue; - server["url"] = "https://orthanc.uclouvain.be/demo/"; - openapi["servers"].append(server); - - std::string s; - Toolbox::WriteStyledJson(s, openapi); - - if (target == "-") - { - std::cout << s; // Print to stdout - } - else - { - SystemToolbox::WriteFile(s, SystemToolbox::PathFromUtf8(target)); - } + ExportOpenApi(target); return 0; } catch (OrthancException&) @@ -2226,26 +2257,7 @@ try { - std::string cheatsheet; - - { - SQLiteDatabaseWrapper inMemoryDatabase; - inMemoryDatabase.Open(); - PluginStorageAreaAdapter inMemoryStorage(new MemoryStorageArea); - ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */, false /* readonly */); - OrthancRestApi restApi(context, false /* no Orthanc Explorer */); - restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://orthanc.uclouvain.be/api/index.html"); - context.Stop(); - } - - if (target == "-") - { - std::cout << cheatsheet; // Print to stdout - } - else - { - SystemToolbox::WriteFile(cheatsheet, SystemToolbox::PathFromUtf8(target)); - } + ExportCheatSheet(target); return 0; } catch (OrthancException&)
