Search in sources :

Example 1 with AaiSchema

use of io.apicurio.datamodels.asyncapi.models.AaiSchema in project apicurio-data-models by Apicurio.

the class DeleteSchemaDefinitionCommand_Aai20 method doRestoreSchemaDefinition.

/**
 * @see DeleteSchemaDefinitionCommand#doRestoreSchemaDefinition(Document, Object)
 */
@Override
protected void doRestoreSchemaDefinition(Document document, Object oldDefinition) {
    Aai20Document aai20Document = (Aai20Document) document;
    if (ModelUtils.isDefined(aai20Document.components)) {
        AaiSchema schemaDef = new Aai20NodeFactory().createSchemaDefinition(aai20Document.components, this._definitionName);
        Library.readNode(oldDefinition, schemaDef);
        aai20Document.components.addSchemaDefinition(this._definitionName, schemaDef);
    }
}
Also used : Aai20Document(io.apicurio.datamodels.asyncapi.v2.models.Aai20Document) Aai20NodeFactory(io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory) AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema)

Example 2 with AaiSchema

use of io.apicurio.datamodels.asyncapi.models.AaiSchema in project apicurio-data-models by Apicurio.

the class AaiTraverser method traverseSchema.

/**
 * @see io.apicurio.datamodels.core.visitors.Traverser#traverseSchema(io.apicurio.datamodels.core.models.common.Schema)
 */
@SuppressWarnings("unchecked")
@Override
protected void traverseSchema(Schema node) {
    super.traverseSchema(node);
    AaiSchema schema = (AaiSchema) node;
    if (NodeCompat.isList(schema.items)) {
        this.traverseCollection((List<Node>) schema.items);
    } else {
        this.traverseIfNotNull((Node) schema.items);
    }
    this.traverseCollection(schema.allOf);
    this.traverseCollection(schema.oneOf);
    this.traverseCollection(schema.anyOf);
    this.traverseIfNotNull(schema.not);
    this.traverseCollection(schema.getProperties());
    if (NodeCompat.isNode(schema.additionalProperties)) {
        this.traverseIfNotNull((Node) schema.additionalProperties);
    }
    this.traverseIfNotNull(schema.externalDocs);
}
Also used : Node(io.apicurio.datamodels.core.models.Node) AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema)

Example 3 with AaiSchema

use of io.apicurio.datamodels.asyncapi.models.AaiSchema in project apicurio-data-models by Apicurio.

the class AaiDataModelReader method readComponents.

