io.swagger.models.properties.StringProperty Java Examples

The following examples show how to use io.swagger.models.properties.StringProperty. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the default value of a property
 *
 * @return the default value of the property
 */
public Optional<Object> getDefaultValue() {
    if (property instanceof BooleanProperty) {
        BooleanProperty booleanProperty = (BooleanProperty) property;
        return Optional.ofNullable(booleanProperty.getDefault());
    } else if (property instanceof StringProperty) {
        StringProperty stringProperty = (StringProperty) property;
        return Optional.ofNullable(stringProperty.getDefault());
    } else if (property instanceof DoubleProperty) {
        DoubleProperty doubleProperty = (DoubleProperty) property;
        return Optional.ofNullable(doubleProperty.getDefault());
    } else if (property instanceof FloatProperty) {
        FloatProperty floatProperty = (FloatProperty) property;
        return Optional.ofNullable(floatProperty.getDefault());
    } else if (property instanceof IntegerProperty) {
        IntegerProperty integerProperty = (IntegerProperty) property;
        return Optional.ofNullable(integerProperty.getDefault());
    } else if (property instanceof LongProperty) {
        LongProperty longProperty = (LongProperty) property;
        return Optional.ofNullable(longProperty.getDefault());
    } else if (property instanceof UUIDProperty) {
        UUIDProperty uuidProperty = (UUIDProperty) property;
        return Optional.ofNullable(uuidProperty.getDefault());
    }
    return Optional.empty();
}
 
Example #2
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param modelObject
 * @param models
 * @param variablName
 * @param classMemberObject
 * @param propObject
 */
private ClassMembers getClassMember(ArrayProperty property, Model modelObject, Map<String, Model> models,
		String variablName) {
	LOGGER.entering(LOGGER.getName(), "getClassMember-ArrayProperty");

	ClassMembers classMemberObject = new ClassMembers();
	Property propObject = property.getItems();

	if (propObject instanceof RefProperty) {
		classMemberObject = getClassMember((RefProperty) propObject, models, modelObject, variablName);
	} else if (propObject instanceof StringProperty) {
		classMemberObject = getClassMember((StringProperty) propObject, variablName);
	}

	LOGGER.exiting(LOGGER.getName(), "getClassMember-ArrayProperty");
	return classMemberObject;
}
 
Example #3
Source File: RestOperationMeta.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
/**
 * EdgeService cannot recognize the map type form body whose value type is String,
 * so there should be this additional setting.
 * @param parameter the swagger information of the parameter
 * @param type the resolved param type
 * @return the corrected param type
 */
private Type correctFormBodyType(Parameter parameter, Type type) {
  if (null != type || !(parameter instanceof BodyParameter)) {
    return type;
  }
  final BodyParameter bodyParameter = (BodyParameter) parameter;
  if (!(bodyParameter.getSchema() instanceof ModelImpl)) {
    return type;
  }
  final Property additionalProperties = ((ModelImpl) bodyParameter.getSchema()).getAdditionalProperties();
  if (additionalProperties instanceof StringProperty) {
    type = RestObjectMapperFactory.getRestObjectMapper().getTypeFactory()
        .constructMapType(Map.class, String.class, String.class);
  }
  return type;
}
 
Example #4
Source File: ModelResolverExt.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
@Override
public Property resolveProperty(JavaType propType, ModelConverterContext context, Annotation[] annotations,
    Iterator<ModelConverter> next) {
  checkType(propType);

  PropertyCreator creator = propertyCreatorMap.get(propType.getRawClass());
  if (creator != null) {
    return creator.createProperty();
  }

  Property property = super.resolveProperty(propType, context, annotations, next);
  if (StringProperty.class.isInstance(property)) {
    if (StringPropertyConverter.isEnum((StringProperty) property)) {
      setType(propType, property.getVendorExtensions());
    }
  }
  return property;
}
 
Example #5
Source File: AbstractOperationGenerator.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
protected void fillBodyParameter(Swagger swagger, Parameter parameter, Type type, List<Annotation> annotations) {
  // so strange, for bodyParameter, swagger return a new instance
  // that will cause lost some information
  // so we must merge them
  BodyParameter newBodyParameter = (BodyParameter) io.swagger.util.ParameterProcessor.applyAnnotations(
      swagger, parameter, type, annotations);

  // swagger missed enum data, fix it
  ModelImpl model = SwaggerUtils.getModelImpl(swagger, newBodyParameter);
  if (model != null) {
    Property property = ModelConverters.getInstance().readAsProperty(type);
    if (property instanceof StringProperty) {
      model.setEnum(((StringProperty) property).getEnum());
    }
  }

  mergeBodyParameter((BodyParameter) parameter, newBodyParameter);
}
 
