Search in sources :

Example 1 with Oas30Schema

use of io.apicurio.datamodels.openapi.v3.models.Oas30Schema in project apicurio-data-models by Apicurio.

the class AbstractSchemaInhCommand method copySchemaJsTo.

/**
 * Copies the given list of schemas to the appropriate property on the model
 * @param schemas
 * @param targetSchema
 * @param inheritanceType
 */
protected void copySchemaJsTo(List<Object> schemas, OasSchema targetSchema, String inheritanceType) {
    if (NodeCompat.equals(TYPE_ALL_OF, inheritanceType)) {
        schemas.forEach(ser -> {
            targetSchema.addAllOfSchema((OasSchema) Library.readNode(ser, targetSchema.createAllOfSchema()));
        });
    }
    if (NodeCompat.equals(TYPE_ANY_OF, inheritanceType)) {
        Oas30Schema targetSchema30 = (Oas30Schema) targetSchema;
        schemas.forEach(ser -> {
            targetSchema30.addAnyOfSchema((Oas30AnyOfSchema) Library.readNode(ser, targetSchema30.createAnyOfSchema()));
        });
    }
    if (NodeCompat.equals(TYPE_ONE_OF, inheritanceType)) {
        Oas30Schema targetSchema30 = (Oas30Schema) targetSchema;
        schemas.forEach(ser -> {
            targetSchema30.addOneOfSchema((Oas30OneOfSchema) Library.readNode(ser, targetSchema30.createOneOfSchema()));
        });
    }
}
Also used : Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema)

Example 2 with Oas30Schema

use of io.apicurio.datamodels.openapi.v3.models.Oas30Schema in project apicurio-data-models by Apicurio.

the class Oas30DataModelReader method readSchema.

/**
 * @see io.apicurio.datamodels.openapi.io.OasDataModelReader#readSchema(java.lang.Object, io.apicurio.datamodels.core.models.common.Schema)
 */
@Override
public void readSchema(Object json, Schema node) {
    Oas30Schema schema = (Oas30Schema) node;
    List<Object> oneOf = JsonCompat.consumePropertyArray(json, Constants.PROP_ONE_OF);
    List<Object> anyOf = JsonCompat.consumePropertyArray(json, Constants.PROP_ANY_OF);
    Object not = JsonCompat.consumeProperty(json, Constants.PROP_NOT);
    Object discriminator = JsonCompat.consumeProperty(json, Constants.PROP_DISCRIMINATOR);
    Boolean nullable = JsonCompat.consumePropertyBoolean(json, Constants.PROP_NULLABLE);
    Boolean writeOnly = JsonCompat.consumePropertyBoolean(json, Constants.PROP_WRITE_ONLY);
    Boolean deprecated = JsonCompat.consumePropertyBoolean(json, Constants.PROP_DEPRECATED);
    schema.nullable = nullable;
    schema.writeOnly = writeOnly;
    schema.deprecated = deprecated;
    if (oneOf != null) {
        oneOf.forEach(oneOfSchema -> {
            Oas30OneOfSchema oneOfSchemaModel = schema.createOneOfSchema();
            this.readSchema(oneOfSchema, oneOfSchemaModel);
            schema.addOneOfSchema(oneOfSchemaModel);
        });
    }
    if (anyOf != null) {
        anyOf.forEach(anyOfSchema -> {
            Oas30AnyOfSchema anyOfSchemaModel = schema.createAnyOfSchema();
            this.readSchema(anyOfSchema, anyOfSchemaModel);
            schema.addAnyOfSchema(anyOfSchemaModel);
        });
    }
    if (not != null) {
        schema.not = schema.createNotSchema();
        this.readSchema(not, schema.not);
    }
    if (discriminator != null) {
        schema.discriminator = schema.createDiscriminator();
        this.readDiscriminator(discriminator, schema.discriminator);
    }
    super.readSchema(json, node);
}
Also used : Oas30OneOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema) Oas30AnyOfSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema)

Example 3 with Oas30Schema

use of io.apicurio.datamodels.openapi.v3.models.Oas30Schema in project apicurio-data-models by Apicurio.

the class Oas30Traverser method traverseSchema.

/**
 * @see io.apicurio.datamodels.openapi.visitors.OasTraverser#traverseSchema(io.apicurio.datamodels.core.models.common.Schema)
 */
@Override
protected void traverseSchema(Schema node) {
    super.traverseSchema(node);
    Oas30Schema schema = (Oas30Schema) node;
    this.traverseCollection(schema.oneOf);
    this.traverseCollection(schema.anyOf);
    this.traverseIfNotNull(schema.not);
    this.traverseIfNotNull(schema.discriminator);
}
Also used : Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema)

Example 4 with Oas30Schema

use of io.apicurio.datamodels.openapi.v3.models.Oas30Schema in project apicurio-data-models by Apicurio.

the class Oas20to30TransformationVisitor method visitItemsSchema.

/**
 * @see io.apicurio.datamodels.openapi.visitors.IOasVisitor#visitItemsSchema(io.apicurio.datamodels.openapi.models.OasSchema)
 */
@Override
public void visitItemsSchema(OasSchema node) {
    Oas30Schema parent30 = (Oas30Schema) this.lookup(node.parent());
    Oas30ItemsSchema items30 = (Oas30ItemsSchema) parent30.createItemsSchema();
    if (!NodeCompat.isNullOrUndefined(parent30.items) && NodeCompat.isNode(parent30.items)) {
        List<Oas30ItemsSchema> items = new ArrayList<>();
        items.add(items30);
        parent30.items = items;
    } else {
        parent30.items = items30;
    }
    this.toSchema(node, items30, true);
    this.mapNode(node, items30);
}
Also used : Oas30ItemsSchema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30ItemsSchema) ArrayList(java.util.ArrayList) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema)

Example 5 with Oas30Schema

use of io.apicurio.datamodels.openapi.v3.models.Oas30Schema 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)

Aggregations

Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)33 Oas30Parameter (io.apicurio.datamodels.openapi.v3.models.Oas30Parameter)9 Oas30Document (io.apicurio.datamodels.openapi.v3.models.Oas30Document)8 Oas30MediaType (io.apicurio.datamodels.openapi.v3.models.Oas30MediaType)6 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)5 Oas30PathItem (io.apicurio.datamodels.openapi.v3.models.Oas30PathItem)5 Oas30Response (io.apicurio.datamodels.openapi.v3.models.Oas30Response)5 Test (org.junit.Test)5 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)4 Oas30Operation (io.apicurio.datamodels.openapi.v3.models.Oas30Operation)4 ArrayList (java.util.ArrayList)4 Oas20Parameter (io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)2 Oas20Schema (io.apicurio.datamodels.openapi.v2.models.Oas20Schema)2 Oas30ParameterDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30ParameterDefinition)2 Oas30RequestBodyDefinition (io.apicurio.datamodels.openapi.v3.models.Oas30RequestBodyDefinition)2 Oas30ItemsSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30ItemsSchema)2 Oas30XML (io.apicurio.datamodels.openapi.v3.models.Oas30XML)2 OpenApiModelInfo (io.syndesis.server.api.generator.openapi.OpenApiModelInfo)2 Map (java.util.Map)2 Element (org.dom4j.Element)2