|
1 | 1 | (ns codegen3.ari4java |
2 | 2 | (:require [codegen3.javagen :as jg] |
3 | 3 | [clojure.spec.alpha :as s] |
4 | | - [orchestra.spec.test :as st])) |
| 4 | + [orchestra.spec.test :as st] |
| 5 | + [codegen3.signatures :as sgn])) |
5 | 6 |
|
6 | 7 | ;; This namespace runs the translation of |
7 | 8 | ;; a swagger database (e.g. sample_db.clj) as read in core |
|
471 | 472 |
|
472 | 473 |
|
473 | 474 | ; ================== |
| 475 | +; ARIBUILDERS and such things |
474 | 476 |
|
475 | 477 | (defn generate-ari-builder-interface |
476 | 478 | "public abstract ActionApplications actionApplications();" |
|
578 | 580 | (map #(generate-ari-builder-impl % DB allmods allacts) allaris) |
579 | 581 | (map #(generate-class-translator-impl % DB allmods allacts) allaris)] |
580 | 582 |
|
581 | | - ) |
| 583 | + ))) |
582 | 584 |
|
583 | 585 |
|
| 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) |
584 | 592 |
|
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 | + ])) |
586 | 604 |
|
| 605 | +(s/def ::odb |
| 606 | + (s/coll-of ::odb_entry :kind sequential? )) |
587 | 607 |
|
588 | 608 |
|
589 | 609 |
|
| 610 | +(defn allActions [ODB] |
| 611 | + (->> ODB |
| 612 | + (map :op_entity) |
| 613 | + set |
| 614 | + sort |
| 615 | + vec )) |
590 | 616 |
|
| 617 | +(s/fdef allActions |
| 618 | + :args (s/cat :odb ::odb) |
| 619 | + :ret vector?) |
591 | 620 |
|
592 | 621 |
|
| 622 | +; op_entity -> op_action |
593 | 623 |
|
594 | 624 |
|
| 625 | +(s/fdef signature |
| 626 | + :args (s/cat :dbe ::odb_entry)) |
595 | 627 |
|
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?) |
597 | 648 |
|
| 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?)) |
598 | 663 |
|
| 664 | +(defn allSignaturesForAction |
| 665 | + [ODB action] |
| 666 | + (let [odb (filter #(= action (:op_entity %)) ODB)] |
| 667 | + (groupTuples (mapv signature odb)))) |
599 | 668 |
|
600 | 669 |
|
601 | 670 |
|
| 671 | +; ================================================================= |
| 672 | +; Try everything once. |
602 | 673 |
|
603 | 674 |
|
604 | 675 | (defn process |
|
618 | 689 | (into enm) |
619 | 690 | (into bld) |
620 | 691 | ) |
621 | | - |
622 | | - _ (prn "Builder" bld) |
623 | | - |
624 | 692 | ] |
625 | 693 |
|
626 | | - |
627 | 694 | (map jg/writeOutKlass all) |
| 695 | + )) |
628 | 696 |
|
629 | 697 |
|
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)) |
643 | 698 |
|
644 | | -(s/fdef xinc |
645 | | - :args number? |
646 | | - :ret number?) |
647 | 699 |
|
648 | 700 | ; Orchestra instrumentation is active automagically |
649 | 701 | (st/instrument) |
0 commit comments