Mercurial > hg > orthanc
comparison OrthancFramework/Sources/RestApi/RestApiCallDocumentation.h @ 4399:80fd140b12ba
New command-line option: "--openapi" to write the OpenAPI documentation of the REST API to a file
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 23 Dec 2020 12:21:03 +0100 |
parents | |
children | 029366f95217 |
comparison
equal
deleted
inserted
replaced
4398:38c22715bb56 | 4399:80fd140b12ba |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with this program. If not, see | |
19 * <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #pragma once | |
24 | |
25 #include "../Enumerations.h" | |
26 | |
27 #include <boost/noncopyable.hpp> | |
28 #include <json/value.h> | |
29 | |
30 #include <map> | |
31 #include <set> | |
32 | |
33 namespace Orthanc | |
34 { | |
35 class RestApiCallDocumentation : public boost::noncopyable | |
36 { | |
37 public: | |
38 enum Type | |
39 { | |
40 Type_Unknown, | |
41 Type_Text, | |
42 Type_String, | |
43 Type_Number, | |
44 Type_Boolean, | |
45 Type_JsonListOfStrings, | |
46 Type_JsonObject | |
47 }; | |
48 | |
49 private: | |
50 struct Parameter | |
51 { | |
52 Type type_; | |
53 std::string description_; | |
54 }; | |
55 | |
56 typedef std::map<std::string, Parameter> Parameters; | |
57 typedef std::map<MimeType, std::string> AllowedTypes; | |
58 | |
59 HttpMethod method_; | |
60 std::string tag_; | |
61 std::string summary_; | |
62 std::string description_; | |
63 Parameters uriComponents_; | |
64 Parameters httpHeaders_; | |
65 Parameters getArguments_; | |
66 AllowedTypes requestTypes_; | |
67 Parameters requestFields_; // For JSON request | |
68 AllowedTypes answerTypes_; | |
69 Parameters answerFields_; // Only if JSON object | |
70 std::string answerDescription_; | |
71 Json::Value sample_; | |
72 | |
73 public: | |
74 RestApiCallDocumentation(HttpMethod method) : | |
75 method_(method), | |
76 sample_(Json::nullValue) | |
77 { | |
78 } | |
79 | |
80 RestApiCallDocumentation& SetTag(const std::string& tag) | |
81 { | |
82 tag_ = tag; | |
83 return *this; | |
84 } | |
85 | |
86 RestApiCallDocumentation& SetSummary(const std::string& summary) | |
87 { | |
88 summary_ = summary; | |
89 return *this; | |
90 } | |
91 | |
92 RestApiCallDocumentation& SetDescription(const std::string& description) | |
93 { | |
94 description_ = description; | |
95 return *this; | |
96 } | |
97 | |
98 RestApiCallDocumentation& AddRequestType(MimeType mime, | |
99 const std::string& description); | |
100 | |
101 RestApiCallDocumentation& SetRequestField(const std::string& name, | |
102 Type type, | |
103 const std::string& description); | |
104 | |
105 RestApiCallDocumentation& AddAnswerType(MimeType type, | |
106 const std::string& description); | |
107 | |
108 RestApiCallDocumentation& SetUriComponent(const std::string& name, | |
109 Type type, | |
110 const std::string& description); | |
111 | |
112 RestApiCallDocumentation& SetHttpHeader(const std::string& name, | |
113 const std::string& description); | |
114 | |
115 RestApiCallDocumentation& SetHttpGetArgument(const std::string& name, | |
116 Type type, | |
117 const std::string& description); | |
118 | |
119 RestApiCallDocumentation& SetAnswerField(const std::string& name, | |
120 Type type, | |
121 const std::string& description); | |
122 | |
123 void SetHttpGetSample(const std::string& url); | |
124 | |
125 void SetSample(const Json::Value& sample) | |
126 { | |
127 sample_ = sample; | |
128 } | |
129 | |
130 bool FormatOpenApi(Json::Value& target) const; | |
131 }; | |
132 } |