2d5c2ac9ffc47c14488cb04b51a4a105658fd590
[netconf.git] / restconf / restconf-openapi / src / main / java / org / opendaylight / restconf / openapi / model / PathEntity.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.core.JsonGenerator;
11 import java.io.IOException;
12 import java.util.Objects;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.eclipse.jdt.annotation.Nullable;
15
16 public final class PathEntity extends OpenApiEntity {
17     private final @NonNull String path;
18     private final @Nullable PostEntity post;
19     private final @Nullable PatchEntity patch;
20     private final @Nullable GetEntity get;
21     private final @Nullable PutEntity put;
22     private final @Nullable DeleteEntity delete;
23
24     public PathEntity(final String path, final PostEntity post, final PatchEntity patch,
25             final PutEntity put, final GetEntity get, final DeleteEntity delete) {
26         this.path = Objects.requireNonNull(path);
27         this.post = post;
28         this.patch = patch;
29         this.put = put;
30         this.delete = delete;
31         this.get = get;
32     }
33
34     @Override
35     public void generate(@NonNull JsonGenerator generator) throws IOException {
36         generator.writeObjectFieldStart(path);
37         final var ref = ref();
38         if (ref != null) {
39             generator.writeStringField("$ref", ref);
40         }
41         final var summary = summary();
42         if (summary != null) {
43             generator.writeStringField("summary", summary);
44         }
45         final var description = description();
46         if (ref != null) {
47             generator.writeStringField("description", description);
48         }
49         final var postOperation = post();
50         if (postOperation != null) {
51             postOperation.generate(generator);
52         }
53         final var putOperation = put();
54         if (putOperation != null) {
55             putOperation.generate(generator);
56         }
57         final var patchOperation = patch();
58         if (patchOperation != null) {
59             patchOperation.generate(generator);
60         }
61         final var deleteOperation = delete();
62         if (deleteOperation != null) {
63             deleteOperation.generate(generator);
64         }
65         final var getOperation = get();
66         if (getOperation != null) {
67             getOperation.generate(generator);
68         }
69         generator.writeEndObject();
70     }
71
72     @Nullable String ref() {
73         return null;
74     }
75
76     @Nullable String summary() {
77         return null;
78     }
79
80     @Nullable String description() {
81         return null;
82     }
83
84     @Nullable OperationEntity post() {
85         return post;
86     }
87
88     @Nullable OperationEntity put() {
89         return put;
90     }
91
92     @Nullable OperationEntity patch() {
93         return patch;
94     }
95
96     @Nullable OperationEntity get() {
97         return get;
98     }
99
100     @Nullable OperationEntity delete() {
101         return delete;
102     }
103 }