public void readComponents(Object json, Components node) {
    AaiComponents components = (AaiComponents) node;
    // schemas
    final Object _jsonSchemas = JsonCompat.consumeProperty(json, Constants.PROP_SCHEMAS);
    if (_jsonSchemas != null) {
        JsonCompat.keys(_jsonSchemas).forEach(key -> {
            Object value = JsonCompat.consumeProperty(_jsonSchemas, key);
            AaiSchema schemaModel = nodeFactory.createSchemaDefinition(node, key);
            this.readSchema(value, schemaModel);
            components.addSchemaDefinition(key, schemaModel);
        });
    }
    // messages
    final Object _jsonMessages = JsonCompat.consumeProperty(json, Constants.PROP_MESSAGES);
    if (_jsonMessages != null) {
        JsonCompat.keys(_jsonMessages).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonMessages, key);
            AaiMessage value = nodeFactory.createMessage(node, key);
            this.readMessage(jsonValue, value);
            components.addMessage(key, value);
        });
    }
    // security schemes
    final Object _jsonSecuritySchemes = JsonCompat.consumeProperty(json, Constants.PROP_SECURITY_SCHEMES);
    if (_jsonSecuritySchemes != null) {
        JsonCompat.keys(_jsonSecuritySchemes).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonSecuritySchemes, key);
            AaiSecurityScheme value = nodeFactory.createSecurityScheme(node, key);
            this.readSecurityScheme(jsonValue, value);
            components.addSecurityScheme(key, value);
        });
    }
    // parameters
    final Object _jsonParams = JsonCompat.consumeProperty(json, Constants.PROP_PARAMETERS);
    if (_jsonParams != null) {
        JsonCompat.keys(_jsonParams).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonParams, key);
            AaiParameter value = nodeFactory.createParameter(node, key);
            this.readAaiParameter(jsonValue, value);
            components.addParameter(key, value);
        });
    }
    // correlationIds
    final Object _jsonCorrelationIds = JsonCompat.consumeProperty(json, Constants.PROP_CORRELATION_IDS);
    if (_jsonCorrelationIds != null) {
        JsonCompat.keys(_jsonCorrelationIds).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonCorrelationIds, key);
            AaiCorrelationId value = nodeFactory.createCorrelationId(node, key);
            this.readCorrelationId(jsonValue, value);
            components.addCorrelationId(key, value);
        });
    }
    // operation traits
    final Object _jsonOpTraits = JsonCompat.consumeProperty(json, Constants.PROP_OPERATION_TRAITS);
    if (_jsonOpTraits != null) {
        JsonCompat.keys(_jsonOpTraits).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonOpTraits, key);
            AaiOperationTraitDefinition traitDef = nodeFactory.createOperationTraitDefinition(node, key);
            this.readOperationTrait(jsonValue, traitDef);
            components.addOperationTraitDefinition(key, traitDef);
        });
    }
    // message traits
    final Object _jsonMessageTraits = JsonCompat.consumeProperty(json, Constants.PROP_MESSAGE_TRAITS);
    if (_jsonMessageTraits != null) {
        JsonCompat.keys(_jsonMessageTraits).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonMessageTraits, key);
            AaiMessageTraitDefinition traitDef = nodeFactory.createMessageTraitDefinition(node, key);
            this.readMessageTrait(jsonValue, traitDef);
            components.addMessageTraitDefinition(key, traitDef);
        });
    }
    // server bindings
    final Object _jsonServerBindings = JsonCompat.consumeProperty(json, Constants.PROP_SERVER_BINDINGS);
    if (_jsonServerBindings != null) {
        JsonCompat.keys(_jsonServerBindings).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonServerBindings, key);
            AaiServerBindingsDefinition bindingsDef = nodeFactory.createServerBindingsDefinition(node, key);
            this.readServerBindings(jsonValue, bindingsDef);
            components.addServerBindingDefinition(key, bindingsDef);
        });
    }
    // channel bindings
    final Object _jsonChannelBindings = JsonCompat.consumeProperty(json, Constants.PROP_CHANNEL_BINDINGS);
    if (_jsonChannelBindings != null) {
        JsonCompat.keys(_jsonChannelBindings).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonChannelBindings, key);
            AaiChannelBindingsDefinition bindingsDef = nodeFactory.createChannelBindingsDefinition(node, key);
            this.readChannelBindings(jsonValue, bindingsDef);
            components.addChannelBindingDefinition(key, bindingsDef);
        });
    }
    // operation bindings
    final Object _jsonOpBindings = JsonCompat.consumeProperty(json, Constants.PROP_OPERATION_BINDINGS);
    if (_jsonOpBindings != null) {
        JsonCompat.keys(_jsonOpBindings).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonOpBindings, key);
            AaiOperationBindingsDefinition bindingsDef = nodeFactory.createOperationBindingsDefinition(node, key);
            this.readOperationBindings(jsonValue, bindingsDef);
            components.addOperationBindingDefinition(key, bindingsDef);
        });
    }
    // message bindings
    final Object _jsonMessageBindings = JsonCompat.consumeProperty(json, Constants.PROP_MESSAGE_BINDINGS);
    if (_jsonMessageBindings != null) {
        JsonCompat.keys(_jsonMessageBindings).forEach(key -> {
            Object jsonValue = JsonCompat.consumeProperty(_jsonMessageBindings, key);
            AaiMessageBindingsDefinition bindingsDef = nodeFactory.createMessageBindingsDefinition(node, key);
            this.readMessageBindings(jsonValue, bindingsDef);
            components.addMessageBindingDefinition(key, bindingsDef);
        });
    }
    this.readExtensions(json, node);
    this.readExtraProperties(json, node);
}
Also used : AaiMessageBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiMessageBindingsDefinition) AaiOperationBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiOperationBindingsDefinition) AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema) AaiMessage(io.apicurio.datamodels.asyncapi.models.AaiMessage) AaiMessageTraitDefinition(io.apicurio.datamodels.asyncapi.models.AaiMessageTraitDefinition) AaiParameter(io.apicurio.datamodels.asyncapi.models.AaiParameter) AaiChannelBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiChannelBindingsDefinition) AaiSecurityScheme(io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme) AaiServerBindingsDefinition(io.apicurio.datamodels.asyncapi.models.AaiServerBindingsDefinition) AaiComponents(io.apicurio.datamodels.asyncapi.models.AaiComponents) AaiCorrelationId(io.apicurio.datamodels.asyncapi.models.AaiCorrelationId) AaiOperationTraitDefinition(io.apicurio.datamodels.asyncapi.models.AaiOperationTraitDefinition)

