use of com.reprezen.kaizen.oasparser.model3.RequestBody in project cobigen by devonfw.
the class OpenAPIInputReader method extractParameters.
/**
* @param operationOverlay overlay of the operation to get all parameters from
* @return a list of {@link ParameterDef} from a collection of parameters of an operation
*/
private List<ParameterDef> extractParameters(Overlay<Operation> operationOverlay) {
Collection<? extends Parameter> parameters = operationOverlay.get().getParameters();
Collection<String> tags = operationOverlay.get().getTags();
RequestBody requestBody = operationOverlay.get().getRequestBody();
List<ParameterDef> parametersList = new LinkedList<>();
ParameterDef parameter;
for (Parameter param : parameters) {
parameter = new ParameterDef();
parameter.setIsBody(false);
switch(param.getIn()) {
case "path":
parameter.setInPath(true);
break;
case "query":
parameter.setInQuery(true);
break;
case "header":
parameter.setInHeader(true);
break;
}
parameter.setName(param.getName());
Schema schema = param.getSchema();
Map<String, Object> constraints = extractConstraints(schema);
if (param.isRequired()) {
constraints.put(ModelConstant.NOTNULL, true);
} else {
constraints.put(ModelConstant.NOTNULL, false);
}
parameter.setConstraints(constraints);
parameter.setDescription(param.getDescription());
if (schema.getType().equals(Constants.ARRAY)) {
parameter.setIsCollection(true);
if (schema.getItemsSchema() != null) {
parameter.setIsEntity(true);
}
}
try {
if (Overlay.isReference(operationOverlay.getOverlay(), param.getKey())) {
parameter.setIsEntity(true);
parameter.setType(schema.getName());
} else {
parameter.setType(schema.getType());
parameter.setFormat(schema.getFormat());
}
} catch (NullPointerException e) {
throw new CobiGenRuntimeException("Error at parameter " + param.getName() + ". Invalid OpenAPI file, path parameters need to have a schema defined.");
}
parametersList.add(parameter);
}
if (requestBody != null) {
Schema mediaSchema;
for (String media : requestBody.getContentMediaTypes().keySet()) {
parameter = new ParameterDef();
parameter.setIsBody(true);
parameter.setMediaType(media);
if (tags.contains(Constants.SEARCH_CRITERIA) || tags.contains(Constants.SEARCH_CRITERIA.toLowerCase())) {
parameter.setIsSearchCriteria(true);
parameter.setName("criteria");
}
if (requestBody.getContentMediaTypes().get(media).getSchema() != null) {
mediaSchema = requestBody.getContentMediaTypes().get(media).getSchema();
parameter.setIsEntity(true);
parameter.setType(requestBody.getContentMediaType(media).getSchema().getName());
if (!parameter.getIsSearchCriteria()) {
char[] c = mediaSchema.getName().toCharArray();
c[0] = Character.toLowerCase(c[0]);
parameter.setName(new String(c));
}
}
if (parameter.getType() != null) {
Map<String, Object> constraints = new HashMap<>();
constraints.put(ModelConstant.NOTNULL, true);
parameter.setConstraints(constraints);
parametersList.add(parameter);
}
}
}
return parametersList;
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project okta-oidc-android by okta.
the class OkHttp method buildRequest.
protected Request buildRequest(Uri uri, ConnectionParameters param) {
try {
mTrustAllSslContext = SSLContext.getInstance("SSL");
mTrustAllSslContext.init(null, mTrustManager, new java.security.SecureRandom());
} catch (NoSuchAlgorithmException | KeyManagementException e) {
throw new RuntimeException(e);
}
mTrustAllSslSocketFactory = mTrustAllSslContext.getSocketFactory();
if (sOkHttpClient == null) {
sOkHttpClient = new OkHttpClient.Builder().readTimeout(param.readTimeOutMs(), TimeUnit.MILLISECONDS).connectTimeout(param.connectionTimeoutMs(), TimeUnit.MILLISECONDS).hostnameVerifier((hostname, session) -> true).sslSocketFactory(mTrustAllSslSocketFactory, (X509TrustManager) mTrustManager[0]).build();
}
Request.Builder requestBuilder = new Request.Builder().url(uri.toString());
for (Map.Entry<String, String> headerEntry : param.requestProperties().entrySet()) {
String key = headerEntry.getKey();
requestBuilder.addHeader(key, headerEntry.getValue());
}
if (param.requestMethod() == ConnectionParameters.RequestMethod.GET) {
requestBuilder = requestBuilder.get();
} else {
Map<String, String> postParameters = param.postParameters();
if (postParameters != null) {
FormBody.Builder formBuilder = new FormBody.Builder();
for (Map.Entry<String, String> postEntry : postParameters.entrySet()) {
String key = postEntry.getKey();
formBuilder.add(key, postEntry.getValue());
}
RequestBody formBody = formBuilder.build();
requestBuilder.post(formBody);
} else {
requestBuilder.post(RequestBody.create(null, ""));
}
}
return requestBuilder.build();
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project org.hl7.fhir.core by hapifhir.
the class Client method issuePostFeedRequest.
public Bundle issuePostFeedRequest(URI resourceUri, Map<String, String> parameters, String resourceName, Resource resource, String resourceFormat) throws IOException {
String boundary = "----WebKitFormBoundarykbMUo6H8QaUnYtRy";
byte[] payload = ByteUtils.encodeFormSubmission(parameters, resourceName, resource, boundary);
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
return executeBundleRequest(request, resourceFormat, new Headers.Builder().build(), null, retryCount, timeout);
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project org.hl7.fhir.core by hapifhir.
the class Client method issuePutRequest.
public <T extends Resource> ResourceRequest<T> issuePutRequest(URI resourceUri, byte[] payload, String resourceFormat, Headers headers, String message, long timeout) throws IOException {
if (payload == null)
throw new EFhirClientException("PUT requests require a non-null payload");
RequestBody body = RequestBody.create(payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).put(body);
return executeFhirRequest(request, resourceFormat, headers, message, retryCount, timeout);
}
use of com.reprezen.kaizen.oasparser.model3.RequestBody in project org.hl7.fhir.core by hapifhir.
the class Client method issuePostRequest.
public <T extends Resource> ResourceRequest<T> issuePostRequest(URI resourceUri, byte[] payload, String resourceFormat, Headers headers, String message, long timeout) throws IOException {
if (payload == null)
throw new EFhirClientException("POST requests require a non-null payload");
RequestBody body = RequestBody.create(MediaType.parse(resourceFormat + ";charset=" + DEFAULT_CHARSET), payload);
Request.Builder request = new Request.Builder().url(resourceUri.toURL()).post(body);
return executeFhirRequest(request, resourceFormat, headers, message, retryCount, timeout);
}
Aggregations