Mercurial > hg > orthanc
annotate OrthancFramework/Sources/RestApi/RestApi.cpp @ 5448:2d23c92c359a
Zip of studies whose PatientName and PatientID did not contain any ASCII character are now valid
author | Alain Mazy <am@osimis.io> |
---|---|
date | Mon, 27 Nov 2023 09:05:05 +0100 |
parents | 002ba12a8bee |
children | 48b8dae6dc77 |
rev | line source |
---|---|
209 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 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 |
5185
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5119
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
0ea402b4d901
upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5119
diff
changeset
|
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
209 | 7 * |
8 * 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
|
9 * 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
|
10 * 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
|
11 * the License, or (at your option) any later version. |
209 | 12 * |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * 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
|
16 * Lesser General Public License for more details. |
209 | 17 * |
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
|
18 * 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
|
19 * 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
|
20 * <http://www.gnu.org/licenses/>. |
209 | 21 **/ |
22 | |
23 | |
824
a811bdf8b8eb
precompiled headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
24 #include "../PrecompiledHeaders.h" |
209 | 25 #include "RestApi.h" |
26 | |
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
|
27 #include "../HttpServer/StringHttpOutput.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
28 #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
|
29 #include "../OrthancException.h" |
1486
f967bdf8534e
refactoring to Logging.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1446
diff
changeset
|
30 |
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
|
31 #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
|
32 #include <boost/math/special_functions/round.hpp> |
249 | 33 #include <stdlib.h> // To define "_exit()" under Windows |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
34 #include <stdio.h> |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
35 |
209 | 36 namespace Orthanc |
37 { | |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
38 namespace |
209 | 39 { |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
40 // Anonymous namespace to avoid clashes between compilation modules |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
41 class HttpHandlerVisitor : public RestApiHierarchy::IVisitor |
209 | 42 { |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
43 private: |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
44 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
|
45 RestApiOutput& output_; |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
46 RequestOrigin origin_; |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
47 const char* remoteIp_; |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
48 const char* username_; |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
49 HttpMethod method_; |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
50 const HttpToolbox::Arguments& headers_; |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
51 const HttpToolbox::Arguments& getArguments_; |
3401 | 52 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
|
53 size_t bodySize_; |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
54 |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
55 public: |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
56 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
|
57 RestApiOutput& output, |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
58 RequestOrigin origin, |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
59 const char* remoteIp, |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
60 const char* username, |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
61 HttpMethod method, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
62 const HttpToolbox::Arguments& headers, |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
63 const HttpToolbox::Arguments& getArguments, |
3401 | 64 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
|
65 size_t bodySize) : |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
66 api_(api), |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
67 output_(output), |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
68 origin_(origin), |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
69 remoteIp_(remoteIp), |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
70 username_(username), |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
71 method_(method), |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
72 headers_(headers), |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
73 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
|
74 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
|
75 bodySize_(bodySize) |
209 | 76 { |
77 } | |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
78 |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
79 virtual bool Visit(const RestApiHierarchy::Resource& resource, |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
80 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
|
81 bool hasTrailing, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
82 const HttpToolbox::Arguments& components, |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
83 const UriComponents& trailing) |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
84 { |
4400 | 85 if (resource.HasHandler(method_)) |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
86 { |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
87 switch (method_) |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
88 { |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
89 case HttpMethod_Get: |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
90 { |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
91 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
|
92 headers_, components, trailing, uri, getArguments_); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
93 resource.Handle(call); |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
94 return true; |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
95 } |
209 | 96 |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
97 case HttpMethod_Post: |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
98 { |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
99 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
|
100 headers_, components, trailing, uri, bodyData_, bodySize_); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
101 resource.Handle(call); |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
102 return true; |
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 |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
105 case HttpMethod_Delete: |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
106 { |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
107 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
|
108 headers_, components, trailing, uri); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
109 resource.Handle(call); |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
110 return true; |
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 |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
113 case HttpMethod_Put: |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
114 { |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
115 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
|
116 headers_, components, trailing, uri, bodyData_, bodySize_); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
117 resource.Handle(call); |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
118 return true; |
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 |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
121 default: |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
122 return false; |
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 |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
126 return false; |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
127 } |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
128 }; |
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
|
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 |
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
|
131 |
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
|
132 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
|
133 { |
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 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
|
135 RestApi& restApi_; |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
136 size_t successPathsCount_; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
137 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
|
138 |
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 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
|
140 virtual bool HandleCall(RestApiCall& call, |
5394
002ba12a8bee
fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
141 const std::string& path, |
4485 | 142 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
|
143 |
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
|
144 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
|
145 explicit DocumentationVisitor(RestApi& restApi) : |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
146 restApi_(restApi), |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
147 successPathsCount_(0), |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
148 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
|
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 } |
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 |
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 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
158 std::string path = Toolbox::FlattenUri(uri); |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
159 if (hasTrailing) |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
160 { |
5393
c5c00bee291a
in openapi generator: renamed '...' into 'path' since '...' is an invalid name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
161 path += "/{path}"; |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
162 } |
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
|
163 |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
164 std::set<std::string> uriArgumentsNames; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
165 HttpToolbox::Arguments uriArguments; |
4401
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
166 |
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
167 for (HttpToolbox::Arguments::const_iterator |
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
168 it = components.begin(); it != components.end(); ++it) |
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
169 { |
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
170 assert(it->second.empty()); |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
171 uriArgumentsNames.insert(it->first.c_str()); |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
172 uriArguments[it->first] = ""; |
4401
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
173 } |
354ea95b294a
documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4400
diff
changeset
|
174 |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
175 if (hasTrailing) |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
176 { |
5393
c5c00bee291a
in openapi generator: renamed '...' into 'path' since '...' is an invalid name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
177 uriArgumentsNames.insert("path"); |
c5c00bee291a
in openapi generator: renamed '...' into 'path' since '...' is an invalid name
Alain Mazy <am@osimis.io>
parents:
5185
diff
changeset
|
178 uriArguments["path"] = ""; |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
179 } |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
180 |
4400 | 181 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
|
182 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
183 totalPathsCount_ ++; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
184 |
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
|
185 StringHttpOutput o1; |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
186 HttpOutput o2(o1, false /* assume no keep-alive */, 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
|
187 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
|
188 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
|
189 "" /* username */, HttpToolbox::Arguments() /* HTTP headers */, |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
190 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
|
191 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
|
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 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
|
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 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
|
196 { |
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 ok = (resource.Handle(call) && |
5394
002ba12a8bee
fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
198 HandleCall(call, path, 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
|
199 } |
4421 | 200 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
|
201 { |
4421 | 202 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
|
203 } |
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
|
204 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
|
205 { |
4421 | 206 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
|
207 } |
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 |
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
|
209 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
|
210 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
211 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
|
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 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
|
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 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
|
216 } |
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
|
217 } |
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 |
4400 | 219 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
|
220 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
221 totalPathsCount_ ++; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
222 |
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
|
223 StringHttpOutput o1; |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
224 HttpOutput o2(o1, false /* assume no keep-alive */, 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
|
225 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
|
226 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
|
227 "" /* username */, HttpToolbox::Arguments() /* HTTP headers */, |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
228 uriArguments, UriComponents() /* trailing */, |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
229 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
|
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 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
|
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 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
|
234 { |
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 ok = (resource.Handle(call) && |
5394
002ba12a8bee
fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
236 HandleCall(call, path, 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
|
237 } |
4421 | 238 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
|
239 { |
4421 | 240 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
|
241 } |
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
|
242 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
|
243 { |
4421 | 244 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
|
245 } |
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 |
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
|
247 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
|
248 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
249 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
|
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 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
|
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 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
|
254 } |
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
|
255 } |
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 |
4400 | 257 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
|
258 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
259 totalPathsCount_ ++; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
260 |
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
|
261 StringHttpOutput o1; |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
262 HttpOutput o2(o1, false /* assume no keep-alive */, 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
|
263 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
|
264 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
|
265 "" /* username */, HttpToolbox::Arguments() /* HTTP headers */, |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
266 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
|
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 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
|
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 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
|
271 { |
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 ok = (resource.Handle(call) && |
5394
002ba12a8bee
fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
273 HandleCall(call, path, 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
|
274 } |
4421 | 275 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
|
276 { |
4421 | 277 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
|
278 } |
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
|
279 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
|
280 { |
4421 | 281 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
|
282 } |
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 |
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
|
284 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
|
285 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
286 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
|
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 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
|
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 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
|
291 } |
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
|
292 } |
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 |
4400 | 294 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
|
295 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
296 totalPathsCount_ ++; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
297 |
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
|
298 StringHttpOutput o1; |
5119
bdec57f3cbf2
New configuration KeepAliveTimeout with a default value of 1 second
Alain Mazy <am@osimis.io>
parents:
4870
diff
changeset
|
299 HttpOutput o2(o1, false /* assume no keep-alive */, 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
|
300 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
|
301 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
|
302 "" /* username */, HttpToolbox::Arguments() /* HTTP headers */, |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
303 uriArguments, UriComponents() /* trailing */, uri, |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
304 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
|
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 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
|
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 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
|
309 { |
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 ok = (resource.Handle(call) && |
5394
002ba12a8bee
fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
311 HandleCall(call, path, 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
|
312 } |
4421 | 313 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
|
314 { |
4421 | 315 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
|
316 } |
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
|
317 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
|
318 { |
4421 | 319 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
|
320 } |
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 |
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
|
322 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
|
323 { |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
324 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
|
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 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
|
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 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
|
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 } |
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 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
|
333 } |
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
|
334 |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
335 size_t GetSuccessPathsCount() const |
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 return successPathsCount_; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
338 } |
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 size_t GetTotalPathsCount() const |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
341 { |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
342 return totalPathsCount_; |
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
343 } |
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
|
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 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
|
346 { |
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 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
|
348 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
|
349 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
|
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 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
|
352 } |
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 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
|
354 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
|
355 |
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 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
|
357 << " 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
|
358 << "(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
|
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 |
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 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
|
364 { |
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 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
|
366 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
|
367 |
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
|
368 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
|
369 virtual bool HandleCall(RestApiCall& call, |
5394
002ba12a8bee
fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
370 const std::string& path, |
4485 | 371 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
|
372 { |
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
|
373 Json::Value v; |
4417
a4518adede59
openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4414
diff
changeset
|
374 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
|
375 { |
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 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
|
377 |
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 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
|
379 { |
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 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
|
381 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
|
382 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
|
383 |
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 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
|
385 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
|
386 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
|
387 |
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 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
|
389 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
|
390 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
|
391 |
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 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
|
393 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
|
394 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
|
395 |
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 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
|
397 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
|
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 |
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 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
|
401 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
|
402 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
|
403 { |
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 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
|
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 |
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 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
|
408 |
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 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
|
410 } |
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 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
|
412 { |
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 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
|
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 |
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 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
|
418 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
|
419 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
|
420 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
|
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 |
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 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
|
425 { |
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 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
|
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 |
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 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
|
432 { |
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 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
|
434 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
|
435 { |
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 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
|
437 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
|
438 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
|
439 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
|
440 bool hasPut_; |
4413 | 441 std::string getTag_; |
442 std::string postTag_; | |
443 std::string deleteTag_; | |
444 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
|
445 std::string summary_; |
4414 | 446 bool getDeprecated_; |
447 bool postDeprecated_; | |
448 bool deleteDeprecated_; | |
449 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
|
450 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
|
451 |
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 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 hasPut_(false), |
4414 | 458 getDeprecated_(false), |
459 postDeprecated_(false), | |
460 deleteDeprecated_(false), | |
461 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
|
462 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
|
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 } |
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
|
465 |
4413 | 466 void AddMethod(HttpMethod method, |
4414 | 467 const std::string& tag, |
468 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
|
469 { |
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 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
|
471 { |
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
|
472 case HttpMethod_Get: |
4413 | 473 if (hasGet_) |
474 { | |
475 throw OrthancException(ErrorCode_InternalError); | |
476 } | |
477 | |
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
|
478 hasGet_ = true; |
4413 | 479 getTag_ = tag; |
4414 | 480 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
|
481 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
|
482 |
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
|
483 case HttpMethod_Post: |
4413 | 484 if (hasPost_) |
485 { | |
486 throw OrthancException(ErrorCode_InternalError); | |
487 } | |
488 | |
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
|
489 hasPost_ = true; |
4413 | 490 postTag_ = tag; |
4414 | 491 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
|
492 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
|
493 |
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
|
494 case HttpMethod_Delete: |
4413 | 495 if (hasDelete_) |
496 { | |
497 throw OrthancException(ErrorCode_InternalError); | |
498 } | |
499 | |
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
|
500 hasDelete_ = true; |
4413 | 501 deleteTag_ = tag; |
4414 | 502 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
|
503 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
|
504 |
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
|
505 case HttpMethod_Put: |
4413 | 506 if (hasPut_) |
507 { | |
508 throw OrthancException(ErrorCode_InternalError); | |
509 } | |
510 | |
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
|
511 hasPut_ = true; |
4413 | 512 putTag_ = tag; |
4414 | 513 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
|
514 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
|
515 |
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 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
|
517 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
|
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 } |
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
|
520 |
4413 | 521 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
|
522 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
|
523 { |
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 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
|
525 { |
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 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
|
527 |
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 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
|
529 { |
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 // 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
|
531 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
|
532 } |
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 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
|
534 { |
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 // 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
|
536 // 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
|
537 // 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
|
538 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
|
539 { |
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 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
|
541 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
|
542 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
|
543 |
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 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
|
545 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
|
546 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
|
547 |
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 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
|
549 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
|
550 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
|
551 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
|
552 |
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 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 |
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 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
|
560 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
|
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 |
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 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
|
565 { |
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 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
|
567 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
|
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 |
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 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
|
573 { |
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 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
|
575 } |
4413 | 576 |
577 static std::string FormatTag(const std::string& tag) | |
578 { | |
579 if (tag.empty()) | |
580 { | |
581 return tag; | |
582 } | |
583 else | |
584 { | |
585 std::string s; | |
586 s.reserve(tag.size()); | |
587 s.push_back(tag[0]); | |
588 | |
589 for (size_t i = 1; i < tag.size(); i++) | |
590 { | |
591 if (tag[i] == ' ') | |
592 { | |
593 s.push_back('-'); | |
594 } | |
595 else if (isupper(tag[i]) && | |
596 tag[i - 1] == ' ') | |
597 { | |
598 s.push_back(tolower(tag[i])); | |
599 } | |
600 else | |
601 { | |
602 s.push_back(tag[i]); | |
603 } | |
604 } | |
605 | |
606 return s; | |
607 } | |
608 } | |
609 | |
610 std::string Format(const std::string& openApiUrl, | |
611 HttpMethod method, | |
612 const std::string& uri) const | |
613 { | |
614 std::string p = uri; | |
615 boost::replace_all(p, "/", "~1"); | |
4414 | 616 |
617 std::string verb; | |
618 std::string url; | |
4413 | 619 |
620 switch (method) | |
621 { | |
622 case HttpMethod_Get: | |
623 if (hasGet_) | |
624 { | |
4414 | 625 verb = (getDeprecated_ ? "(get)" : "GET"); |
626 url = openApiUrl + "#tag/" + FormatTag(getTag_) + "/paths/" + p + "/get"; | |
4413 | 627 } |
628 break; | |
629 | |
630 case HttpMethod_Post: | |
631 if (hasPost_) | |
632 { | |
4414 | 633 verb = (postDeprecated_ ? "(post)" : "POST"); |
634 url = openApiUrl + "#tag/" + FormatTag(postTag_) + "/paths/" + p + "/post"; | |
4413 | 635 } |
636 break; | |
637 | |
638 case HttpMethod_Delete: | |
639 if (hasDelete_) | |
640 { | |
4414 | 641 verb = (deleteDeprecated_ ? "(delete)" : "DELETE"); |
642 url = openApiUrl + "#tag/" + FormatTag(deleteTag_) + "/paths/" + p + "/delete"; | |
4413 | 643 } |
644 break; | |
645 | |
646 case HttpMethod_Put: | |
647 if (hasPut_) | |
648 { | |
4414 | 649 verb = (putDeprecated_ ? "(put)" : "PUT"); |
650 url = openApiUrl + "#tag/" + FormatTag(putTag_) + "/paths/" + p + "/put"; | |
4413 | 651 } |
4414 | 652 break; |
4413 | 653 |
654 default: | |
655 throw OrthancException(ErrorCode_InternalError); | |
656 } | |
657 | |
4414 | 658 if (verb.empty()) |
659 { | |
660 return ""; | |
661 } | |
662 else if (openApiUrl.empty()) | |
663 { | |
664 return verb; | |
665 } | |
666 else | |
667 { | |
668 return "`" + verb + " <" + url + ">`__"; | |
669 } | |
670 } | |
671 | |
672 bool HasDeprecated() const | |
673 { | |
674 return ((hasGet_ && getDeprecated_) || | |
675 (hasPost_ && postDeprecated_) || | |
676 (hasDelete_ && deleteDeprecated_) || | |
677 (hasPut_ && putDeprecated_)); | |
4413 | 678 } |
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
|
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 |
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 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
|
682 |
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 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
|
684 |
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 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
|
686 virtual bool HandleCall(RestApiCall& call, |
5394
002ba12a8bee
fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
687 const std::string& _path, |
4485 | 688 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
|
689 { |
5394
002ba12a8bee
fix openapi & cheatsheet visitors to include trailing 'path' in /instances/{id}/content/{path} url
Alain Mazy <am@osimis.io>
parents:
5393
diff
changeset
|
690 Path& path = paths_[ _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
|
691 |
4414 | 692 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
|
693 |
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
|
694 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
|
695 { |
4413 | 696 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
|
697 } |
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 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
|
700 } |
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 |
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 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
|
703 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
|
704 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
|
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 } |
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 |
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 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
|
709 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
|
710 { |
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 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
|
712 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
|
713 { |
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
|
714 target += "``" + it->first + "``,"; |
4413 | 715 target += it->second.Format(openApiUrl, HttpMethod_Get, it->first) + ","; |
716 target += it->second.Format(openApiUrl, HttpMethod_Post, it->first) + ","; | |
717 target += it->second.Format(openApiUrl, HttpMethod_Delete, it->first) + ","; | |
718 target += it->second.Format(openApiUrl, HttpMethod_Put, it->first) + ","; | |
4414 | 719 |
720 if (it->second.HasDeprecated()) | |
721 { | |
722 target += "*(deprecated)* "; | |
723 } | |
724 | |
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
|
725 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
|
726 } |
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
|
727 } |
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
|
728 }; |
209 | 729 } |
730 | |
731 | |
732 | |
733 static void AddMethod(std::string& target, | |
734 const std::string& method) | |
735 { | |
736 if (target.size() > 0) | |
737 target += "," + method; | |
738 else | |
739 target = method; | |
740 } | |
741 | |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
742 static std::string MethodsToString(const std::set<HttpMethod>& methods) |
209 | 743 { |
744 std::string s; | |
745 | |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
746 if (methods.find(HttpMethod_Get) != methods.end()) |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
747 { |
209 | 748 AddMethod(s, "GET"); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
749 } |
209 | 750 |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
751 if (methods.find(HttpMethod_Post) != methods.end()) |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
752 { |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
753 AddMethod(s, "POST"); |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
754 } |
209 | 755 |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
756 if (methods.find(HttpMethod_Put) != methods.end()) |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
757 { |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
758 AddMethod(s, "PUT"); |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
759 } |
209 | 760 |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
761 if (methods.find(HttpMethod_Delete) != methods.end()) |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
762 { |
209 | 763 AddMethod(s, "DELETE"); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
764 } |
209 | 765 |
766 return s; | |
767 } | |
768 | |
769 | |
770 | |
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
|
771 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
|
772 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
|
773 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
|
774 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
|
775 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
|
776 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
|
777 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
|
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 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
|
780 } |
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
|
781 |
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
|
782 |
895
7e8cde5905fd
allow superposition of REST handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
783 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
|
784 RequestOrigin origin, |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
785 const char* remoteIp, |
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
786 const char* username, |
473
c9a5d72f8481
changing the namespace of HTTP enumerations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
416
diff
changeset
|
787 HttpMethod method, |
209 | 788 const UriComponents& uri, |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
789 const HttpToolbox::Arguments& headers, |
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
790 const HttpToolbox::GetArguments& getArguments, |
3401 | 791 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
|
792 size_t bodySize) |
209 | 793 { |
1368 | 794 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
|
795 |
2136
dd609a99d39a
uniformization of the macro naming
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1900
diff
changeset
|
796 #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
|
797 { |
1511
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
798 // 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
|
799 // 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
|
800 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
|
801 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
|
802 { |
1511
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
803 std::vector<std::string> accepted; |
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
804 Toolbox::TokenizeString(accepted, it->second, ';'); |
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
805 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
|
806 { |
2905
ae20fccdd867
refactoring mime types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
807 if (accepted[i] == MIME_XML) |
1511
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
808 { |
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
809 wrappedOutput.SetConvertJsonToXml(true); |
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
810 } |
1046
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
811 |
2905
ae20fccdd867
refactoring mime types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
812 if (accepted[i] == MIME_JSON) |
1511
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
813 { |
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
814 wrappedOutput.SetConvertJsonToXml(false); |
7962563129c9
starting support of deflate/gzip content types
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1486
diff
changeset
|
815 } |
1046
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 } |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
818 } |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
819 #endif |
00f9f36bcd94
on-the-fly conversion of JSON to XML according to HTTP Accept
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1042
diff
changeset
|
820 |
4330
a01b1c9cbef4
moving generic type definitions from IHttpHandler to HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4119
diff
changeset
|
821 HttpToolbox::Arguments compiled; |
1441
f3672356c121
refactoring: IHttpHandler and HttpToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
822 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
|
823 |
1571
3232f1c995a5
provide the origin of the requests to HTTP handlers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1517
diff
changeset
|
824 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
|
825 method, headers, compiled, bodyData, bodySize); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
826 |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
827 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
|
828 { |
1113
ba5c0908600c
Refactoring of HttpOutput ("Content-Length" header is now always sent)
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1063
diff
changeset
|
829 wrappedOutput.Finalize(); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
830 return true; |
901
7d88f3f4a3b3
refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
895
diff
changeset
|
831 } |
7d88f3f4a3b3
refactoring IsServedUri, answer PNG images, regular expression groups
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
895
diff
changeset
|
832 |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
833 std::set<HttpMethod> methods; |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
834 root_.GetAcceptedMethods(methods, uri); |
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 if (methods.empty()) |
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 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
|
839 } |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
840 else |
209 | 841 { |
477 | 842 LOG(INFO) << "REST method " << EnumerationToString(method) |
416 | 843 << " not allowed on: " << Toolbox::FlattenUri(uri); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
844 |
1042
8d1845feb277
set cookies, not allowed methods, unauthorized in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
980
diff
changeset
|
845 output.SendMethodNotAllowed(MethodsToString(methods)); |
980
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
846 |
f1ff2a2f06cd
use RestApiHierarchy inside RestApi
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
977
diff
changeset
|
847 return true; |
209 | 848 } |
849 } | |
850 | |
851 void RestApi::Register(const std::string& path, | |
974 | 852 RestApiGetCall::Handler handler) |
209 | 853 { |
977 | 854 root_.Register(path, handler); |
209 | 855 } |
856 | |
857 void RestApi::Register(const std::string& path, | |
974 | 858 RestApiPutCall::Handler handler) |
209 | 859 { |
977 | 860 root_.Register(path, handler); |
209 | 861 } |
862 | |
863 void RestApi::Register(const std::string& path, | |
974 | 864 RestApiPostCall::Handler handler) |
209 | 865 { |
977 | 866 root_.Register(path, handler); |
209 | 867 } |
868 | |
869 void RestApi::Register(const std::string& path, | |
974 | 870 RestApiDeleteCall::Handler handler) |
209 | 871 { |
977 | 872 root_.Register(path, handler); |
209 | 873 } |
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
|
874 |
0332e6e8c679
Fix automated generation of the list of resource children in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1046
diff
changeset
|
875 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
|
876 { |
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
|
877 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
|
878 .SetTag("Other") |
4424
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
879 .SetSummary("List operations") |
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
880 .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
|
881 .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
|
882 |
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
|
883 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
|
884 |
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 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
|
886 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
|
887 { |
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
|
888 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
|
889 { |
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
|
890 call.GetDocumentation().SetSample(directory); |
4424
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
891 |
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
892 std::set<std::string> c; |
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
893 call.GetUriComponentsNames(c); |
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
894 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
|
895 { |
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
896 call.GetDocumentation().SetUriArgument(*it, RestApiCallDocumentation::Type_String, ""); |
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
897 } |
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
|
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 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
|
900 { |
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
|
901 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
|
902 } |
4424
83371ccdfe80
openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4421
diff
changeset
|
903 } |
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
|
904 } |
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
|
905 |
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 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
|
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 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
|
910 |
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
|
911 UriComponents root; |
4406
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
912 std::set<std::string> uriArgumentsNames; |
4cb9f66a1c7c
documenting generation of images
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4405
diff
changeset
|
913 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
|
914 |
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
|
915 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
|
916 |
4403 | 917 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
|
918 target["openapi"] = "3.0.0"; |
4403 | 919 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
|
920 target["paths"] = visitor.GetPaths(); |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
921 |
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
|
922 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
|
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 |
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 |
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 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
|
927 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
|
928 { |
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 ReStructuredTextCheatSheet visitor(*this); |
4405
5466f336b09f
gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4403
diff
changeset
|
930 |
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
|
931 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
|
932 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
|
933 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
|
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.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
|
936 |
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
|
937 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
|
938 } |
209 | 939 } |