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

com.reprezen.genflow.openapi3.doc.XGenerateOpenApi3Doc Maven / Gradle / Ivy

package com.reprezen.genflow.openapi3.doc;

import com.google.common.collect.Lists;
import com.reprezen.genflow.api.openapi3.OpenApi3OutputItem;
import com.reprezen.genflow.common.HtmlInjections;
import com.reprezen.genflow.openapi3.doc.HelperHelper;
import com.reprezen.genflow.openapi3.doc.HtmlHelper;
import com.reprezen.genflow.openapi3.doc.MiscHelper;
import com.reprezen.genflow.openapi3.doc.ModelDoc;
import com.reprezen.genflow.openapi3.doc.OptionHelper;
import com.reprezen.genflow.openapi3.doc.ParamDoc;
import com.reprezen.genflow.openapi3.doc.PathDoc;
import com.reprezen.genflow.openapi3.doc.ResponseDoc;
import com.reprezen.genflow.openapi3.doc.TopMatter;
import com.reprezen.kaizen.oasparser.model3.Info;
import com.reprezen.kaizen.oasparser.model3.OpenApi3;
import com.reprezen.kaizen.oasparser.model3.Parameter;
import com.reprezen.kaizen.oasparser.model3.Path;
import com.reprezen.kaizen.oasparser.model3.Response;
import com.reprezen.kaizen.oasparser.model3.Schema;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Conversions;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.IterableExtensions;

@SuppressWarnings("all")
public class XGenerateOpenApi3Doc extends OpenApi3OutputItem {
  @Extension
  private OptionHelper optionHelper;
  
  @Extension
  private HtmlHelper htmlHelper;
  
  @Extension
  private MiscHelper miscHelper;
  
  @Extension
  private HtmlInjections htmlInjections;
  
