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