Example 4 with AaiSchema

use of io.apicurio.datamodels.asyncapi.models.AaiSchema in project apicurio-data-models by Apicurio.

the class AaiDataModelReader method readSchema.

@Override
public void readSchema(Object json, Schema node) {
    AaiSchema schema = (AaiSchema) node;
    String format = JsonCompat.consumePropertyString(json, Constants.PROP_FORMAT);
    String title = JsonCompat.consumePropertyString(json, Constants.PROP_TITLE);
    String description = JsonCompat.consumePropertyString(json, Constants.PROP_DESCRIPTION);
    Object default_ = JsonCompat.consumePropertyObject(json, Constants.PROP_DEFAULT);
    Number multipleOf = JsonCompat.consumePropertyNumber(json, Constants.PROP_MULTIPLE_OF);
    Number maximum = JsonCompat.consumePropertyNumber(json, Constants.PROP_MAXIMUM);
    Boolean exclusiveMaximum = JsonCompat.consumePropertyBoolean(json, Constants.PROP_EXCLUSIVE_MAXIMUM);
    Number minimum = JsonCompat.consumePropertyNumber(json, Constants.PROP_MINIMUM);
    Boolean exclusiveMinimum = JsonCompat.consumePropertyBoolean(json, Constants.PROP_EXCLUSIVE_MINIMUM);
    Number maxLength = JsonCompat.consumePropertyNumber(json, Constants.PROP_MAX_LENGTH);
    Number minLength = JsonCompat.consumePropertyNumber(json, Constants.PROP_MIN_LENGTH);
    String pattern = JsonCompat.consumePropertyString(json, Constants.PROP_PATTERN);
    Number maxItems = JsonCompat.consumePropertyNumber(json, Constants.PROP_MAX_ITEMS);
    Number minItems = JsonCompat.consumePropertyNumber(json, Constants.PROP_MIN_ITEMS);
    Boolean uniqueItems = JsonCompat.consumePropertyBoolean(json, Constants.PROP_UNIQUE_ITEMS);
    Number maxProperties = JsonCompat.consumePropertyNumber(json, Constants.PROP_MAX_PROPERTIES);
    Number minProperties = JsonCompat.consumePropertyNumber(json, Constants.PROP_MIN_PROPERTIES);
    List<String> required = JsonCompat.consumePropertyStringArray(json, Constants.PROP_REQUIRED);
    List<Object> enum_ = JsonCompat.consumePropertyArray(json, Constants.PROP_ENUM);
    String type = JsonCompat.consumePropertyString(json, Constants.PROP_TYPE);
    Object items = JsonCompat.consumeProperty(json, Constants.PROP_ITEMS);
    List<Object> allOf = JsonCompat.consumePropertyArray(json, Constants.PROP_ALL_OF);
    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 properties = JsonCompat.consumeProperty(json, Constants.PROP_PROPERTIES);
    Object additionalProperties = JsonCompat.consumeProperty(json, Constants.PROP_ADDITIONAL_PROPERTIES);
    Boolean readOnly = JsonCompat.consumePropertyBoolean(json, Constants.PROP_READ_ONLY);
    Boolean writeOnly = JsonCompat.consumePropertyBoolean(json, Constants.PROP_WRITE_ONLY);
    String discriminator = JsonCompat.consumePropertyString(json, Constants.PROP_DISCRIMINATOR);
    Boolean deprecated = JsonCompat.consumePropertyBoolean(json, Constants.PROP_DEPRECATED);
    schema.format = format;
    schema.title = title;
    schema.description = description;
    schema.default_ = default_;
    schema.multipleOf = multipleOf;
    schema.maximum = maximum;
    schema.exclusiveMaximum = exclusiveMaximum;
    schema.minimum = minimum;
    schema.exclusiveMinimum = exclusiveMinimum;
    schema.maxLength = maxLength;
    schema.minLength = minLength;
    schema.pattern = pattern;
    schema.maxItems = maxItems;
    schema.minItems = minItems;
    schema.uniqueItems = uniqueItems;
    schema.maxProperties = maxProperties;
    schema.minProperties = minProperties;
    schema.required = required;
    schema.enum_ = enum_;
    schema.type = type;
    schema.readOnly = readOnly;
    schema.writeOnly = writeOnly;
    schema.discriminator = discriminator;
    schema.deprecated = deprecated;
    if (items != null) {
        if (JsonCompat.isArray(items)) {
            List<AaiSchema> schemaModels = new ArrayList<>();
            List<Object> itemList = JsonCompat.toList(items);
            for (Object item : itemList) {
                AaiSchema itemsSchemaModel = schema.createItemsSchema();
                this.readSchema(item, itemsSchemaModel);
                schemaModels.add(itemsSchemaModel);
            }
            schema.items = schemaModels;
        } else {
            schema.items = schema.createItemsSchema();
            this.readSchema(items, (AaiSchema) schema.items);
        }
    }
    if (allOf != null) {
        List<AaiSchema> schemaModels = new ArrayList<>();
        for (Object allOfSchema : allOf) {
            AaiSchema allOfSchemaModel = schema.createAllOfSchema();
            this.readSchema(allOfSchema, allOfSchemaModel);
            schemaModels.add(allOfSchemaModel);
        }
        schema.allOf = schemaModels;
    }
    if (oneOf != null) {
        oneOf.forEach(oneOfSchema -> {
            AaiSchema oneOfSchemaModel = schema.createOneOfSchema();
            this.readSchema(oneOfSchema, oneOfSchemaModel);
            schema.addOneOfSchema(oneOfSchemaModel);
        });
    }
    if (anyOf != null) {
        anyOf.forEach(anyOfSchema -> {
            AaiSchema anyOfSchemaModel = schema.createAnyOfSchema();
            this.readSchema(anyOfSchema, anyOfSchemaModel);
            schema.addAnyOfSchema(anyOfSchemaModel);
        });
    }
    if (not != null) {
        schema.not = schema.createNotSchema();
        this.readSchema(not, schema.not);
    }
    if (properties != null) {
        List<String> propertyNames = JsonCompat.keys(properties);
        for (String propertyName : propertyNames) {
            Object propertySchema = JsonCompat.consumeProperty(properties, propertyName);
            Schema propertySchemaModel = schema.createPropertySchema(propertyName);
            this.readSchema(propertySchema, propertySchemaModel);
            schema.addProperty(propertyName, propertySchemaModel);
        }
    }
    if (additionalProperties != null) {
        if (JsonCompat.isBoolean(additionalProperties)) {
            schema.additionalProperties = JsonCompat.toBoolean(additionalProperties);
        } else {
            AaiSchema additionalPropertiesModel = schema.createAdditionalPropertiesSchema();
            this.readSchema(additionalProperties, additionalPropertiesModel);
            schema.additionalProperties = additionalPropertiesModel;
        }
    }
    super.readSchema(json, schema);
}
Also used : AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema) Schema(io.apicurio.datamodels.core.models.common.Schema) ArrayList(java.util.ArrayList) AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema)

Example 5 with AaiSchema

use of io.apicurio.datamodels.asyncapi.models.AaiSchema in project apicurio-data-models by Apicurio.

the class AaiDataModelWriter method writeSchema.

/**
 * @see io.apicurio.datamodels.core.io.DataModelWriter#writeSchema(java.lang.Object, io.apicurio.datamodels.core.models.common.Schema)
 */
@Override
protected void writeSchema(Object json, Schema node) {
    AaiSchema schema = (AaiSchema) node;
    JsonCompat.setPropertyString(json, Constants.PROP_$REF, schema.$ref);
    JsonCompat.setPropertyString(json, Constants.PROP_FORMAT, schema.format);
    JsonCompat.setPropertyString(json, Constants.PROP_TITLE, schema.title);
    JsonCompat.setPropertyString(json, Constants.PROP_DESCRIPTION, schema.description);
    JsonCompat.setProperty(json, Constants.PROP_DEFAULT, schema.default_);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MULTIPLE_OF, schema.multipleOf);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MAXIMUM, schema.maximum);
    JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MAXIMUM, schema.exclusiveMaximum);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MINIMUM, schema.minimum);
    JsonCompat.setPropertyBoolean(json, Constants.PROP_EXCLUSIVE_MINIMUM, schema.exclusiveMinimum);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_LENGTH, schema.maxLength);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_LENGTH, schema.minLength);
    JsonCompat.setPropertyString(json, Constants.PROP_PATTERN, schema.pattern);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_ITEMS, schema.maxItems);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_ITEMS, schema.minItems);
    JsonCompat.setPropertyBoolean(json, Constants.PROP_UNIQUE_ITEMS, schema.uniqueItems);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MAX_PROPERTIES, schema.maxProperties);
    JsonCompat.setPropertyNumber(json, Constants.PROP_MIN_PROPERTIES, schema.minProperties);
    JsonCompat.setPropertyStringArray(json, Constants.PROP_REQUIRED, schema.required);
    if (schema.enum_ != null) {
        for (Object enumValue : schema.enum_) {
            JsonCompat.appendToArrayProperty(json, Constants.PROP_ENUM, enumValue);
        }
    }
    JsonCompat.setPropertyString(json, Constants.PROP_TYPE, schema.type);
    JsonCompat.setPropertyNull(json, Constants.PROP_ITEMS);
    JsonCompat.setPropertyNull(json, Constants.PROP_ALL_OF);
    JsonCompat.setPropertyNull(json, Constants.PROP_ONE_OF);
    JsonCompat.setPropertyNull(json, Constants.PROP_ANY_OF);
    JsonCompat.setPropertyNull(json, Constants.PROP_NOT);
    JsonCompat.setPropertyNull(json, Constants.PROP_PROPERTIES);
    if (NodeCompat.isNode(schema.additionalProperties)) {
        JsonCompat.setPropertyNull(json, Constants.PROP_ADDITIONAL_PROPERTIES);
    } else {
        JsonCompat.setPropertyBoolean(json, Constants.PROP_ADDITIONAL_PROPERTIES, (Boolean) schema.additionalProperties);
    }
    JsonCompat.setPropertyBoolean(json, Constants.PROP_READ_ONLY, schema.readOnly);
    JsonCompat.setPropertyBoolean(json, Constants.PROP_WRITE_ONLY, schema.writeOnly);
    JsonCompat.setPropertyString(json, Constants.PROP_DISCRIMINATOR, schema.discriminator);
    JsonCompat.setPropertyBoolean(json, Constants.PROP_DEPRECATED, schema.deprecated);
    JsonCompat.setPropertyNull(json, Constants.PROP_EXTERNAL_DOCS);
    JsonCompat.setProperty(json, Constants.PROP_EXAMPLE, schema.example);
    super.writeSchema(json, schema);
}
Also used : AaiSchema(io.apicurio.datamodels.asyncapi.models.AaiSchema)

