All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.regnosys.rosetta.generator.jsonschema.JsonSchemaGeneratorHelper Maven / Gradle / Ivy

There is a newer version: 11.22.1
Show newest version
package com.regnosys.rosetta.generator.jsonschema;

import com.regnosys.rosetta.generator.object.ExpandedAttribute;
import com.regnosys.rosetta.generator.object.ExpandedType;
import com.regnosys.rosetta.rosetta.RosettaType;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.StringExtensions;

@SuppressWarnings("all")
public class JsonSchemaGeneratorHelper {
  public String replaceTabsWithSpaces(final CharSequence code) {
    return code.toString().replace("\t", "  ");
  }

  public String getNamespace(final RosettaType type) {
    return type.getModel().getName();
  }

  public String getMetaNamespace(final ExpandedType type) {
    String _name = type.getModel().getName();
    return (_name + ".metafields");
  }

  public String getFilename(final RosettaType type) {
    return this.getFilename(this.getNamespace(type), type.getName());
  }

  public String getFilename(final String namespace, final CharSequence typeName) {
    String _replace = namespace.replace(".", "-");
    String _plus = (_replace + "-");
    String _plus_1 = (_plus + typeName);
    return (_plus_1 + ".schema.json");
  }

  public CharSequence toType(final ExpandedAttribute attribute) {
    CharSequence _xifexpression = null;
    boolean _hasMetas = attribute.hasMetas();
    boolean _not = (!_hasMetas);
    if (_not) {
      _xifexpression = JsonSchemaTranslator.toJsonSchemaType(attribute.getType());
    } else {
      CharSequence _xifexpression_1 = null;
      int _refIndex = attribute.refIndex();
      boolean _greaterEqualsThan = (_refIndex >= 0);
      if (_greaterEqualsThan) {
        _xifexpression_1 = this.toReferenceWithMetaTypeName(attribute.getType());
      } else {
        _xifexpression_1 = this.toFieldWithMetaTypeName(attribute.getType());
      }
      _xifexpression = _xifexpression_1;
    }
    return _xifexpression;
  }

  public CharSequence toReferenceWithMetaTypeName(final ExpandedType type) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("ReferenceWithMeta");
    String _metaTypeName = JsonSchemaGeneratorHelper.toMetaTypeName(type);
    _builder.append(_metaTypeName);
    return _builder;
  }

  public CharSequence toFieldWithMetaTypeName(final ExpandedType type) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("FieldWithMeta");
    String _metaTypeName = JsonSchemaGeneratorHelper.toMetaTypeName(type);
    _builder.append(_metaTypeName);
    return _builder;
  }

  public static String toMetaTypeName(final ExpandedType type) {
    final String name = JsonSchemaTranslator.toJsonSchemaType(type);
    boolean _isEnumeration = type.isEnumeration();
    if (_isEnumeration) {
      return name;
    } else {
      boolean _contains = name.contains(".");
      if (_contains) {
        int _lastIndexOf = name.lastIndexOf(".");
        int _plus = (_lastIndexOf + 1);
        return StringExtensions.toFirstUpper(name.substring(_plus));
      }
    }
    return StringExtensions.toFirstUpper(name);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy