Search in sources :

Example 11 with OasSchema

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

the class OasInvalidSchemaTypeValueRule method visitSchema.

/**
 * @see io.apicurio.datamodels.combined.visitors.CombinedAllNodeVisitor#visitSchema(io.apicurio.datamodels.core.models.common.Schema)
 */
@Override
public void visitSchema(Schema node) {
    OasSchema schema = (OasSchema) node;
    this.reportIfInvalid(isValidType(schema.type), schema, Constants.PROP_TYPE, map("type", schema.type, "allowedTypes", NodeCompat.joinArray(", ", ALLOWED_TYPES)));
}
Also used : OasSchema(io.apicurio.datamodels.openapi.models.OasSchema)

Example 12 with OasSchema

use of io.apicurio.datamodels.openapi.models.OasSchema in project syndesis by syndesisio.

the class UnifiedJsonDataShapeSupport method createJsonSchemaForBodyOf.

protected ObjectNode createJsonSchemaForBodyOf(final ObjectNode json, final T openApiDoc, final O operation) {
    final Optional<NameAndSchema> maybeRequestBody = findBodySchema(openApiDoc, operation);
    if (!maybeRequestBody.isPresent()) {
        return null;
    }
    final OasSchema requestSchema = maybeRequestBody.get().schema;
    final String name = maybeRequestBody.get().name;
    return createSchemaFromModel(json, name, requestSchema);
}
Also used : OasSchema(io.apicurio.datamodels.openapi.models.OasSchema)

Example 13 with OasSchema

use of io.apicurio.datamodels.openapi.models.OasSchema in project syndesis by syndesisio.

the class UnifiedJsonDataShapeSupport method createSchemaFromModel.

protected static ObjectNode createSchemaFromModel(final ObjectNode json, final String name, final OasSchema schema) {
    if (OasModelHelper.isArrayType(schema)) {
        final OasSchema items = (OasSchema) schema.items;
        final ObjectNode itemSchema = createSchemaFromProperty(json, name, items);
        itemSchema.remove(Arrays.asList("$schema", "title"));
        final ObjectNode jsonSchema = JsonNodeFactory.instance.objectNode();
        jsonSchema.put("type", "array");
        jsonSchema.set("items", itemSchema);
        return jsonSchema;
    } else if (OasModelHelper.isReferenceType(schema)) {
        final String title = determineTitleOf(name, schema);
        return JsonSchemaHelper.resolveSchemaForReference(json, title, schema.$ref);
    }
    return createSchemaFromModelImpl(name, schema);
}
Also used : OasSchema(io.apicurio.datamodels.openapi.models.OasSchema) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Example 14 with OasSchema

use of io.apicurio.datamodels.openapi.models.OasSchema in project syndesis by syndesisio.

the class UnifiedXmlDataShapeSupport method defineComplexElement.

private Element defineComplexElement(final OasSchema property, final Element parent, final T openApiDoc, final Map<String, SchemaPrefixAndElement> moreSchemas) {
    final OasSchema model = dereference(property, openApiDoc);
    Element ret;
    Element elementToDeclareIn;
    final String namespace = XmlSchemaHelper.xmlTargetNamespaceOrNull(model);
    final String name = XmlSchemaHelper.xmlNameOrDefault(model.xml, getName(model));
    if (namespace != null && parent != null) {
        // this is element that could be in a (possibly) previously unknown
        // namespace
        final SchemaPrefixAndElement schemaPrefixAndElement = moreSchemas.computeIfAbsent(namespace, n -> {
            return new SchemaPrefixAndElement("p" + moreSchemas.size(), XmlSchemaHelper.newXmlSchema(n));
        });
        elementToDeclareIn = XmlSchemaHelper.addElement(schemaPrefixAndElement.schema, ELEMENT);
        elementToDeclareIn.addAttribute(NAME, name);
        ret = XmlSchemaHelper.addElement(parent, ELEMENT);
        ret.addAttribute(REF, schemaPrefixAndElement.prefix + ":" + name);
        ret.addNamespace(schemaPrefixAndElement.prefix, namespace);
    } else {
        if (parent == null) {
            // this is the top level element (in a new namespace)
            ret = XmlSchemaHelper.newXmlSchema(namespace);
            elementToDeclareIn = XmlSchemaHelper.addElement(ret, ELEMENT);
            elementToDeclareIn.addAttribute(NAME, name);
        } else {
            // this is a nested element in the same namespace
            ret = XmlSchemaHelper.addElement(parent, ELEMENT);
            ret.addAttribute(NAME, name);
            elementToDeclareIn = ret;
        }
    }
    final Element complex = XmlSchemaHelper.addElement(elementToDeclareIn, COMPLEX_TYPE);
    final Element sequence = XmlSchemaHelper.addElement(complex, SEQUENCE);
    defineElementPropertiesOf(sequence, model, openApiDoc, moreSchemas);
    defineAttributePropertiesOf(complex, model);
    return ret;
}
Also used : OasSchema(io.apicurio.datamodels.openapi.models.OasSchema) Element(org.dom4j.Element)

Example 15 with OasSchema

use of io.apicurio.datamodels.openapi.models.OasSchema in project syndesis by syndesisio.

the class UnifiedXmlDataShapeSupport method defineElementPropertiesOf.

protected void defineElementPropertiesOf(final Element parent, final OasSchema model, final T openApiDoc, final Map<String, SchemaPrefixAndElement> moreSchemas) {
    final Map<String, OasSchema> properties = model.properties;
    for (final Map.Entry<String, OasSchema> propertyEntry : properties.entrySet()) {
        final String propertyName = propertyEntry.getKey();
        final OasSchema property = propertyEntry.getValue();
        if (XmlSchemaHelper.isElement(property)) {
            defineElementProperty(propertyName, property, parent, openApiDoc, moreSchemas);
        }
    }
}
Also used : OasSchema(io.apicurio.datamodels.openapi.models.OasSchema) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)46 Map (java.util.Map)10 OasResponse (io.apicurio.datamodels.openapi.models.OasResponse)4 Oas30Schema (io.apicurio.datamodels.openapi.v3.models.Oas30Schema)4 ArrayList (java.util.ArrayList)4 OasParameter (io.apicurio.datamodels.openapi.models.OasParameter)3 List (java.util.List)3 Element (org.dom4j.Element)3 Citrus (com.consol.citrus.Citrus)2 CitrusSettings (com.consol.citrus.CitrusSettings)2 TestCaseRunner (com.consol.citrus.TestCaseRunner)2 CitrusAnnotations (com.consol.citrus.annotations.CitrusAnnotations)2 CitrusFramework (com.consol.citrus.annotations.CitrusFramework)2 CitrusResource (com.consol.citrus.annotations.CitrusResource)2 TestContext (com.consol.citrus.context.TestContext)2 Node (io.apicurio.datamodels.core.models.Node)2 OasOperation (io.apicurio.datamodels.openapi.models.OasOperation)2 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)2 OasXML (io.apicurio.datamodels.openapi.models.OasXML)2 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)2