
com.reprezen.genflow.swagger.doc.SchemaHelper Maven / Gradle / Ivy
The newest version!
/**
* Copyright © 2013, 2016 Modelsolv, Inc.
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains the property
* of ModelSolv, Inc. See the file license.html in the root directory of
* this project for further information.
*/
package com.reprezen.genflow.swagger.doc;
import com.reprezen.genflow.swagger.doc.ArrayHelper;
import com.reprezen.genflow.swagger.doc.AttrDetails;
import com.reprezen.genflow.swagger.doc.AttributeHelper;
import com.reprezen.genflow.swagger.doc.Helper;
import com.reprezen.genflow.swagger.doc.HelperHelper;
import com.reprezen.genflow.swagger.doc.RefHelper;
import com.reprezen.genflow.swagger.doc.StructureTable;
import io.swagger.models.ArrayModel;
import io.swagger.models.Model;
import io.swagger.models.ModelImpl;
import io.swagger.models.Swagger;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.ObjectProperty;
import io.swagger.models.properties.Property;
import java.util.Collections;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
@SuppressWarnings("all")
public class SchemaHelper implements Helper {
private Swagger swagger;
@Extension
private RefHelper refHelper;
@Extension
private AttributeHelper attributeHelper;
@Extension
private ArrayHelper arrayHelper;
@Override
public void init() {
this.swagger = HelperHelper.getSwagger();
this.refHelper = HelperHelper.getRefHelper();
this.attributeHelper = HelperHelper.getAttributeHelper();
this.arrayHelper = HelperHelper.getArrayHelper();
}
public CharSequence renderSchema(final Object schema) {
CharSequence _xblockexpression = null;
{
final Object resolved = this.refHelper.safeResolve(schema);
CharSequence _switchResult = null;
boolean _matched = false;
if (resolved instanceof ObjectProperty) {
_matched=true;
_switchResult = this.renderSchemaTable(resolved);
}
if (!_matched) {
if (resolved instanceof ArrayProperty) {
_matched=true;
_switchResult = this.renderArraySchema(resolved);
}
}
if (!_matched) {
if (resolved instanceof Property) {
_matched=true;
_switchResult = this.renderPrimitiveSchema(resolved);
}
}
if (!_matched) {
if (resolved instanceof ArrayModel) {
_matched=true;
_switchResult = this.renderArraySchema(resolved);
}
}
if (!_matched) {
if (resolved instanceof ModelImpl) {
boolean _and = false;
boolean _isEmpty = ((ModelImpl)resolved).getProperties().isEmpty();
if (!_isEmpty) {
_and = false;
} else {
Property _additionalProperties = ((ModelImpl)resolved).getAdditionalProperties();
Object _safeResolve = null;
if (_additionalProperties!=null) {
_safeResolve=this.refHelper.safeResolve(_additionalProperties);
}
boolean _tripleEquals = (_safeResolve == null);
_and = _tripleEquals;
}
if (_and) {
_matched=true;
_switchResult = this.renderPrimitiveSchema(resolved);
}
}
}
if (!_matched) {
if (resolved instanceof Model) {
_matched=true;
_switchResult = this.renderSchemaTable(resolved);
}
}
_xblockexpression = _switchResult;
}
return _xblockexpression;
}
private String renderSchemaTable(final Object schema) {
String _xblockexpression = null;
{
final StructureTable table = StructureTable.get(this.swagger, new String[] { "name", "Name" }, new String[] { "type", "Type" }, new String[] { "doc", "Description" });
_xblockexpression = table.render(schema, null, null);
}
return _xblockexpression;
}
public CharSequence renderArraySchema(final Object schema) {
CharSequence _xblockexpression = null;
{
final String typeSpec = this.arrayHelper.getArrayTypeSpec(schema);
final Object eltType = this.arrayHelper.getElementType(schema);
final AttrDetails details = new AttrDetails(eltType);
StringConcatenation _builder = new StringConcatenation();
_builder.append("");
_builder.append(typeSpec);
_builder.append("
");
_builder.newLineIfNotEmpty();
{
boolean _isPrimitive = this.isPrimitive(eltType);
if (_isPrimitive) {
CharSequence _infoButton = details.getInfoButton();
_builder.append(_infoButton);
CharSequence _details = details.details(true);
_builder.append(_details);
} else {
String _renderSchemaTable = this.renderSchemaTable(eltType);
_builder.append(_renderSchemaTable);
}
}
_builder.newLineIfNotEmpty();
_xblockexpression = _builder;
}
return _xblockexpression;
}
public boolean isPrimitive(final Object obj) {
boolean _switchResult = false;
boolean _matched = false;
if (obj instanceof ObjectProperty) {
_matched=true;
_switchResult = false;
}
if (!_matched) {
if (obj instanceof ArrayProperty) {
_matched=true;
_switchResult = false;
}
}
if (!_matched) {
if (obj instanceof Property) {
_matched=true;
_switchResult = true;
}
}
if (!_matched) {
if (obj instanceof ModelImpl) {
boolean _and = false;
boolean _isEmpty = ((ModelImpl)obj).getProperties().isEmpty();
if (!_isEmpty) {
_and = false;
} else {
Property _additionalProperties = ((ModelImpl)obj).getAdditionalProperties();
Object _safeResolve = null;
if (_additionalProperties!=null) {
_safeResolve=this.refHelper.safeResolve(_additionalProperties);
}
boolean _tripleEquals = (_safeResolve == null);
_and = _tripleEquals;
}
if (_and) {
_matched=true;
_switchResult = true;
}
}
}
if (!_matched) {
if (obj instanceof Model) {
_matched=true;
_switchResult = false;
}
}
return _switchResult;
}
public CharSequence renderPrimitiveSchema(final Object schema) {
CharSequence _xblockexpression = null;
{
final AttrDetails details = new AttrDetails(schema);
StringConcatenation _builder = new StringConcatenation();
_builder.append("");
String _type = this.attributeHelper.getType(schema);
_builder.append(_type);
_builder.append("
");
CharSequence _infoButton = details.getInfoButton();
_builder.append(_infoButton);
CharSequence _details = details.details(true);
_builder.append(_details);
_xblockexpression = _builder;
}
return _xblockexpression;
}
public String getSchemaTitle(final Object schema) {
String _xblockexpression = null;
{
final Object resolved = this.refHelper.safeResolve(schema);
String _title = this.attributeHelper.getTitle(resolved);
String _rzveTypeName = this.attributeHelper.getRzveTypeName(resolved);
final Function1 _function = (String it) -> {
return Boolean.valueOf((it != null));
};
_xblockexpression = IterableExtensions.last(IterableExtensions.filter(Collections.unmodifiableList(CollectionLiterals.newArrayList(_title, _rzveTypeName)), _function));
}
return _xblockexpression;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy