Search in sources :

Example 1 with Oas30AnyOfSchema

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

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

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

the class AddChildSchemaCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[AddChildSchemaCommand] Executing.");
    this._nullChildList = false;
    this._childIndex = -1;
    OasSchema schema = (OasSchema) this._schemaPath.resolve(document);
    if (this.isNullOrUndefined(schema)) {
        return;
    }
    List<OasSchema> schemas = null;
    OasSchema newSchema = null;
    if (NodeCompat.equals(TYPE_ALL_OF, _newChildSchemaType)) {
        schemas = schema.allOf;
        newSchema = schema.createAllOfSchema();
        Library.readNode(this._newChildSchemaObj, newSchema);
        schema.addAllOfSchema(newSchema);
        this._childIndex = schema.allOf.size() - 1;
    }
    if (NodeCompat.equals(TYPE_ANY_OF, _newChildSchemaType)) {
        Oas30Schema schema30 = (Oas30Schema) schema;
        schemas = schema30.anyOf;
        newSchema = ((Oas30Schema) schema).createAnyOfSchema();
        Library.readNode(this._newChildSchemaObj, newSchema);
        ((Oas30Schema) schema).addAnyOfSchema((Oas30AnyOfSchema) newSchema);
        this._childIndex = ((Oas30Schema) schema).anyOf.size() - 1;
    }
    if (NodeCompat.equals(TYPE_ONE_OF, _newChildSchemaType)) {
        Oas30Schema schema30 = (Oas30Schema) schema;
        schemas = schema30.oneOf;
        newSchema = ((Oas30Schema) schema).createOneOfSchema();
        Library.readNode(this._newChildSchemaObj, newSchema);
        ((Oas30Schema) schema).addOneOfSchema((Oas30OneOfSchema) newSchema);
        this._childIndex = ((Oas30Schema) schema).oneOf.size() - 1;
    }
    if (schemas == null) {
        this._nullChildList = true;
    }
}
Also used : OasSchema(io.apicurio.datamodels.openapi.models.OasSchema) Oas30Schema(io.apicurio.datamodels.openapi.v3.models.Oas30Schema)

Aggregations

Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)3 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)1 Oas30AnyOfSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30AnyOfSchema)1 Oas30OneOfSchema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema.Oas30OneOfSchema)1