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

com.reprezen.genflow.openapi.swaggerui.v3.XGenerateSwaggerUIv3 Maven / Gradle / Ivy

There is a newer version: 1.4.2
Show 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.openapi.swaggerui.v3;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.base.Strings;
import com.reprezen.genflow.api.normal.openapi.OpenApiNormalizer;
import com.reprezen.genflow.api.normal.openapi.Option;
import com.reprezen.genflow.api.template.IGenTemplateContext;
import com.reprezen.genflow.common.HtmlInjections;
import com.reprezen.genflow.openapi.swaggerui.v2.SwaggerUiOptions;
import com.reprezen.genflow.openapi.swaggerui.v3.SwaggerUi3Options;
import java.io.File;
import java.net.URI;
import java.net.URL;
import java.util.Map;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function0;

@SuppressWarnings("all")
public class XGenerateSwaggerUIv3 {
  @Extension
  private HtmlInjections htmlInjections;
  
  private final static ObjectMapper mapper = new Function0() {
    public ObjectMapper apply() {
      ObjectMapper _xifexpression = null;
      Boolean _valueOf = Boolean.valueOf(true);
      if ((_valueOf).booleanValue()) {
        ObjectMapper _xblockexpression = null;
        {
          final ObjectMapper m = new ObjectMapper();
          m.setSerializationInclusion(JsonInclude.Include.NON_NULL);
          _xblockexpression = m;
        }
        _xifexpression = _xblockexpression;
      }
      return _xifexpression;
    }
  }.apply();
  
  public String generate(final String json, final String uriPrefix, final String version, final IGenTemplateContext context) {
    return this.generate(json, uriPrefix, false, SwaggerUi3Options.DEFAULT, context);
  }
  
  public String generateNormalized(final String modelText, final File inputFile, final Integer modelVersion, final String uriPrefix, final boolean isLiveView, final IGenTemplateContext context) {
    try {
      OpenApiNormalizer _openApiNormalizer = new OpenApiNormalizer(modelVersion, Option.MINIMAL_OPTIONS);
      OpenApiNormalizer _of = _openApiNormalizer.of(modelText);
      URI _uRI = inputFile.toURI();
      URL _uRL = _uRI.toURL();
      final JsonNode normalized = _of.normalizeToJson(_uRL);
      String _writeValueAsString = XGenerateSwaggerUIv3.mapper.writeValueAsString(normalized);
      return this.generate(_writeValueAsString, uriPrefix, isLiveView, SwaggerUi3Options.DEFAULT, context);
    } catch (Throwable _e) {
      throw Exceptions.sneakyThrow(_e);
    }
  }
  
  public String generate(final String modelText, final String uriPrefix, final boolean isLiveView, final SwaggerUi3Options options, final IGenTemplateContext context) {
    String _xblockexpression = null;
    {
      HtmlInjections _elvis = null;
      Map _genTargetParameters = context.getGenTargetParameters();
      Object _get = _genTargetParameters.get(HtmlInjections.HTML_INJECTIONS_PARAM);
      if (((HtmlInjections) _get) != null) {
        _elvis = ((HtmlInjections) _get);
      } else {
        HtmlInjections _htmlInjections = new HtmlInjections();
        _elvis = _htmlInjections;
      }
      this.htmlInjections = _elvis;
      final String json = this.toJson(modelText);
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("");
      _builder.newLine();
      _builder.append("");
      _builder.newLine();
      _builder.append("");
      _builder.newLine();
      _builder.append("\t");
      _builder.append("");
      _builder.newLine();
      _builder.append("  \t\t");
      String _inject = this.htmlInjections.inject(HtmlInjections.HEAD_TOP);
      _builder.append(_inject, "  \t\t");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      _builder.append("\t\t");
      _builder.append("");
      _builder.newLine();
      _builder.append("  \t\t");
      _builder.append("Swagger UI");
      _builder.newLine();
      _builder.append("  \t\t");
      _builder.append("");
      _builder.newLine();
      _builder.append("  \t\t");
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("\t  \t");
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("  \t\t");
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("  \t\t");
      _builder.append("");
      _builder.newLineIfNotEmpty();
      _builder.append("  \t\t");
      _builder.append("");
      _builder.newLine();
      _builder.newLine();
      _builder.append("  \t\t");
      String _inject_1 = this.htmlInjections.inject(HtmlInjections.HEAD_BOTTOM);
      _builder.append(_inject_1, "  \t\t");
      _builder.newLineIfNotEmpty();
      _builder.append("\t");
      _builder.append("");
      _builder.newLine();
      _builder.newLine();
      _builder.append("\t");
      _builder.append("");
      _builder.newLine();
      _builder.append("\t\t");
      String _inject_2 = this.htmlInjections.inject(HtmlInjections.BODY_TOP);
      _builder.append(_inject_2, "\t\t");
      _builder.newLineIfNotEmpty();
      _builder.newLine();
      {
        if ((!isLiveView)) {
          _builder.append("\t\t");
          _builder.append("
"); _builder.newLine(); _builder.append("\t\t"); _builder.append("Created with "); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("
"); _builder.newLine(); } } _builder.newLine(); _builder.append("\t\t"); _builder.append(""); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append("\t \t\t"); _builder.append(""); _builder.newLine(); _builder.append("\t \t\t"); _builder.append(""); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append("\t \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append("\t \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.newLine(); _builder.append("\t\t \t"); _builder.append(""); _builder.newLine(); _builder.append("\t \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append("\t\t \t"); _builder.append(""); _builder.newLine(); _builder.newLine(); _builder.append("\t\t \t"); _builder.append(""); _builder.newLine(); _builder.append("\t \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.newLine(); _builder.append("\t\t \t"); _builder.append(""); _builder.newLine(); _builder.append("\t \t\t \t"); _builder.append(""); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append("\t \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.newLine(); _builder.append(" \t\t\t"); _builder.append(""); _builder.newLine(); _builder.append("\t\t"); _builder.append(""); _builder.newLine(); _builder.newLine(); _builder.append("\t\t"); _builder.append("
"); _builder.newLine(); _builder.newLine(); _builder.append("\t\t"); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append(""); _builder.newLine(); { if (isLiveView) { _builder.append("\t\t"); _builder.append(""); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append(""); _builder.newLineIfNotEmpty(); } } _builder.append("\t\t"); String _inject_3 = this.htmlInjections.inject(HtmlInjections.BODY_BOTTOM); _builder.append(_inject_3, "\t\t"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append(""); _builder.newLine(); _builder.append(""); _builder.newLine(); _xblockexpression = _builder.toString(); } return _xblockexpression; } private final static ObjectMapper jsonMapper = new ObjectMapper(); private final static ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory()); private String toJson(final String modelText) { try { String _trim = modelText.trim(); boolean _startsWith = _trim.startsWith("{"); if (_startsWith) { return modelText; } final JsonNode tree = XGenerateSwaggerUIv3.yamlMapper.readTree(modelText); return XGenerateSwaggerUIv3.jsonMapper.writeValueAsString(tree); } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } } private CharSequence maybeFunction(final String option) { CharSequence _xifexpression = null; boolean _startsWith = option.startsWith("function"); if (_startsWith) { _xifexpression = option; } else { StringConcatenation _builder = new StringConcatenation(); _builder.append("\""); _builder.append(option, ""); _builder.append("\""); _xifexpression = _builder; } return _xifexpression; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy