in swagger/swagger-generator/generator-core/src/main/java/org/apache/servicecomb/swagger/generator/ParameterGenerator.java [127:202]
public void generate() {
this.parameterGeneratorContext.updateConsumes(
this.operationGenerator.isForm(), this.operationGenerator.isBinary(), this.operationGenerator.isWebsocket());
if (this.parameterGeneratorContext.getHttpParameterType() == HttpParameterType.BODY) {
if (parameterGeneratorContext.getSupportedConsumes().size() == 0) {
throw new IllegalArgumentException("Consumes not provided for BODY parameter, or is empty "
+ "by annotations rule.");
}
RequestBody requestBody = new RequestBody();
requestBody.setRequired(parameterGeneratorContext.getRequired());
Map<String, Object> extensions = new HashMap<>();
extensions.put(SwaggerConst.EXT_BODY_NAME, parameterGeneratorContext.getParameterName());
if (parameterGeneratorContext.getRawJson() != null) {
extensions.put(SwaggerConst.EXT_RAW_JSON_TYPE, parameterGeneratorContext.getRawJson());
}
requestBody.setExtensions(extensions);
requestBody.setContent(new Content());
for (String media : parameterGeneratorContext.getSupportedConsumes()) {
MediaType mediaType = new MediaType();
mediaType.setSchema(parameterGeneratorContext.getSchema());
requestBody.getContent().addMediaType(media, mediaType);
}
this.operationGenerator.getOperation().setRequestBody(requestBody);
return;
}
if (this.parameterGeneratorContext.getHttpParameterType() == HttpParameterType.FORM) {
if (parameterGeneratorContext.getSupportedConsumes().size() == 0) {
throw new IllegalArgumentException("Consumes not provided for FORM parameter, or is empty "
+ "by annotations rule.");
}
RequestBody requestBody = this.operationGenerator.getOperation().getRequestBody();
if (requestBody == null) {
requestBody = new RequestBody();
requestBody.setContent(new Content());
this.operationGenerator.getOperation().setRequestBody(requestBody);
}
for (String media : parameterGeneratorContext.getSupportedConsumes()) {
MediaType mediaType = requestBody.getContent().get(media);
if (mediaType == null) {
mediaType = new MediaType();
mediaType.setSchema(new ObjectSchema());
requestBody.getContent().addMediaType(media, mediaType);
}
mediaType.getSchema().addProperty(parameterGeneratorContext.getParameterName(),
parameterGeneratorContext.getSchema());
}
return;
}
Parameter parameter;
switch (this.parameterGeneratorContext.getHttpParameterType()) {
case PATH -> parameter = new PathParameter();
case QUERY -> parameter = new QueryParameter();
case HEADER -> parameter = new HeaderParameter();
case COOKIE -> parameter = new CookieParameter();
default -> throw new IllegalStateException("not support httpParameterType "
+ this.parameterGeneratorContext.getHttpParameterType());
}
parameter.setName(parameterGeneratorContext.getParameterName());
parameter.setSchema(parameterGeneratorContext.getSchema());
parameter.setRequired(parameterGeneratorContext.getRequired());
parameter.setExplode(parameterGeneratorContext.getExplode());
this.operationGenerator.getOperation().addParametersItem(parameter);
// validations and other annotations supported by swagger default
if (parameterGeneratorContext.getParameterType() != null) {
io.swagger.v3.core.util.ParameterProcessor.applyAnnotations(parameter,
parameterGeneratorContext.getParameterType(),
annotations, operationGenerator.getSwagger().getComponents(),
null, null, null);
}
// spring mvc DefaultValue annotation not processed by swagger api.
if (parameterGeneratorContext.getDefaultValue() != null) {
parameter.getSchema().setDefault(parameterGeneratorContext.getDefaultValue());
}
}