annotate OrthancFramework/Sources/RestApi/RestApiCallDocumentation.cpp @ 5523:d82cc7c9720a pg-transactions

comment
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 31 Jan 2024 09:26:31 +0100
parents 48b8dae6dc77
children f7adfb22e20e
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
5485
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium
48b8dae6dc77 upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5185
diff changeset
6 * 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
7 *
80fd140b12ba New command-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 * 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
9 * 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
10 * 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
11 * 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
12 *
80fd140b12ba New command-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 * 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
14 * 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
15 * 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
16 * 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
17 *
80fd140b12ba New command-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 * 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
19 * 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
20 * <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
21 **/
80fd140b12ba New command-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 #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
25 #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
26
80fd140b12ba New command-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 #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
28 # 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
29 #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
30
80fd140b12ba New command-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 #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
32 #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
33
80fd140b12ba New command-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 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
36 {
80fd140b12ba New command-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 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
38 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
39 {
80fd140b12ba New command-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 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
41 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
42 {
80fd140b12ba New command-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 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
44 }
80fd140b12ba New command-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 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
46 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
47 {
80fd140b12ba New command-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 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
49 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
50 }
80fd140b12ba New command-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 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
52 {
80fd140b12ba New command-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 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
54 }
80fd140b12ba New command-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 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
57 }
80fd140b12ba New command-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 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
61 Type type,
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
62 const std::string& description,
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
63 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
64 {
80fd140b12ba New command-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 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
66 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
67 {
80fd140b12ba New command-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 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
69 }
80fd140b12ba New command-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 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
72 {
80fd140b12ba New command-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 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
74 }
80fd140b12ba New command-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 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
77 {
80fd140b12ba New command-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 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
79 }
80fd140b12ba New command-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 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
81 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
82 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
83 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
84 }
80fd140b12ba New command-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 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
89 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
90 {
80fd140b12ba New command-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 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
92 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
93 {
80fd140b12ba New command-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 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
95 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
96 }
80fd140b12ba New command-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 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
98 {
80fd140b12ba New command-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 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
100 }
80fd140b12ba New command-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 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
103 }
80fd140b12ba New command-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
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
106 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
107 Type type,
4404
f34634916d8c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4403
diff changeset
108 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
109 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
110 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
111 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
112 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
113 }
80fd140b12ba New command-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 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
115 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
116 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
117 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
118 }
80fd140b12ba New command-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 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
123 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
124 {
80fd140b12ba New command-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 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
126 {
80fd140b12ba New command-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 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
128 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 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
130 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
131 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
132 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
133 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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 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
138 Type type,
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
139 const std::string& description,
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
140 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
141 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 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
143 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 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
145 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
146 }
80fd140b12ba New command-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 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
148 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 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
150 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 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
152 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
153 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
154 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
155 }
80fd140b12ba New command-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 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
160 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
161 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
162 {
80fd140b12ba New command-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 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
164 {
80fd140b12ba New command-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 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
166 }
80fd140b12ba New command-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 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
169 {
80fd140b12ba New command-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 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
171 }
80fd140b12ba New command-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 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
173 {
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
174 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
175 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
176 }
80fd140b12ba New command-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
4622
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
180 RestApiCallDocumentation& RestApiCallDocumentation::SetAnswerHeader(const std::string& name,
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
181 const std::string& description)
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
182 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
183 if (answerHeaders_.find(name) != answerHeaders_.end())
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
184 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
185 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
186 }
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
187 else
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
188 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
189 answerHeaders_[name] = Parameter(Type_String, description, false);
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
190 return *this;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
191 }
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
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
195 void RestApiCallDocumentation::SetHttpGetSample(const std::string& url,
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
196 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
197 {
80fd140b12ba New command-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 #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
199 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
200 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
201 client.SetHttpsVerifyPeers(false);
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
202
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
203 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
204 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
205 if (!client.Apply(sampleJson_))
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
206 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
207 LOG(ERROR) << "Cannot GET: " << url;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
208 sampleJson_ = Json::nullValue;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
209 }
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 else
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
212 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
213 if (client.Apply(sampleText_))
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
214 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
215 hasSampleText_ = true;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
216 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
217 else
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
218 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
219 LOG(ERROR) << "Cannot GET: " << url;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
220 hasSampleText_ = false;
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
221 }
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
222 }
80fd140b12ba New command-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 #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
224 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
225 #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
226 }
80fd140b12ba New command-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
4415
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
229 static void Truncate(Json::Value& value,
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
230 size_t size)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
231 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
232 if (value.type() == Json::arrayValue)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
233 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
234 if (value.size() > size)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
235 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
236 value.resize(size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
237 value.append("...");
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
238 }
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 for (Json::Value::ArrayIndex i = 0; i < value.size(); i++)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
241 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
242 Truncate(value[i], size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
243 }
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 else if (value.type() == Json::objectValue)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
246 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
247 std::vector<std::string> members = value.getMemberNames();
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
248 if (members.size() > size)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
249 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
250 members.resize(size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
251
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
252 Json::Value v = Json::objectValue;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
253 for (size_t i = 0; i < members.size(); i++)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
254 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
255 v[members[i]] = value[members[i]];
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
256 }
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 // 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
259 // table, which places "..." at the end of the object in OpenAPI
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
260 v["{...}"] = "...";
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
261
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
262 value = v;
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
263 }
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 for (size_t i = 0; i < members.size(); i++)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
266 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
267 Truncate(value[members[i]], size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
268 }
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 void RestApiCallDocumentation::SetTruncatedJsonHttpGetSample(const std::string& url,
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
274 size_t size)
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
275 {
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
276 SetHttpGetSample(url, true);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
277 Truncate(sampleJson_, size);
b50410d0e98c cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4414
diff changeset
278 }
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
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
282 static void TypeToSchema(Json::Value& target,
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
283 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
284 {
80fd140b12ba New command-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 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
286 {
80fd140b12ba New command-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 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
288 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
289
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 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
291 case RestApiCallDocumentation::Type_Text:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
292 target["type"] = "string";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
293 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
294
80fd140b12ba New command-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 case RestApiCallDocumentation::Type_Number:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
296 target["type"] = "number";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
297 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
298
80fd140b12ba New command-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 case RestApiCallDocumentation::Type_Boolean:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
300 target["type"] = "boolean";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
301 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
302
80fd140b12ba New command-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 case RestApiCallDocumentation::Type_JsonObject:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
304 target["type"] = "object";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
305 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
306
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
307 case RestApiCallDocumentation::Type_JsonListOfStrings:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
308 target["type"] = "array";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
309 target["items"]["type"] = "string";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
310 return;
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
311
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
312 case RestApiCallDocumentation::Type_JsonListOfObjects:
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
313 target["type"] = "array";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
314 target["items"]["type"] = "object";
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
315 return;
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
316
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
317 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
318 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
319 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
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
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
323 bool RestApiCallDocumentation::FormatOpenApi(Json::Value& target,
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
324 const std::set<std::string>& expectedUriArguments,
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
325 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
326 {
80fd140b12ba New command-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 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
328 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
329 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 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
331 }
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 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
333 {
80fd140b12ba New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 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
335
80fd140b12ba New command-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 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
337 {
80fd140b12ba New command-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 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
339 }
80fd140b12ba New command-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 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
342 {
80fd140b12ba New command-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 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
344 }
80fd140b12ba New command-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 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
346 {
80fd140b12ba New command-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 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
348 }
80fd140b12ba New command-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 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
351 {
80fd140b12ba New command-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 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
353 }
80fd140b12ba New command-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 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
355 {
80fd140b12ba New command-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 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
357 }
80fd140b12ba New command-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
4414
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
359 target["deprecated"] = deprecated_;
d928dfcacb4b cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4413
diff changeset
360
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
361 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
362 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
363 {
80fd140b12ba New command-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 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
365 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
366 {
80fd140b12ba New command-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 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
368 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
369
80fd140b12ba New command-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 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
371 {
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
372 for (Parameters::const_iterator field = requestFields_.begin();
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
373 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
374 {
80fd140b12ba New command-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 Json::Value p = Json::objectValue;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
376 TypeToSchema(p, field->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
377 p["description"] = field->second.GetDescription();
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
378 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
379 }
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
380
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
381 if (!it->second.empty() &&
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
382 answerFields_.size() > 0)
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
383 {
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
384 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
385 << EnumerationToString(method_) << " " << uri;
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
386 }
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
387 }
80fd140b12ba New command-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 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
392
80fd140b12ba New command-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 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
394 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
395 {
80fd140b12ba New command-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 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
397 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
398
80fd140b12ba New command-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 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
400 {
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
401 for (Parameters::const_iterator field = answerFields_.begin();
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
402 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
403 {
80fd140b12ba New command-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 Json::Value p = Json::objectValue;
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
405 TypeToSchema(p, field->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
406 p["description"] = field->second.GetDescription();
4400
029366f95217 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4399
diff changeset
407 schema["properties"][field->first] = p;
4417
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
408 }
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 if (!it->second.empty() &&
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
411 answerFields_.size() > 0)
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
412 {
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
413 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
414 << EnumerationToString(method_) << " " << uri;
a4518adede59 openapi for plugins and jobs
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4415
diff changeset
415 }
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
416 }
80fd140b12ba New command-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 }
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
418
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
419 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
420 it != answerTypes_.end(); ++it)
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
421 {
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
422 if (it->first == MimeType_Json &&
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
423 sampleJson_.type() != Json::nullValue)
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
424 {
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
425 // Handled below
4405
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
426 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
427 else if (it->first == MimeType_PlainText &&
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
428 hasSampleText_)
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
429 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
430 // Handled below
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
431 }
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
432 else
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
433 {
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
434 // No sample for this MIME type
5466f336b09f gathering statistics about progress of api documentation
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4404
diff changeset
435 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
436 }
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
437 }
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
438
4409
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
439 if (sampleJson_.type() != Json::nullValue)
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
440 {
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
441 target["responses"]["200"]["content"][EnumerationToString(MimeType_Json)]["schema"]["example"] = sampleJson_;
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
442 }
5784a9eaf502 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4405
diff changeset
443
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
444 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
445 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
446 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
447 }
80fd140b12ba New command-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
4622
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
449 if (!answerHeaders_.empty())
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
450 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
451 Json::Value answerHeaders = Json::objectValue;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
452
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
453 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
454 {
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
455 Json::Value h = Json::objectValue;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
456 h["description"] = it->second.GetDescription();
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
457 answerHeaders[it->first] = h;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
458 }
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 target["responses"]["200"]["headers"] = answerHeaders;
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
461 }
9086aeb9d9d2 RestApiCallDocumentation::SetAnswerHeader() and Toolbox::RemoveSurroundingQuotes()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4437
diff changeset
462
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
463 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
464
80fd140b12ba New command-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 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
466 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
467 {
80fd140b12ba New command-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 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
469 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
470 p["in"] = "query";
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
471 p["required"] = it->second.IsRequired();
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
472 TypeToSchema(p["schema"], it->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
473 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
474 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
475 }
80fd140b12ba New command-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 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
478 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
479 {
80fd140b12ba New command-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 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
481 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
482 p["in"] = "header";
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
483 p["required"] = it->second.IsRequired();
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
484 TypeToSchema(p["schema"], it->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
485 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
486 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
487 }
80fd140b12ba New command-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
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
489 for (Parameters::const_iterator it = uriArguments_.begin();
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
490 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
491 {
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
492 if (expectedUriArguments.find(it->first) == expectedUriArguments.end())
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
493 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
494 throw OrthancException(ErrorCode_InternalError, "Unexpected URI argument: " + it->first);
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
495 }
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
496
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
497 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
498 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
499 p["in"] = "path";
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
500 p["required"] = it->second.IsRequired();
4413
22a1352a0823 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4409
diff changeset
501 TypeToSchema(p["schema"], it->second.GetType());
4403
ad646ff506d0 cont openapi
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4401
diff changeset
502 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
503 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
504 }
80fd140b12ba New command-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
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
506 for (std::set<std::string>::const_iterator it = expectedUriArguments.begin();
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
507 it != expectedUriArguments.end(); ++it)
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
508 {
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
509 if (uriArguments_.find(*it) == uriArguments_.end())
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
510 {
4424
83371ccdfe80 openapi documentation is now completed
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4417
diff changeset
511 throw OrthancException(ErrorCode_InternalError, "Missing URI argument: " + *it);
4401
354ea95b294a documenting system calls
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4400
diff changeset
512 }
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
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
515 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
516
80fd140b12ba New command-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 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
518 }
80fd140b12ba New command-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 }