Example #6
Source File: ConverterMgr.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private static void initConverters() {
  // inner converters
  for (Class<? extends Property> propertyCls : PROPERTY_MAP.keySet()) {
    addInnerConverter(propertyCls);
  }

  converterMap.put(RefProperty.class, new RefPropertyConverter());
  converterMap.put(ArrayProperty.class, new ArrayPropertyConverter());
  converterMap.put(MapProperty.class, new MapPropertyConverter());
  converterMap.put(StringProperty.class, new StringPropertyConverter());
  converterMap.put(ObjectProperty.class, new ObjectPropertyConverter());

  converterMap.put(ModelImpl.class, new ModelImplConverter());
  converterMap.put(RefModel.class, new RefModelConverter());
  converterMap.put(ArrayModel.class, new ArrayModelConverter());
}
 
Example #7
Source File: ConverterMgr.java    From servicecomb-java-chassis with Apache License 2.0 6 votes vote down vote up
private static void initPropertyMap() {
  PROPERTY_MAP.put(BooleanProperty.class, TypeFactory.defaultInstance().constructType(Boolean.class));

  PROPERTY_MAP.put(FloatProperty.class, TypeFactory.defaultInstance().constructType(Float.class));
  PROPERTY_MAP.put(DoubleProperty.class, TypeFactory.defaultInstance().constructType(Double.class));
  PROPERTY_MAP.put(DecimalProperty.class, TypeFactory.defaultInstance().constructType(BigDecimal.class));

  PROPERTY_MAP.put(ByteProperty.class, TypeFactory.defaultInstance().constructType(Byte.class));
  PROPERTY_MAP.put(ShortProperty.class, TypeFactory.defaultInstance().constructType(Short.class));
  PROPERTY_MAP.put(IntegerProperty.class, TypeFactory.defaultInstance().constructType(Integer.class));
  PROPERTY_MAP.put(BaseIntegerProperty.class, TypeFactory.defaultInstance().constructType(Integer.class));
  PROPERTY_MAP.put(LongProperty.class, TypeFactory.defaultInstance().constructType(Long.class));

  // stringProperty include enum scenes, not always be string type
  // if convert by StringPropertyConverter, can support enum scenes
  PROPERTY_MAP.put(StringProperty.class, TypeFactory.defaultInstance().constructType(String.class));

  PROPERTY_MAP.put(DateProperty.class, TypeFactory.defaultInstance().constructType(LocalDate.class));
  PROPERTY_MAP.put(DateTimeProperty.class, TypeFactory.defaultInstance().constructType(Date.class));

  PROPERTY_MAP.put(ByteArrayProperty.class, TypeFactory.defaultInstance().constructType(byte[].class));

  PROPERTY_MAP.put(FileProperty.class, TypeFactory.defaultInstance().constructType(Part.class));
}
 
Example #8
Source File: SwaggerGenerator.java    From endpoints-java with Apache License 2.0 6 votes vote down vote up
private static Property getSwaggerArrayProperty(TypeToken<?> typeToken) {
  Class<?> type = typeToken.getRawType();
  if (type == String.class) {
    return new StringProperty();
  } else if (type == Boolean.class || type == Boolean.TYPE) {
    return new BooleanProperty();
  } else if (type == Integer.class || type == Integer.TYPE) {
    return new IntegerProperty();
  } else if (type == Long.class || type == Long.TYPE) {
    return new LongProperty();
  } else if (type == Float.class || type == Float.TYPE) {
    return new FloatProperty();
  } else if (type == Double.class || type == Double.TYPE) {
    return new DoubleProperty();
  } else if (type == byte[].class) {
    return new ByteArrayProperty();
  } else if (type.isEnum()) {
    return new StringProperty();
  }
  throw new IllegalArgumentException("invalid property type");
}
 
