io.swagger.v3.oas.models.media.FileSchema Java Examples

The following examples show how to use io.swagger.v3.oas.models.media.FileSchema. 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: GenericParameterBuilder.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Calculate request body schema schema.
 *
 * @param components the components
 * @param parameterInfo the parameter info
 * @param requestBodyInfo the request body info
 * @param schemaN the schema n
 * @param paramName the param name
 * @return the schema
 */
private Schema calculateRequestBodySchema(Components components, ParameterInfo parameterInfo, RequestBodyInfo requestBodyInfo, Schema schemaN, String paramName) {
	if (schemaN != null && StringUtils.isEmpty(schemaN.getDescription()) && parameterInfo.getParameterModel() != null) {
		String description = parameterInfo.getParameterModel().getDescription();
		if (schemaN.get$ref() != null && schemaN.get$ref().contains(AnnotationsUtils.COMPONENTS_REF)) {
			String key = schemaN.get$ref().substring(21);
			Schema existingSchema = components.getSchemas().get(key);
			existingSchema.setDescription(description);
		}
		else
			schemaN.setDescription(description);
	}

	if (requestBodyInfo.getMergedSchema() != null) {
		requestBodyInfo.getMergedSchema().addProperties(paramName, schemaN);
		schemaN = requestBodyInfo.getMergedSchema();
	}
	else if (schemaN instanceof FileSchema || schemaN instanceof ArraySchema && ((ArraySchema) schemaN).getItems() instanceof FileSchema) {
		schemaN = new ObjectSchema().addProperties(paramName, schemaN);
		requestBodyInfo.setMergedSchema(schemaN);
	}
	else
		requestBodyInfo.addProperties(paramName, schemaN);
	return schemaN;
}
 
Example #2
Source File: MultipartFileInterceptor.java    From servicecomb-toolkit with Apache License 2.0 5 votes vote down vote up
@Override
public Schema process(Type cls, Components components) {

  if (!MultipartFile.class.equals(cls)) {
    return null;
  }

  return new FileSchema();
}
 
Example #3
Source File: FileSupportConverter.java    From springdoc-openapi with Apache License 2.0 5 votes vote down vote up
@Override
public Schema resolve(AnnotatedType type, ModelConverterContext context, Iterator<ModelConverter> chain) {
	JavaType javaType = Json.mapper().constructType(type.getType());
	if (javaType != null) {
		Class<?> cls = javaType.getRawClass();
		if (isFile(cls))
			return new FileSchema();
	}
	return (chain.hasNext()) ? chain.next().resolve(type, context, chain) : null;
}
 
Example #4
Source File: TypeScriptInversifyClientCodegen.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Override
public String getTypeDeclaration(Schema p) {
    if (p instanceof FileSchema || p instanceof BinarySchema) {
        return "Blob";
    } else {
        return super.getTypeDeclaration(p);
    }
}
 
Example #5
Source File: DataGenerator.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
public boolean isSupported(Schema<?> schema) {
    return schema instanceof ArraySchema
            || schema instanceof BooleanSchema
            || schema instanceof FileSchema
            || schema instanceof IntegerSchema
            || schema instanceof MapSchema
            || schema instanceof NumberSchema
            || schema instanceof StringSchema;
}
 
Example #6
Source File: SpringAnnotationProcessorTest.java    From servicecomb-toolkit with Apache License 2.0 4 votes vote down vote up
@Test
public void parseParameter() throws NoSuchMethodException {
  Class<ParamAnnotationResource> paramAnnotationResourceClass = ParamAnnotationResource.class;
  OasContext oasContext = new OasContext(null);
  OperationContext operationContext;
  ParameterContext parameterContext;

  RequestParamAnnotationProcessor requestParamAnnotationProcessor = new RequestParamAnnotationProcessor();
  Method requestParamMethod = paramAnnotationResourceClass.getMethod("requestParam", String.class);
  Parameter requestParamMethodParam = requestParamMethod.getParameters()[0];
  RequestParam requestParamAnnotation = requestParamMethodParam
      .getAnnotation(RequestParam.class);
  operationContext = new OperationContext(requestParamMethod, oasContext);
  parameterContext = new ParameterContext(operationContext, requestParamMethodParam);
  requestParamAnnotationProcessor.process(requestParamAnnotation, parameterContext);
  io.swagger.v3.oas.models.parameters.Parameter oasParameter = parameterContext.toParameter();
  Assert.assertNull(parameterContext.getDefaultValue());
  Assert.assertNull(oasParameter.getSchema().getDefault());

  PathVariableAnnotationProcessor pathVariableAnnotationProcessor = new PathVariableAnnotationProcessor();
  Method pathVariableMethod = paramAnnotationResourceClass.getMethod("pathVariable", String.class);
  Parameter pathVariableMethodParam = pathVariableMethod.getParameters()[0];
  PathVariable pathVariableAnnotation = pathVariableMethodParam
      .getAnnotation(PathVariable.class);
  operationContext = new OperationContext(pathVariableMethod, oasContext);
  parameterContext = new ParameterContext(operationContext, pathVariableMethodParam);
  pathVariableAnnotationProcessor.process(pathVariableAnnotation, parameterContext);
  parameterContext.toParameter();
  Assert.assertTrue(parameterContext.isRequired());

  RequestPartAnnotationProcessor requestPartAnnotationProcessor = new RequestPartAnnotationProcessor();
  Method requestPartMethod = paramAnnotationResourceClass.getMethod("requestPart", MultipartFile.class);
  Parameter requestPartMethodParam = requestPartMethod.getParameters()[0];
  RequestPart requestPartParamAnnotation = requestPartMethodParam
      .getAnnotation(RequestPart.class);
  operationContext = new OperationContext(requestPartMethod, oasContext);
  parameterContext = new ParameterContext(operationContext, requestPartMethodParam);
  requestPartAnnotationProcessor.process(requestPartParamAnnotation, parameterContext);
  oasParameter = parameterContext.toParameter();
  Assert.assertNull(parameterContext.getDefaultValue());
  Assert.assertEquals(FileSchema.class, oasParameter.getSchema().getClass());

  RequestHeaderAnnotationProcessor requestHeaderAnnotationProcessor = new RequestHeaderAnnotationProcessor();
  Method requestHeaderMethod = paramAnnotationResourceClass.getMethod("requestHeader", String.class);
  Parameter requestHeaderMethodParam = requestHeaderMethod.getParameters()[0];
  RequestHeader requestHeaderParamAnnotation = requestHeaderMethodParam
      .getAnnotation(RequestHeader.class);
  operationContext = new OperationContext(requestPartMethod, oasContext);
  parameterContext = new ParameterContext(operationContext, requestHeaderMethodParam);
  requestHeaderAnnotationProcessor.process(requestHeaderParamAnnotation, parameterContext);
  oasParameter = parameterContext.toParameter();
  Assert.assertNull(parameterContext.getDefaultValue());
  Assert.assertNull(oasParameter.getSchema().getDefault());

  RequestBodyAnnotationProcessor requestBodyAnnotationProcessor = new RequestBodyAnnotationProcessor();
  Method requestBodyMethod = paramAnnotationResourceClass.getMethod("requestBody", String.class);
  Parameter requestBodyMethodParam = requestBodyMethod.getParameters()[0];
  RequestBody requestBodyParamAnnotation = requestBodyMethodParam
      .getAnnotation(RequestBody.class);
  operationContext = new OperationContext(requestBodyMethod, oasContext);
  parameterContext = new ParameterContext(operationContext, requestBodyMethodParam);
  requestBodyAnnotationProcessor.process(requestBodyParamAnnotation, parameterContext);
  parameterContext.toParameter();
  Assert.assertTrue(parameterContext.isRequired());
}