annotate OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp @ 5640:f7adfb22e20e

updated copyright, as Orthanc Team now replaces Osimis
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 May 2024 21:19:57 +0200
parents 48b8dae6dc77
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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:
diff changeset
1 /**
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
5640
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
f7adfb22e20e updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5485
diff changeset
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
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:
diff changeset
8 *
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * This program is free software: you can redistribute it and/or
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * modify it under the terms of the GNU Lesser General Public License
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * as published by the Free Software Foundation, either version 3 of
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * the License, or (at your option) any later version.
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 *
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * This program is distributed in the hope that it will be useful, but
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * Lesser General Public License for more details.
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 *
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 * You should have received a copy of the GNU Lesser General Public
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * License along with this program. If not, see
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * <http://www.gnu.org/licenses/>.
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../PrecompiledHeaders.h"
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "RestApiCallDocumentation.h"
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #if ORTHANC_ENABLE_CURL == 1
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 # include "../HttpClient.h"
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #endif
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include "../Logging.h"
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include "../OrthancException.h"
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 namespace Orthanc
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 RestApiCallDocumentation& RestApiCallDocumentation::AddRequestType(MimeType mime,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 const std::string& description)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 if (method_ != 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:
diff changeset
42 method_ != 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:
diff changeset
43 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 throw OrthancException(ErrorCode_BadParameterType, "Request body is only allowed on POST and 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:
diff changeset
45 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 else if (requestTypes_.find(mime) != requestTypes_.end() &&
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 mime != MimeType_Json)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 throw OrthancException(ErrorCode_BadSequenceOfCalls, "Cannot register twice the same type of request: " +
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 std::string(EnumerationToString(mime)));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 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:
diff changeset
53 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 requestTypes_[mime] = description;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 return *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:
diff changeset
58 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 RestApiCallDocumentation& RestApiCallDocumentation::SetRequestField(const std::string& name,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 Type type,
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
63 const std::string& description,
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
64 bool required)
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:
diff changeset
65 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 if (method_ != 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:
diff changeset
67 method_ != 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:
diff changeset
68 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 throw OrthancException(ErrorCode_BadParameterType, "Request body is only allowed on POST and 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:
diff changeset
70 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 if (requestTypes_.find(MimeType_Json) == requestTypes_.end())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 requestTypes_[MimeType_Json] = "";
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 if (requestFields_.find(name) != requestFields_.end())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 throw OrthancException(ErrorCode_ParameterOutOfRange, "Field \"" + name + "\" of JSON request is already documented");
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 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:
diff changeset
82 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
83 requestFields_[name] = Parameter(type, description, required);
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:
diff changeset
84 return *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:
diff changeset
85 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 RestApiCallDocumentation& RestApiCallDocumentation::AddAnswerType(MimeType mime,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 const std::string& description)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 if (answerTypes_.find(mime) != answerTypes_.end() &&
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 mime != MimeType_Json)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 throw OrthancException(ErrorCode_BadSequenceOfCalls, "Cannot register twice the same type of answer: " +
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 std::string(EnumerationToString(mime)));
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 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:
diff changeset
99 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 answerTypes_[mime] = description;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 return *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:
diff changeset
104 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
107 RestApiCallDocumentation& RestApiCallDocumentation::SetUriArgument(const std::string& name,
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
108 Type type,
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
109 const std::string& description)
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:
diff changeset
110 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
111 if (uriArguments_.find(name) != uriArguments_.end())
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:
diff changeset
112 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
113 throw OrthancException(ErrorCode_ParameterOutOfRange, "URI argument \"" + name + "\" is already documented");
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:
diff changeset
114 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 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:
diff changeset
116 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
117 uriArguments_[name] = Parameter(type, description, true);
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:
diff changeset
118 return *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:
diff changeset
119 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 RestApiCallDocumentation& RestApiCallDocumentation::SetHttpHeader(const std::string& name,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 const std::string& description)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 if (httpHeaders_.find(name) != httpHeaders_.end())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 throw OrthancException(ErrorCode_ParameterOutOfRange, "HTTP header \"" + name + "\" is already documented");
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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:
diff changeset
130 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:
diff changeset
131 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
132 httpHeaders_[name] = Parameter(Type_String, description, false);
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:
diff changeset
133 return *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:
diff changeset
134 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 RestApiCallDocumentation& RestApiCallDocumentation::SetHttpGetArgument(const std::string& name,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 Type type,
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
140 const std::string& description,
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
141 bool required)
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:
diff changeset
142 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 if (method_ != 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:
diff changeset
144 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 throw OrthancException(ErrorCode_InternalError, "Cannot set a HTTP GET argument on HTTP 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:
diff changeset
146 std::string(EnumerationToString(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:
diff changeset
147 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 else if (getArguments_.find(name) != getArguments_.end())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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:
diff changeset
150 throw OrthancException(ErrorCode_ParameterOutOfRange, "GET argument \"" + name + "\" is already documented");
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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:
diff changeset
152 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:
diff changeset
153 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
154 getArguments_[name] = Parameter(type, description, required);
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:
diff changeset
155 return *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:
diff changeset
156 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 RestApiCallDocumentation& RestApiCallDocumentation::SetAnswerField(const std::string& name,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 Type type,
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 const std::string& description)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 if (answerTypes_.find(MimeType_Json) == answerTypes_.end())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 answerTypes_[MimeType_Json] = "";
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 if (answerFields_.find(name) != answerFields_.end())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 throw OrthancException(ErrorCode_ParameterOutOfRange, "Field \"" + name + "\" of JSON answer is already documented");
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 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:
diff changeset
174 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
175 answerFields_[name] = Parameter(type, description, false);
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:
diff changeset
176 return *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:
diff changeset
177 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
4622
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
181 RestApiCallDocumentation& RestApiCallDocumentation::SetAnswerHeader(const std::string& name,
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
182 const std::string& description)
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
183 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
184 if (answerHeaders_.find(name) != answerHeaders_.end())
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
185 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
186 throw OrthancException(ErrorCode_ParameterOutOfRange, "Answer HTTP header \"" + name + "\" is already documented");
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
187 }
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
188 else
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
189 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
190 answerHeaders_[name] = Parameter(Type_String, description, false);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
191 return *this;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
192 }
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
193 }
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
194
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
195
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
196 void RestApiCallDocumentation::SetHttpGetSample(const std::string& url,
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
197 bool isJson)
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:
diff changeset
198 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 #if ORTHANC_ENABLE_CURL == 1
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 HttpClient client;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 client.SetUrl(url);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 client.SetHttpsVerifyPeers(false);
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
203
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
204 if (isJson)
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:
diff changeset
205 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
206 if (!client.Apply(sampleJson_))
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
207 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
208 LOG(ERROR) << "Cannot GET: " << url;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
209 sampleJson_ = Json::nullValue;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
210 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
211 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
212 else
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
213 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
214 if (client.Apply(sampleText_))
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
215 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
216 hasSampleText_ = true;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
217 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
218 else
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
219 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
220 LOG(ERROR) << "Cannot GET: " << url;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
221 hasSampleText_ = false;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
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:
diff changeset
223 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 #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:
diff changeset
225 LOG(WARNING) << "HTTP client is not available to generated the documentation";
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 #endif
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
230 static void Truncate(Json::Value& value,
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
231 size_t size)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
232 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
233 if (value.type() == Json::arrayValue)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
234 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
235 if (value.size() > size)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
236 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
237 value.resize(size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
238 value.append("...");
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
239 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
240
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
241 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
242 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
243 Truncate(value[i], size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
244 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
245 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
246 else if (value.type() == Json::objectValue)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
247 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
248 std::vector<std::string> members = value.getMemberNames();
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
249 if (members.size() > size)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
250 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
251 members.resize(size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
252
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
253 Json::Value v = Json::objectValue;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
254 for (size_t i = 0; i < members.size(); i++)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
255 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
256 v[members[i]] = value[members[i]];
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
257 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
258
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
259 // We use the "{" symbol, as it the last in the 7bit ASCII
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
260 // table, which places "..." at the end of the object in OpenAPI
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
261 v["{...}"] = "...";
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
262
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
263 value = v;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
264 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
265
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
266 for (size_t i = 0; i < members.size(); i++)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
267 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
268 Truncate(value[members[i]], size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
269 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
270 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
271 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
272
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
273
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
274 void RestApiCallDocumentation::SetTruncatedJsonHttpGetSample(const std::string& url,
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
275 size_t size)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
276 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
277 SetHttpGetSample(url, true);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
278 Truncate(sampleJson_, size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
279 }
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
280
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
281
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
282
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
283 static void TypeToSchema(Json::Value& target,
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
284 RestApiCallDocumentation::Type type)
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:
diff changeset
285 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 switch (type)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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:
diff changeset
288 case RestApiCallDocumentation::Type_Unknown:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 throw OrthancException(ErrorCode_ParameterOutOfRange);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 case RestApiCallDocumentation::Type_String:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 case RestApiCallDocumentation::Type_Text:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
293 target["type"] = "string";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
294 return;
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:
diff changeset
295
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 case RestApiCallDocumentation::Type_Number:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
297 target["type"] = "number";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
298 return;
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:
diff changeset
299
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 case RestApiCallDocumentation::Type_Boolean:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
301 target["type"] = "boolean";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
302 return;
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:
diff changeset
303
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 case RestApiCallDocumentation::Type_JsonObject:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
305 target["type"] = "object";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
306 return;
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:
diff changeset
307
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
308 case RestApiCallDocumentation::Type_JsonListOfStrings:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
309 target["type"] = "array";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
310 target["items"]["type"] = "string";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
311 return;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
312
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
313 case RestApiCallDocumentation::Type_JsonListOfObjects:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
314 target["type"] = "array";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
315 target["items"]["type"] = "object";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
316 return;
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
317
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:
diff changeset
318 default:
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 throw OrthancException(ErrorCode_ParameterOutOfRange);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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:
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:
diff changeset
322
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
324 bool RestApiCallDocumentation::FormatOpenApi(Json::Value& target,
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
325 const std::set<std::string>& expectedUriArguments,
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
326 const std::string& uri) const
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:
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:
diff changeset
328 if (summary_.empty() &&
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 description_.empty())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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:
diff changeset
331 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:
diff changeset
332 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 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:
diff changeset
334 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 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:
diff changeset
336
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 if (!tag_.empty())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 target["tags"].append(tag_);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 if (!summary_.empty())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 target["summary"] = summary_;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 else if (!description_.empty())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 target["summary"] = description_;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 if (!description_.empty())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 target["description"] = description_;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 else if (!summary_.empty())
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 target["description"] = summary_;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
360 target["deprecated"] = deprecated_;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
361
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:
diff changeset
362 if (method_ == 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:
diff changeset
363 method_ == 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:
diff changeset
364 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 for (AllowedTypes::const_iterator it = requestTypes_.begin();
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 it != requestTypes_.end(); ++it)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 Json::Value& schema = target["requestBody"]["content"][EnumerationToString(it->first)]["schema"];
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 schema["description"] = it->second;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 if (it->first == MimeType_Json)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 {
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
373 for (Parameters::const_iterator field = requestFields_.begin();
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
374 field != requestFields_.end(); ++field)
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:
diff changeset
375 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 Json::Value p = Json::objectValue;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
377 TypeToSchema(p, field->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
378 p["description"] = field->second.GetDescription();
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
379 schema["properties"][field->first] = p;
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:
diff changeset
380 }
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
381
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
382 if (!it->second.empty() &&
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
383 answerFields_.size() > 0)
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
384 {
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
385 LOG(WARNING) << "The JSON description will not be visible if the fields of the JSON request are detailed: "
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
386 << EnumerationToString(method_) << " " << uri;
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
387 }
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:
diff changeset
388 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 target["responses"]["200"]["description"] = (answerDescription_.empty() ? "" : answerDescription_);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394 for (AllowedTypes::const_iterator it = answerTypes_.begin();
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 it != answerTypes_.end(); ++it)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 Json::Value& schema = target["responses"]["200"]["content"][EnumerationToString(it->first)]["schema"];
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 schema["description"] = it->second;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 if (it->first == MimeType_Json)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 {
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
402 for (Parameters::const_iterator field = answerFields_.begin();
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
403 field != answerFields_.end(); ++field)
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:
diff changeset
404 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 Json::Value p = Json::objectValue;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
406 TypeToSchema(p, field->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
407 p["description"] = field->second.GetDescription();
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
408 schema["properties"][field->first] = p;
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
409 }
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
410
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
411 if (!it->second.empty() &&
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
412 answerFields_.size() > 0)
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
413 {
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
414 LOG(WARNING) << "The JSON description will not be visible if the fields of the JSON answer are detailed: "
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
415 << EnumerationToString(method_) << " " << uri;
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
416 }
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:
diff changeset
417 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 }
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
419
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
420 for (AllowedTypes::const_iterator it = answerTypes_.begin();
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
421 it != answerTypes_.end(); ++it)
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
422 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
423 if (it->first == MimeType_Json &&
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
424 sampleJson_.type() != Json::nullValue)
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
425 {
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
426 // Handled below
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
427 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
428 else if (it->first == MimeType_PlainText &&
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
429 hasSampleText_)
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
430 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
431 // Handled below
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
432 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
433 else
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
434 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
435 // No sample for this MIME type
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
436 target["responses"]["200"]["content"][EnumerationToString(it->first)]["examples"] = Json::objectValue;
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
437 }
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:
diff changeset
438 }
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
439
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
440 if (sampleJson_.type() != Json::nullValue)
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
441 {
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
442 target["responses"]["200"]["content"][EnumerationToString(MimeType_Json)]["schema"]["example"] = sampleJson_;
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
443 }
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
444
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
445 if (hasSampleText_)
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:
diff changeset
446 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
447 target["responses"]["200"]["content"][EnumerationToString(MimeType_PlainText)]["example"] = sampleText_;
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:
diff changeset
448 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449
4622
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
450 if (!answerHeaders_.empty())
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
451 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
452 Json::Value answerHeaders = Json::objectValue;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
453
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
454 for (Parameters::const_iterator it = answerHeaders_.begin(); it != answerHeaders_.end(); ++it)
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
455 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
456 Json::Value h = Json::objectValue;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
457 h["description"] = it->second.GetDescription();
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
458 answerHeaders[it->first] = h;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
459 }
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
460
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
461 target["responses"]["200"]["headers"] = answerHeaders;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
462 }
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
463
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:
diff changeset
464 Json::Value parameters = Json::arrayValue;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 for (Parameters::const_iterator it = getArguments_.begin();
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 it != getArguments_.end(); ++it)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 Json::Value p = 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:
diff changeset
470 p["name"] = it->first;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 p["in"] = "query";
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
472 p["required"] = it->second.IsRequired();
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
473 TypeToSchema(p["schema"], it->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
474 p["description"] = it->second.GetDescription();
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:
diff changeset
475 parameters.append(p);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 for (Parameters::const_iterator it = httpHeaders_.begin();
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 it != httpHeaders_.end(); ++it)
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 Json::Value p = 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:
diff changeset
482 p["name"] = it->first;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 p["in"] = "header";
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
484 p["required"] = it->second.IsRequired();
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
485 TypeToSchema(p["schema"], it->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
486 p["description"] = it->second.GetDescription();
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:
diff changeset
487 parameters.append(p);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
490 for (Parameters::const_iterator it = uriArguments_.begin();
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
491 it != uriArguments_.end(); ++it)
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:
diff changeset
492 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
493 if (expectedUriArguments.find(it->first) == expectedUriArguments.end())
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
494 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
495 throw OrthancException(ErrorCode_InternalError, "Unexpected URI argument: " + it->first);
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
496 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
497
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:
diff changeset
498 Json::Value p = 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:
diff changeset
499 p["name"] = it->first;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 p["in"] = "path";
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
501 p["required"] = it->second.IsRequired();
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
502 TypeToSchema(p["schema"], it->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
503 p["description"] = it->second.GetDescription();
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:
diff changeset
504 parameters.append(p);
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
507 for (std::set<std::string>::const_iterator it = expectedUriArguments.begin();
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
508 it != expectedUriArguments.end(); ++it)
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
509 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
510 if (uriArguments_.find(*it) == uriArguments_.end())
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
511 {
4424
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
512 throw OrthancException(ErrorCode_InternalError, "Missing URI argument: " + *it);
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
513 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
514 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
515
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:
diff changeset
516 target["parameters"] = parameters;
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 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:
diff changeset
519 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 }