- int (*init)(struct afb_service service);
- void (*onevent)(const char *event, struct json_object *object);
-
- struct api_so_v1 *desc = closure;
-
- /* check state */
- if (desc->service != NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* already started: it is an error */
- ERROR("Service %s already started", desc->binding->v1.prefix);
- return -1;
- }
-
- /* get the initialisation */
- init = dlsym(desc->handle, afb_api_so_v1_service_init);
- if (init == NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* no initialisation method */
- ERROR("Binding %s is not a service", desc->binding->v1.prefix);
- return -1;
- }
-
- /* get the event handler if any */
- onevent = dlsym(desc->handle, afb_api_so_v1_service_event);
- desc->service = afb_svc_create(share_session, init, onevent);
- if (desc->service == NULL) {
- /* starting error */
- ERROR("Starting service %s failed", desc->binding->v1.prefix);
- return -1;
+ char buffer[256];
+ const struct afb_verb_desc_v1 *verb;
+ struct json_object *r, *f, *a, *i, *p, *g;
+
+ r = json_object_new_object();
+ json_object_object_add(r, "openapi", json_object_new_string("3.0.0"));
+
+ i = json_object_new_object();
+ json_object_object_add(r, "info", i);
+ json_object_object_add(i, "title", json_object_new_string(apiname));
+ json_object_object_add(i, "version", json_object_new_string("0.0.0"));
+ json_object_object_add(i, "description", json_object_new_string(binding->v1.info ?: apiname));
+
+ p = json_object_new_object();
+ json_object_object_add(r, "paths", p);
+ verb = binding->v1.verbs;
+ while (verb->name) {
+ buffer[0] = '/';
+ strncpy(buffer + 1, verb->name, sizeof buffer - 1);
+ buffer[sizeof buffer - 1] = 0;
+ f = json_object_new_object();
+ json_object_object_add(p, buffer, f);
+ g = json_object_new_object();
+ json_object_object_add(f, "get", g);
+
+ a = afb_auth_json_x1(verb->session);
+ if (a)
+ json_object_object_add(g, "x-permissions", a);
+
+ a = json_object_new_object();
+ json_object_object_add(g, "responses", a);
+ f = json_object_new_object();
+ json_object_object_add(a, "200", f);
+ json_object_object_add(f, "description", json_object_new_string(verb->info));
+ verb++;