Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Clojure] Add model generation and conforming (#122)
* [Clojure] Add model generation and verification - Generate clojure.specs from models - Optionally validate them at runtime (validation is active if orchestra.spec.test/instrument is called after specs are imported) - Coerce the results of the API calls to get objects that conform to the spec (e.g. get Date objects for dates and time instead of strings) * [Clojure] Make model conforming configurable and opt-out * [Clojure] Move specs from a single file to a ns per model So that the order of the forms will be resolved by the compiler, otherwise we'd have to implement a topological ordering. * [Clojure] Update petstore sample and set automatic decoding off * [Clojure] Stop testing Clojure generator on Java7 * [Clojure] Fix tests and handling of multiple arity * [Clojure] Fix tests and add testing for the new decoding feature * [Clojure] Capitalize names of generated models * [Clojure] Rename petstore specs to be capitalized * Revert to lowercase spec names, and postfix the data specs
- Loading branch information
Showing
18 changed files
with
529 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
modules/openapi-generator/src/main/resources/clojure/spec.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{{=< >=}}(ns <package>.<classname> | ||
(:require [clojure.spec.alpha :as s] | ||
[spec-tools.data-spec :as ds] | ||
<#models><#model><#vars><^isContainer><^vendorExtensions.x-baseSpec>[<package>.<complexType> :refer :all] | ||
</vendorExtensions.x-baseSpec></isContainer><#isContainer><^vendorExtensions.x-baseSpec>[<package>.<complexType> :refer :all] | ||
</vendorExtensions.x-baseSpec></isContainer></vars></model></models>) | ||
(:import (java.io File))) | ||
|
||
<#models><#model> | ||
(def <classname>-data | ||
{<#vars> | ||
(ds/<#required>req</required><^required>opt</required> :<name>) <datatype></vars> | ||
}) | ||
|
||
(def <classname>-spec | ||
(ds/spec | ||
{:name ::<classname> | ||
:spec <classname>-data})) | ||
</model></models> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.