Java Code Examples for io.swagger.models.parameters.Parameter#getRequired()
The following examples show how to use
io.swagger.models.parameters.Parameter#getRequired() .
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: BodyProcessorCreator.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Override public ParamValueProcessor create(Parameter parameter, Type genericParamType) { Model model = ((BodyParameter) parameter).getSchema(); JavaType swaggerType = null; if (model instanceof ModelImpl) { swaggerType = ConverterMgr.findJavaType(((ModelImpl) model).getType(), ((ModelImpl) model).getFormat()); } boolean isString = swaggerType != null && swaggerType.getRawClass().equals(String.class); JavaType targetType = genericParamType == null ? null : TypeFactory.defaultInstance().constructType(genericParamType); boolean rawJson = SwaggerUtils.isRawJsonType(parameter); if (rawJson) { return new RawJsonBodyProcessor(targetType, (String) parameter.getVendorExtensions() .get(SwaggerConst.EXT_JSON_VIEW), isString, parameter.getRequired()); } return new BodyProcessor(targetType, (String) parameter.getVendorExtensions() .get(SwaggerConst.EXT_JSON_VIEW), isString, parameter.getRequired()); }
Example 2
Source File: RequestValidator.java From light-rest-4j with Apache License 2.0 | 6 votes |
private Status validateQueryParameter(final HttpServerExchange exchange, final SwaggerOperation swaggerOperation, final Parameter queryParameter) { final Collection<String> queryParameterValues = exchange.getQueryParameters().get(queryParameter.getName()); if ((queryParameterValues == null || queryParameterValues.isEmpty())) { if(queryParameter.getRequired()) { return new Status(VALIDATOR_REQUEST_PARAMETER_QUERY_MISSING, queryParameter.getName(), swaggerOperation.getPathString().original()); } } else { Optional<Status> optional = queryParameterValues .stream() .map((v) -> parameterValidators.validate(v, queryParameter)) .filter(s -> s != null) .findFirst(); if(optional.isPresent()) { return optional.get(); } } return null; }
Example 3
Source File: RequestValidator.java From light-rest-4j with Apache License 2.0 | 6 votes |
private Status validateHeader(final HttpServerExchange exchange, final SwaggerOperation swaggerOperation, final Parameter headerParameter) { final HeaderValues headerValues = exchange.getRequestHeaders().get(headerParameter.getName()); if ((headerValues == null || headerValues.isEmpty())) { if(headerParameter.getRequired()) { return new Status(VALIDATOR_REQUEST_PARAMETER_HEADER_MISSING, headerParameter.getName(), swaggerOperation.getPathString().original()); } } else { Optional<Status> optional = headerValues .stream() .map((v) -> parameterValidators.validate(v, headerParameter)) .filter(s -> s != null) .findFirst(); if(optional.isPresent()) { return optional.get(); } } return null; }
Example 4
Source File: CookieProcessorCreator.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Override public ParamValueProcessor create(Parameter parameter, Type genericParamType) { JavaType targetType = genericParamType == null ? null : TypeFactory.defaultInstance().constructType(genericParamType); return new CookieProcessor(parameter.getName(), targetType, ((CookieParameter) parameter).getDefaultValue(), parameter.getRequired()); }
Example 5
Source File: DefaultCodegen.java From TypeScript-Microservices with MIT License | 4 votes |
/** * Return the example path * * @param path the path of the operation * @param operation Swagger operation object * @return string presentation of the example path */ @SuppressWarnings("static-method") public String generateExamplePath(String path, Operation operation) { StringBuilder sb = new StringBuilder(); sb.append(path); if (operation.getParameters() != null) { int count = 0; for (Parameter param : operation.getParameters()) { if (param instanceof QueryParameter) { StringBuilder paramPart = new StringBuilder(); QueryParameter qp = (QueryParameter) param; if (count == 0) { paramPart.append("?"); } else { paramPart.append(","); } count += 1; if (!param.getRequired()) { paramPart.append("["); } paramPart.append(param.getName()).append("="); paramPart.append("{"); if (qp.getCollectionFormat() != null) { paramPart.append(param.getName()).append("1"); if ("csv".equals(qp.getCollectionFormat())) { paramPart.append(","); } else if ("pipes".equals(qp.getCollectionFormat())) { paramPart.append("|"); } else if ("tsv".equals(qp.getCollectionFormat())) { paramPart.append("\t"); } else if ("multi".equals(qp.getCollectionFormat())) { paramPart.append("&").append(param.getName()).append("="); paramPart.append(param.getName()).append("2"); } } else { paramPart.append(param.getName()); } paramPart.append("}"); if (!param.getRequired()) { paramPart.append("]"); } sb.append(paramPart.toString()); } } } return sb.toString(); }