Skip to content

Commit c99ad90

Browse files
lenzlenz
authored andcommitted
Working interface signatures
1 parent 758e01d commit c99ad90

1 file changed

Lines changed: 76 additions & 24 deletions

File tree

codegen3/src/codegen3/ari4java.clj

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
(ns codegen3.ari4java
22
(:require [codegen3.javagen :as jg]
33
[clojure.spec.alpha :as s]
4-
[orchestra.spec.test :as st]))
4+
[orchestra.spec.test :as st]
5+
[codegen3.signatures :as sgn]))
56

67
;; This namespace runs the translation of
78
;; a swagger database (e.g. sample_db.clj) as read in core
@@ -471,6 +472,7 @@
471472

472473

473474
; ==================
475+
; ARIBUILDERS and such things
474476

475477
(defn generate-ari-builder-interface
476478
"public abstract ActionApplications actionApplications();"
@@ -578,27 +580,96 @@
578580
(map #(generate-ari-builder-impl % DB allmods allacts) allaris)
579581
(map #(generate-class-translator-impl % DB allmods allacts) allaris)]
580582

581-
)
583+
)))
582584

583585

586+
; =================================================================
587+
; ACTIONS
588+
; Generation of all actions is based on an opsDb
589+
; when testing, you can:
590+
; (def ODB (opsDb (codegen3.core/readAll)))
591+
; (allSignaturesForAction ODB :applications)
584592

585-
)
593+
(s/def ::odb_entry
594+
(s/keys :req-un [::op_path
595+
::op_description
596+
::op_version
597+
::op_entity
598+
::httpMethod
599+
::summary
600+
::nickname
601+
::responseClass
602+
;::parameters
603+
]))
586604

605+
(s/def ::odb
606+
(s/coll-of ::odb_entry :kind sequential? ))
587607

588608

589609

610+
(defn allActions [ODB]
611+
(->> ODB
612+
(map :op_entity)
613+
set
614+
sort
615+
vec ))
590616

617+
(s/fdef allActions
618+
:args (s/cat :odb ::odb)
619+
:ret vector?)
591620

592621

622+
; op_entity -> op_action
593623

594624

625+
(s/fdef signature
626+
:args (s/cat :dbe ::odb_entry))
595627

596-
)
628+
(defn signature
629+
"Gets a signature tuple. [{:nick....} :ari_0]
630+
As :parameters might not exist, we read it through a get
631+
so we can put a default."
632+
[dbe]
633+
(let [p (get dbe :parameters [])]
634+
[{:nickname (:nickname dbe)
635+
:parms (sgn/explode-parms-permutations p)
636+
:responseClass (:responseClass dbe)
637+
}
638+
(:op_version dbe)]
639+
))
640+
641+
(s/def ::tuple
642+
(s/and vector?
643+
#(= 2 (count %)) ))
644+
645+
(s/fdef groupTuples
646+
:args (s/cat :tuples (s/coll-of ::tuple ))
647+
:ret map?)
597648

649+
(defn groupTuples
650+
"Translates a sequence of [ [item tag]...]
651+
into a map {item [tag...]}
652+
"
653+
[sTuples]
654+
(into {}
655+
(map
656+
(fn [[k v]] [k (mapv second v)] )
657+
(group-by first sTuples))))
658+
659+
660+
(s/fdef allSignaturesForAction
661+
:args (s/cat :dbe ::odb
662+
:action keyword?))
598663

664+
(defn allSignaturesForAction
665+
[ODB action]
666+
(let [odb (filter #(= action (:op_entity %)) ODB)]
667+
(groupTuples (mapv signature odb))))
599668

600669

601670

671+
; =================================================================
672+
; Try everything once.
602673

603674

604675
(defn process
@@ -618,32 +689,13 @@
618689
(into enm)
619690
(into bld)
620691
)
621-
622-
_ (prn "Builder" bld)
623-
624692
]
625693

626-
627694
(map jg/writeOutKlass all)
695+
))
628696

629697

630-
)
631-
632-
633-
)
634-
635-
636-
637-
;-----------
638-
; LEARN SOME SPEC
639-
; https://blog.jeaye.com/2017/05/31/clojure-spec/
640-
641-
(defn xinc [n]
642-
(inc n))
643698

644-
(s/fdef xinc
645-
:args number?
646-
:ret number?)
647699

648700
; Orchestra instrumentation is active automagically
649701
(st/instrument)

0 commit comments

Comments
 (0)