Search in sources :

Example 1 with Oas20PropertySchema

use of io.apicurio.datamodels.openapi.v2.models.Oas20Schema.Oas20PropertySchema in project apicurio-data-models by Apicurio.

the class Oas20to30TransformationVisitor method visitPropertySchema.

/**
 * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitPropertySchema(io.apicurio.datamodels.core.models.common.IPropertySchema)
 */
@Override
public void visitPropertySchema(IPropertySchema node) {
    Oas20PropertySchema ps20 = (Oas20PropertySchema) node;
    Oas30Schema parent30 = (Oas30Schema) this.lookup(ps20.parent());
    Oas30PropertySchema property30 = (Oas30PropertySchema) parent30.createPropertySchema(ps20.getPropertyName());
    parent30.addProperty(ps20.getPropertyName(), property30);
    this.toSchema(ps20, property30, true);
    this.mapNode(ps20, property30);
}
Also used : Oas30PropertySchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30PropertySchema) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas20PropertySchema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema.Oas20PropertySchema)

Example 2 with Oas20PropertySchema

use of io.apicurio.datamodels.openapi.v2.models.Oas20Schema.Oas20PropertySchema in project apicurio-data-models by Apicurio.

the class IoTestRunner method cloneNode.

static Node cloneNode(Node node) {
    Constructor<? extends Node> constructor;
    Node clonedNode = null;
    try {
        if (node instanceof INamed) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((INamed) node).getName());
        } else if (node instanceof OasPathItem) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((OasPathItem) node).getPath());
        } else if (node instanceof Operation) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((Operation) node).getType());
        } else if (node instanceof Oas20PropertySchema) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((Oas20PropertySchema) node).getPropertyName());
        } else if (node instanceof Oas30PropertySchema) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((Oas30PropertySchema) node).getPropertyName());
        } else if (node instanceof ServerVariable) {
            constructor = node.getClass().getConstructor(String.class);
            clonedNode = constructor.newInstance(((ServerVariable) node).getName());
        } else {
            constructor = node.getClass().getConstructor();
            clonedNode = constructor.newInstance();
        }
    } catch (SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        System.err.println("Skipping partial I/O for: " + node.getClass().getSimpleName());
    }
    if (clonedNode != null) {
        clonedNode._parent = node._parent;
        clonedNode._ownerDocument = node.ownerDocument();
        if (clonedNode instanceof Document) {
            clonedNode._ownerDocument = (Document) clonedNode;
        }
    }
    return clonedNode;
}
Also used : Node(io.apicurio.datamodels.core.models.Node) Operation(io.apicurio.datamodels.core.models.common.Operation) Document(io.apicurio.datamodels.core.models.Document) ServerVariable(io.apicurio.datamodels.core.models.common.ServerVariable) Oas20PropertySchema(io.apicurio.datamodels.openapi.v2.models.Oas20Schema.Oas20PropertySchema) InvocationTargetException(java.lang.reflect.InvocationTargetException) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Oas30PropertySchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30PropertySchema) INamed(io.apicurio.datamodels.core.models.common.INamed)

Aggregations

Oas20PropertySchema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema.Oas20PropertySchema)2 Oas30PropertySchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30PropertySchema)2 Document (io.apicurio.datamodels.core.models.Document)1 Node (io.apicurio.datamodels.core.models.Node)1 INamed (io.apicurio.datamodels.core.models.common.INamed)1 Operation (io.apicurio.datamodels.core.models.common.Operation)1 ServerVariable (io.apicurio.datamodels.core.models.common.ServerVariable)1 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)1 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1