Skip to content

Commit

Permalink
Generate API docs in JSON format
Browse files Browse the repository at this point in the history
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
  • Loading branch information
robhoes committed May 25, 2010
1 parent b4eb75b commit 71d2b50
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 10 deletions.
4 changes: 4 additions & 0 deletions .hgignore
Expand Up @@ -104,6 +104,7 @@ stunnel-4.15/tools/stunnel.conf-sample
stunnel-4.15/tools/stunnel.init
zurich/java/com/xensource/autogen/*.java
js/api.js
java
ocaml/cdrommon/cdrommon
ocaml/console/console
ocaml/database/db_filter_lex.ml
Expand All @@ -115,6 +116,9 @@ ocaml/database/block_device_io
ocaml/db_process/xapi-db-process
ocaml/db_process/xapi-db-upgrade-4.2
ocaml/doc/content
ocaml/doc/api
ocaml/doc/jsapi
ocaml/doc/components.js
ocaml/events/event_listen
ocaml/fdhelper/closeandexec
ocaml/fdhelper/closeandexec_static
Expand Down
11 changes: 11 additions & 0 deletions OMakeroot
Expand Up @@ -95,6 +95,17 @@ OCamlDocProgram(name, modules) =
OCamlDocLibrary(name, modules) =
OCamlDoc($(name), $(modules), "library")

#
# Use Camlp4
#
UseCamlp4(packs, files) =
OCAMLPACKS += $(packs)
OCAMLFINDFLAGS += -syntax camlp4o
$(addsuffix .cmx, $(files)):
$(addsuffix .o, $(files)):
$(addsuffix .cmi, $(files)):
$(addsuffix .cmo, $(files)):

#
# Include the OMakefile in this directory.
#
Expand Down
11 changes: 10 additions & 1 deletion ocaml/doc/OMakefile
Expand Up @@ -2,7 +2,16 @@ OCAMLINCLUDES += +ocamldoc
BYTE_ENABLED = TRUE
OCamlLibrary(odoc_json, odoc_json)

OCAML_LIBS += ../idl/datamodel
OCAMLINCLUDES += ../idl
OCamlProgram(jsapi, jsapi)

.PHONY: doc
doc: jsapi
mkdir -p api
./jsapi

.PHONY: clean
clean:
rm -f *~ *.cmi *.cmx *.cmo *.a *.cma *.cmxa *.run *.opt *.annot *.o
rm -rf components.js content
rm -rf components.js content jsapi
27 changes: 27 additions & 0 deletions ocaml/doc/jsapi.ml
@@ -0,0 +1,27 @@
(*
* Copyright (C) 2006-2009 Citrix Systems Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; version 2.1 only. with the special
* exception on linking described in file LICENSE.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*)

let _ =
let api = (* Datamodel_utils.add_implicit_messages *) (Datamodel.all_api) in
let objs = Dm_api.objects_of_api api in
let create_json obj =
let name = obj.Datamodel_types.name in
let s = Jsonrpc.to_string (Datamodel_types.rpc_of_obj obj) in
Unixext.write_string_to_file ("api/" ^ name ^ ".json") s;
name
in
let names = List.map create_json objs in
let class_list = String.concat ", " (List.map (fun s -> "'" ^ s ^ "'") names) in
Unixext.write_string_to_file "api/index.json" ("classes = [" ^ class_list ^ "]")

4 changes: 4 additions & 0 deletions ocaml/idl/OMakefile
Expand Up @@ -8,6 +8,10 @@ PSTOPDF = $(shell bash -c "which pstopdf || which ps2pdf || which ps2pdf14 || ec
OCAMLINCLUDES = ocaml_backend ../database
OCAMLPACKS = xml-light2 sexpr log

CAMLP4_FILES = datamodel_types

UseCamlp4(rpc-light.syntax, $(CAMLP4_FILES))

# -----------------------------------------------------------------------
# Build datamodel library
# -----------------------------------------------------------------------
Expand Down
31 changes: 22 additions & 9 deletions ocaml/idl/datamodel_types.ml
Expand Up @@ -26,6 +26,12 @@
*)

module Date = struct
include Date
let iso8601_of_rpc rpc = Date.of_string (Rpc.string_of_rpc rpc)
let rpc_of_iso8601 date = Rpc.rpc_of_string (Date.to_string date)
end

(* useful constants for product vsn tracking *)
let oss_since_303 = Some "3.0.3"
let rel_george = "george"
Expand Down Expand Up @@ -65,6 +71,7 @@ type ty =
| Map of ty * ty
| Ref of string
| Record of string
with rpc

type api_value =
VString of string
Expand All @@ -76,7 +83,8 @@ type api_value =
| VMap of (api_value*api_value) list
| VSet of api_value list
| VRef of string

with rpc

(** Each database field has a qualifier associated with it: *)
type qualifier =
| RW
Expand All @@ -88,13 +96,14 @@ type qualifier =
| DynamicRO
(** Read-only database field whose value is computed dynamically and
not specified at the time of object construction. *)

with rpc

(** Release keeps track of which versions of opensource/internal products fields and messages are included in *)
type release = {
opensource: string list;
internal: string list;
internal_deprecated_since: string option; (* first release we said it was deprecated *)
}
} with rpc

(** Messages are tagged with one of these indicating whether the message was
specified explicitly in the datamodel, or is one of the automatically
Expand Down Expand Up @@ -136,7 +145,7 @@ and message = {
msg_hide_from_docs: bool;
msg_allowed_roles: string list option;
msg_map_keys_roles: (string * (string list option)) list
}
}

and field = {
release: release;
Expand All @@ -153,7 +162,7 @@ and field = {
field_setter_roles: string list option;
field_getter_roles: string list option;
field_map_keys_roles: (string * (string list option)) list
}
}

and error = {
err_name: string;
Expand All @@ -164,7 +173,7 @@ and error = {
and mess = {
mess_name: string;
mess_doc: string;
}
} with rpc

(** Getters and Setters will be generated for each field, depending on the qualifier.
Namespaces allow fields to be grouped together (and this can get reflected in the XML
Expand All @@ -173,11 +182,12 @@ and mess = {
type content =
| Field of field (** An individual field *)
| Namespace of string * content list (** A nice namespace for a group of fields *)

with rpc

(* Note: there used be more than 2 persist_options -- that's why it isn't a bool.
I figured even though there's only 2 now I may as well leave it as an enumeration type.. *)

type persist_option = PersistNothing | PersistEverything
type persist_option = PersistNothing | PersistEverything with rpc
(* PersistEverything - all creates/writes persisted;
PersistNothing - no creates/writes to this table persisted *)

Expand All @@ -195,7 +205,10 @@ type obj = { name : string;
persist: persist_option;
obj_release: release;
in_database: bool (* If the object is in the database *)
}
} with rpc

(* val rpc_of_obj : obj -> Rpc.t *)
(* let s = Jsonrpc.to_string (rpc_of_obj o) *)

(** A relation binds two fields together *)
type relation = (string * string) * (string * string)
Expand Down

0 comments on commit 71d2b50

Please sign in to comment.