Aggregations

AaiSchema (io.apicurio.datamodels.asyncapi.models.AaiSchema)13 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)2 Node (io.apicurio.datamodels.core.models.Node)2 AaiChannelBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiChannelBindingsDefinition)1 AaiComponents (io.apicurio.datamodels.asyncapi.models.AaiComponents)1 AaiCorrelationId (io.apicurio.datamodels.asyncapi.models.AaiCorrelationId)1 AaiMessage (io.apicurio.datamodels.asyncapi.models.AaiMessage)1 AaiMessageBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiMessageBindingsDefinition)1 AaiMessageTraitDefinition (io.apicurio.datamodels.asyncapi.models.AaiMessageTraitDefinition)1 AaiOperationBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiOperationBindingsDefinition)1 AaiOperationTraitDefinition (io.apicurio.datamodels.asyncapi.models.AaiOperationTraitDefinition)1 AaiParameter (io.apicurio.datamodels.asyncapi.models.AaiParameter)1 AaiSecurityScheme (io.apicurio.datamodels.asyncapi.models.AaiSecurityScheme)1 AaiServerBindingsDefinition (io.apicurio.datamodels.asyncapi.models.AaiServerBindingsDefinition)1 Aai20NodeFactory (io.apicurio.datamodels.asyncapi.v2.models.Aai20NodeFactory)1 IDefinition (io.apicurio.datamodels.core.models.common.IDefinition)1 Schema (io.apicurio.datamodels.core.models.common.Schema)1 ArrayList (java.util.ArrayList)1