Example #9
Source File: JaxrsReader.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
private void handleJsonTypeInfo(Type responseClassType, Map<String, Model> modelMap) {
    if (responseClassType instanceof ParameterizedType) {
        Type[] actualTypes = ((ParameterizedType) responseClassType).getActualTypeArguments();
        for (Type type : actualTypes) {
            handleJsonTypeInfo(type, modelMap);
        }
    } else if (responseClassType instanceof Class<?>){
        Class<?> responseClass = ((Class<?>) responseClassType);
        if (responseClass.isArray()) {
            responseClass = responseClass.getComponentType();
        }

        JsonTypeInfo typeInfo = responseClass.getAnnotation(JsonTypeInfo.class);
        if (typeInfo == null || StringUtils.isEmpty(typeInfo.property()) || typeInfo.include().equals(As.EXISTING_PROPERTY)) {
            return;
        }

        Map<String, Property> properties = modelMap.get(responseClass.getSimpleName()).getProperties();
        if (properties != null && !properties.containsKey(typeInfo.property())) {
            properties.put(typeInfo.property(), new StringProperty());
        }
    }
}
 
Example #10
Source File: SpringSwaggerExtension.java    From swagger-maven-plugin with Apache License 2.0 6 votes vote down vote up
private Property readAsPropertyIfPrimitive(Type type) {
    if (com.github.kongchen.swagger.docgen.util.TypeUtils.isPrimitive(type)) {
        return ModelConverters.getInstance().readAsProperty(type);
    } else {
        String msg = String.format("Non-primitive type: %s used as request/path/cookie parameter", type);
        log.warn(msg);

        // fallback to string if type is simple wrapper for String to support legacy code
        JavaType ct = constructType(type);
        if (isSimpleWrapperForString(ct.getRawClass())) {
            log.warn(String.format("Non-primitive type: %s used as string for request/path/cookie parameter", type));
            return new StringProperty();
        }
    }
    return null;
}
 
Example #11
Source File: SwaggerSpecificationProcessor.java    From swagger-coverage with Apache License 2.0 6 votes vote down vote up
public static List<String> extractEnum(Parameter p) {
    List<String> enumValues = null;

    if (p instanceof SerializableParameter) {
        SerializableParameter serializableParameter = (SerializableParameter) p;
        if (serializableParameter.getEnum() != null && !serializableParameter.getEnum().isEmpty()) {
            enumValues = serializableParameter.getEnum();
        }

        if (enumValues == null && serializableParameter.getItems() != null) {
            Property items = serializableParameter.getItems();
            if (items instanceof StringProperty) {
                StringProperty stringProperty = (StringProperty) items;
                if (stringProperty.getEnum() != null && !stringProperty.getEnum().isEmpty()) {
                    enumValues = stringProperty.getEnum();
                }
            }
        }
    }

    return enumValues;
}
 
Example #12
Source File: PropertyValidator.java    From assertj-swagger with Apache License 2.0 6 votes vote down vote up
void validateProperty(Property actualProperty, Property expectedProperty, String message) {
    if (expectedProperty == null || !isAssertionEnabled(SwaggerAssertionType.PROPERTIES)) {
        return;
    }

    // TODO Validate Property schema
    if (shouldValidateRefProperty(expectedProperty)) {
        validateBasicPropertyFeatures(actualProperty, expectedProperty, message);
        // TODO improve validation by verifying property based on RefProperty type
    } else if (shouldValidateArrayProperty(expectedProperty)) {
        validateBasicPropertyFeatures(actualProperty, expectedProperty, message);
        // TODO improve validation by verifying property based on ArrayProperty type
    } else if (shouldValidateByteArrayProperty(expectedProperty)) {
        validateBasicPropertyFeatures(actualProperty, expectedProperty, message);
        // TODO improve validation by verifying property based on ByteArrayProperty type
    } else if (shouldValidateStringProperty(expectedProperty)) {
        StringProperty expectedStringProperty = (StringProperty) expectedProperty;
        validateBasicPropertyFeatures(actualProperty, expectedProperty, message);
        if (isPropertyOfEnumType(actualProperty)) {
            StringProperty actualStringProperty = (StringProperty) actualProperty;
            validateEnumPropertyFeatures(actualStringProperty, expectedStringProperty);
        }
    } else {
        validateBasicPropertyFeatures(actualProperty, expectedProperty, message);
    }
}
 
Example #13
Source File: ParameterDiff.java    From swagger-diff with Apache License 2.0 5 votes vote down vote up
private Property mapToProperty(Parameter rightPara) {
    Property prop = new StringProperty();
    prop.setAccess(rightPara.getAccess());
    prop.setAllowEmptyValue(rightPara.getAllowEmptyValue());
    prop.setDescription(rightPara.getDescription());
    prop.setName(rightPara.getName());
    prop.setReadOnly(rightPara.isReadOnly());
    prop.setRequired(rightPara.getRequired());
    return prop;
}
 
Example #14
Source File: JaxRs2Extension.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Property enforcePrimitive(final Property in, final int level) {
    if (in instanceof RefProperty) {
        return new StringProperty();
    }
    if (in instanceof ArrayProperty) {
        if (level == 0) {
            final ArrayProperty array = (ArrayProperty) in;
            array.setItems(enforcePrimitive(array.getItems(), level + 1));
        } else {
            return new StringProperty();
        }
    }
    return in;
}
 
Example #15
Source File: WSDL11SOAPOperationExtractor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
private Property getPropertyFromDataType(String dataType) {

        switch (dataType) {
        case "string":
            return new StringProperty();
        case "boolean":
            return new BooleanProperty();
        case "int":
            return new IntegerProperty();
        case "nonNegativeInteger":
            return new IntegerProperty();
        case "integer":
            return new IntegerProperty();
        case "positiveInteger":
            return new IntegerProperty();
        case "double":
            return new DoubleProperty();
        case "float":
            return new FloatProperty();
        case "long":
            return new LongProperty();
        case "date":
            return new DateProperty();
        case "dateTime":
            return new DateTimeProperty();
        default:
            return new RefProperty();
        }
    }
 
Example #16
Source File: PropertyValidator.java    From assertj-swagger with Apache License 2.0 5 votes vote down vote up
private void validateEnumPropertyFeatures(StringProperty actualStringProperty,
    StringProperty expectedStringProperty) {
    List<String> expectedEnums = expectedStringProperty.getEnum();
    if (CollectionUtils.isNotEmpty(expectedEnums)) {
        softAssertions.assertThat(actualStringProperty.getEnum()).hasSameElementsAs(expectedEnums);
    } else {
        softAssertions.assertThat(actualStringProperty.getEnum()).isNullOrEmpty();
    }
}
 
Example #17
Source File: PlantUMLCodegen.java    From swagger2puml with Apache License 2.0 5 votes vote down vote up
/**
 * 
 * @param stringProperty
 * @param models
 * @param modelObject
 * @param variablName
 * @return
 */
private ClassMembers getClassMember(StringProperty stringProperty, String variablName) {
	LOGGER.entering(LOGGER.getName(), "getClassMember-StringProperty");

	ClassMembers classMemberObject = new ClassMembers();
	classMemberObject.setDataType(getDataType(stringProperty.getType(), true));
	classMemberObject.setName(variablName);

	LOGGER.exiting(LOGGER.getName(), "getClassMember-StringProperty");
	return classMemberObject;
}
 
Example #18
Source File: ModelDiff.java    From swagger-diff with Apache License 2.0 5 votes vote down vote up
private List<String> enumValues(Property prop) {
    if (prop instanceof StringProperty && ((StringProperty) prop).getEnum() != null) {
        return ((StringProperty) prop).getEnum();
    } else {
        return new ArrayList<>();
    }
}
 
