Skip to content
Snippets Groups Projects
Commit 597ecd5f authored by Martti Käärik's avatar Martti Käärik
Browse files

Basic importing for anyOf/allOf/oneOf schemas (TODO Java mappings)

parent 301cda7d
No related branches found
Tags 20250326.09.07
No related merge requests found
Pipeline #12840 passed
......@@ -436,9 +436,25 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator {
}
}
}
private void getAllProperties(Schema<?> schema, Map<String, Schema> properties) {
List<Schema> xOf = schema.getAllOf();
if (xOf == null)
xOf = schema.getAnyOf();
if (xOf == null)
xOf = schema.getOneOf();
if (xOf != null) {
for (Schema ofSchema : xOf)
this.getAllProperties(ofSchema, properties);
}
if (schema.getProperties() != null)
properties.putAll(schema.getProperties());
}
private DataType translate(Schema<?> schema, String prefix, DataType superType) {
if (getSchemaType(schema) == null && (schema.getProperties() == null || schema.getProperties().isEmpty())) {
Map<String, Schema> properties = new Hashtable<>();
this.getAllProperties(schema, properties);
if (getSchemaType(schema) == null && properties.isEmpty()) {
if (schema.getName() == null) {
System.out.println("Why?");
}
......@@ -448,8 +464,7 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator {
if (schema.getName() == null) {
name = prefix + "___item";
}
if (schema.getProperties() != null && !schema.getProperties().isEmpty()
|| getSchemaType(schema).equals("object")) {
if (!properties.isEmpty() || getSchemaType(schema).equals("object")) {
DataType t = translateObject(schema, name);
addSuperType(t, superType);
return t;
......@@ -505,12 +520,14 @@ public class OpenAPI2TDLTranslatorNext extends AbstractTranslator {
}
private DataType translateObject(Schema<?> schema, String name) {
Map<String, Schema> properties = new Hashtable<>();
this.getAllProperties(schema, properties);
StructuredDataType dataType = getStructuredDataTypeFor(name);
if (schema.getProperties() == null || !dataType.getMember().isEmpty()) {
if (properties.isEmpty() || !dataType.getMember().isEmpty()) {
return dataType;
}
for (Object propertyName : schema.getProperties().keySet()) {
Schema<?> propertySchema = (Schema<?>) schema.getProperties().get(propertyName);
for (Object propertyName : properties.keySet()) {
Schema<?> propertySchema = (Schema<?>) properties.get(propertyName);
String reference = propertySchema.get$ref();
DataType memberType = null;
if (reference != null) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment