io.apicurio.datamodels.openapi.visitors.OasNodePathVisitor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of data-models-test Show documentation
Show all versions of data-models-test Show documentation
Open Source API Design Studio
/*
* Copyright 2019 Red Hat
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.apicurio.datamodels.openapi.visitors;
import io.apicurio.datamodels.compat.NodeCompat;
import io.apicurio.datamodels.core.Constants;
import io.apicurio.datamodels.core.models.common.IDefinition;
import io.apicurio.datamodels.core.models.common.IExample;
import io.apicurio.datamodels.core.visitors.NodePathVisitor;
import io.apicurio.datamodels.openapi.models.IOasPropertySchema;
import io.apicurio.datamodels.openapi.models.OasHeader;
import io.apicurio.datamodels.openapi.models.OasPathItem;
import io.apicurio.datamodels.openapi.models.OasPaths;
import io.apicurio.datamodels.openapi.models.OasResponse;
import io.apicurio.datamodels.openapi.models.OasResponses;
import io.apicurio.datamodels.openapi.models.OasSchema;
import io.apicurio.datamodels.openapi.models.OasXML;
/**
* @author [email protected]
*/
public class OasNodePathVisitor extends NodePathVisitor implements IOasVisitor {
/**
* Constructor.
*/
public OasNodePathVisitor() {
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPaths(io.apicurio.datamodels.openapi.models.OasPaths)
*/
@Override
public void visitPaths(OasPaths node) {
this.path.prependSegment(Constants.PROP_PATHS, false);
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)
*/
@Override
public void visitPathItem(OasPathItem node) {
this.path.prependSegment(node.getPath(), true);
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponses(io.apicurio.datamodels.openapi.models.OasResponses)
*/
@Override
public void visitResponses(OasResponses node) {
this.path.prependSegment(Constants.PROP_RESPONSES, false);
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponse(io.apicurio.datamodels.openapi.models.OasResponse)
*/
@Override
public void visitResponse(OasResponse node) {
if (node.getName() == null) {
this.path.prependSegment(Constants.PROP_DEFAULT, false);
} else {
this.path.prependSegment(node.getName(), true);
}
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitXML(io.apicurio.datamodels.openapi.models.OasXML)
*/
@Override
public void visitXML(OasXML node) {
this.path.prependSegment(Constants.PROP_XML, false);
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitAllOfSchema(io.apicurio.datamodels.openapi.models.OasSchema)
*/
@Override
public void visitAllOfSchema(OasSchema node) {
int idx = NodeCompat.indexOf(node, node.parent(), Constants.PROP_ALL_OF);
if (idx != -1) {
this.path.prependSegment(String.valueOf(idx), true);
this.path.prependSegment(Constants.PROP_ALL_OF, false);
}
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitItemsSchema(io.apicurio.datamodels.openapi.models.OasSchema)
*/
@Override
public void visitItemsSchema(OasSchema node) {
if (node.hasItemsSchemas()) {
int idx = NodeCompat.indexOf(node, node.parent(), Constants.PROP_ITEMS);
if (idx != -1) {
this.path.prependSegment(String.valueOf(idx), true);
this.path.prependSegment(Constants.PROP_ITEMS, false);
}
} else {
this.path.prependSegment(Constants.PROP_ITEMS, false);
}
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitAdditionalPropertiesSchema(io.apicurio.datamodels.openapi.models.OasSchema)
*/
@Override
public void visitAdditionalPropertiesSchema(OasSchema node) {
this.path.prependSegment(Constants.PROP_ADDITIONAL_PROPERTIES, false);
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPropertySchema(io.apicurio.datamodels.openapi.models.IOasPropertySchema)
*/
@Override
public void visitPropertySchema(IOasPropertySchema node) {
this.path.prependSegment(node.getPropertyName(), true);
this.path.prependSegment(Constants.PROP_PROPERTIES, false);
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitHeader(io.apicurio.datamodels.openapi.models.OasHeader)
*/
@Override
public void visitHeader(OasHeader node) {
this.path.prependSegment(node.getName(), true);
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponseDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
*/
@Override
public void visitResponseDefinition(IDefinition node) {
this.path.prependSegment(node.getName(), true);
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
*/
@Override
public void visitExample(IExample node) {
throw new RuntimeException("Must be implemented by subclasses.");
}
}