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)));
}
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);
}
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);
}
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;
}
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);
}
}
}
Aggregations