Example #19
Source File: TestRBeanSwaggerModel.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllTypes() {
  Map<String, Model> modelMap = ModelConverters.getInstance()
      .read(TypeToken.of(RAllTypes.class).getType());

  Model rAllTypes = modelMap.get(RAllTypes.class.getSimpleName());
  Assert.assertNotNull(rAllTypes);

  Map<String, Class<? extends Property>> expectedProperties = ImmutableMap.<String, Class<? extends Property>>builder()
      .put("id", StringProperty.class)
      .put("rChar", StringProperty.class)
      .put("rDate", LongProperty.class)
      .put("rTime", LongProperty.class)
      .put("rDatetime", LongProperty.class)
      .put("rLong", LongProperty.class)
      .put("rDouble", DoubleProperty.class)
      .put("rDecimal", DecimalProperty.class)
      .put("rEnum", StringProperty.class)
      .put("rSubBean", RefProperty.class)
      .put("rSubBeanList", ArrayProperty.class)
      .build();

  Assert.assertEquals(expectedProperties.size(), rAllTypes.getProperties().size());
  expectedProperties.forEach(
      (k, v) -> Assert.assertEquals(v, rAllTypes.getProperties().get(k).getClass())
  );
  StringProperty rEnumProperty = ((StringProperty)rAllTypes.getProperties().get("rEnum"));
  Assert.assertTrue(
      new HashSet<>(rEnumProperty.getEnum())
          .containsAll(Arrays.stream(Alphabet.values()).map(Enum::name).collect(Collectors.toSet()))
  );

  RefProperty refProperty = (RefProperty) rAllTypes.getProperties().get("rSubBean");
  Assert.assertEquals(refProperty.getSimpleRef(), RSubBean.class.getSimpleName());

  ArrayProperty arrayProperty = (ArrayProperty) rAllTypes.getProperties().get("rSubBeanList");
  Assert.assertEquals(((RefProperty)arrayProperty.getItems()).getSimpleRef(), RSubBean.class.getSimpleName());
}
 
Example #20
Source File: SwaggerDefinition.java    From Web-API with MIT License 5 votes vote down vote up
private static Response constructResponse(int status, String error) {
    Property statusProp = new IntegerProperty()
            .description("The status code of the error (also provided in the HTTP header)");
    statusProp.setExample(status);

    Property errorProp = new StringProperty()
            .description("The error message describing the error");
    errorProp.setExample((Object)error);

    return new Response()
            .description(error)
            .schema(new ObjectProperty()
                    .property("status", statusProp)
                    .property("error", errorProp));
}
 
Example #21
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Generate a default example value for property.
 *
 * @param property         property
 * @param markupDocBuilder doc builder
 * @return a generated example for the property
 */
public static Object generateExample(Property property, MarkupDocBuilder markupDocBuilder) {

    if (property.getType() == null) {
        return "untyped";
    }

    switch (property.getType()) {
        case "integer":
            return ExamplesUtil.generateIntegerExample(property instanceof IntegerProperty ? ((IntegerProperty) property).getEnum() : null);
        case "number":
            return 0.0;
        case "boolean":
            return true;
        case "string":
            return ExamplesUtil.generateStringExample(property.getFormat(), property instanceof StringProperty ? ((StringProperty) property).getEnum() : null);
        case "ref":
            if (property instanceof RefProperty) {
                if (logger.isDebugEnabled()) logger.debug("generateExample RefProperty for " + property.getName());
                return markupDocBuilder.copy(false).crossReference(((RefProperty) property).getSimpleRef()).toString();
            } else {
                if (logger.isDebugEnabled()) logger.debug("generateExample for ref not RefProperty");
            }
        case "array":
            if (property instanceof ArrayProperty) {
                return generateArrayExample((ArrayProperty) property, markupDocBuilder);
            }
        default:
            return property.getType();
    }
}
 
Example #22
Source File: PropertyAdapter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getEnum() {
  if (property instanceof StringProperty) {
    return ((StringProperty) property).getEnum();
  }

  return Collections.emptyList();
}
 
Example #23
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the minLength of a property
 *
 * @return the minLength of the property
 */
public Optional<Integer> getMinlength() {
    if (property instanceof StringProperty) {
        StringProperty stringProperty = (StringProperty) property;
        return Optional.ofNullable(stringProperty.getMinLength());
    } else if (property instanceof UUIDProperty) {
        UUIDProperty uuidProperty = (UUIDProperty) property;
        return Optional.ofNullable(uuidProperty.getMinLength());
    }
    return Optional.empty();
}
 
Example #24
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the maxLength of a property
 *
 * @return the maxLength of the property
 */
public Optional<Integer> getMaxlength() {
    if (property instanceof StringProperty) {
        StringProperty stringProperty = (StringProperty) property;
        return Optional.ofNullable(stringProperty.getMaxLength());
    } else if (property instanceof UUIDProperty) {
        UUIDProperty uuidProperty = (UUIDProperty) property;
        return Optional.ofNullable(uuidProperty.getMaxLength());
    }
    return Optional.empty();
}
 
Example #25
Source File: PropertyAdapter.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieves the pattern of a property
 *
 * @return the pattern of the property
 */
