use of io.swagger.models.parameters.AbstractSerializableParameter in project teiid by teiid.
the class SwaggerMetadataProcessor method addProcedureParameters.
private void addProcedureParameters(final MetadataFactory mf, final Swagger swagger, final Procedure procedure, final Operation operation) throws TranslatorException {
for (final Parameter parameter : operation.getParameters()) {
if (parameter instanceof BodyParameter) {
PropertyAction pa = new PropertyAction() {
@Override
public void execute(String name, String nameInSource, Property property, boolean array) {
String type = getPropertyType(property, array);
if (procedure.getParameterByName(nameInSource) == null) {
ProcedureParameter param = mf.addProcedureParameter(name, type, Type.In, procedure);
param.setProperty(PARAMETER_TYPE, parameter.getIn());
if (property != null && !property.getRequired()) {
param.setProperty(BaseColumn.DEFAULT_HANDLING, BaseColumn.OMIT_DEFAULT);
}
param.setNullType(NullType.No_Nulls);
param.setAnnotation(property != null ? property.getDescription() : null);
if (!name.equalsIgnoreCase(nameInSource)) {
param.setNameInSource(nameInSource);
}
}
}
};
Model model = ((BodyParameter) parameter).getSchema();
if (model instanceof RefModel) {
RefModel refModel = (RefModel) model;
if (refModel.getProperties() != null) {
walkProperties(swagger, refModel.getProperties(), null, null, pa);
} else if (refModel.getReference() != null) {
Model m = swagger.getDefinitions().get(refModel.getSimpleRef());
walkProperties(swagger, m.getProperties(), null, null, pa);
}
} else {
if ((model instanceof ModelImpl) && model.getProperties() != null) {
walkProperties(swagger, model.getProperties(), null, null, pa);
} else {
ProcedureParameter p = mf.addProcedureParameter(parameter.getName(), DataTypeManager.DefaultDataTypes.CLOB, Type.In, procedure);
p.setProperty(PARAMETER_TYPE, parameter.getIn());
p.setNullType(NullType.No_Nulls);
p.setAnnotation(parameter.getDescription());
}
}
} else {
String name = parameter.getName();
ProcedureParameter pp = null;
String type = null;
Object defaultValue = null;
String collectionFormat = null;
if (parameter instanceof AbstractSerializableParameter) {
AbstractSerializableParameter p = (AbstractSerializableParameter) parameter;
type = p.getType();
if (p.getType().equalsIgnoreCase("array")) {
Property ap = p.getItems();
type = ap.getType();
}
type = SwaggerTypeManager.teiidType(type, p.getFormat(), p.getItems() != null);
defaultValue = p.getDefaultValue();
collectionFormat = p.getCollectionFormat();
} else {
// $NON-NLS-1$
throw new MetadataException("Unknown property type" + parameter.getClass().getName());
}
pp = mf.addProcedureParameter(name, type, Type.In, procedure);
pp.setProperty(PARAMETER_TYPE, parameter.getIn());
boolean required = parameter.getRequired();
if (!required) {
pp.setProperty(BaseColumn.DEFAULT_HANDLING, BaseColumn.OMIT_DEFAULT);
}
pp.setNullType(NullType.No_Nulls);
pp.setAnnotation(parameter.getDescription());
if (defaultValue != null) {
pp.setDefaultValue(defaultValue.toString());
}
if (collectionFormat != null) {
pp.setProperty(COLLECION_FORMAT, collectionFormat);
}
// extended properties
for (Entry<String, Object> extension : parameter.getVendorExtensions().entrySet()) {
pp.setProperty(extension.getKey(), extension.getValue().toString());
}
}
}
}
use of io.swagger.models.parameters.AbstractSerializableParameter in project swagger-parser by swagger-api.
the class SwaggerConverter method convert.
public Parameter convert(io.swagger.models.parameters.Parameter v2Parameter) {
Parameter v3Parameter = new Parameter();
if (StringUtils.isNotBlank(v2Parameter.getDescription())) {
v3Parameter.setDescription(v2Parameter.getDescription());
}
if (v2Parameter instanceof SerializableParameter) {
v3Parameter.setAllowEmptyValue(((SerializableParameter) v2Parameter).getAllowEmptyValue());
}
v3Parameter.setIn(v2Parameter.getIn());
v3Parameter.setName(v2Parameter.getName());
Object exampleExtension = v2Parameter.getVendorExtensions().get("x-example");
if (exampleExtension != null) {
v3Parameter.setExample(exampleExtension);
}
Schema schema = null;
if (v2Parameter instanceof RefParameter) {
RefParameter ref = (RefParameter) v2Parameter;
if (ref.get$ref().indexOf("#/parameters") == 0) {
String updatedRef = "#/components/";
if (components.getRequestBodies() != null && components.getRequestBodies().get(ref.getSimpleRef()) != null) {
updatedRef += "requestBodies";
} else if (components.getSchemas() != null && components.getSchemas().get("formData_" + ref.getSimpleRef()) != null) {
updatedRef += "schemas";
} else {
updatedRef += "parameters";
}
updatedRef += ref.get$ref().substring("#/parameters".length());
ref.set$ref(updatedRef);
}
v3Parameter.set$ref(ref.get$ref());
} else if (v2Parameter instanceof SerializableParameter) {
SerializableParameter sp = (SerializableParameter) v2Parameter;
if ("array".equals(sp.getType())) {
ArraySchema a = new ArraySchema();
// TODO: convert arrays to proper template format
String cf = sp.getCollectionFormat();
if (StringUtils.isEmpty(cf)) {
cf = "csv";
}
switch(cf) {
case "ssv":
if ("query".equals(v2Parameter.getIn())) {
v3Parameter.setStyle(Parameter.StyleEnum.SPACEDELIMITED);
}
break;
case "pipes":
if ("query".equals(v2Parameter.getIn())) {
v3Parameter.setStyle((Parameter.StyleEnum.PIPEDELIMITED));
}
break;
case "tsv":
break;
case "multi":
if ("query".equals(v2Parameter.getIn())) {
v3Parameter.setStyle(Parameter.StyleEnum.FORM);
v3Parameter.setExplode(true);
}
break;
case "csv":
default:
if ("query".equals(v2Parameter.getIn())) {
v3Parameter.setStyle(Parameter.StyleEnum.FORM);
v3Parameter.setExplode(false);
} else if ("header".equals(v2Parameter.getIn()) || "path".equals(v2Parameter.getIn())) {
v3Parameter.setStyle(Parameter.StyleEnum.SIMPLE);
v3Parameter.setExplode(false);
}
}
Property items = sp.getItems();
Schema itemsSchema = convert(items);
a.setItems(itemsSchema);
if (sp.getMaxItems() != null) {
a.setMaxItems(sp.getMaxItems());
}
if (sp.getMinItems() != null) {
a.setMinItems(sp.getMinItems());
}
if (sp.isUniqueItems() != null) {
a.setUniqueItems(sp.isUniqueItems());
}
schema = a;
} else {
schema = SchemaTypeUtil.createSchema(sp.getType(), sp.getFormat());
schema.setType(sp.getType());
schema.setFormat(sp.getFormat());
schema.setMaximum(sp.getMaximum());
schema.setExclusiveMaximum(sp.isExclusiveMaximum());
schema.setMinimum(sp.getMinimum());
schema.setExclusiveMinimum(sp.isExclusiveMinimum());
schema.setMinLength(sp.getMinLength());
schema.setMaxLength(sp.getMaxLength());
if (sp.getMultipleOf() != null) {
schema.setMultipleOf(new BigDecimal(sp.getMultipleOf().toString()));
}
schema.setPattern(sp.getPattern());
}
if (sp.getEnum() != null) {
for (String e : sp.getEnum()) {
switch(sp.getType() == null ? SchemaTypeUtil.OBJECT_TYPE : sp.getType()) {
case SchemaTypeUtil.INTEGER_TYPE:
schema.addEnumItemObject(Integer.parseInt(e));
break;
case SchemaTypeUtil.NUMBER_TYPE:
schema.addEnumItemObject(new BigDecimal(e));
break;
case SchemaTypeUtil.BOOLEAN_TYPE:
schema.addEnumItemObject(Boolean.valueOf(e));
break;
default:
schema.addEnumItemObject(e);
break;
}
}
}
if (sp.getVendorExtensions() != null) {
Object nullableExtension = sp.getVendorExtensions().get("x-nullable");
if (nullableExtension != null) {
schema.setNullable((Boolean) nullableExtension);
}
}
schema.setExtensions(convert(sp.getVendorExtensions()));
if (sp instanceof AbstractSerializableParameter) {
AbstractSerializableParameter ap = (AbstractSerializableParameter) sp;
schema.setDefault(ap.getDefault());
}
}
if (v2Parameter.getRequired()) {
v3Parameter.setRequired(v2Parameter.getRequired());
}
v3Parameter.setSchema(schema);
v3Parameter.setExtensions(convert(v2Parameter.getVendorExtensions()));
return v3Parameter;
}
use of io.swagger.models.parameters.AbstractSerializableParameter in project syndesis by syndesisio.
the class UnifiedJsonDataShapeGenerator method createJsonSchemaForParametersOf.
private static JsonNode createJsonSchemaForParametersOf(final Operation operation) {
final List<Parameter> operationParameters = operation.getParameters();
final List<AbstractSerializableParameter<?>> serializableParameters = //
operationParameters.stream().filter(//
PARAM_CLASS::isInstance).map(//
PARAM_CLASS::cast).collect(Collectors.toList());
if (serializableParameters.isEmpty()) {
return null;
}
final ObjectNode schema = newJsonObjectSchema();
final ObjectNode properties = schema.putObject("properties");
final ObjectNode parameters = properties.putObject("parameters");
parameters.put("type", "object");
final ObjectNode parametersProperties = parameters.putObject("properties");
for (final AbstractSerializableParameter<?> serializableParameter : serializableParameters) {
final String type = serializableParameter.getType();
final String name = trimToNull(serializableParameter.getName());
final String description = trimToNull(serializableParameter.getDescription());
if ("file".equals(type)) {
// 'file' type is not allowed in JSON schema
continue;
}
final ObjectNode parameterParameter = parametersProperties.putObject(name);
if (type != null) {
parameterParameter.put("type", type);
}
if (name != null) {
parameterParameter.put("title", name);
}
if (description != null) {
parameterParameter.put("description", description);
}
final Object defaultValue = serializableParameter.getDefault();
if (defaultValue != null) {
parameterParameter.put("default", String.valueOf(defaultValue));
}
addEnumsTo(parameterParameter, serializableParameter);
}
return schema;
}
use of io.swagger.models.parameters.AbstractSerializableParameter in project java-chassis by ServiceComb.
the class AbstractOperationGenerator method fillParameter.
protected void fillParameter(Swagger swagger, Parameter parameter, String parameterName, JavaType type, List<Annotation> annotations) {
for (Annotation annotation : annotations) {
ParameterProcessor<Parameter, Annotation> processor = findParameterProcessors(annotation.annotationType());
if (processor != null) {
processor.fillParameter(swagger, swaggerOperation, parameter, type, annotation);
}
}
if (type == null) {
return;
}
ParameterProcessor<Parameter, Annotation> processor = findParameterProcessors(type);
if (processor != null) {
processor.fillParameter(swagger, swaggerOperation, parameter, type, null);
}
if (parameter instanceof AbstractSerializableParameter) {
io.swagger.util.ParameterProcessor.applyAnnotations(swagger, parameter, type, annotations);
annotations.stream().forEach(annotation -> {
if (NOT_NULL_ANNOTATIONS.contains(annotation.annotationType().getSimpleName())) {
parameter.setRequired(true);
}
});
return;
}
fillBodyParameter(swagger, parameter, type, annotations);
}
use of io.swagger.models.parameters.AbstractSerializableParameter in project java-chassis by ServiceComb.
the class EnumPostProcessor method processParameterDescription.
private void processParameterDescription(ParameterGenerator parameterGenerator) {
JavaType genericType = parameterGenerator.getGenericType();
Annotation[] annotations = parameterGenerator.getAnnotations().toArray(new Annotation[0]);
String description = generateDescription(genericType, annotations);
if (description != null) {
AbstractSerializableParameter<?> parameter = (AbstractSerializableParameter<?>) parameterGenerator.getGeneratedParameter();
parameter.setDescription(description);
}
}
Aggregations