Add Builder for Operations
[netconf.git] / restconf / restconf-openapi / src / main / java / org / opendaylight / restconf / openapi / model / Operation.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech s.r.o and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.openapi.model;
9
10 import com.fasterxml.jackson.annotation.JsonInclude;
11 import com.fasterxml.jackson.databind.node.ArrayNode;
12 import com.fasterxml.jackson.databind.node.ObjectNode;
13
14 @JsonInclude(JsonInclude.Include.NON_NULL)
15 public record Operation(boolean deprecated, ArrayNode tags, ArrayNode parameters, ArrayNode security, ArrayNode servers,
16         ObjectNode callbacks, ObjectNode externalDocs, ObjectNode requestBody, ObjectNode responses,
17         String description, String operationId, String summary) {
18
19     private Operation(final Builder builder) {
20         this(builder.deprecated, builder.tags, builder.parameters, builder.security, builder.servers, builder.callbacks,
21             builder.externalDocs, builder.requestBody, builder.responses, builder.description, builder.operationId,
22             builder.summary);
23     }
24
25     @SuppressWarnings("checkstyle:hiddenField")
26     public static class Builder {
27         private boolean deprecated;
28         private ArrayNode tags;
29         private ArrayNode parameters;
30         private ArrayNode security;
31         private ArrayNode servers;
32         private ObjectNode callbacks;
33         private ObjectNode externalDocs;
34         private ObjectNode requestBody;
35         private ObjectNode responses;
36         private String description;
37         private String operationId;
38         private String summary;
39
40         public Builder deprecated(final boolean deprecated) {
41             this.deprecated = deprecated;
42             return this;
43         }
44
45         public Builder tags(final ArrayNode tags) {
46             this.tags = tags;
47             return this;
48         }
49
50         public Builder parameters(final ArrayNode parameters) {
51             this.parameters = parameters;
52             return this;
53         }
54
55         public Builder security(final ArrayNode security) {
56             this.security = security;
57             return this;
58         }
59
60         public Builder servers(final ArrayNode servers) {
61             this.servers = servers;
62             return this;
63         }
64
65         public Builder callbacks(final ObjectNode callbacks) {
66             this.callbacks = callbacks;
67             return this;
68         }
69
70         public Builder externalDocs(final ObjectNode externalDocs) {
71             this.externalDocs = externalDocs;
72             return this;
73         }
74
75         public Builder requestBody(final ObjectNode requestBody) {
76             this.requestBody = requestBody;
77             return this;
78         }
79
80         public Builder responses(final ObjectNode responses) {
81             this.responses = responses;
82             return this;
83         }
84
85         public Builder description(final String description) {
86             this.description = description;
87             return this;
88         }
89
90         public Builder operationId(final String operationId) {
91             this.operationId = operationId;
92             return this;
93         }
94
95         public Builder summary(final String summary) {
96             this.summary = summary;
97             return this;
98         }
99
100         public Operation build() {
101             return new Operation(this);
102         }
103     }
104 }