public Optional<String> getPattern() {
    if (property instanceof StringProperty) {
        StringProperty stringProperty = (StringProperty) property;
        return Optional.ofNullable(stringProperty.getPattern());
    } else if (property instanceof UUIDProperty) {
        UUIDProperty uuidProperty = (UUIDProperty) property;
        return Optional.ofNullable(uuidProperty.getPattern());
    }
    return Optional.empty();
}
 
Example #26
Source File: OpenApiTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
protected void setParameterDetails(AbstractSerializableParameter<?> oasParameter, Class<?> type, Annotation[] annotations) {
	if (byte.class.equals(type) || short.class.equals(type) || int.class.equals(type) || Byte.class.equals(type) ||
		Short.class.equals(type) || Integer.class.equals(type)) {
		oasParameter.setProperty(new IntegerProperty());
	} else if (long.class.equals(type) || Long.class.equals(type) || BigInteger.class.equals(type)) {
		oasParameter.setProperty(new LongProperty());
	} else if (float.class.equals(type) || Float.class.equals(type)) {
		oasParameter.setProperty(new FloatProperty().vendorExtension("x-type", "System.BigDecimal"));
	} else if (double.class.equals(type) || Double.class.equals(type) || BigDecimal.class.equals(type)) {
		oasParameter.setProperty(new DoubleProperty().vendorExtension("x-type", "System.BigDecimal"));
	} else if (char.class.equals(type) || Character.class.equals(type) || String.class.equals(type)) {
		oasParameter.setProperty(new StringProperty());
	} else if (boolean.class.equals(type) || Boolean.class.equals(type)) {
		oasParameter.setProperty(new BooleanProperty());
	} else if (List.class.equals(type)) {
		oasParameter.setProperty(createArrayProperty(type, null, annotations));
	} else if (LocalDate.class.equals(type) || Date.class.equals(type)) {
		oasParameter.setProperty(new DateProperty());
	} else if (LocalDateTime.class.equals(type) || LocalTime.class.equals(type)) {
		oasParameter.setProperty(new DateTimeProperty());
	}  else if (type.isEnum()) {
		mapEnum(oasParameter, type);
	} else {
		oasParameter.setProperty(createRefProperty(type, null));
	}
	asList(annotations).forEach(annotation -> applyAnnotationDetailsOnParameter(oasParameter, annotation));
}
 
Example #27
Source File: OpenApiTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
@SuppressWarnings("squid:S1192") // better in-place defined for better readability
protected Property createStringProperty(String format, Annotation[] annotations) {
	StringProperty schema = new StringProperty();
	if (StringUtils.isNotBlank(format)) {
		schema.setFormat(format);
	}
	if (annotations != null) {
		asList(annotations).forEach(annotation -> applyStringAnnotationDetails(schema, annotation));
	}
	return schema;
}
 
Example #28
Source File: StringPropertyConverter.java    From servicecomb-java-chassis with Apache License 2.0 5 votes vote down vote up
@Override
public JavaType doConvert(Swagger swagger, Object property) {
  StringProperty stringProperty = (StringProperty) property;

  List<String> enums = stringProperty.getEnum();
  if (!isEnum(enums)) {
    return ConverterMgr.findJavaType(stringProperty.getType(), stringProperty.getFormat());
  }

  return OBJECT_JAVA_TYPE;
}
 
Example #29
Source File: OpenApiTransformer.java    From spring-openapi with MIT License 5 votes vote down vote up
protected void applyStringAnnotationDetails(StringProperty schema, Annotation annotation) {
	if (annotation instanceof Pattern) {
		schema.pattern(((Pattern) annotation).regexp());
	} else if (annotation instanceof Size) {
		schema.minLength(((Size) annotation).min());
		schema.maxLength(((Size) annotation).max());
	} else if (annotation instanceof Deprecated) {
		schema.setVendorExtension("x-deprecated", true);
	}
}
 
Example #30
Source File: DefaultParameterExtension.java    From dorado with Apache License 2.0 5 votes vote down vote up
private Property enforcePrimitive(Property in, int level) {
	if (in instanceof RefProperty) {
		return new StringProperty();
	}
	if (in instanceof ArrayProperty) {
		if (level == 0) {
			final ArrayProperty array = (ArrayProperty) in;
			array.setItems(enforcePrimitive(array.getItems(), level + 1));
		} else {
			return new StringProperty();
		}
	}
	return in;
}