private boolean isPublishable(Route route) { return route.isAPI() // non-API routes (e.g. pages) won't be published && !route.config().internal() // don't publish internal routes && route.config().meta().publish() // a route can be configured not to be published && !route.path().startsWith("/_"); // routes having paths starting with '/_' are considered private }
private Map<String, Object> descRoute(Route route, Map<String, Object> components) { Map<String, Object> desc = U.map(); RouteMeta meta = route.config().meta(); if (meta.summary() != null) { desc.put("summary", meta.summary()); } if (meta.description() != null) { desc.put("description", meta.description()); } if (meta.id() != null) { desc.put("operationId", meta.id()); } if (U.notEmpty(meta.tags())) { desc.put("tags", meta.tags()); } if (U.notEmpty(meta.inputSchema())) { desc.put("parameters", meta.inputSchema().toOpenAPISchema()); } desc.put("responses", U.notEmpty(meta.responses()) ? meta.responses() : defaultResponses(route)); return desc; }
private Map<String, Object> defaultResponses(Route route) { RouteMeta meta = route.config().meta(); Map<String, Object> responses = U.map(); Map<String, Object> schema = U.notEmpty(meta.outputSchema()) ? meta.outputSchema().toOpenAPISchema() : U.map(); MediaType mediaType = U.or(route.config().contentType(), MediaType.JSON); String contentType = new String(mediaType.getBytes()); Map<String, Object> ok = U.map( "description", "success", "content", U.map( contentType, schema ) ); responses.put("200", ok); Map<String, Object> error = U.map( "description", "unexpected error", "content", U.map( contentType, OpenAPIModel.schemaRef("Error") ) ); responses.put("default", error); return responses; }