Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.reprezen.genflow.rapidml.swagger.XGenerateSwagger Maven / Gradle / Ivy
/**
* 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.rapidml.swagger;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.Iterables;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.reprezen.genflow.api.template.IGenTemplateContext;
import com.reprezen.genflow.api.zenmodel.ZenModelOutputItem;
import com.reprezen.genflow.common.jsonschema.JsonSchemaHelper;
import com.reprezen.genflow.common.xtend.ExtensionsHelper;
import com.reprezen.genflow.common.xtend.ZenModelHelper;
import com.reprezen.genflow.rapidml.swagger.JsonSchemaForSwaggerGenerator;
import com.reprezen.genflow.rapidml.swagger.SwaggerOutputFormat;
import com.reprezen.genflow.rapidml.swagger.XSwaggerGenTemplate;
import com.reprezen.rapidml.AuthenticationFlows;
import com.reprezen.rapidml.AuthenticationMethod;
import com.reprezen.rapidml.AuthenticationTypes;
import com.reprezen.rapidml.Constraint;
import com.reprezen.rapidml.Example;
import com.reprezen.rapidml.Extensible;
import com.reprezen.rapidml.Feature;
import com.reprezen.rapidml.HTTPMethods;
import com.reprezen.rapidml.HasSecurityValue;
import com.reprezen.rapidml.HttpMessageParameterLocation;
import com.reprezen.rapidml.LengthConstraint;
import com.reprezen.rapidml.MediaType;
import com.reprezen.rapidml.MessageParameter;
import com.reprezen.rapidml.Method;
import com.reprezen.rapidml.PrimitiveProperty;
import com.reprezen.rapidml.PropertyRealization;
import com.reprezen.rapidml.PropertyReference;
import com.reprezen.rapidml.RapidmlFactory;
import com.reprezen.rapidml.RegExConstraint;
import com.reprezen.rapidml.ResourceAPI;
import com.reprezen.rapidml.ResourceDefinition;
import com.reprezen.rapidml.SecurityScheme;
import com.reprezen.rapidml.SecuritySchemeLibrary;
import com.reprezen.rapidml.SecuritySchemeParameter;
import com.reprezen.rapidml.SecurityScope;
import com.reprezen.rapidml.ServiceDataResource;
import com.reprezen.rapidml.SingleValueType;
import com.reprezen.rapidml.SourceReference;
import com.reprezen.rapidml.Structure;
import com.reprezen.rapidml.TemplateParameter;
import com.reprezen.rapidml.TypedMessage;
import com.reprezen.rapidml.TypedRequest;
import com.reprezen.rapidml.TypedResponse;
import com.reprezen.rapidml.URIParameter;
import com.reprezen.rapidml.ValueRangeConstraint;
import com.reprezen.rapidml.ZenModel;
import com.reprezen.rapidml.util.OAuth2Parameters;
import io.swagger.models.Info;
import io.swagger.models.Model;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.RefModel;
import io.swagger.models.Response;
import io.swagger.models.Scheme;
import io.swagger.models.Swagger;
import io.swagger.models.Tag;
import io.swagger.models.auth.ApiKeyAuthDefinition;
import io.swagger.models.auth.BasicAuthDefinition;
import io.swagger.models.auth.In;
import io.swagger.models.auth.OAuth2Definition;
import io.swagger.models.auth.SecuritySchemeDefinition;
import io.swagger.models.parameters.AbstractParameter;
import io.swagger.models.parameters.AbstractSerializableParameter;
import io.swagger.models.parameters.BodyParameter;
import io.swagger.models.parameters.HeaderParameter;
import io.swagger.models.parameters.Parameter;
import io.swagger.models.parameters.PathParameter;
import io.swagger.models.parameters.QueryParameter;
import io.swagger.models.properties.AbstractNumericProperty;
import io.swagger.models.properties.AbstractProperty;
import io.swagger.models.properties.ArrayProperty;
import io.swagger.models.properties.BooleanProperty;
import io.swagger.models.properties.DateProperty;
import io.swagger.models.properties.DateTimeProperty;
import io.swagger.models.properties.DecimalProperty;
import io.swagger.models.properties.DoubleProperty;
import io.swagger.models.properties.FloatProperty;
import io.swagger.models.properties.IntegerProperty;
import io.swagger.models.properties.LongProperty;
import io.swagger.models.properties.Property;
import io.swagger.models.properties.RefProperty;
import io.swagger.models.properties.StringProperty;
import io.swagger.util.Json;
import io.swagger.util.Yaml;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.ecore.EObject;
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.ExclusiveRange;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.eclipse.xtext.xbase.lib.ListExtensions;
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.yaml.snakeyaml.DumperOptions;
@SuppressWarnings("all")
public class XGenerateSwagger extends ZenModelOutputItem {
public final static String OUTPUT_FORMAT_PARAM = "format";
public final static String OPTION_RETAIN_EMPTY_PARAMATERS = "retainEmptyParameters";
@Extension
private ZenModelHelper _zenModelHelper = new ZenModelHelper();
@Extension
private JsonSchemaHelper _jsonSchemaHelper = new JsonSchemaHelper();
@Extension
private ExtensionsHelper _extensionsHelper = new ExtensionsHelper();
private final String defaultFormat;
private final JsonSchemaForSwaggerGenerator jsonSchemaGenerator;
public XGenerateSwagger() {
this(SwaggerOutputFormat.JSON);
}
public XGenerateSwagger(final SwaggerOutputFormat format) {
this(format, new JsonSchemaForSwaggerGenerator());
}
public XGenerateSwagger(final SwaggerOutputFormat format, final JsonSchemaForSwaggerGenerator jsonSchemaGenerator) {
String _string = format.toString();
this.defaultFormat = _string;
this.jsonSchemaGenerator = jsonSchemaGenerator;
}
@Override
public void init(final IGenTemplateContext context) {
super.init(context);
}
@Override
public String generate(final ZenModel model) {
try {
final Map templateParam = this.context.getGenTargetParameters();
final Swagger swagger = this.getSwagger(model);
final ObjectWriter mapper = Json.pretty();
String content = mapper.writeValueAsString(swagger);
final ObjectMapper tempMapper = new ObjectMapper();
final ObjectNode jsonSchemasDefinitionsNode = this.jsonSchemaGenerator.generateDefinitionsNode(model, templateParam);
JsonNode _readTree = tempMapper.readTree(content);
final JsonNode swaggerNode = ((ObjectNode) _readTree).set("definitions", jsonSchemasDefinitionsNode);
Object _xifexpression = null;
Object _get = null;
if (templateParam!=null) {
_get=templateParam.get(XGenerateSwagger.OUTPUT_FORMAT_PARAM);
}
boolean _tripleNotEquals = (_get != null);
if (_tripleNotEquals) {
_xifexpression = templateParam.get(XGenerateSwagger.OUTPUT_FORMAT_PARAM);
} else {
_xifexpression = this.defaultFormat;
}
final Object format = _xifexpression;
String _string = SwaggerOutputFormat.YAML.toString();
boolean _equals = Objects.equal(_string, format);
if (_equals) {
final ObjectMapper swaggerYamlMapper = Yaml.mapper();
Object _get_1 = null;
if (templateParam!=null) {
_get_1=templateParam.get(XSwaggerGenTemplate.FOLD_MULTILINE);
}
final Object foldMultiline = _get_1;
boolean _and = false;
if (!(foldMultiline instanceof Boolean)) {
_and = false;
} else {
_and = (((Boolean) foldMultiline)).booleanValue();
}
if (_and) {
final DumperOptions opts = new DumperOptions();
opts.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
final org.yaml.snakeyaml.Yaml yaml = new org.yaml.snakeyaml.Yaml(opts);
ObjectMapper _objectMapper = new ObjectMapper();
Object _convertValue = _objectMapper.convertValue(swaggerNode, Object.class);
return yaml.dump(_convertValue);
}
return swaggerYamlMapper.writeValueAsString(swaggerNode);
} else {
ObjectWriter _writerWithDefaultPrettyPrinter = tempMapper.writerWithDefaultPrettyPrinter();
return _writerWithDefaultPrettyPrinter.writeValueAsString(swaggerNode);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
public Swagger getSwagger(final ZenModel model) {
final Swagger swagger = new Swagger();
EList _extensions = ((Extensible) model).getExtensions();
final Function1 _function = (com.reprezen.rapidml.Extension it) -> {
String _name = it.getName();
return Boolean.valueOf(_name.startsWith("openAPI.tags."));
};
final Iterable groups = IterableExtensions.filter(_extensions, _function);
boolean _isEmpty = IterableExtensions.isEmpty(groups);
boolean _not = (!_isEmpty);
if (_not) {
final Consumer _function_1 = (com.reprezen.rapidml.Extension it) -> {
final Tag tag = new Tag();
String _name = it.getName();
String _substring = _name.substring(13);
tag.setName(_substring);
final String description = it.getValue();
tag.setDescription(description);
swagger.addTag(tag);
};
groups.forEach(_function_1);
}
this.setVendorExtensions(model, swagger);
EList _resourceAPIs = model.getResourceAPIs();
boolean _isEmpty_1 = _resourceAPIs.isEmpty();
if (_isEmpty_1) {
this.addDefaultResourceAPI(model);
}
EList _resourceAPIs_1 = model.getResourceAPIs();
final ResourceAPI resourceAPI = _resourceAPIs_1.get(0);
String _elvis = null;
String _baseURI = resourceAPI.getBaseURI();
if (_baseURI != null) {
_elvis = _baseURI;
} else {
_elvis = "http://localhost";
}
final URI uri = URI.create(_elvis);
String _xifexpression = null;
boolean _and = false;
String _path = uri.getPath();
boolean _tripleNotEquals = (_path != null);
if (!_tripleNotEquals) {
_and = false;
} else {
String _path_1 = uri.getPath();
boolean _isEmpty_2 = _path_1.isEmpty();
boolean _not_1 = (!_isEmpty_2);
_and = _not_1;
}
if (_and) {
_xifexpression = uri.getPath();
} else {
_xifexpression = "/";
}
swagger.setBasePath(_xifexpression);
String _host = uri.getHost();
String _xifexpression_1 = null;
int _port = uri.getPort();
boolean _greaterEqualsThan = (_port >= 0);
if (_greaterEqualsThan) {
int _port_1 = uri.getPort();
_xifexpression_1 = (":" + Integer.valueOf(_port_1));
} else {
_xifexpression_1 = "";
}
String _plus = (_host + _xifexpression_1);
swagger.setHost(_plus);
String _scheme = uri.getScheme();
boolean _tripleNotEquals_1 = (_scheme != null);
if (_tripleNotEquals_1) {
String _scheme_1 = uri.getScheme();
Scheme _forValue = Scheme.forValue(_scheme_1);
swagger.addScheme(_forValue);
}
Info _info = new Info();
swagger.setInfo(_info);
Info _info_1 = swagger.getInfo();
String _xifexpression_2 = null;
String _version = resourceAPI.getVersion();
boolean _isNullOrEmpty = Strings.isNullOrEmpty(_version);
boolean _not_2 = (!_isNullOrEmpty);
if (_not_2) {
_xifexpression_2 = resourceAPI.getVersion();
} else {
_xifexpression_2 = "1.0.0";
}
_info_1.setVersion(_xifexpression_2);
Info _info_2 = swagger.getInfo();
String _name = resourceAPI.getName();
_info_2.setTitle(_name);
Info _info_3 = swagger.getInfo();
String _documentation = this._zenModelHelper.getDocumentation(resourceAPI);
_info_3.setDescription(_documentation);
EList _definedMediaTypes = resourceAPI.getDefinedMediaTypes();
final Consumer _function_2 = (MediaType it) -> {
String _name_1 = it.getName();
swagger.addConsumes(_name_1);
String _name_2 = it.getName();
swagger.addProduces(_name_2);
};
_definedMediaTypes.forEach(_function_2);
EList _resourceAPIs_2 = model.getResourceAPIs();
final Function1> _function_3 = (ResourceAPI it) -> {
return it.getOwnedResourceDefinitions();
};
List> _map = ListExtensions.>map(_resourceAPIs_2, _function_3);
Iterable _flatten = Iterables.concat(_map);
final Consumer _function_4 = (ResourceDefinition it) -> {
final Tag tag = new Tag();
String _name_1 = it.getName();
tag.setName(_name_1);
String _documentation_1 = this._zenModelHelper.getDocumentation(it);
tag.setDescription(_documentation_1);
swagger.addTag(tag);
String _xifexpression_3 = null;
com.reprezen.rapidml.URI _uRI = it.getURI();
boolean _tripleNotEquals_2 = (_uRI != null);
if (_tripleNotEquals_2) {
com.reprezen.rapidml.URI _uRI_1 = it.getURI();
_xifexpression_3 = _uRI_1.toString();
} else {
_xifexpression_3 = "";
}
final String pathUri = ("/" + _xifexpression_3);
Path _createSwaggerPath = this.createSwaggerPath(it);
swagger.path(pathUri, _createSwaggerPath);
};
_flatten.forEach(_function_4);
Map _paths = swagger.getPaths();
boolean _tripleEquals = (_paths == null);
if (_tripleEquals) {
Map _emptyMap = Collections.emptyMap();
swagger.setPaths(_emptyMap);
}
ArrayList _allUsedSecuritySchemes = this.getAllUsedSecuritySchemes(model);
final Consumer _function_5 = (SecurityScheme it) -> {
String _name_1 = it.getName();
SecuritySchemeDefinition _createSecurityScheme = this.createSecurityScheme(it);
swagger.addSecurityDefinition(_name_1, _createSecurityScheme);
};
_allUsedSecuritySchemes.forEach(_function_5);
return swagger;
}
public ArrayList getAllUsedSecuritySchemes(final ZenModel model) {
final ArrayList result = Lists.newArrayList();
SecuritySchemeLibrary _securitySchemesLibrary = model.getSecuritySchemesLibrary();
boolean _tripleNotEquals = (_securitySchemesLibrary != null);
if (_tripleNotEquals) {
SecuritySchemeLibrary _securitySchemesLibrary_1 = model.getSecuritySchemesLibrary();
EList _securitySchemes = _securitySchemesLibrary_1.getSecuritySchemes();
result.addAll(_securitySchemes);
}
TreeIterator _eAllContents = model.eAllContents();
Iterator _filter = Iterators.filter(_eAllContents, HasSecurityValue.class);
List _list = IteratorExtensions.toList(_filter);
final Function1> _function = (HasSecurityValue it) -> {
return it.getSecuredBy();
};
List> _map = ListExtensions.>map(_list, _function);
Iterable _flatten = Iterables.concat(_map);
final Consumer _function_1 = (AuthenticationMethod it) -> {
SecurityScheme _scheme = it.getScheme();
result.add(_scheme);
};
_flatten.forEach(_function_1);
return result;
}
public SecuritySchemeDefinition createSecurityScheme(final SecurityScheme scheme) {
AuthenticationTypes _type = scheme.getType();
if (_type != null) {
switch (_type) {
case OAUTH2:
final OAuth2Definition result = new OAuth2Definition();
this.setVendorExtensions(scheme, result);
String _switchResult_1 = null;
AuthenticationFlows _flow = scheme.getFlow();
if (_flow != null) {
switch (_flow) {
case IMPLICIT:
_switchResult_1 = "implicit";
break;
case PASSWORD:
_switchResult_1 = "password";
break;
case APPLICATION:
_switchResult_1 = "application";
break;
case ACCESS_CODE:
_switchResult_1 = "accessCode";
break;
default:
break;
}
}
result.setFlow(_switchResult_1);
EList _settings = scheme.getSettings();
final Function1 _function = (SecuritySchemeParameter it) -> {
String _name = it.getName();
return Boolean.valueOf(Objects.equal(_name, OAuth2Parameters.AUTHORIZATION_URL));
};
final SecuritySchemeParameter authorizationUrlSetting = IterableExtensions.findFirst(_settings, _function);
String _value = null;
if (authorizationUrlSetting!=null) {
_value=authorizationUrlSetting.getValue();
}
result.setAuthorizationUrl(_value);
EList _settings_1 = scheme.getSettings();
final Function1 _function_1 = (SecuritySchemeParameter it) -> {
String _name = it.getName();
return Boolean.valueOf(Objects.equal(_name, OAuth2Parameters.TOKEN_URL));
};
final SecuritySchemeParameter tokenUrlSetting = IterableExtensions.findFirst(_settings_1, _function_1);
if ((tokenUrlSetting != null)) {
String _value_1 = tokenUrlSetting.getValue();
result.setTokenUrl(_value_1);
} else {
EList _settings_2 = scheme.getSettings();
final Function1 _function_2 = (SecuritySchemeParameter it) -> {
String _name = it.getName();
return Boolean.valueOf(Objects.equal(_name, OAuth2Parameters.ACCESS_TOKEN_URL));
};
final SecuritySchemeParameter accessTokenUrlSetting = IterableExtensions.findFirst(_settings_2, _function_2);
String _value_2 = null;
if (accessTokenUrlSetting!=null) {
_value_2=accessTokenUrlSetting.getValue();
}
result.setTokenUrl(_value_2);
}
EList _scopes = scheme.getScopes();
final Consumer _function_3 = (SecurityScope it) -> {
String _name = it.getName();
String _documentation = this._zenModelHelper.getDocumentation(it);
result.addScope(_name, _documentation);
};
_scopes.forEach(_function_3);
result.setType("oauth2");
return result;
case BASIC:
final BasicAuthDefinition result_1 = new BasicAuthDefinition();
this.setVendorExtensions(scheme, result_1);
result_1.setType("basic");
return result_1;
case CUSTOM:
final ApiKeyAuthDefinition result_2 = new ApiKeyAuthDefinition();
this.setVendorExtensions(scheme, result_2);
EList _parameters = scheme.getParameters();
boolean _isEmpty = _parameters.isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
EList _parameters_1 = scheme.getParameters();
final MessageParameter param = _parameters_1.get(0);
String _name = param.getName();
result_2.setName(_name);
In _xifexpression = null;
SingleValueType _type_1 = param.getType();
boolean _equals = Objects.equal(_type_1, HttpMessageParameterLocation.HEADER);
if (_equals) {
_xifexpression = In.HEADER;
} else {
_xifexpression = In.QUERY;
}
final In in = _xifexpression;
result_2.setIn(in);
}
result_2.setType("apiKey");
return result_2;
default:
break;
}
}
return null;
}
public Path createSwaggerPath(final ResourceDefinition res) {
final Path path = new Path();
this.setVendorExtensions(((Extensible) res), path);
com.reprezen.rapidml.URI _uRI = ((ServiceDataResource) res).getURI();
boolean _tripleNotEquals = (_uRI != null);
if (_tripleNotEquals) {
com.reprezen.rapidml.URI _uRI_1 = ((ServiceDataResource) res).getURI();
EList _uriParameters = _uRI_1.getUriParameters();
final Consumer _function = (URIParameter it) -> {
AbstractSerializableParameter> _xifexpression = null;
if ((it instanceof TemplateParameter)) {
_xifexpression = new PathParameter();
} else {
_xifexpression = new QueryParameter();
}
final AbstractSerializableParameter> param = _xifexpression;
String _documentation = this._zenModelHelper.getDocumentation(it);
param.setDescription(_documentation);
String _name = it.getName();
param.setName(_name);
SourceReference _sourceReference = it.getSourceReference();
SingleValueType _type = _sourceReference.getType();
String _jSONSchemaTypeName = this._jsonSchemaHelper.getJSONSchemaTypeName(_type);
param.setType(_jSONSchemaTypeName);
SourceReference _sourceReference_1 = it.getSourceReference();
SingleValueType _type_1 = _sourceReference_1.getType();
String _jSONSchemaTypeFormat = this._jsonSchemaHelper.getJSONSchemaTypeFormat(_type_1);
boolean _tripleNotEquals_1 = (_jSONSchemaTypeFormat != null);
if (_tripleNotEquals_1) {
SourceReference _sourceReference_2 = it.getSourceReference();
SingleValueType _type_2 = _sourceReference_2.getType();
String _jSONSchemaTypeFormat_1 = this._jsonSchemaHelper.getJSONSchemaTypeFormat(_type_2);
param.setFormat(_jSONSchemaTypeFormat_1);
}
this.setVendorExtensions(it, param);
boolean _matched = false;
if (!_matched) {
if (param instanceof PathParameter) {
_matched=true;
((PathParameter)param).setRequired(true);
String _default = it.getDefault();
((PathParameter)param).setDefaultValue(_default);
}
}
if (!_matched) {
if (param instanceof QueryParameter) {
_matched=true;
boolean _isRequired = it.isRequired();
((QueryParameter)param).setRequired(_isRequired);
String _default = it.getDefault();
((QueryParameter)param).setDefaultValue(_default);
}
}
path.addParameter(param);
};
_uriParameters.forEach(_function);
}
EList _methods = res.getMethods();
final Consumer _function_1 = (Method it) -> {
this.createSwaggerOperation(path, it);
};
_methods.forEach(_function_1);
return path;
}
public void createSwaggerOperation(final Path path, final Method method) {
final Operation operation = new Operation();
this.setVendorExtensions(method, operation);
String _id = method.getId();
operation.setOperationId(_id);
String _documentation = this._zenModelHelper.getDocumentation(method);
operation.setDescription(_documentation);
EList _extensions = ((Extensible) method).getExtensions();
final Function1 _function = (com.reprezen.rapidml.Extension it) -> {
String _name = it.getName();
return Boolean.valueOf(Objects.equal(_name, "openAPI.tags"));
};
final Iterable groups = IterableExtensions.filter(_extensions, _function);
boolean _isEmpty = IterableExtensions.isEmpty(groups);
boolean _not = (!_isEmpty);
if (_not) {
final Consumer _function_1 = (com.reprezen.rapidml.Extension it) -> {
Splitter _on = Splitter.on(",");
String _value = it.getValue();
Iterable _split = _on.split(_value);
final Consumer _function_2 = (String tag) -> {
String _trim = tag.trim();
operation.addTag(_trim);
};
_split.forEach(_function_2);
};
groups.forEach(_function_1);
} else {
ResourceDefinition _containingResourceDefinition = method.getContainingResourceDefinition();
String _name = _containingResourceDefinition.getName();
operation.addTag(_name);
}
EList _responses = method.getResponses();
final Consumer _function_2 = (TypedResponse it) -> {
String _xifexpression = null;
int _statusCode = it.getStatusCode();
boolean _greaterThan = (_statusCode > 0);
if (_greaterThan) {
int _statusCode_1 = it.getStatusCode();
_xifexpression = Integer.valueOf(_statusCode_1).toString();
} else {
_xifexpression = "200";
}
Response _response = this.getResponse(it);
operation.addResponse(_xifexpression, _response);
};
_responses.forEach(_function_2);
EList _responses_1 = method.getResponses();
final Function1> _function_3 = (TypedResponse it) -> {
return it.getMediaTypes();
};
List> _map = ListExtensions.>map(_responses_1, _function_3);
Iterable _flatten = Iterables.concat(_map);
final Function1 _function_4 = (MediaType it) -> {
return it.getName();
};
Iterable _map_1 = IterableExtensions.map(_flatten, _function_4);
Set _set = IterableExtensions.toSet(_map_1);
final Consumer _function_5 = (String it) -> {
XGenerateSwagger.safeAddProduces(operation, it);
};
_set.forEach(_function_5);
TypedRequest _request = method.getRequest();
EList _mediaTypes = _request.getMediaTypes();
final Function1 _function_6 = (MediaType it) -> {
return it.getName();
};
List _map_2 = ListExtensions.map(_mediaTypes, _function_6);
Set _set_1 = IterableExtensions.toSet(_map_2);
final Consumer _function_7 = (String it) -> {
XGenerateSwagger.safeAddConsumes(operation, it);
};
_set_1.forEach(_function_7);
TypedRequest _request_1 = method.getRequest();
EList _parameters = _request_1.getParameters();
final Function1 _function_8 = (MessageParameter it) -> {
HttpMessageParameterLocation _httpLocation = it.getHttpLocation();
return Boolean.valueOf((!Objects.equal(_httpLocation, HttpMessageParameterLocation.QUERY)));
};
Iterable _filter = IterableExtensions.filter(_parameters, _function_8);
final Consumer _function_9 = (MessageParameter it) -> {
HeaderParameter _messageHeaderParameter = this.getMessageHeaderParameter(it);
operation.addParameter(_messageHeaderParameter);
};
_filter.forEach(_function_9);
TypedRequest _request_2 = method.getRequest();
EList _parameters_1 = _request_2.getParameters();
final Function1 _function_10 = (MessageParameter it) -> {
HttpMessageParameterLocation _httpLocation = it.getHttpLocation();
return Boolean.valueOf(Objects.equal(_httpLocation, HttpMessageParameterLocation.QUERY));
};
Iterable _filter_1 = IterableExtensions.filter(_parameters_1, _function_10);
final Consumer _function_11 = (MessageParameter it) -> {
QueryParameter _messageQueryParameter = this.getMessageQueryParameter(it);
operation.addParameter(_messageQueryParameter);
};
_filter_1.forEach(_function_11);
boolean _shouldRetainEmptyParameters = this.shouldRetainEmptyParameters();
boolean _not_1 = (!_shouldRetainEmptyParameters);
if (_not_1) {
List _parameters_2 = operation.getParameters();
boolean _isEmpty_1 = _parameters_2.isEmpty();
if (_isEmpty_1) {
operation.setParameters(null);
}
}
TypedRequest _request_3 = method.getRequest();
final String requestTypeName = this.getDefinitionName(_request_3);
if ((requestTypeName != null)) {
final BodyParameter param = new BodyParameter();
operation.addParameter(param);
param.setName(requestTypeName);
param.setDescription("Request body");
TypedRequest _request_4 = method.getRequest();
String _messageDocumentation = this.getMessageDocumentation(_request_4);
param.setDescription(_messageDocumentation);
Model _referenceToType = this.getReferenceToType(requestTypeName);
param.setSchema(_referenceToType);
TypedRequest _request_5 = method.getRequest();
this.setVendorExtensions(_request_5, param);
param.setRequired(true);
}
HTTPMethods _httpMethod = method.getHttpMethod();
String _name_1 = _httpMethod.getName();
switch (_name_1) {
case "GET":
path.setGet(operation);
break;
case "POST":
path.setPost(operation);
break;
case "PUT":
path.setPut(operation);
break;
case "DELETE":
path.setDelete(operation);
break;
case "OPTIONS":
path.setOptions(operation);
break;
case "PATCH":
path.setPatch(operation);
break;
}
EList _securedBy = method.getSecuredBy();
final Consumer _function_12 = (AuthenticationMethod it) -> {
SecurityScheme _scheme = it.getScheme();
String _name_2 = _scheme.getName();
EList _scopes = it.getScopes();
final Function1 _function_13 = (SecurityScope it_1) -> {
return it_1.getName();
};
List _map_3 = ListExtensions.map(_scopes, _function_13);
operation.addSecurity(_name_2, _map_3);
};
_securedBy.forEach(_function_12);
}
/**
* @returns creates Swagger Response from ZEN TypedResponse
*/
public Response getResponse(final TypedResponse rapidResponse) {
final Response swaggerResponse = new Response();
this.setVendorExtensions(((Extensible) rapidResponse), swaggerResponse);
EList _allExamples = rapidResponse.getAllExamples();
final Example example = IterableExtensions.head(_allExamples);
boolean _and = false;
if (!(example != null)) {
_and = false;
} else {
String _body = example.getBody();
boolean _tripleNotEquals = (_body != null);
_and = _tripleNotEquals;
}
if (_and) {
EList _mediaTypes = rapidResponse.getMediaTypes();
final MediaType type = IterableExtensions.head(_mediaTypes);
if ((type != null)) {
EList _mediaTypes_1 = rapidResponse.getMediaTypes();
MediaType _head = IterableExtensions.head(_mediaTypes_1);
String _name = _head.getName();
String _body_1 = example.getBody();
String _name_1 = type.getName();
Object _renderExample = this.renderExample(_body_1, _name_1);
swaggerResponse.example(_name, _renderExample);
}
}
final String typeName = this.getDefinitionName(rapidResponse);
String _messageDocumentation = this.getMessageDocumentation(rapidResponse);
swaggerResponse.setDescription(_messageDocumentation);
if ((typeName != null)) {
final RefProperty property = new RefProperty();
property.set$ref(("#/definitions/" + typeName));
swaggerResponse.setSchema(property);
}
EList _parameters = rapidResponse.getParameters();
final Consumer _function = (MessageParameter it) -> {
Map _headers = swaggerResponse.getHeaders();
boolean _tripleEquals = (_headers == null);
if (_tripleEquals) {
HashMap _hashMap = new HashMap();
swaggerResponse.setHeaders(_hashMap);
}
boolean _isArrayProperty = this._jsonSchemaHelper.isArrayProperty(it);
if (_isArrayProperty) {
final ArrayProperty prop = new ArrayProperty();
Property _createSwaggerPropertyWithConstraints = this.createSwaggerPropertyWithConstraints(it);
prop.setItems(_createSwaggerPropertyWithConstraints);
String _documentation = this._zenModelHelper.getDocumentation(it);
prop.setDescription(_documentation);
Map _headers_1 = swaggerResponse.getHeaders();
String _name_2 = it.getName();
_headers_1.put(_name_2, prop);
} else {
final Property prop_1 = this.createSwaggerPropertyWithConstraints(it);
String _documentation_1 = this._zenModelHelper.getDocumentation(it);
prop_1.setDescription(_documentation_1);
Map _headers_2 = swaggerResponse.getHeaders();
String _name_3 = it.getName();
_headers_2.put(_name_3, prop_1);
}
};
_parameters.forEach(_function);
return swaggerResponse;
}
private Object renderExample(final String example, final String type) {
Object _switchResult = null;
switch (type) {
case "application/json":
_switchResult = this.getJsonExample(example);
break;
default:
_switchResult = example;
break;
}
return _switchResult;
}
private final static ObjectMapper jsonMapper = new ObjectMapper();
private final static ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
private Object getJsonExample(final String example) {
try {
return XGenerateSwagger.jsonMapper.readTree(example);
} catch (final Throwable _t) {
if (_t instanceof IOException) {
final IOException exception = (IOException)_t;
} else {
throw Exceptions.sneakyThrow(_t);
}
}
try {
String _removeIndentation = this.removeIndentation(example);
return XGenerateSwagger.yamlMapper.readTree(_removeIndentation);
} catch (final Throwable _t_1) {
if (_t_1 instanceof Exception) {
final Exception exception_1 = (Exception)_t_1;
} else {
throw Exceptions.sneakyThrow(_t_1);
}
}
return example;
}
private String removeIndentation(final String text) {
String[] lines = text.split("(?m)^");
final String[] _converted_lines = (String[])lines;
final Function1 _function = (String it) -> {
String _trim = it.trim();
return Boolean.valueOf(_trim.isEmpty());
};
Iterable _dropWhile = IterableExtensions.dropWhile(((Iterable extends String>)Conversions.doWrapArray(_converted_lines)), _function);
lines = ((String[])Conversions.unwrapArray(_dropWhile, String.class));
final String[] _converted_lines_1 = (String[])lines;
List _reverse = ListExtensions.reverse(((List)Conversions.doWrapArray(_converted_lines_1)));
final Function1 _function_1 = (String it) -> {
String _trim = it.trim();
return Boolean.valueOf(_trim.isEmpty());
};
Iterable _dropWhile_1 = IterableExtensions.dropWhile(_reverse, _function_1);
List _list = IterableExtensions.toList(_dropWhile_1);
List _reverse_1 = ListExtensions.reverse(_list);
lines = ((String[])Conversions.unwrapArray(_reverse_1, String.class));
final String[] _converted_lines_2 = (String[])lines;
String _head = IterableExtensions.head(((Iterable)Conversions.doWrapArray(_converted_lines_2)));
final String indent = this.findIndent(_head);
final String[] _converted_lines_3 = (String[])lines;
final Function1 _function_2 = (String it) -> {
return Boolean.valueOf(it.startsWith(indent));
};
boolean _forall = IterableExtensions.forall(((Iterable)Conversions.doWrapArray(_converted_lines_3)), _function_2);
if (_forall) {
final String[] _converted_lines_4 = (String[])lines;
final Function1 _function_3 = (String it) -> {
int _length = indent.length();
return it.substring(_length);
};
List _map = ListExtensions.map(((List)Conversions.doWrapArray(_converted_lines_4)), _function_3);
return IterableExtensions.join(_map, "\n");
} else {
return text;
}
}
private String findIndent(final String line) {
if ((line != null)) {
int _length = line.length();
ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _length, true);
for (final Integer i : _doubleDotLessThan) {
char _charAt = line.charAt((i).intValue());
int _indexOf = " \t".indexOf(_charAt);
boolean _lessThan = (_indexOf < 0);
if (_lessThan) {
return line.substring(0, (i).intValue());
}
}
}
return line;
}
public String getMessageDocumentation(final TypedMessage message) {
String result = this._zenModelHelper.getDocumentation(message);
boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(result);
if (_isNullOrEmpty) {
Structure _xifexpression = null;
Structure _actualType = message.getActualType();
boolean _tripleNotEquals = (_actualType != null);
if (_tripleNotEquals) {
_xifexpression = message.getActualType();
} else {
Structure _xifexpression_1 = null;
ResourceDefinition _resourceType = message.getResourceType();
if ((_resourceType instanceof ServiceDataResource)) {
ResourceDefinition _resourceType_1 = message.getResourceType();
_xifexpression_1 = ((ServiceDataResource) _resourceType_1).getDataType();
}
_xifexpression = _xifexpression_1;
}
final Structure dataType = _xifexpression;
if ((dataType != null)) {
String _documentation = this._zenModelHelper.getDocumentation(dataType);
result = _documentation;
}
}
return result;
}
public String getDefinitionName(final TypedMessage message) {
if ((message == null)) {
return null;
}
String _xifexpression = null;
Structure _actualType = message.getActualType();
boolean _tripleNotEquals = (_actualType != null);
if (_tripleNotEquals) {
_xifexpression = this.jsonSchemaGenerator.getDefinitionName(message);
} else {
String _xifexpression_1 = null;
ResourceDefinition _resourceType = message.getResourceType();
boolean _tripleNotEquals_1 = (_resourceType != null);
if (_tripleNotEquals_1) {
ResourceDefinition _resourceType_1 = message.getResourceType();
_xifexpression_1 = this.jsonSchemaGenerator.getDefinitionName(((ServiceDataResource) _resourceType_1));
} else {
_xifexpression_1 = null;
}
_xifexpression = _xifexpression_1;
}
String typeName = _xifexpression;
return typeName;
}
public Model getReferenceToType(final String typeName) {
RefModel _xblockexpression = null;
{
final RefModel ref = new RefModel();
ref.set$ref(("#/definitions/" + typeName));
_xblockexpression = ref;
}
return _xblockexpression;
}
public Property createSwaggerPropertyWithConstraints(final MessageParameter parameter) {
Property _xblockexpression = null;
{
final SourceReference sourceReference = parameter.getSourceReference();
SingleValueType _type = sourceReference.getType();
String _name = _type.getName();
final Property prop = this.getSwaggerProperty(_name);
List _messageParameterConstraints = this.getMessageParameterConstraints(parameter);
this.setConstraints(prop, _messageParameterConstraints);
_xblockexpression = prop;
}
return _xblockexpression;
}
public Property getSwaggerProperty(final String typeName) {
AbstractProperty _switchResult = null;
boolean _matched = false;
if (!_matched) {
boolean _contains = Collections.unmodifiableList(CollectionLiterals.newArrayList("anyURI", "duration", "gMonth", "gMonthDay", "gDay", "gYearMonth", "gYear", "QName", "time", "string", "NCName")).contains(typeName);
if (_contains) {
_matched=true;
_switchResult = new StringProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "boolean")) {
_matched=true;
_switchResult = new BooleanProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "date")) {
_matched=true;
_switchResult = new DateProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "dateTime")) {
_matched=true;
_switchResult = new DateTimeProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "decimal")) {
_matched=true;
_switchResult = new DecimalProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "double")) {
_matched=true;
_switchResult = new DoubleProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "float")) {
_matched=true;
_switchResult = new FloatProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "integer")) {
_matched=true;
_switchResult = new IntegerProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "int")) {
_matched=true;
_switchResult = new IntegerProperty();
}
}
if (!_matched) {
if (Objects.equal(typeName, "long")) {
_matched=true;
_switchResult = new LongProperty();
}
}
if (!_matched) {
RefProperty _xblockexpression = null;
{
final RefProperty prop = new RefProperty();
prop.set$ref(("#/definitions/" + typeName));
_xblockexpression = prop;
}
_switchResult = _xblockexpression;
}
return _switchResult;
}
public void setConstraints(final Property property, final List constraints) {
boolean _or = false;
if ((constraints == null)) {
_or = true;
} else {
boolean _isEmpty = constraints.isEmpty();
_or = _isEmpty;
}
if (_or) {
return;
}
boolean _matched = false;
if (!_matched) {
if (property instanceof StringProperty) {
_matched=true;
Iterable _filter = Iterables.filter(constraints, LengthConstraint.class);
final Consumer _function = (LengthConstraint it) -> {
boolean _isSetMinLength = it.isSetMinLength();
if (_isSetMinLength) {
int _minLength = it.getMinLength();
((StringProperty)property).setMinLength(Integer.valueOf(_minLength));
}
boolean _isSetMaxLength = it.isSetMaxLength();
if (_isSetMaxLength) {
int _maxLength = it.getMaxLength();
((StringProperty)property).setMaxLength(Integer.valueOf(_maxLength));
}
};
_filter.forEach(_function);
Iterable _filter_1 = Iterables.filter(constraints, RegExConstraint.class);
final Consumer _function_1 = (RegExConstraint it) -> {
String _pattern = it.getPattern();
((StringProperty)property).setPattern(_pattern);
};
_filter_1.forEach(_function_1);
}
}
if (!_matched) {
if (property instanceof AbstractNumericProperty) {
_matched=true;
Iterable _filter = Iterables.filter(constraints, ValueRangeConstraint.class);
final Consumer _function = (ValueRangeConstraint it) -> {
String _minValue = it.getMinValue();
boolean _tripleNotEquals = (_minValue != null);
if (_tripleNotEquals) {
String _minValue_1 = it.getMinValue();
BigDecimal _bigDecimal = new BigDecimal(_minValue_1);
((AbstractNumericProperty)property).setMinimum(_bigDecimal);
boolean _isMinValueExclusive = it.isMinValueExclusive();
((AbstractNumericProperty)property).setExclusiveMinimum(Boolean.valueOf(_isMinValueExclusive));
}
String _maxValue = it.getMaxValue();
boolean _tripleNotEquals_1 = (_maxValue != null);
if (_tripleNotEquals_1) {
String _maxValue_1 = it.getMaxValue();
BigDecimal _bigDecimal_1 = new BigDecimal(_maxValue_1);
((AbstractNumericProperty)property).setMaximum(_bigDecimal_1);
boolean _isMaxValueExclusive = it.isMaxValueExclusive();
((AbstractNumericProperty)property).setExclusiveMaximum(Boolean.valueOf(_isMaxValueExclusive));
}
};
_filter.forEach(_function);
}
}
}
public HeaderParameter getMessageHeaderParameter(final MessageParameter parameter) {
final HeaderParameter swaggerParameter = new HeaderParameter();
boolean _isArrayProperty = this._jsonSchemaHelper.isArrayProperty(parameter);
if (_isArrayProperty) {
final Property items = this.createSwaggerPropertyWithConstraints(parameter);
ArrayProperty _arrayProperty = new ArrayProperty(items);
swaggerParameter.setProperty(_arrayProperty);
} else {
Property _createSwaggerPropertyWithConstraints = this.createSwaggerPropertyWithConstraints(parameter);
swaggerParameter.setProperty(_createSwaggerPropertyWithConstraints);
}
String _documentation = this._zenModelHelper.getDocumentation(parameter);
swaggerParameter.setDescription(_documentation);
String _name = parameter.getName();
swaggerParameter.setName(_name);
boolean _isRequired = parameter.isRequired();
swaggerParameter.setRequired(_isRequired);
this.setVendorExtensions(parameter, swaggerParameter);
return swaggerParameter;
}
private void setVendorExtensions(final Extensible rapidElement, final Swagger swaggerObj) {
final Iterable extensions = this._extensionsHelper.getRapidExtensions(rapidElement);
final Consumer _function = (com.reprezen.rapidml.Extension it) -> {
String _name = it.getName();
String _value = it.getValue();
swaggerObj.setVendorExtension(_name, _value);
};
extensions.forEach(_function);
}
private void setVendorExtensions(final Extensible rapidElement, final Path swaggerObj) {
final Iterable extensions = this._extensionsHelper.getRapidExtensions(rapidElement);
final Consumer _function = (com.reprezen.rapidml.Extension it) -> {
String _name = it.getName();
String _value = it.getValue();
swaggerObj.setVendorExtension(_name, _value);
};
extensions.forEach(_function);
}
private void setVendorExtensions(final Extensible rapidElement, final Operation swaggerObj) {
final Iterable extensions = this._extensionsHelper.getRapidExtensions(rapidElement);
final Consumer _function = (com.reprezen.rapidml.Extension it) -> {
String _name = it.getName();
String _value = it.getValue();
swaggerObj.setVendorExtension(_name, _value);
};
extensions.forEach(_function);
}
private void setVendorExtensions(final Extensible rapidElement, final AbstractParameter swaggerObj) {
final Iterable extensions = this._extensionsHelper.getRapidExtensions(rapidElement);
final Consumer _function = (com.reprezen.rapidml.Extension it) -> {
String _name = it.getName();
String _value = it.getValue();
swaggerObj.setVendorExtension(_name, _value);
};
extensions.forEach(_function);
}
private void setVendorExtensions(final Extensible rapidElement, final Response swaggerObj) {
final Iterable extensions = this._extensionsHelper.getRapidExtensions(rapidElement);
final Consumer _function = (com.reprezen.rapidml.Extension it) -> {
String _name = it.getName();
String _value = it.getValue();
swaggerObj.setVendorExtension(_name, _value);
};
extensions.forEach(_function);
}
private void setVendorExtensions(final Extensible rapidElement, final SecuritySchemeDefinition swaggerObj) {
final Iterable extensions = this._extensionsHelper.getRapidExtensions(rapidElement);
final Consumer _function = (com.reprezen.rapidml.Extension it) -> {
String _name = it.getName();
String _value = it.getValue();
swaggerObj.setVendorExtension(_name, _value);
};
extensions.forEach(_function);
}
public QueryParameter getMessageQueryParameter(final MessageParameter parameter) {
final QueryParameter swaggerParameter = new QueryParameter();
boolean _isArrayProperty = this._jsonSchemaHelper.isArrayProperty(parameter);
if (_isArrayProperty) {
final Property items = this.createSwaggerPropertyWithConstraints(parameter);
ArrayProperty _arrayProperty = new ArrayProperty(items);
swaggerParameter.setProperty(_arrayProperty);
} else {
Property _createSwaggerPropertyWithConstraints = this.createSwaggerPropertyWithConstraints(parameter);
swaggerParameter.setProperty(_createSwaggerPropertyWithConstraints);
}
String _documentation = this._zenModelHelper.getDocumentation(parameter);
swaggerParameter.setDescription(_documentation);
String _name = parameter.getName();
swaggerParameter.setName(_name);
boolean _isRequired = parameter.isRequired();
swaggerParameter.setRequired(_isRequired);
this.setVendorExtensions(parameter, swaggerParameter);
return swaggerParameter;
}
public List getMessageParameterConstraints(final MessageParameter parameter) {
final SourceReference ref = parameter.getSourceReference();
boolean _matched = false;
if (!_matched) {
if (ref instanceof PropertyReference) {
_matched=true;
TypedMessage _containingMessage = parameter.getContainingMessage();
EList _includedProperties = _containingMessage.getIncludedProperties();
final Function1 _function = (PropertyRealization it) -> {
Feature _baseProperty = it.getBaseProperty();
PrimitiveProperty _conceptualFeature = ((PropertyReference)ref).getConceptualFeature();
return Boolean.valueOf(Objects.equal(_baseProperty, _conceptualFeature));
};
PropertyRealization property = IterableExtensions.findFirst(_includedProperties, _function);
if ((property == null)) {
PrimitiveProperty _conceptualFeature = ((PropertyReference)ref).getConceptualFeature();
return _conceptualFeature.getAllConstraints();
}
return property.getAllConstraints();
}
}
return null;
}
public boolean addDefaultResourceAPI(final ZenModel model) {
boolean _xblockexpression = false;
{
final ResourceAPI resourceAPI = RapidmlFactory.eINSTANCE.createResourceAPI();
resourceAPI.setBaseURI("http://localhost");
String _name = model.getName();
resourceAPI.setName(_name);
EList _resourceAPIs = model.getResourceAPIs();
_xblockexpression = _resourceAPIs.add(resourceAPI);
}
return _xblockexpression;
}
private boolean shouldRetainEmptyParameters() {
Map _genTargetParameters = null;
if (this.context!=null) {
_genTargetParameters=this.context.getGenTargetParameters();
}
Object _get = null;
if (_genTargetParameters!=null) {
_get=_genTargetParameters.get(XGenerateSwagger.OPTION_RETAIN_EMPTY_PARAMATERS);
}
final Object option = _get;
Boolean _xifexpression = null;
if ((option instanceof Boolean)) {
_xifexpression = ((Boolean) option);
} else {
boolean _xifexpression_1 = false;
if ((option == null)) {
_xifexpression_1 = false;
} else {
Class> _class = option.getClass();
String _simpleName = _class.getSimpleName();
String _format = String.format("Only boolean values are allowed for \'%s\', current value is of type %s",
XGenerateSwagger.OPTION_RETAIN_EMPTY_PARAMATERS, _simpleName);
throw new IllegalArgumentException(_format);
}
_xifexpression = Boolean.valueOf(_xifexpression_1);
}
return (_xifexpression).booleanValue();
}
private static void safeAddConsumes(final Operation op, final String mediaType) {
boolean _or = false;
List _consumes = op.getConsumes();
boolean _tripleEquals = (_consumes == null);
if (_tripleEquals) {
_or = true;
} else {
List _consumes_1 = op.getConsumes();
boolean _contains = _consumes_1.contains(mediaType);
boolean _not = (!_contains);
_or = _not;
}
if (_or) {
op.addConsumes(mediaType);
}
}
private static void safeAddProduces(final Operation op, final String mediaType) {
boolean _or = false;
List _produces = op.getProduces();
boolean _tripleEquals = (_produces == null);
if (_tripleEquals) {
_or = true;
} else {
List _produces_1 = op.getProduces();
boolean _contains = _produces_1.contains(mediaType);
boolean _not = (!_contains);
_or = _not;
}
if (_or) {
op.addProduces(mediaType);
}
}
}