io.apicurio.datamodels.cloning.Oas30ModelClonerVisitor 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.AuthorizationCodeOAuthFlow;
import io.apicurio.datamodels.core.models.common.ClientCredentialsOAuthFlow;
import io.apicurio.datamodels.core.models.common.Components;
import io.apicurio.datamodels.core.models.common.IDefinition;
import io.apicurio.datamodels.core.models.common.IExample;
import io.apicurio.datamodels.core.models.common.ImplicitOAuthFlow;
import io.apicurio.datamodels.core.models.common.OAuthFlows;
import io.apicurio.datamodels.core.models.common.Operation;
import io.apicurio.datamodels.core.models.common.Parameter;
import io.apicurio.datamodels.core.models.common.PasswordOAuthFlow;
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.core.models.common.Server;
import io.apicurio.datamodels.core.models.common.ServerVariable;
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.v3.models.Oas30Callback;
import io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition;
import io.apicurio.datamodels.openapi.v3.models.Oas30CallbackPathItem;
import io.apicurio.datamodels.openapi.v3.models.Oas30Discriminator;
import io.apicurio.datamodels.openapi.v3.models.Oas30Document;
import io.apicurio.datamodels.openapi.v3.models.Oas30Encoding;
import io.apicurio.datamodels.openapi.v3.models.Oas30Example;
import io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition;
import io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition;
import io.apicurio.datamodels.openapi.v3.models.Oas30Link;
import io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition;
import io.apicurio.datamodels.openapi.v3.models.Oas30LinkParameterExpression;
import io.apicurio.datamodels.openapi.v3.models.Oas30LinkRequestBodyExpression;
import io.apicurio.datamodels.openapi.v3.models.Oas30LinkServer;
import io.apicurio.datamodels.openapi.v3.models.Oas30MediaType;
import io.apicurio.datamodels.openapi.v3.models.Oas30Operation;
import io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody;
import io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition;
import io.apicurio.datamodels.openapi.v3.models.Oas30Response;
import io.apicurio.datamodels.openapi.v3.models.Oas30ResponseDefinition;
import io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema;
import io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30NotSchema;
import io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema;
import io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor;
/**
* TODO: create model factories for OpenAPI (already exists for AsyncAPI) to make this easier
*
* @author [email protected]
*/
public class Oas30ModelClonerVisitor extends ModelClonerVisitor implements IOas30Visitor {
/**
* @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 = ((Oas30Response) ((OasDocument) node.ownerDocument()).createPaths().createPathItem("")
.createOperation(null).createResponses().createDefaultResponse()).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 = (Oas30ResponseDefinition) ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createResponseDefinition(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 = (((Oas30Document) ((Node) node).ownerDocument()).createComponents().createParameterDefinition("").createExample(((Oas30Example) node).getName()));
}
/**
* @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 = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createParameterDefinition(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 = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().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 = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSecurityScheme(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitComponents(io.apicurio.datamodels.core.models.common.Components)
*/
@Override
public void visitComponents(Components node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitCallbackPathItem(io.apicurio.datamodels.openapi.v3.models.Oas30CallbackPathItem)
*/
@Override
public void visitCallbackPathItem(Oas30CallbackPathItem node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createCallbackDefinition("").createPathItem(node.getPath());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitCallback(io.apicurio.datamodels.openapi.v3.models.Oas30Callback)
*/
@Override
public void visitCallback(Oas30Callback node) {
this.clone = ((Oas30Operation) ((OasDocument) (((Node) node).ownerDocument())).createPaths().createPathItem("/").createOperation("GET")).createCallback(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitLinkServer(io.apicurio.datamodels.openapi.v3.models.Oas30LinkServer)
*/
@Override
public void visitLinkServer(Oas30LinkServer node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createLinkDefinition("").createServer();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitCallbackDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30CallbackDefinition)
*/
@Override
public void visitCallbackDefinition(Oas30CallbackDefinition node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createCallbackDefinition(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitLink(io.apicurio.datamodels.openapi.v3.models.Oas30Link)
*/
@Override
public void visitLink(Oas30Link node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createResponseDefinition("").createLink(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitLinkRequestBodyExpression(io.apicurio.datamodels.openapi.v3.models.Oas30LinkRequestBodyExpression)
*/
@Override
public void visitLinkRequestBodyExpression(Oas30LinkRequestBodyExpression node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createLinkDefinition("").createLinkRequestBodyExpression(node.getValue());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitLinkParameterExpression(io.apicurio.datamodels.openapi.v3.models.Oas30LinkParameterExpression)
*/
@Override
public void visitLinkParameterExpression(Oas30LinkParameterExpression node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createLinkDefinition("").createLinkParameterExpression(node.getName(), node.getValue());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitLinkDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30LinkDefinition)
*/
@Override
public void visitLinkDefinition(Oas30LinkDefinition node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createLinkDefinition(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitAuthorizationCodeOAuthFlow(io.apicurio.datamodels.core.models.common.AuthorizationCodeOAuthFlow)
*/
@Override
public void visitAuthorizationCodeOAuthFlow(AuthorizationCodeOAuthFlow node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSecurityScheme("").createOAuthFlows().createAuthorizationCodeOAuthFlow();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitClientCredentialsOAuthFlow(io.apicurio.datamodels.core.models.common.ClientCredentialsOAuthFlow)
*/
@Override
public void visitClientCredentialsOAuthFlow(ClientCredentialsOAuthFlow node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSecurityScheme("").createOAuthFlows().createClientCredentialsOAuthFlow();
}
@Override
public void visitPasswordOAuthFlow(PasswordOAuthFlow node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSecurityScheme("").createOAuthFlows().createPasswordOAuthFlow();
}
@Override
public void visitImplicitOAuthFlow(ImplicitOAuthFlow node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSecurityScheme("").createOAuthFlows().createImplicitOAuthFlow();
}
@Override
public void visitOAuthFlows(OAuthFlows node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSecurityScheme("").createOAuthFlows();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitEncoding(io.apicurio.datamodels.openapi.v3.models.Oas30Encoding)
*/
@Override
public void visitEncoding(Oas30Encoding node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createRequestBodyDefinition("").createMediaType("").createEncoding(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitMediaType(io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)
*/
@Override
public void visitMediaType(Oas30MediaType node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createRequestBodyDefinition("").createMediaType(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitHeaderDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30HeaderDefinition)
*/
@Override
public void visitHeaderDefinition(Oas30HeaderDefinition node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createHeaderDefinition(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitRequestBody(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBody)
*/
@Override
public void visitRequestBody(Oas30RequestBody node) {
this.clone = ((Oas30Operation) ((OasDocument) node.ownerDocument()).createPaths().createPathItem("").createOperation("GET")).createRequestBody();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitRequestBodyDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition)
*/
@Override
public void visitRequestBodyDefinition(Oas30RequestBodyDefinition node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createRequestBodyDefinition(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitExampleDefinition(io.apicurio.datamodels.openapi.v3.models.Oas30ExampleDefinition)
*/
@Override
public void visitExampleDefinition(Oas30ExampleDefinition node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createExampleDefinition(node.getName());
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitDiscriminator(io.apicurio.datamodels.openapi.v3.models.Oas30Discriminator)
*/
@Override
public void visitDiscriminator(Oas30Discriminator node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSchemaDefinition("").createDiscriminator();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitNotSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30NotSchema)
*/
@Override
public void visitNotSchema(Oas30NotSchema node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSchemaDefinition("").createNotSchema();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitOneOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema)
*/
@Override
public void visitOneOfSchema(Oas30OneOfSchema node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSchemaDefinition("").createOneOfSchema();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitAnyOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema)
*/
@Override
public void visitAnyOfSchema(Oas30AnyOfSchema node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createComponents().createSchemaDefinition("").createAnyOfSchema();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitServer(io.apicurio.datamodels.core.models.common.Server)
*/
@Override
public void visitServer(Server node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createServer();
}
/**
* @see io.apicurio.datamodels.openapi.v3.visitors.IOas30Visitor#visitServerVariable(io.apicurio.datamodels.core.models.common.ServerVariable)
*/
@Override
public void visitServerVariable(ServerVariable node) {
this.clone = ((Oas30Document) ((Node) node).ownerDocument()).createServer().createServerVariable(node.getName());
}
}