2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.restconf.openapi.model;
10 import static org.opendaylight.restconf.openapi.model.PropertyEntity.isSchemaNodeMandatory;
11 import static org.opendaylight.restconf.openapi.util.RestDocgenUtil.widthList;
13 import com.fasterxml.jackson.core.JsonGenerator;
14 import java.io.IOException;
15 import java.util.HashMap;
16 import java.util.List;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.opendaylight.restconf.openapi.impl.DefinitionNames;
20 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
22 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
24 import org.opendaylight.yangtools.yang.model.util.SchemaInferenceStack;
26 public final class NodeSchemaEntity extends SchemaEntity {
28 public NodeSchemaEntity(final @NonNull SchemaNode value, final @NonNull String title,
29 final @Nullable String discriminator, final @NonNull String type,
30 final @NonNull SchemaInferenceStack context, final @NonNull String parentName, final boolean isParentConfig,
31 final @NonNull DefinitionNames definitionNames, final @NonNull Integer width,
32 final @NonNull Integer depth, final @NonNull Integer nodeDepth) {
33 super(value, title, discriminator, type, context, parentName, isParentConfig, definitionNames, width, depth,
38 void generateProperties(final @NonNull JsonGenerator generator, final @NonNull List<String> required)
40 if (depth > 0 && nodeDepth + 1 > depth) {
43 final var childNodes = new HashMap<String, DataSchemaNode>();
44 final var dataSchemaNodes = widthList((DataNodeContainer) value(), width);
45 for (final var childNode : dataSchemaNodes) {
46 childNodes.put(childNode.getQName().getLocalName(), childNode);
48 final boolean isValueConfig = ((DataSchemaNode) value()).isConfiguration();
50 for (final var childNode : childNodes.values()) {
51 if (shouldBeAddedAsProperty(childNode, isValueConfig)) {
52 new PropertyEntity(childNode, generator, stack(), required, parentName() + "_"
53 + value().getQName().getLocalName(), isValueConfig, definitionNames(), width, depth, nodeDepth);
58 private static boolean shouldBeAddedAsProperty(final DataSchemaNode childNode, final boolean isValueConfig) {
59 final boolean isChildNodeConfig = childNode.isConfiguration();
60 if (childNode instanceof ContainerSchemaNode) {
61 return isChildNodeConfig || isSchemaNodeMandatory(childNode) || !isValueConfig;
63 return isChildNodeConfig || !isValueConfig;