use of com.liferay.apio.architect.documentation.Documentation in project com-liferay-apio-architect by liferay.
the class DocumentationMessageBodyWriter method writeTo.
@Override
public void writeTo(Documentation documentation, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
PrintWriter printWriter = new PrintWriter(outputStreamWriter, true);
Optional<DocumentationMessageMapper> optional = _documentationMessageMapperManager.getDocumentationMessageMapperOptional(_request);
DocumentationMessageMapper documentationMessageMapper = optional.orElseThrow(NotSupportedException::new);
RequestInfo requestInfo = RequestInfo.create(builder -> builder.httpHeaders(_httpHeaders).httpServletRequest(_httpServletRequest).serverURL(_providerManager.provideMandatory(_httpServletRequest, ServerURL.class)).embedded(_providerManager.provideOptional(_httpServletRequest, Embedded.class).orElse(__ -> false)).fields(_providerManager.provideOptional(_httpServletRequest, Fields.class).orElse(__ -> string -> true)).language(_providerManager.provideOptional(_httpServletRequest, Language.class).orElse(Locale::getDefault)).build());
DocumentationWriter documentationWriter = DocumentationWriter.create(builder -> builder.documentation(documentation).documentationMessageMapper(documentationMessageMapper).requestInfo(requestInfo).build());
httpHeaders.put(CONTENT_TYPE, Collections.singletonList(documentationMessageMapper.getMediaType()));
printWriter.println(documentationWriter.write());
printWriter.close();
}
use of com.liferay.apio.architect.documentation.Documentation in project com-liferay-apio-architect by liferay.
the class RootEndpointImpl method activate.
@Activate
public void activate() {
RequestFunction<Optional<APITitle>> apiTitleRequestFunction = httpServletRequest -> _providerManager.provideOptional(httpServletRequest, APITitle.class);
RequestFunction<Optional<APIDescription>> apiDescriptionRequestFunction = httpServletRequest -> _providerManager.provideOptional(httpServletRequest, APIDescription.class);
_documentation = new Documentation(apiTitleRequestFunction, apiDescriptionRequestFunction);
}
use of com.liferay.apio.architect.documentation.Documentation in project com-liferay-apio-architect by liferay.
the class MockDocumentationWriter method write.
/**
* Writes a {@link Documentation} object.
*
* @param httpHeaders the request's HTTP headers
* @param documentationMessageMapper the {@code DocumentationMessageMapper}
* to use for writing the JSON object
*/
public static JsonObject write(HttpHeaders httpHeaders, DocumentationMessageMapper documentationMessageMapper) {
RequestInfo requestInfo = getRequestInfo(httpHeaders);
Documentation documentation = new Documentation(__ -> Optional.of(() -> "Title"), __ -> Optional.of(() -> "Description"));
DocumentationWriter documentationWriter = DocumentationWriter.create(builder -> builder.documentation(documentation).documentationMessageMapper(documentationMessageMapper).requestInfo(requestInfo).build());
return new Gson().fromJson(documentationWriter.write(), JsonObject.class);
}
Aggregations