use of org.raml.jaxrs.plugins.TypeHandler in project raml-for-jax-rs by mulesoft-labs.
the class ModelEmitter method writeMultiPartFormData.
private void writeMultiPartFormData(RamlResourceMethod method, BodyBuilder body) throws IOException {
TypeBuilder typeBuilder = TypeBuilder.type("object");
List<RamlMultiFormDataParameter> formData = method.getMultiFormDataParameter();
for (RamlMultiFormDataParameter formDatum : formData) {
Type type = formDatum.getPartEntity().getType();
TypeHandler typeHandler = pickTypeHandler(type);
typeBuilder.withProperty(TypePropertyBuilder.property(formDatum.getName(), typeHandler.writeType(typeRegistry, formDatum.getPartEntity())));
}
body.ofType(typeBuilder);
}
use of org.raml.jaxrs.plugins.TypeHandler in project raml-for-jax-rs by mulesoft-labs.
the class ModelEmitter method writeQueryParameters.
private void writeQueryParameters(Iterable<RamlQueryParameter> queryParameters, MethodBuilder builder) throws IOException {
for (RamlQueryParameter parameter : queryParameters) {
TypeHandler typeHandler = pickTypeHandler(parameter.getEntity().getType());
ParameterEmitter parameterEmitter = new ParameterEmitter(typeRegistry, typeHandler);
ParameterBuilder parameterBuilder = parameterEmitter.emit(parameter);
builder.withQueryParameter(parameterBuilder);
}
}
use of org.raml.jaxrs.plugins.TypeHandler in project raml-for-jax-rs by mulesoft-labs.
the class ModelEmitter method writeHeaderParameters.
private void writeHeaderParameters(Iterable<RamlHeaderParameter> headerParameters, MethodBuilder builder) throws IOException {
for (RamlHeaderParameter parameter : headerParameters) {
TypeHandler typeHandler = pickTypeHandler(parameter.getEntity().getType());
ParameterEmitter parameterEmitter = new ParameterEmitter(typeRegistry, typeHandler);
ParameterBuilder parameterBuilder = parameterEmitter.emit(parameter);
builder.withHeaderParameters(parameterBuilder);
}
}
use of org.raml.jaxrs.plugins.TypeHandler in project raml-for-jax-rs by mulesoft-labs.
the class DefaultResponseHandler method writeResponses.
@Override
public void writeResponses(TypeRegistry typeRegistry, RamlResourceMethod method, TypeSelector selector, MethodBuilder methodBuilder) throws IOException {
if (!method.getProducedType().isPresent()) {
return;
}
// We have no clue what the error responses are, however, we want to generate
// well formed raml, so we pick one.
ResponseBuilder responseBuilder = ResponseBuilder.response(200);
for (RamlMediaType producedMediaType : method.getProducedMediaTypes()) {
BodyBuilder body = BodyBuilder.body(producedMediaType.toStringRepresentation());
responseBuilder.withBodies(body);
TypeHandler typeHandler = selector.pickTypeWriter(method, producedMediaType);
TypeBuilder type = typeHandler.writeType(typeRegistry, method.getProducedType().get());
body.ofType(type);
}
methodBuilder.withResponses(responseBuilder);
}
use of org.raml.jaxrs.plugins.TypeHandler in project raml-for-jax-rs by mulesoft-labs.
the class ModelEmitter method writeMethod.
private void writeMethod(ResourceBuilder resourceBuilder, RamlResourceMethod method) throws IOException {
MethodBuilder methodBuilder = MethodBuilder.method(method.getHttpMethod());
ModelEmitterAnnotations.annotate(supportedAnnotations, method, methodBuilder);
Optional<String> description = method.getDescription();
if (description.isPresent() && !description.get().isEmpty()) {
methodBuilder.with(property("description", description.get()));
}
if (!method.getConsumedMediaTypes().isEmpty() && (method.getConsumedType().isPresent() || !method.getMultiFormDataParameter().isEmpty() || !method.getFormParameters().isEmpty())) {
for (RamlMediaType ramlMediaType : method.getConsumedMediaTypes()) {
BodyBuilder body = body(ramlMediaType.toStringRepresentation());
methodBuilder.withBodies(body);
if (ramlMediaType.toStringRepresentation().equals("multipart/form-data")) {
writeMultiPartFormData(method, body);
} else {
if (ramlMediaType.toStringRepresentation().equals("application/x-www-form-urlencoded")) {
writeFormParam(method, body);
} else {
Type type = method.getConsumedType().get().getType();
TypeHandler typeHandler = pickTypeHandler(type);
body.ofType(typeHandler.writeType(typeRegistry, method.getConsumedType().get()));
}
}
}
}
ResponseHandler handler = pickResponseHandler(method);
TypeSelector selector = new TypeSelector() {
@Override
public TypeHandler pickTypeWriter(RamlResourceMethod method, RamlMediaType producedMediaType) throws IOException {
return pickTypeHandler(method.getProducedType().get().getType());
}
};
if (!method.getProducedMediaTypes().isEmpty()) {
handler.writeResponses(typeRegistry, method, selector, methodBuilder);
}
if (!method.getHeaderParameters().isEmpty()) {
writeHeaderParameters(method.getHeaderParameters(), methodBuilder);
}
if (!method.getQueryParameters().isEmpty()) {
writeQueryParameters(method.getQueryParameters(), methodBuilder);
}
resourceBuilder.with(methodBuilder);
}
Aggregations