001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.bean.openapi3; 018 019import static org.apache.juneau.commons.utils.StringUtils.*; 020 021import java.net.*; 022 023import org.apache.juneau.*; 024 025/** 026 * Various useful static methods for creating OpenAPI elements. 027 * 028 * <h5 class='section'>See Also:</h5><ul> 029 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanOpenApi3">juneau-bean-openapi-v3</a> 030 * </ul> 031 */ 032public class OpenApiBuilder { 033 034 /** 035 * Creates an empty {@link Callback} element. 036 * 037 * @return The new element. 038 */ 039 public static final Callback callback() { 040 return new Callback(); 041 } 042 043 /** 044 * Creates an empty {@link Components} element. 045 * 046 * @return The new element. 047 */ 048 public static final Components components() { 049 return new Components(); 050 } 051 052 /** 053 * Creates an empty {@link Contact} element. 054 * 055 * @return The new element. 056 */ 057 public static final Contact contact() { 058 return new Contact(); 059 } 060 061 /** 062 * Creates an {@link Contact} element with the specified {@link Contact#setName(String) name} attribute. 063 * 064 * @param name The {@link Contact#setName(String) name} attribute. 065 * @return The new element. 066 */ 067 public static final Contact contact(String name) { 068 return contact().setName(name); 069 } 070 071 /** 072 * Creates an {@link Contact} element with the specified {@link Contact#setName(String) name}, {@link Contact#setUrl(URI) url}, 073 * and {@link Contact#setEmail(String) email} attributes. 074 * 075 * @param name The {@link Contact#setName(String) name} attribute. 076 * @param url 077 * The {@link Contact#setUrl(URI) url} attribute. 078 * <br>The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 079 * <br>Strings must be valid URIs. 080 * <br>URIs defined by {@link UriResolver} can be used for values. 081 * @param email The {@link Contact#setEmail(String) email} attribute. 082 * @return The new element. 083 */ 084 public static final Contact contact(String name, Object url, String email) { 085 return contact().setName(name).setUrl(toUri(url)).setEmail(email); 086 } 087 088 /** 089 * Creates an empty {@link Discriminator} element. 090 * 091 * @return The new element. 092 */ 093 public static final Discriminator discriminator() { 094 return new Discriminator(); 095 } 096 097 /** 098 * Creates a {@link Discriminator} element with the specified {@link Discriminator#setPropertyName(String) propertyName} attribute. 099 * 100 * @param propertyName The {@link Discriminator#setPropertyName(String) propertyName} attribute. 101 * @return The new element. 102 */ 103 public static final Discriminator discriminator(String propertyName) { 104 return discriminator().setPropertyName(propertyName); 105 } 106 107 /** 108 * Creates an empty {@link Encoding} element. 109 * 110 * @return The new element. 111 */ 112 public static final Encoding encoding() { 113 return new Encoding(); 114 } 115 116 /** 117 * Creates an {@link Encoding} element with the specified {@link Encoding#setContentType(String) contentType} attribute. 118 * 119 * @param contentType The {@link Encoding#setContentType(String) contentType} attribute. 120 * @return The new element. 121 */ 122 public static final Encoding encoding(String contentType) { 123 return encoding().setContentType(contentType); 124 } 125 126 /** 127 * Creates an empty {@link Example} element. 128 * 129 * @return The new element. 130 */ 131 public static final Example example() { 132 return new Example(); 133 } 134 135 /** 136 * Creates an empty {@link ExternalDocumentation} element. 137 * 138 * @return The new element. 139 */ 140 public static final ExternalDocumentation externalDocumentation() { 141 return new ExternalDocumentation(); 142 } 143 144 /** 145 * Creates an {@link ExternalDocumentation} element with the specified {@link ExternalDocumentation#setUrl(URI) url} 146 * attribute. 147 * 148 * @param url 149 * The {@link ExternalDocumentation#setUrl(URI) url} attribute. 150 * <br>The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 151 * <br>Strings must be valid URIs. 152 * <br>URIs defined by {@link UriResolver} can be used for values. 153 * @return The new element. 154 */ 155 public static final ExternalDocumentation externalDocumentation(Object url) { 156 return externalDocumentation().setUrl(toUri(url)); 157 } 158 159 /** 160 * Creates an {@link ExternalDocumentation} element with the specified {@link ExternalDocumentation#setUrl(URI) url} 161 * and {@link ExternalDocumentation#setDescription(String) description} attributes. 162 * 163 * @param url 164 * The {@link ExternalDocumentation#setUrl(URI) url} attribute. 165 * <br>The value can be of any of the following types: {@link URI}, {@link URL}, {@link String}. 166 * <br>Strings must be valid URIs. 167 * <br>URIs defined by {@link UriResolver} can be used for values. 168 * @param description The {@link ExternalDocumentation#setDescription(String) description} attribute. 169 * @return The new element. 170 */ 171 public static final ExternalDocumentation externalDocumentation(Object url, String description) { 172 return externalDocumentation().setUrl(toUri(url)).setDescription(description); 173 } 174 175 /** 176 * Creates an empty {@link HeaderInfo} element. 177 * 178 * @return The new element. 179 */ 180 public static final HeaderInfo headerInfo() { 181 return new HeaderInfo(); 182 } 183 184 /** 185 * Creates an {@link HeaderInfo} element with the specified {@link HeaderInfo#setSchema(SchemaInfo) schema} attribute. 186 * 187 * @param schema The {@link HeaderInfo#setSchema(SchemaInfo) schema} attribute. 188 * @return The new element. 189 */ 190 public static final HeaderInfo headerInfo(SchemaInfo schema) { 191 return headerInfo().setSchema(schema); 192 } 193 194 /** 195 * Creates an empty {@link Info} element. 196 * 197 * @return The new element. 198 */ 199 public static final Info info() { 200 return new Info(); 201 } 202 203 /** 204 * Creates an {@link Info} element with the specified {@link Info#setTitle(String) title} and {@link Info#setVersion(String) version} 205 * attributes. 206 * 207 * @param title The {@link Info#setTitle(String) title} attribute. 208 * @param version The {@link Info#setVersion(String) version} attribute. 209 * @return The new element. 210 */ 211 public static final Info info(String title, String version) { 212 return info().setTitle(title).setVersion(version); 213 } 214 215 /** 216 * Creates an empty {@link Items} element. 217 * 218 * @return The new element. 219 */ 220 public static final Items items() { 221 return new Items(); 222 } 223 224 /** 225 * Creates an {@link Items} element with the specified {@link Items#setType(String) type} attribute. 226 * 227 * @param type The {@link Items#setType(String) type} attribute. 228 * @return The new element. 229 */ 230 public static final Items items(String type) { 231 return items().setType(type); 232 } 233 234 /** 235 * Creates an empty {@link License} element. 236 * 237 * @return The new element. 238 */ 239 public static final License license() { 240 return new License(); 241 } 242 243 /** 244 * Creates an {@link License} element with the specified {@link License#setName(String) name} attribute. 245 * 246 * @param name The {@link License#setName(String) name} attribute. 247 * @return The new element. 248 */ 249 public static final License license(String name) { 250 return license().setName(name); 251 } 252 253 /** 254 * Creates an {@link License} element with the specified {@link License#setName(String) name} and {@link License#setUrl(URI) url} attributes. 255 * 256 * @param name The {@link License#setName(String) name} attribute. 257 * @param url The {@link License#setUrl(URI) url} attribute. 258 * @return The new element. 259 */ 260 public static final License license(String name, URI url) { 261 return license().setName(name).setUrl(url); 262 } 263 264 /** 265 * Creates an empty {@link Link} element. 266 * 267 * @return The new element. 268 */ 269 public static final Link link() { 270 return new Link(); 271 } 272 273 /** 274 * Creates an empty {@link MediaType} element. 275 * 276 * @return The new element. 277 */ 278 public static final MediaType mediaType() { 279 return new MediaType(); 280 } 281 282 /** 283 * Creates an empty {@link OAuthFlow} element. 284 * 285 * @return The new element. 286 */ 287 public static final OAuthFlow oAuthFlow() { 288 return new OAuthFlow(); 289 } 290 291 /** 292 * Creates an empty {@link OAuthFlows} element. 293 * 294 * @return The new element. 295 */ 296 public static final OAuthFlows oAuthFlows() { 297 return new OAuthFlows(); 298 } 299 300 /** 301 * Creates an empty {@link OpenApi} element. 302 * 303 * @return The new element. 304 */ 305 public static final OpenApi openApi() { 306 return new OpenApi(); 307 } 308 309 /** 310 * Creates an {@link OpenApi} element with the specified {@link OpenApi#setInfo(Info) info} attribute. 311 * 312 * @param info The {@link OpenApi#setInfo(Info) info} attribute. 313 * @return The new element. 314 */ 315 public static final OpenApi openApi(Info info) { 316 return openApi().setInfo(info); 317 } 318 319 /** 320 * Creates an empty {@link Operation} element. 321 * 322 * @return The new element. 323 */ 324 public static final Operation operation() { 325 return new Operation(); 326 } 327 328 /** 329 * Creates an empty {@link Parameter} element. 330 * 331 * @return The new element. 332 */ 333 public static final Parameter parameter() { 334 return new Parameter(); 335 } 336 337 /** 338 * Creates a {@link Parameter} element with the specified {@link Parameter#setIn(String) in} and {@link Parameter#setName(String) name} attributes. 339 * 340 * @param in The {@link Parameter#setIn(String) in} attribute. 341 * @param name The {@link Parameter#setName(String) name} attribute. 342 * @return The new element. 343 */ 344 public static final Parameter parameter(String in, String name) { 345 return parameter().setIn(in).setName(name); 346 } 347 348 /** 349 * Creates an empty {@link PathItem} element. 350 * 351 * @return The new element. 352 */ 353 public static final PathItem pathItem() { 354 return new PathItem(); 355 } 356 357 /** 358 * Creates an empty {@link RequestBodyInfo} element. 359 * 360 * @return The new element. 361 */ 362 public static final RequestBodyInfo requestBodyInfo() { 363 return new RequestBodyInfo(); 364 } 365 366 /** 367 * Creates an empty {@link Response} element. 368 * 369 * @return The new element. 370 */ 371 public static final Response response() { 372 return new Response(); 373 } 374 375 /** 376 * Creates a {@link Response} element with the specified {@link Response#setDescription(String) description} attribute. 377 * 378 * @param description The {@link Response#setDescription(String) description} attribute. 379 * @return The new element. 380 */ 381 public static final Response response(String description) { 382 return response().setDescription(description); 383 } 384 385 /** 386 * Creates an empty {@link SchemaInfo} element. 387 * 388 * @return The new element. 389 */ 390 public static final SchemaInfo schemaInfo() { 391 return new SchemaInfo(); 392 } 393 394 /** 395 * Creates an {@link SchemaInfo} element with the specified {@link SchemaInfo#setType(String) type} attribute. 396 * 397 * @param type The {@link SchemaInfo#setType(String) type} attribute. 398 * @return The new element. 399 */ 400 public static final SchemaInfo schemaInfo(String type) { 401 return schemaInfo().setType(type); 402 } 403 404 /** 405 * Creates an empty {@link SecurityRequirement} element. 406 * 407 * @return The new element. 408 */ 409 public static final SecurityRequirement securityRequirement() { 410 return new SecurityRequirement(); 411 } 412 413 /** 414 * Creates an empty {@link SecuritySchemeInfo} element. 415 * 416 * @return The new element. 417 */ 418 public static final SecuritySchemeInfo securitySchemeInfo() { 419 return new SecuritySchemeInfo(); 420 } 421 422 /** 423 * Creates an {@link SecuritySchemeInfo} element with the specified {@link SecuritySchemeInfo#setType(String) type} attribute. 424 * 425 * @param type The {@link SecuritySchemeInfo#setType(String) type} attribute. 426 * @return The new element. 427 */ 428 public static final SecuritySchemeInfo securitySchemeInfo(String type) { 429 return securitySchemeInfo().setType(type); 430 } 431 432 /** 433 * Creates an empty {@link Server} element. 434 * 435 * @return The new element. 436 */ 437 public static final Server server() { 438 return new Server(); 439 } 440 441 /** 442 * Creates an {@link Server} element with the specified {@link Server#setUrl(URI) url} attribute. 443 * 444 * @param url The {@link Server#setUrl(URI) url} attribute. 445 * @return The new element. 446 */ 447 public static final Server server(URI url) { 448 return server().setUrl(url); 449 } 450 451 /** 452 * Creates an empty {@link ServerVariable} element. 453 * 454 * @return The new element. 455 */ 456 public static final ServerVariable serverVariable() { 457 return new ServerVariable(); 458 } 459 460 /** 461 * Creates a {@link ServerVariable} element with the specified {@link ServerVariable#setDefault(String) default} attribute. 462 * 463 * @param defaultValue The {@link ServerVariable#setDefault(String) default} attribute. 464 * @return The new element. 465 */ 466 public static final ServerVariable serverVariable(String defaultValue) { 467 return serverVariable().setDefault(defaultValue); 468 } 469 470 /** 471 * Creates an empty {@link Tag} element. 472 * 473 * @return The new element. 474 */ 475 public static final Tag tag() { 476 return new Tag(); 477 } 478 479 /** 480 * Creates an {@link Tag} element with the specified {@link Tag#setName(String) name} attribute. 481 * 482 * @param name The {@link Tag#setName(String) name} attribute. 483 * @return The new element. 484 */ 485 public static final Tag tag(String name) { 486 return tag().setName(name); 487 } 488 489 /** 490 * Creates an empty {@link Xml} element. 491 * 492 * @return The new element. 493 */ 494 public static final Xml xml() { 495 return new Xml(); 496 } 497 498 /** 499 * Constructor. 500 */ 501 private OpenApiBuilder() {} 502}