  @Override
  public String generate(final OpenApi3 model) {
    try {
      String _xtrycatchfinallyexpression = null;
      try {
        String _xblockexpression = null;
        {
          HelperHelper.open(model, this.context);
          this.optionHelper = HelperHelper.getOptionHelper();
          this.htmlHelper = HelperHelper.getHtmlHelper();
          this.miscHelper = HelperHelper.getMiscHelper();
          HtmlInjections _elvis = null;
          Object _get = this.context.getGenTargetParameters().get(HtmlInjections.HTML_INJECTIONS_PARAM);
          if (((HtmlInjections) _get) != null) {
            _elvis = ((HtmlInjections) _get);
          } else {
            HtmlInjections _htmlInjections = new HtmlInjections();
            _elvis = _htmlInjections;
          }
          this.htmlInjections = _elvis;
          _xblockexpression = this.doGenerate(model);
        }
        _xtrycatchfinallyexpression = _xblockexpression;
      } finally {
        HelperHelper.close();
      }
      return _xtrycatchfinallyexpression;
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  public String doGenerate(final OpenApi3 model) {
    String _xblockexpression = null;
    {
      final String urlPrefix = this.optionHelper.getUrlPrefix();
      final Boolean preview = this.optionHelper.isPreview();
      final long startTime = System.nanoTime();
      boolean _isEmpty = model.getPaths().isEmpty();
      final boolean showPaths = (!_isEmpty);
      final boolean showDefs = (((!(preview).booleanValue()) || (!showPaths)) && (!model.getSchemas().isEmpty()));
      final boolean showParams = (((!(preview).booleanValue()) || (!showPaths)) && (!model.getParameters().isEmpty()));
      final boolean showResponses = (((!(preview).booleanValue()) || (!showPaths)) && (!model.getResponses().isEmpty()));
      final boolean includeTOC = ((!(preview).booleanValue()) && (this.optionHelper.isIncludeTOC()).booleanValue());
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLine();
      _builder.append("");
      _builder.newLine();
      _builder.append("    ");
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("    ");
      CharSequence _htmlHeadSection = this.htmlHeadSection(model, urlPrefix, (preview).booleanValue());
      _builder.append(_htmlHeadSection, "    ");
      _builder.newLineIfNotEmpty();
      _builder.append("    ");
      _builder.append("            ");
      _builder.newLine();
      _builder.append("       ");
      _builder.append("");
      _builder.newLine();
      _builder.append("       ");
      _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
    "); _builder.newLine(); _builder.append(" "); _builder.append("
  • Created with
  • "); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); { if (includeTOC) { _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); } } _builder.append(" "); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

OpenApi3 Specification

"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.append(" "); CharSequence _get = new TopMatter().get(model); _builder.append(_get, " "); _builder.newLineIfNotEmpty(); _builder.append(" "); CharSequence _xifexpression = null; if (showPaths) { _xifexpression = this.pathsHtml(model); } _builder.append(_xifexpression, " "); _builder.newLineIfNotEmpty(); _builder.append(" "); CharSequence _xifexpression_1 = null; if (showParams) { _xifexpression_1 = this.parametersHtml(model); } _builder.append(_xifexpression_1, " "); _builder.newLineIfNotEmpty(); _builder.append(" "); CharSequence _xifexpression_2 = null; if (showResponses) { _xifexpression_2 = this.responsesHtml(model); } _builder.append(_xifexpression_2, " "); _builder.newLineIfNotEmpty(); _builder.append(" "); CharSequence _xifexpression_3 = null; if (showDefs) { _xifexpression_3 = this.definitionsHtml(model); } _builder.append(_xifexpression_3, " "); _builder.newLineIfNotEmpty(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.append(" "); _builder.append(""); _builder.newLine(); { if ((preview).booleanValue()) { _builder.append(" "); String _inject = this.htmlInjections.inject(HtmlInjections.BODY_BOTTOM); _builder.append(_inject, " "); _builder.newLineIfNotEmpty(); } } { if (includeTOC) { _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); } } _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.append(""); _builder.newLine(); final String html = _builder.toString(); _xblockexpression = this.removeUnwantedIndentation(html); } return _xblockexpression; } private String elapsedTime(final long nano) { String _xblockexpression = null; { final long msec = (nano / 1000000); _xblockexpression = String.format("%d.%03d", Long.valueOf((msec / 1000)), Long.valueOf((msec % 1000))); } return _xblockexpression; } private CharSequence htmlHeadSection(final OpenApi3 model, final String urlPrefix, final boolean preview) { StringConcatenation _builder = new StringConcatenation(); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append(" "); _builder.append(""); Info _info = null; if (model!=null) { _info=model.getInfo(); } String _title = null; if (_info!=null) { _title=_info.getTitle(); } _builder.append(_title, " "); _builder.append(" Documentation"); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); { if (preview) { _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); } } _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); _builder.append(" "); _builder.append(""); _builder.newLine(); { if (preview) { String _inject = this.htmlInjections.inject(HtmlInjections.HEAD_BOTTOM); _builder.append(_inject); _builder.newLineIfNotEmpty(); } } _builder.append(""); _builder.newLine(); return _builder; } private CharSequence pathsHtml(final OpenApi3 model) { StringConcatenation _builder = new StringConcatenation(); _builder.append(""); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

Path Specifications

"); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

Path Specifications

"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); { List _elvis = null; Map _paths = model.getPaths(); Set _keySet = null; if (_paths!=null) { _keySet=_paths.keySet(); } List _sortByPosition = this.miscHelper.sortByPosition(_keySet, model.getPaths()); if (_sortByPosition != null) { _elvis = _sortByPosition; } else { _elvis = Collections.unmodifiableList(CollectionLiterals.newArrayList()); } for(final String path : _elvis) { _builder.append(" "); CharSequence _html = new PathDoc(path).getHtml(); _builder.append(_html, " "); _builder.newLineIfNotEmpty(); } } _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append("
"); _builder.newLine(); return _builder; } private CharSequence parametersHtml(final OpenApi3 model) { StringConcatenation _builder = new StringConcatenation(); _builder.append(""); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

Parameters

"); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

Parameters

"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); { List _sortByPosition = this.miscHelper.sortByPosition(model.getParameters().keySet(), model.getParameters()); for(final String param : _sortByPosition) { _builder.append(" "); CharSequence _html = new ParamDoc(model, param).getHtml(); _builder.append(_html, " "); _builder.newLineIfNotEmpty(); } } _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append("
"); _builder.newLine(); return _builder; } private CharSequence responsesHtml(final OpenApi3 model) { StringConcatenation _builder = new StringConcatenation(); _builder.append(""); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

Responses

"); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

Responses

"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
\t\t\t "); _builder.newLine(); { List _sortByPosition = this.miscHelper.sortByPosition(model.getResponses().keySet(), model.getResponses()); for(final String response : _sortByPosition) { _builder.append(" "); CharSequence _html = new ResponseDoc(response).getHtml(); _builder.append(_html, " "); _builder.newLineIfNotEmpty(); } } _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append("
"); _builder.newLine(); return _builder; } private CharSequence definitionsHtml(final OpenApi3 model) { StringConcatenation _builder = new StringConcatenation(); _builder.append(""); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

Schema Definitions

"); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("

Schema Definitions

"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append(" "); _builder.append("
"); _builder.newLine(); { List _sortByPosition = this.miscHelper.sortByPosition(model.getSchemas().keySet(), model.getSchemas()); for(final String definition : _sortByPosition) { _builder.append(" "); CharSequence _html = new ModelDoc(definition).getHtml(); _builder.append(_html, " "); _builder.newLineIfNotEmpty(); } } _builder.append(" "); _builder.append("
"); _builder.newLine(); _builder.append("
"); _builder.newLine(); return _builder; } private final Pattern indentedPreBlock = Pattern.compile("^(\\s*)]*class=\"remove-xtend-indent\"[^>]*>.*$", (Pattern.CASE_INSENSITIVE + Pattern.DOTALL)); private String removeUnwantedIndentation(final String html) { return this.removeUnwantedIndentation(((List)Conversions.doWrapArray(html.split("\n")))); } private String removeUnwantedIndentation(final List lines) { String _xblockexpression = null; { int i = 0; final ArrayList unindentedLines = Lists.newArrayList(); while ((i < lines.size())) { { String line = lines.get(i); Matcher matcher = this.indentedPreBlock.matcher(line); boolean _matches = matcher.matches(); if (_matches) { String indentation = matcher.group(1); int indentLen = matcher.end(1); while (((i < lines.size()) && line.startsWith(indentation))) { { unindentedLines.add(line.substring(indentLen)); i = (i + 1); String _xifexpression = null; int _size = lines.size(); boolean _lessThan = (i < _size); if (_lessThan) { _xifexpression = lines.get(i); } else { _xifexpression = ""; } line = _xifexpression; } } } else { unindentedLines.add(lines.get(i)); i = (i + 1); } } } _xblockexpression = IterableExtensions.join(unindentedLines, "\n"); } return _xblockexpression; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy