annotate OrthancFramework/Sources/RestApi/RestApi.cpp @ 4527:31f940334496

Handle public tags with "UN" value representation and containing a string (cf. DICOM CP 246)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 24 Feb 2021 12:39:35 +0100
parents f19de27a2465
children 7053502fbf97
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1288
6e7e5ed91c2d upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1113
diff changeset
4 * Department, University Hospital of Liege, Belgium
4437
d9473bd5ed43 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4424
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * the License, or (at your option) any later version.
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
15 * Lesser General Public License for more details.
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * <http://www.gnu.org/licenses/>.
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
824
a811bdf8b8eb precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 689
diff changeset
23 #include "../PrecompiledHeaders.h"
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "RestApi.h"
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
26 #include "../HttpServer/StringHttpOutput.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
27 #include "../Logging.h"
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
28 #include "../OrthancException.h"
1486
f967bdf8534e refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1446
diff changeset
29
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
30 #include <boost/algorithm/string/replace.hpp>
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
31 #include <boost/math/special_functions/round.hpp>
249
5694365ecb96 fixes for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 215
diff changeset
32 #include <stdlib.h> // To define "_exit()" under Windows
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
33 #include <stdio.h>
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
34
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace Orthanc
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
37 namespace
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
39 // Anonymous namespace to avoid clashes between compilation modules
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
40 class HttpHandlerVisitor : public RestApiHierarchy::IVisitor
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 {
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
42 private:
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
43 RestApi& api_;
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
44 RestApiOutput& output_;
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
45 RequestOrigin origin_;
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
46 const char* remoteIp_;
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
47 const char* username_;
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
48 HttpMethod method_;
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
49 const HttpToolbox::Arguments& headers_;
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
50 const HttpToolbox::Arguments& getArguments_;
3401
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
51 const void* bodyData_;
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
52 size_t bodySize_;
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
53
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
54 public:
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
55 HttpHandlerVisitor(RestApi& api,
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
56 RestApiOutput& output,
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
57 RequestOrigin origin,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
58 const char* remoteIp,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
59 const char* username,
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
60 HttpMethod method,
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
61 const HttpToolbox::Arguments& headers,
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
62 const HttpToolbox::Arguments& getArguments,
3401
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
63 const void* bodyData,
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
64 size_t bodySize) :
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
65 api_(api),
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
66 output_(output),
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
67 origin_(origin),
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
68 remoteIp_(remoteIp),
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
69 username_(username),
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
70 method_(method),
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
71 headers_(headers),
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
72 getArguments_(getArguments),
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
73 bodyData_(bodyData),
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
74 bodySize_(bodySize)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 }
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
77
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
78 virtual bool Visit(const RestApiHierarchy::Resource& resource,
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
79 const UriComponents& uri,
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
80 bool hasTrailing,
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
81 const HttpToolbox::Arguments& components,
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
82 const UriComponents& trailing)
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
83 {
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
84 if (resource.HasHandler(method_))
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
85 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
86 switch (method_)
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
87 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
88 case HttpMethod_Get:
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
89 {
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
90 RestApiGetCall call(output_, api_, origin_, remoteIp_, username_,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
91 headers_, components, trailing, uri, getArguments_);
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
92 resource.Handle(call);
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
93 return true;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
94 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
96 case HttpMethod_Post:
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
97 {
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
98 RestApiPostCall call(output_, api_, origin_, remoteIp_, username_,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
99 headers_, components, trailing, uri, bodyData_, bodySize_);
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
100 resource.Handle(call);
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
101 return true;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
102 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
103
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
104 case HttpMethod_Delete:
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
105 {
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
106 RestApiDeleteCall call(output_, api_, origin_, remoteIp_, username_,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
107 headers_, components, trailing, uri);
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
108 resource.Handle(call);
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
109 return true;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
110 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
111
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
112 case HttpMethod_Put:
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
113 {
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
114 RestApiPutCall call(output_, api_, origin_, remoteIp_, username_,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
115 headers_, components, trailing, uri, bodyData_, bodySize_);
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
116 resource.Handle(call);
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
117 return true;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
118 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
119
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
120 default:
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
121 return false;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
122 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
123 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
124
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
125 return false;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
126 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
127 };
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
128
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
129
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
130
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
131 class DocumentationVisitor : public RestApiHierarchy::IVisitor
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
132 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
133 private:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
134 RestApi& restApi_;
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
135 size_t successPathsCount_;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
136 size_t totalPathsCount_;
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
137
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
138 protected:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
139 virtual bool HandleCall(RestApiCall& call,
4485
f19de27a2465 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
140 const std::set<std::string>& uriArgumentsNames) = 0;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
141
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
142 public:
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
143 explicit DocumentationVisitor(RestApi& restApi) :
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
144 restApi_(restApi),
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
145 successPathsCount_(0),
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
146 totalPathsCount_(0)
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
147 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
148 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
149
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
150 virtual bool Visit(const RestApiHierarchy::Resource& resource,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
151 const UriComponents& uri,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
152 bool hasTrailing,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
153 const HttpToolbox::Arguments& components,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
154 const UriComponents& trailing)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
155 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
156 std::string path = Toolbox::FlattenUri(uri);
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
157 if (hasTrailing)
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
158 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
159 path += "/{...}";
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
160 }
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
161
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
162 std::set<std::string> uriArgumentsNames;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
163 HttpToolbox::Arguments uriArguments;
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
164
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
165 for (HttpToolbox::Arguments::const_iterator
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
166 it = components.begin(); it != components.end(); ++it)
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
167 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
168 assert(it->second.empty());
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
169 uriArgumentsNames.insert(it->first.c_str());
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
170 uriArguments[it->first] = "";
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
171 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
172
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
173 if (hasTrailing)
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
174 {
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
175 uriArgumentsNames.insert("...");
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
176 uriArguments["..."] = "";
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
177 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
178
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
179 if (resource.HasHandler(HttpMethod_Get))
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
180 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
181 totalPathsCount_ ++;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
182
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
183 StringHttpOutput o1;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
184 HttpOutput o2(o1, false);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
185 RestApiOutput o3(o2, HttpMethod_Get);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
186 RestApiGetCall call(o3, restApi_, RequestOrigin_Documentation, "" /* remote IP */,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
187 "" /* username */, HttpToolbox::Arguments() /* HTTP headers */,
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
188 uriArguments, UriComponents() /* trailing */,
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
189 uri, HttpToolbox::Arguments() /* GET arguments */);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
190
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
191 bool ok = false;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
192
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
193 try
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
194 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
195 ok = (resource.Handle(call) &&
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
196 HandleCall(call, uriArgumentsNames));
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
197 }
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
198 catch (OrthancException& e)
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
199 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
200 LOG(ERROR) << "Exception while documenting GET " << path << ": " << e.What();
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
201 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
202 catch (boost::bad_lexical_cast&)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
203 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
204 LOG(ERROR) << "Bad lexical cast while documenting GET " << path;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
205 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
206
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
207 if (ok)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
208 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
209 successPathsCount_ ++;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
210 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
211 else
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
212 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
213 LOG(WARNING) << "Ignoring URI without API documentation: GET " << path;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
214 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
215 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
216
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
217 if (resource.HasHandler(HttpMethod_Post))
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
218 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
219 totalPathsCount_ ++;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
220
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
221 StringHttpOutput o1;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
222 HttpOutput o2(o1, false);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
223 RestApiOutput o3(o2, HttpMethod_Post);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
224 RestApiPostCall call(o3, restApi_, RequestOrigin_Documentation, "" /* remote IP */,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
225 "" /* username */, HttpToolbox::Arguments() /* HTTP headers */,
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
226 uriArguments, UriComponents() /* trailing */,
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
227 uri, NULL /* body */, 0 /* body size */);
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
228
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
229 bool ok = false;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
230
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
231 try
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
232 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
233 ok = (resource.Handle(call) &&
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
234 HandleCall(call, uriArgumentsNames));
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
235 }
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
236 catch (OrthancException& e)
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
237 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
238 LOG(ERROR) << "Exception while documenting POST " << path << ": " << e.What();
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
239 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
240 catch (boost::bad_lexical_cast&)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
241 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
242 LOG(ERROR) << "Bad lexical cast while documenting POST " << path;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
243 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
244
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
245 if (ok)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
246 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
247 successPathsCount_ ++;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
248 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
249 else
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
250 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
251 LOG(WARNING) << "Ignoring URI without API documentation: POST " << path;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
252 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
253 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
254
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
255 if (resource.HasHandler(HttpMethod_Delete))
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
256 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
257 totalPathsCount_ ++;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
258
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
259 StringHttpOutput o1;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
260 HttpOutput o2(o1, false);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
261 RestApiOutput o3(o2, HttpMethod_Delete);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
262 RestApiDeleteCall call(o3, restApi_, RequestOrigin_Documentation, "" /* remote IP */,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
263 "" /* username */, HttpToolbox::Arguments() /* HTTP headers */,
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
264 uriArguments, UriComponents() /* trailing */, uri);
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
265
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
266 bool ok = false;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
267
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
268 try
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
269 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
270 ok = (resource.Handle(call) &&
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
271 HandleCall(call, uriArgumentsNames));
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
272 }
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
273 catch (OrthancException& e)
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
274 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
275 LOG(ERROR) << "Exception while documenting DELETE " << path << ": " << e.What();
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
276 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
277 catch (boost::bad_lexical_cast&)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
278 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
279 LOG(ERROR) << "Bad lexical cast while documenting DELETE " << path;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
280 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
281
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
282 if (ok)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
283 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
284 successPathsCount_ ++;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
285 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
286 else
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
287 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
288 LOG(WARNING) << "Ignoring URI without API documentation: DELETE " << path;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
289 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
290 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
291
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
292 if (resource.HasHandler(HttpMethod_Put))
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
293 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
294 totalPathsCount_ ++;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
295
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
296 StringHttpOutput o1;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
297 HttpOutput o2(o1, false);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
298 RestApiOutput o3(o2, HttpMethod_Put);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
299 RestApiPutCall call(o3, restApi_, RequestOrigin_Documentation, "" /* remote IP */,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
300 "" /* username */, HttpToolbox::Arguments() /* HTTP headers */,
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
301 uriArguments, UriComponents() /* trailing */, uri,
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
302 NULL /* body */, 0 /* body size */);
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
303
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
304 bool ok = false;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
305
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
306 try
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
307 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
308 ok = (resource.Handle(call) &&
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
309 HandleCall(call, uriArgumentsNames));
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
310 }
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
311 catch (OrthancException& e)
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
312 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
313 LOG(ERROR) << "Exception while documenting PUT " << path << ": " << e.What();
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
314 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
315 catch (boost::bad_lexical_cast&)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
316 {
4421
a7d72378e1cb cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
317 LOG(ERROR) << "Bad lexical cast while documenting PUT " << path;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
318 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
319
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
320 if (ok)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
321 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
322 successPathsCount_ ++;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
323 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
324 else
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
325 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
326 LOG(WARNING) << "Ignoring URI without API documentation: PUT " << path;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
327 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
328 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
329
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
330 return true;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
331 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
332
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
333 size_t GetSuccessPathsCount() const
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
334 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
335 return successPathsCount_;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
336 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
337
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
338 size_t GetTotalPathsCount() const
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
339 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
340 return totalPathsCount_;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
341 }
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
342
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
343 void LogStatistics() const
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
344 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
345 assert(GetSuccessPathsCount() <= GetTotalPathsCount());
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
346 size_t total = GetTotalPathsCount();
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
347 if (total == 0)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
348 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
349 total = 1; // Avoid division by zero
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
350 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
351 float coverage = (100.0f * static_cast<float>(GetSuccessPathsCount()) /
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
352 static_cast<float>(total));
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
353
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
354 LOG(WARNING) << "The documentation of the REST API contains " << GetSuccessPathsCount()
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
355 << " paths over a total of " << GetTotalPathsCount() << " paths "
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
356 << "(coverage: " << static_cast<unsigned int>(boost::math::iround(coverage)) << "%)";
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
357 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
358 };
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
359
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
360
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
361 class OpenApiVisitor : public DocumentationVisitor
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
362 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
363 private:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
364 Json::Value paths_;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
365
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
366 protected:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
367 virtual bool HandleCall(RestApiCall& call,
4485
f19de27a2465 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
368 const std::set<std::string>& uriArgumentsNames) ORTHANC_OVERRIDE
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
369 {
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
370 const std::string path = Toolbox::FlattenUri(call.GetFullUri());
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
371
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
372 Json::Value v;
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
373 if (call.GetDocumentation().FormatOpenApi(v, uriArgumentsNames, path))
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
374 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
375 std::string method;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
376
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
377 switch (call.GetMethod())
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
378 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
379 case HttpMethod_Get:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
380 method = "get";
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
381 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
382
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
383 case HttpMethod_Post:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
384 method = "post";
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
385 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
386
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
387 case HttpMethod_Delete:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
388 method = "delete";
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
389 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
390
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
391 case HttpMethod_Put:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
392 method = "put";
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
393 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
394
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
395 default:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
396 throw OrthancException(ErrorCode_ParameterOutOfRange);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
397 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
398
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
399 if ((paths_.isMember(path) &&
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
400 paths_[path].type() != Json::objectValue) ||
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
401 paths_[path].isMember(method))
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
402 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
403 throw OrthancException(ErrorCode_InternalError);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
404 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
405
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
406 paths_[path][method] = v;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
407
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
408 return true;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
409 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
410 else
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
411 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
412 return false;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
413 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
414 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
415
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
416 public:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
417 explicit OpenApiVisitor(RestApi& restApi) :
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
418 DocumentationVisitor(restApi),
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
419 paths_(Json::objectValue)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
420 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
421 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
422
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
423 const Json::Value& GetPaths() const
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
424 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
425 return paths_;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
426 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
427 };
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
428
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
429
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
430 class ReStructuredTextCheatSheet : public DocumentationVisitor
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
431 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
432 private:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
433 class Path
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
434 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
435 private:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
436 bool hasGet_;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
437 bool hasPost_;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
438 bool hasDelete_;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
439 bool hasPut_;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
440 std::string getTag_;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
441 std::string postTag_;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
442 std::string deleteTag_;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
443 std::string putTag_;
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
444 std::string summary_;
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
445 bool getDeprecated_;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
446 bool postDeprecated_;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
447 bool deleteDeprecated_;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
448 bool putDeprecated_;
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
449 HttpMethod summaryOrigin_;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
450
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
451 public:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
452 Path() :
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
453 hasGet_(false),
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
454 hasPost_(false),
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
455 hasDelete_(false),
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
456 hasPut_(false),
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
457 getDeprecated_(false),
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
458 postDeprecated_(false),
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
459 deleteDeprecated_(false),
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
460 putDeprecated_(false),
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
461 summaryOrigin_(HttpMethod_Get) // Dummy initialization
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
462 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
463 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
464
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
465 void AddMethod(HttpMethod method,
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
466 const std::string& tag,
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
467 bool deprecated)
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
468 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
469 switch (method)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
470 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
471 case HttpMethod_Get:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
472 if (hasGet_)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
473 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
474 throw OrthancException(ErrorCode_InternalError);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
475 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
476
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
477 hasGet_ = true;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
478 getTag_ = tag;
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
479 getDeprecated_ = deprecated;
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
480 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
481
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
482 case HttpMethod_Post:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
483 if (hasPost_)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
484 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
485 throw OrthancException(ErrorCode_InternalError);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
486 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
487
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
488 hasPost_ = true;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
489 postTag_ = tag;
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
490 postDeprecated_ = deprecated;
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
491 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
492
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
493 case HttpMethod_Delete:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
494 if (hasDelete_)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
495 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
496 throw OrthancException(ErrorCode_InternalError);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
497 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
498
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
499 hasDelete_ = true;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
500 deleteTag_ = tag;
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
501 deleteDeprecated_ = deprecated;
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
502 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
503
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
504 case HttpMethod_Put:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
505 if (hasPut_)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
506 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
507 throw OrthancException(ErrorCode_InternalError);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
508 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
509
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
510 hasPut_ = true;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
511 putTag_ = tag;
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
512 putDeprecated_ = deprecated;
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
513 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
514
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
515 default:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
516 throw OrthancException(ErrorCode_ParameterOutOfRange);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
517 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
518 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
519
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
520 void SetSummary(const std::string& summary,
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
521 HttpMethod newOrigin)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
522 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
523 if (!summary.empty())
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
524 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
525 bool replace;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
526
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
527 if (summary_.empty())
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
528 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
529 // We don't have a summary so far
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
530 replace = true;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
531 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
532 else
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
533 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
534 // We already have a summary. Replace it if the new
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
535 // summary is associated with a HTTP method of higher
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
536 // weight (GET > POST > DELETE > PUT)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
537 switch (summaryOrigin_)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
538 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
539 case HttpMethod_Get:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
540 replace = false;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
541 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
542
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
543 case HttpMethod_Post:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
544 replace = (newOrigin == HttpMethod_Get);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
545 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
546
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
547 case HttpMethod_Delete:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
548 replace = (newOrigin == HttpMethod_Get ||
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
549 newOrigin == HttpMethod_Post);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
550 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
551
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
552 case HttpMethod_Put:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
553 replace = (newOrigin == HttpMethod_Get ||
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
554 newOrigin == HttpMethod_Post ||
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
555 newOrigin == HttpMethod_Delete);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
556 break;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
557
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
558 default:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
559 throw OrthancException(ErrorCode_ParameterOutOfRange);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
560 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
561 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
562
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
563 if (replace)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
564 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
565 summary_ = summary;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
566 summaryOrigin_ = newOrigin;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
567 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
568 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
569 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
570
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
571 const std::string& GetSummary() const
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
572 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
573 return summary_;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
574 }
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
575
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
576 static std::string FormatTag(const std::string& tag)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
577 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
578 if (tag.empty())
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
579 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
580 return tag;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
581 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
582 else
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
583 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
584 std::string s;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
585 s.reserve(tag.size());
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
586 s.push_back(tag[0]);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
587
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
588 for (size_t i = 1; i < tag.size(); i++)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
589 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
590 if (tag[i] == ' ')
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
591 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
592 s.push_back('-');
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
593 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
594 else if (isupper(tag[i]) &&
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
595 tag[i - 1] == ' ')
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
596 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
597 s.push_back(tolower(tag[i]));
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
598 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
599 else
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
600 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
601 s.push_back(tag[i]);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
602 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
603 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
604
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
605 return s;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
606 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
607 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
608
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
609 std::string Format(const std::string& openApiUrl,
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
610 HttpMethod method,
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
611 const std::string& uri) const
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
612 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
613 std::string p = uri;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
614 boost::replace_all(p, "/", "~1");
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
615
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
616 std::string verb;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
617 std::string url;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
618
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
619 switch (method)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
620 {
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
621 case HttpMethod_Get:
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
622 if (hasGet_)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
623 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
624 verb = (getDeprecated_ ? "(get)" : "GET");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
625 url = openApiUrl + "#tag/" + FormatTag(getTag_) + "/paths/" + p + "/get";
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
626 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
627 break;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
628
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
629 case HttpMethod_Post:
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
630 if (hasPost_)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
631 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
632 verb = (postDeprecated_ ? "(post)" : "POST");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
633 url = openApiUrl + "#tag/" + FormatTag(postTag_) + "/paths/" + p + "/post";
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
634 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
635 break;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
636
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
637 case HttpMethod_Delete:
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
638 if (hasDelete_)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
639 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
640 verb = (deleteDeprecated_ ? "(delete)" : "DELETE");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
641 url = openApiUrl + "#tag/" + FormatTag(deleteTag_) + "/paths/" + p + "/delete";
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
642 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
643 break;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
644
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
645 case HttpMethod_Put:
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
646 if (hasPut_)
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
647 {
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
648 verb = (putDeprecated_ ? "(put)" : "PUT");
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
649 url = openApiUrl + "#tag/" + FormatTag(putTag_) + "/paths/" + p + "/put";
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
650 }
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
651 break;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
652
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
653 default:
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
654 throw OrthancException(ErrorCode_InternalError);
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
655 }
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
656
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
657 if (verb.empty())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
658 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
659 return "";
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
660 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
661 else if (openApiUrl.empty())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
662 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
663 return verb;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
664 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
665 else
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
666 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
667 return "`" + verb + " <" + url + ">`__";
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
668 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
669 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
670
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
671 bool HasDeprecated() const
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
672 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
673 return ((hasGet_ && getDeprecated_) ||
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
674 (hasPost_ && postDeprecated_) ||
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
675 (hasDelete_ && deleteDeprecated_) ||
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
676 (hasPut_ && putDeprecated_));
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
677 }
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
678 };
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
679
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
680 typedef std::map<std::string, Path> Paths;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
681
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
682 Paths paths_;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
683
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
684 protected:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
685 virtual bool HandleCall(RestApiCall& call,
4485
f19de27a2465 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
686 const std::set<std::string>& uriArgumentsNames) ORTHANC_OVERRIDE
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
687 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
688 Path& path = paths_[ Toolbox::FlattenUri(call.GetFullUri()) ];
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
689
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
690 path.AddMethod(call.GetMethod(), call.GetDocumentation().GetTag(), call.GetDocumentation().IsDeprecated());
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
691
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
692 if (call.GetDocumentation().HasSummary())
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
693 {
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
694 path.SetSummary(call.GetDocumentation().GetSummary(), call.GetMethod());
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
695 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
696
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
697 return true;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
698 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
699
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
700 public:
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
701 explicit ReStructuredTextCheatSheet(RestApi& restApi) :
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
702 DocumentationVisitor(restApi)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
703 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
704 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
705
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
706 void Format(std::string& target,
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
707 const std::string& openApiUrl) const
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
708 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
709 target += "Path,GET,POST,DELETE,PUT,Summary\n";
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
710 for (Paths::const_iterator it = paths_.begin(); it != paths_.end(); ++it)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
711 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
712 target += "``" + it->first + "``,";
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
713 target += it->second.Format(openApiUrl, HttpMethod_Get, it->first) + ",";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
714 target += it->second.Format(openApiUrl, HttpMethod_Post, it->first) + ",";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
715 target += it->second.Format(openApiUrl, HttpMethod_Delete, it->first) + ",";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4412
diff changeset
716 target += it->second.Format(openApiUrl, HttpMethod_Put, it->first) + ",";
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
717
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
718 if (it->second.HasDeprecated())
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
719 {
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
720 target += "*(deprecated)* ";
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
721 }
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
722
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
723 target += it->second.GetSummary() + "\n";
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
724 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
725 }
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
726 };
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 static void AddMethod(std::string& target,
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 const std::string& method)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 if (target.size() > 0)
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 target += "," + method;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 else
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 target = method;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
740 static std::string MethodsToString(const std::set<HttpMethod>& methods)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 {
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 std::string s;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
744 if (methods.find(HttpMethod_Get) != methods.end())
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
745 {
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 AddMethod(s, "GET");
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
747 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
749 if (methods.find(HttpMethod_Post) != methods.end())
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
750 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
751 AddMethod(s, "POST");
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
752 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
754 if (methods.find(HttpMethod_Put) != methods.end())
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
755 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
756 AddMethod(s, "PUT");
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
757 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
759 if (methods.find(HttpMethod_Delete) != methods.end())
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
760 {
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 AddMethod(s, "DELETE");
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
762 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 return s;
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
769 bool RestApi::CreateChunkedRequestReader(std::unique_ptr<IChunkedRequestReader>& target,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
770 RequestOrigin origin,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
771 const char* remoteIp,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
772 const char* username,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
773 HttpMethod method,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
774 const UriComponents& uri,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
775 const HttpToolbox::Arguments& headers)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
776 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
777 return false;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
778 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
779
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
780
895
7e8cde5905fd allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
781 bool RestApi::Handle(HttpOutput& output,
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
782 RequestOrigin origin,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
783 const char* remoteIp,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
784 const char* username,
473
c9a5d72f8481 changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 416
diff changeset
785 HttpMethod method,
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 const UriComponents& uri,
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
787 const HttpToolbox::Arguments& headers,
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
788 const HttpToolbox::GetArguments& getArguments,
3401
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
789 const void* bodyData,
1446
8dc80ba768aa refactoring: IHttpHandler does not use std::string to hold the request body
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1441
diff changeset
790 size_t bodySize)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 {
1368
b22ba8c5edbe query retrieve
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1363
diff changeset
792 RestApiOutput wrappedOutput(output, method);
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
793
2136
dd609a99d39a uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
794 #if ORTHANC_ENABLE_PUGIXML == 1
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
795 {
1511
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
796 // Look if the client wishes XML answers instead of JSON
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
797 // http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html#z3
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
798 HttpToolbox::Arguments::const_iterator it = headers.find("accept");
1511
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
799 if (it != headers.end())
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
800 {
1511
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
801 std::vector<std::string> accepted;
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
802 Toolbox::TokenizeString(accepted, it->second, ';');
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
803 for (size_t i = 0; i < accepted.size(); i++)
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
804 {
2905
ae20fccdd867 refactoring mime types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
805 if (accepted[i] == MIME_XML)
1511
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
806 {
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
807 wrappedOutput.SetConvertJsonToXml(true);
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
808 }
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
809
2905
ae20fccdd867 refactoring mime types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2447
diff changeset
810 if (accepted[i] == MIME_JSON)
1511
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
811 {
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
812 wrappedOutput.SetConvertJsonToXml(false);
7962563129c9 starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1486
diff changeset
813 }
1046
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
814 }
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
815 }
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
816 }
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
817 #endif
00f9f36bcd94 on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1042
diff changeset
818
4330
a01b1c9cbef4 moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4119
diff changeset
819 HttpToolbox::Arguments compiled;
1441
f3672356c121 refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1368
diff changeset
820 HttpToolbox::CompileGetArguments(compiled, getArguments);
1363
feaf2840917c Plugins now receive duplicated GET arguments in their REST callbacks
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1288
diff changeset
821
1571
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
822 HttpHandlerVisitor visitor(*this, wrappedOutput, origin, remoteIp, username,
3232f1c995a5 provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1517
diff changeset
823 method, headers, compiled, bodyData, bodySize);
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
824
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
825 if (root_.LookupResource(uri, visitor))
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
826 {
1113
ba5c0908600c Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1063
diff changeset
827 wrappedOutput.Finalize();
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
828 return true;
901
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
829 }
7d88f3f4a3b3 refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 895
diff changeset
830
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
831 std::set<HttpMethod> methods;
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
832 root_.GetAcceptedMethods(methods, uri);
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
833
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
834 if (methods.empty())
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
835 {
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
836 return false; // This URI is not served by this REST API
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
837 }
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
838 else
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 {
477
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 473
diff changeset
840 LOG(INFO) << "REST method " << EnumerationToString(method)
416
1188cb0ddaa5 http method faking
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 398
diff changeset
841 << " not allowed on: " << Toolbox::FlattenUri(uri);
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
842
1042
8d1845feb277 set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 980
diff changeset
843 output.SendMethodNotAllowed(MethodsToString(methods));
980
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
844
f1ff2a2f06cd use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 977
diff changeset
845 return true;
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 void RestApi::Register(const std::string& path,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
850 RestApiGetCall::Handler handler)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 {
977
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
852 root_.Register(path, handler);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 void RestApi::Register(const std::string& path,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
856 RestApiPutCall::Handler handler)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 {
977
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
858 root_.Register(path, handler);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861 void RestApi::Register(const std::string& path,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
862 RestApiPostCall::Handler handler)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 {
977
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
864 root_.Register(path, handler);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 }
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867 void RestApi::Register(const std::string& path,
974
83622b0f544c refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 824
diff changeset
868 RestApiDeleteCall::Handler handler)
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 {
977
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 976
diff changeset
870 root_.Register(path, handler);
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 }
1063
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
872
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
873 void RestApi::AutoListChildren(RestApiGetCall& call)
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
874 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
875 call.GetDocumentation()
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
876 .SetTag("Other")
4424
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
877 .SetSummary("List operations")
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
878 .SetDescription("List the available operations under URI `" + call.FlattenUri() + "`")
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
879 .AddAnswerType(MimeType_Json, "List of the available operations");
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
880
1063
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
881 RestApi& context = call.GetContext();
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
882
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
883 Json::Value directory;
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
884 if (context.root_.GetDirectory(directory, call.GetFullUri()))
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
885 {
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
886 if (call.IsDocumentation())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
887 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
888 call.GetDocumentation().SetSample(directory);
4424
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
889
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
890 std::set<std::string> c;
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
891 call.GetUriComponentsNames(c);
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
892 for (std::set<std::string>::const_iterator it = c.begin(); it != c.end(); ++it)
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
893 {
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
894 call.GetDocumentation().SetUriArgument(*it, RestApiCallDocumentation::Type_String, "");
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
895 }
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
896 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
897 else
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
898 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
899 call.GetOutput().AnswerJson(directory);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
900 }
4424
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4421
diff changeset
901 }
1063
0332e6e8c679 Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1046
diff changeset
902 }
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
903
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
904
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
905 void RestApi::GenerateOpenApiDocumentation(Json::Value& target)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
906 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
907 OpenApiVisitor visitor(*this);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
908
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
909 UriComponents root;
4406
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
910 std::set<std::string> uriArgumentsNames;
4cb9f66a1c7c documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
911 root_.ExploreAllResources(visitor, root, uriArgumentsNames);
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
912
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
913 target = Json::objectValue;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
914
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
915 target["info"] = Json::objectValue;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
916 target["openapi"] = "3.0.0";
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
917 target["servers"] = Json::arrayValue;
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
918 target["paths"] = visitor.GetPaths();
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
919
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
920 visitor.LogStatistics();
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
921 }
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
922
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
923
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
924 void RestApi::GenerateReStructuredTextCheatSheet(std::string& target,
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
925 const std::string& openApiUrl)
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
926 {
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
927 ReStructuredTextCheatSheet visitor(*this);
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
928
4412
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
929 UriComponents root;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
930 std::set<std::string> uriArgumentsNames;
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
931 root_.ExploreAllResources(visitor, root, uriArgumentsNames);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
932
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
933 visitor.Format(target, openApiUrl);
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
934
68b96234fbd6 automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4410
diff changeset
935 visitor.LogStatistics();
4399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4330
diff changeset
936 }
209
9960642f0f45 abstraction of RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 }