io.apicurio.datamodels.cloning.Oas20ModelClonerVisitor Maven / Gradle / Ivy
/*
* Copyright 2019 JBoss Inc
*
* 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.cloning;
import io.apicurio.datamodels.core.models.Node;
import io.apicurio.datamodels.core.models.common.IDefinition;
import io.apicurio.datamodels.core.models.common.IExample;
import io.apicurio.datamodels.core.models.common.Operation;
import io.apicurio.datamodels.core.models.common.Parameter;
import io.apicurio.datamodels.core.models.common.Schema;
import io.apicurio.datamodels.core.models.common.SecurityRequirement;
import io.apicurio.datamodels.core.models.common.SecurityScheme;
import io.apicurio.datamodels.openapi.models.IOasPropertySchema;
import io.apicurio.datamodels.openapi.models.OasDocument;
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;
import io.apicurio.datamodels.openapi.v2.models.Oas20Definitions;
import io.apicurio.datamodels.openapi.v2.models.Oas20Document;
import io.apicurio.datamodels.openapi.v2.models.Oas20Headers;
import io.apicurio.datamodels.openapi.v2.models.Oas20Items;
import io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinitions;
import io.apicurio.datamodels.openapi.v2.models.Oas20Response;
import io.apicurio.datamodels.openapi.v2.models.Oas20ResponseDefinitions;
import io.apicurio.datamodels.openapi.v2.models.Oas20Scopes;
import io.apicurio.datamodels.openapi.v2.models.Oas20SecurityDefinitions;
import io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor;
/**
* @author [email protected]
*/
public class Oas20ModelClonerVisitor extends ModelClonerVisitor implements IOas20Visitor {
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPaths(io.apicurio.datamodels.openapi.models.OasPaths)
*/
@Override
public void visitPaths(OasPaths node) {
this.clone = ((OasDocument) node.ownerDocument()).createPaths();
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)
*/
@Override
public void visitPathItem(OasPathItem node) {
this.clone = ((OasDocument) node.ownerDocument()).createPaths().createPathItem(node.getPath());
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponse(io.apicurio.datamodels.openapi.models.OasResponse)
*/
@Override
public void visitResponse(OasResponse node) {
this.clone = ((OasDocument) node.ownerDocument()).createPaths().createPathItem("")
.createOperation(null).createResponses().createResponse(node.getStatusCode());
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponses(io.apicurio.datamodels.openapi.models.OasResponses)
*/
@Override
public void visitResponses(OasResponses node) {
this.clone = ((OasDocument) node.ownerDocument()).createPaths().createPathItem("")
.createOperation(null).createResponses();
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitXML(io.apicurio.datamodels.openapi.models.OasXML)
*/
@Override
public void visitXML(OasXML node) {
this.clone = ((OasSchema) ((OasDocument) node.ownerDocument()).createPaths().createPathItem("")
.createOperation(null).createParameter().createSchema()).createXML();
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitAllOfSchema(io.apicurio.datamodels.openapi.models.OasSchema)
*/
@Override
public void visitAllOfSchema(OasSchema node) {
this.clone = node.createAllOfSchema();
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitItemsSchema(io.apicurio.datamodels.openapi.models.OasSchema)
*/
@Override
public void visitItemsSchema(OasSchema node) {
this.clone = ((OasSchema) ((OasDocument) node.ownerDocument()).createPaths().createPathItem("")
.createOperation(null).createParameter().createSchema()).createItemsSchema();
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitAdditionalPropertiesSchema(io.apicurio.datamodels.openapi.models.OasSchema)
*/
@Override
public void visitAdditionalPropertiesSchema(OasSchema node) {
this.clone = ((OasSchema) ((OasDocument) node.ownerDocument()).createPaths().createPathItem("")
.createOperation(null).createParameter().createSchema()).createAdditionalPropertiesSchema();
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPropertySchema(io.apicurio.datamodels.openapi.models.IOasPropertySchema)
*/
@Override
public void visitPropertySchema(IOasPropertySchema node) {
this.clone = ((OasSchema) ((OasDocument) ((Node) node).ownerDocument()).createPaths().createPathItem("")
.createOperation(null).createParameter().createSchema()).createPropertySchema(node.getPropertyName());
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitHeader(io.apicurio.datamodels.openapi.models.OasHeader)
*/
@Override
public void visitHeader(OasHeader node) {
this.clone = ((Oas20Response) ((OasDocument) node.ownerDocument()).createPaths().createPathItem("")
.createOperation(null).createResponses().createDefaultResponse()).createHeaders().createHeader(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitResponseDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
*/
@Override
public void visitResponseDefinition(IDefinition node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createResponseDefinitions().createResponse(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitExample(io.apicurio.datamodels.core.models.common.IExample)
*/
@Override
public void visitExample(IExample node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createResponseDefinitions().createResponse("").createExample();
}
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitOperation(io.apicurio.datamodels.core.models.common.Operation)
*/
@Override
public void visitOperation(Operation node) {
this.clone = ((OasDocument) node.ownerDocument()).createPaths().createPathItem("").createOperation(node.getType());
}
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitParameterDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
*/
@Override
public void visitParameterDefinition(IDefinition node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createParameterDefinitions().createParameter(node.getName());
}
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitParameter(io.apicurio.datamodels.core.models.common.Parameter)
*/
@Override
public void visitParameter(Parameter node) {
this.clone = ((OasDocument) node.ownerDocument()).createPaths().createPathItem("").createParameter();
}
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitSchemaDefinition(io.apicurio.datamodels.core.models.common.IDefinition)
*/
@Override
public void visitSchemaDefinition(IDefinition node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createDefinitions().createSchemaDefinition(node.getName());
}
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitSchema(io.apicurio.datamodels.core.models.common.Schema)
*/
@Override
public void visitSchema(Schema node) {
this.clone = ((OasDocument) node.ownerDocument()).createPaths().createPathItem("").createParameter().createSchema();
}
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitSecurityRequirement(io.apicurio.datamodels.core.models.common.SecurityRequirement)
*/
@Override
public void visitSecurityRequirement(SecurityRequirement node) {
this.clone = ((OasDocument) node.ownerDocument()).createSecurityRequirement();
}
/**
* @see io.apicurio.datamodels.core.visitors.IVisitor#visitSecurityScheme(io.apicurio.datamodels.core.models.common.SecurityScheme)
*/
@Override
public void visitSecurityScheme(SecurityScheme node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createSecurityDefinitions().createSecurityScheme(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitItems(io.apicurio.datamodels.openapi.v2.models.Oas20Items)
*/
@Override
public void visitItems(Oas20Items node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createDefinitions().createSchemaDefinition("").createItemsSchema();
}
/**
* @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitScopes(io.apicurio.datamodels.openapi.v2.models.Oas20Scopes)
*/
@Override
public void visitScopes(Oas20Scopes node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createSecurityDefinitions().createSecurityScheme("").createScopes();
}
/**
* @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitSecurityDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityDefinitions)
*/
@Override
public void visitSecurityDefinitions(Oas20SecurityDefinitions node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createSecurityDefinitions();
}
/**
* @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20Definitions)
*/
@Override
public void visitDefinitions(Oas20Definitions node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createDefinitions();
}
/**
* @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitParameterDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinitions)
*/
@Override
public void visitParameterDefinitions(Oas20ParameterDefinitions node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createParameterDefinitions();
}
/**
* @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitHeaders(io.apicurio.datamodels.openapi.v2.models.Oas20Headers)
*/
@Override
public void visitHeaders(Oas20Headers node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createResponseDefinitions().createResponse("").createHeaders();
}
/**
* @see io.apicurio.datamodels.openapi.v2.visitors.IOas20Visitor#visitResponseDefinitions(io.apicurio.datamodels.openapi.v2.models.Oas20ResponseDefinitions)
*/
@Override
public void visitResponseDefinitions(Oas20ResponseDefinitions node) {
this.clone = ((Oas20Document) ((Node) node).ownerDocument()).createResponseDefinitions();
}
}