]> xenbits.xensource.com Git - xcp/xen-api.git/commitdiff
Generate API docs in JSON format
authorRob Hoes <rob.hoes@citrix.com>
Tue, 25 May 2010 13:26:27 +0000 (14:26 +0100)
committerRob Hoes <rob.hoes@citrix.com>
Tue, 25 May 2010 13:26:27 +0000 (14:26 +0100)
Signed-off-by: Rob Hoes <rob.hoes@citrix.com>
.hgignore
OMakeroot
ocaml/doc/OMakefile
ocaml/doc/jsapi.ml
ocaml/idl/OMakefile
ocaml/idl/datamodel_types.ml

index 73ea500280a5dbeae4a9ed89238b8af0f15f59ed..b2ab9af4e7f491cd970eba6eb53eab858621801b 100644 (file)
--- a/.hgignore
+++ b/.hgignore
@@ -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
@@ -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
index fb2dec8bcf462c8b8a4e48e6456b65243f6506dd..e060b7bd501aa22b7090c4e1540c8c65ae06120f 100644 (file)
--- a/OMakeroot
+++ b/OMakeroot
@@ -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.
 #
index 91918d2d0fd5157f74bd8262ea23c66e1967dfa3..ef3359c587e273cf86c6a58ba51e123285da8ece 100644 (file)
@@ -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
index 07a4bdf12e3445ddc76a78112a6f93c42694c7f6..86d25b9e3590cbecfcd00fa3305cd887263f3170 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *)
-open Datamodel_types
-open Stringext
-
-type change_t = lifecycle_change * string * string
-and changes_t = change_t list
-with rpc
 
 let _ =
-       let api = (Datamodel.all_api) in
+       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.name in
-               let s = Jsonrpc.to_string (rpc_of_obj obj) in
-               Unixext.write_string_to_file ("api/" ^ name ^ ".json") ("clsdoc = " ^ s);
+               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 ^ "]");
+       Unixext.write_string_to_file "api/index.json" ("classes = [" ^ class_list ^ "]")
        
-       let changes_in_release rel =
-               let search_obj obj =
-                       let changes = List.filter (fun (transition, release, doc) -> release = rel) obj.obj_lifecycle in
-                       let obj_changes : changes_t = 
-                               List.map (fun (transition, release, doc) -> (transition, obj.name, doc)) changes in
-                       
-                       let changes_for_msg m =
-                               let changes = List.filter (fun (transition, release, doc) -> release = rel) m.msg_lifecycle in
-                               List.map (fun (transition, release, doc) -> (transition, m.msg_name, doc)) changes
-                       in
-                       let msgs = List.filter (fun m -> not m.msg_hide_from_docs) obj.messages in
-                       let msg_changes : changes_t = List.fold_left (fun l m -> l @ (changes_for_msg m)) [] msgs in
-                       
-                       let changes_for_field f =
-                               let changes = List.filter (fun (transition, release, doc) -> release = rel) f.lifecycle in
-                               let field_name = String.concat "_" f.full_name in
-                               List.map (fun (transition, release, doc) -> (transition, field_name, doc)) changes
-                       in
-                       let rec flatten_contents contents =
-                               List.fold_left (fun l -> function
-                                       | Field f -> f :: l
-                                       | Namespace (name, contents) -> flatten_contents contents @ l
-                               ) [] contents
-                       in
-                       let fields = flatten_contents obj.contents in
-                       let field_changes : changes_t = List.fold_left (fun l f -> l @ (changes_for_field f)) [] fields in
-                       
-                       "{'cls': '" ^ obj.name ^ "', 'obj_changes': " ^ Jsonrpc.to_string (rpc_of_changes_t obj_changes) ^ ", 'field_changes': " ^ Jsonrpc.to_string (rpc_of_changes_t field_changes) ^ ", 'msg_changes': " ^ Jsonrpc.to_string (rpc_of_changes_t msg_changes) ^ "}"
-               in
-               let release_info = String.concat ", " (List.map search_obj objs) in
-               Unixext.write_string_to_file ("api/" ^ rel ^ ".json") ("release_info = [" ^ release_info ^ "]")
-       in
-       List.iter changes_in_release release_order;
-       let release_list = String.concat ", " (List.map (fun s -> "'" ^ s ^ "'") release_order) in
-       Unixext.write_string_to_file "api/releases.json" ("releases = [" ^ release_list ^ "]");
index 9fccfdc15a4022a6c2ff7437cdbdf244093b5fde..2565e101680eeb1a167850783985e6c276d1a0a7 100644 (file)
@@ -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
 # -----------------------------------------------------------------------
index 96c8627251ff386aed12b479ff7bcb393440c05d..634be87ca7432d1f3ae07cbdc40ec751892f978e 100644 (file)
 
 *)
 
+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"
@@ -65,6 +71,7 @@ type ty =
     | Map of ty * ty
     | Ref of string
     | Record of string
+    with rpc
 
 type api_value =
     VString of string
@@ -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
@@ -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
@@ -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;
@@ -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;
@@ -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
@@ -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 *)
 
@@ -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)