1 package io.swagger.v3.oas.models;
2
3 import com.fasterxml.jackson.annotation.JsonIgnore;
4 import io.swagger.v3.oas.models.annotations.OpenAPI31;
5 import io.swagger.v3.oas.models.info.Info;
6 import io.swagger.v3.oas.models.media.Schema;
7 import io.swagger.v3.oas.models.security.SecurityRequirement;
8 import io.swagger.v3.oas.models.security.SecurityScheme;
9 import io.swagger.v3.oas.models.servers.Server;
10 import io.swagger.v3.oas.models.tags.Tag;
11
12 import java.util.ArrayList;
13 import java.util.LinkedHashMap;
14 import java.util.List;
15 import java.util.Map;
16 import java.util.Objects;
17
18
24
25 public class OpenAPI {
26 private String openapi = "3.0.1";
27 private Info info = null;
28 private ExternalDocumentation externalDocs = null;
29 private List<Server> servers = null;
30 private List<SecurityRequirement> security = null;
31 private List<Tag> tags = null;
32 private Paths paths = null;
33 private Components components = null;
34 private java.util.Map<String, Object> extensions = null;
35
36
39 @OpenAPI31
40 private String jsonSchemaDialect;
41
42 public OpenAPI() {}
43 public OpenAPI(SpecVersion specVersion) { this.specVersion = specVersion;}
44 private SpecVersion specVersion = SpecVersion.V30;
45
46 @JsonIgnore
47 public SpecVersion getSpecVersion() {
48 return this.specVersion;
49 }
50
51 public void setSpecVersion(SpecVersion specVersion) {
52 this.specVersion = specVersion;
53 }
54
55 public OpenAPI specVersion(SpecVersion specVersion) {
56 this.setSpecVersion(specVersion);
57 return this;
58 }
59
60
63 @OpenAPI31
64 private java.util.Map<String, PathItem> webhooks = null;
65
66
71
72 public String getOpenapi() {
73 return openapi;
74 }
75
76 public void setOpenapi(String openapi) {
77 this.openapi = openapi;
78 }
79
80 public OpenAPI openapi(String openapi) {
81 this.openapi = openapi;
82 return this;
83 }
84
85
90
91 public Info getInfo() {
92 return info;
93 }
94
95 public void setInfo(Info info) {
96 this.info = info;
97 }
98
99 public OpenAPI info(Info info) {
100 this.info = info;
101 return this;
102 }
103
104
109
110 public ExternalDocumentation getExternalDocs() {
111 return externalDocs;
112 }
113
114 public void setExternalDocs(ExternalDocumentation externalDocs) {
115 this.externalDocs = externalDocs;
116 }
117
118 public OpenAPI externalDocs(ExternalDocumentation externalDocs) {
119 this.externalDocs = externalDocs;
120 return this;
121 }
122
123
128
129 public List<Server> getServers() {
130 return servers;
131 }
132
133 public void setServers(List<Server> servers) {
134 this.servers = servers;
135 }
136
137 public OpenAPI servers(List<Server> servers) {
138 this.servers = servers;
139 return this;
140 }
141
142 public OpenAPI addServersItem(Server serversItem) {
143 if (this.servers == null) {
144 this.servers = new ArrayList<>();
145 }
146 this.servers.add(serversItem);
147 return this;
148 }
149
150
155
156 public List<SecurityRequirement> getSecurity() {
157 return security;
158 }
159
160 public void setSecurity(List<SecurityRequirement> security) {
161 this.security = security;
162 }
163
164 public OpenAPI security(List<SecurityRequirement> security) {
165 this.security = security;
166 return this;
167 }
168
169 public OpenAPI addSecurityItem(SecurityRequirement securityItem) {
170 if (this.security == null) {
171 this.security = new ArrayList<>();
172 }
173 this.security.add(securityItem);
174 return this;
175 }
176
177
182
183 public List<Tag> getTags() {
184 return tags;
185 }
186
187 public void setTags(List<Tag> tags) {
188 this.tags = tags;
189 }
190
191 public OpenAPI tags(List<Tag> tags) {
192 this.tags = tags;
193 return this;
194 }
195
196 public OpenAPI addTagsItem(Tag tagsItem) {
197 if (this.tags == null) {
198 this.tags = new ArrayList<>();
199 }
200 this.tags.add(tagsItem);
201 return this;
202 }
203
204
209
210 public Paths getPaths() {
211 return paths;
212 }
213
214 public void setPaths(Paths paths) {
215 this.paths = paths;
216 }
217
218 public OpenAPI paths(Paths paths) {
219 this.paths = paths;
220 return this;
221 }
222
223
228
229 public Components getComponents() {
230 return components;
231 }
232
233 public void setComponents(Components components) {
234 this.components = components;
235 }
236
237 public OpenAPI components(Components components) {
238 this.components = components;
239 return this;
240 }
241
242
245
246 public OpenAPI path(String name, PathItem path) {
247 if (this.paths == null) {
248 this.paths = new Paths();
249 }
250
251 this.paths.addPathItem(name, path);
252 return this;
253 }
254
255 public OpenAPI schema(String name, Schema schema) {
256 if (components == null) {
257 this.components = new Components();
258 }
259 components.addSchemas(name, schema);
260 return this;
261 }
262
263 public OpenAPI schemaRequirement(String name, SecurityScheme securityScheme) {
264 if (components == null) {
265 this.components = new Components();
266 }
267 components.addSecuritySchemes(name, securityScheme);
268 return this;
269 }
270
271
277
278 @OpenAPI31
279 public Map<String, PathItem> getWebhooks() {
280 return webhooks;
281 }
282
283 @OpenAPI31
284 public void setWebhooks(Map<String, PathItem> webhooks) {
285 this.webhooks = webhooks;
286 }
287
288 @OpenAPI31
289 public OpenAPI webhooks(Map<String, PathItem> webhooks) {
290 this.webhooks = webhooks;
291 return this;
292 }
293
294 @OpenAPI31
295 public OpenAPI addWebhooks(String key, PathItem pathItem) {
296 if (this.webhooks == null) {
297 this.webhooks = new LinkedHashMap<>();
298 }
299 this.webhooks.put(key, pathItem);
300 return this;
301 }
302
303
306 @OpenAPI31
307 public String getJsonSchemaDialect() {
308 return jsonSchemaDialect;
309 }
310
311
314 @OpenAPI31
315 public void setJsonSchemaDialect(String jsonSchemaDialect) {
316 this.jsonSchemaDialect = jsonSchemaDialect;
317 }
318
319 @OpenAPI31
320 public OpenAPI jsonSchemaDialect(String jsonSchemaDialect) {
321 this.jsonSchemaDialect = jsonSchemaDialect;
322 return this;
323 }
324
325
326 @Override
327 public boolean equals(java.lang.Object o) {
328 if (this == o) {
329 return true;
330 }
331 if (o == null || getClass() != o.getClass()) {
332 return false;
333 }
334 OpenAPI openAPI = (OpenAPI) o;
335 return Objects.equals(this.openapi, openAPI.openapi) &&
336 Objects.equals(this.info, openAPI.info) &&
337 Objects.equals(this.externalDocs, openAPI.externalDocs) &&
338 Objects.equals(this.servers, openAPI.servers) &&
339 Objects.equals(this.security, openAPI.security) &&
340 Objects.equals(this.tags, openAPI.tags) &&
341 Objects.equals(this.paths, openAPI.paths) &&
342 Objects.equals(this.components, openAPI.components) &&
343 Objects.equals(this.webhooks, openAPI.webhooks) &&
344 Objects.equals(this.extensions, openAPI.extensions) &&
345 Objects.equals(this.jsonSchemaDialect, openAPI.jsonSchemaDialect);
346 }
347
348 @Override
349 public int hashCode() {
350 return Objects.hash(openapi, info, externalDocs, servers, security, tags, paths, components, webhooks, extensions, jsonSchemaDialect);
351 }
352
353 public java.util.Map<String, Object> getExtensions() {
354 return extensions;
355 }
356
357 public void addExtension(String name, Object value) {
358 if (name == null || name.isEmpty() || !name.startsWith("x-")) {
359 return;
360 }
361 if (this.extensions == null) {
362 this.extensions = new java.util.LinkedHashMap<>();
363 }
364 this.extensions.put(name, value);
365 }
366
367 @OpenAPI31
368 public void addExtension31(String name, Object value) {
369 if (name != null && (name.startsWith("x-oas-") || name.startsWith("x-oai-"))) {
370 return;
371 }
372 addExtension(name, value);
373 }
374
375 public void setExtensions(java.util.Map<String, Object> extensions) {
376 this.extensions = extensions;
377 }
378
379 public OpenAPI extensions(java.util.Map<String, Object> extensions) {
380 this.extensions = extensions;
381 return this;
382 }
383
384 @Override
385 public String toString() {
386 StringBuilder sb = new StringBuilder();
387 sb.append("class OpenAPI {\n");
388
389 sb.append(" openapi: ").append(toIndentedString(openapi)).append("\n");
390 sb.append(" info: ").append(toIndentedString(info)).append("\n");
391 sb.append(" externalDocs: ").append(toIndentedString(externalDocs)).append("\n");
392 sb.append(" servers: ").append(toIndentedString(servers)).append("\n");
393 sb.append(" security: ").append(toIndentedString(security)).append("\n");
394 sb.append(" tags: ").append(toIndentedString(tags)).append("\n");
395 sb.append(" paths: ").append(toIndentedString(paths)).append("\n");
396 sb.append(" components: ").append(toIndentedString(components)).append("\n");
397 if (specVersion == SpecVersion.V31) sb.append(" webhooks: ").append(toIndentedString(webhooks)).append("\n");
398 if (specVersion == SpecVersion.V31) sb.append(" jsonSchemaDialect: ").append(toIndentedString(jsonSchemaDialect)).append("\n");
399 sb.append("}");
400 return sb.toString();
401 }
402
403
407 private String toIndentedString(java.lang.Object o) {
408 if (o == null) {
409 return "null";
410 }
411 return o.toString().replace("\n", "\n ");
412 }
413
414 }
415
416