Separate logic of get root path
[netconf.git] / restconf / restconf-openapi / src / main / java / org / opendaylight / restconf / openapi / model / GetRootEntity.java
1 /*
2  * Copyright (c) 2024 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 static java.util.Objects.requireNonNull;
11 import static javax.ws.rs.core.Response.Status.OK;
12
13 import com.fasterxml.jackson.core.JsonGenerator;
14 import java.io.IOException;
15 import javax.ws.rs.HttpMethod;
16 import org.eclipse.jdt.annotation.NonNull;
17
18 public final class GetRootEntity extends GetEntity {
19     private final String type;
20
21     public GetRootEntity(final @NonNull String deviceName, final @NonNull String type) {
22         super(null, deviceName, "", null, null, false);
23         this.type = requireNonNull(type);
24     }
25
26     @Override
27     public void generate(final @NonNull JsonGenerator generator) throws IOException {
28         generator.writeObjectFieldStart("get");
29         generator.writeStringField(DESCRIPTION, type.equals("data")
30             ? "Queries the config (startup) datastore on the mounted hosted."
31             : "Queries the available operations (RPC calls) on the mounted hosted.");
32         generator.writeObjectFieldStart(RESPONSES);
33         generator.writeObjectFieldStart(String.valueOf(OK.getStatusCode()));
34         generator.writeStringField(DESCRIPTION, "OK");
35         generator.writeEndObject(); //end of 200
36         generator.writeEndObject(); // end of responses
37         final var summary = HttpMethod.GET + " - " + deviceName() + " - datastore - " + type;
38         generator.writeStringField(SUMMARY, summary);
39         generator.writeArrayFieldStart("tags");
40         generator.writeString(deviceName() + " GET root");
41         generator.writeEndArray(); //end of tags
42         generator.writeEndObject(); //end of get
43     }
44 }