Skip to content

Commit

Permalink
OpenAPI parameters (#94)
Browse files Browse the repository at this point in the history
* Test for expected behaviour #93
* fixing poor keywordizing #93
  • Loading branch information
oliyh authored Aug 26, 2020
1 parent a3695b8 commit 28146b5
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/src/martian/openapi.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
;; which aren't the associated OPTIONS call.
:when (and (:operationId definition)
(not= :options method))
:let [parameters (group-by :in (:parameters definition))
:let [parameters (group-by (comp keyword :in) (:parameters definition))
body (process-body (:requestBody definition) components (:encodes content-types))
responses (process-responses (:responses definition) components (:decodes content-types))]]
{:path-parts (vec (tokenise-path url))
Expand Down
55 changes: 55 additions & 0 deletions core/test-resources/openapi2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"openapi": "3.0.1",
"info": {
"title": "My API",
"version": "1"
},
"paths": {
"/project/{projectKey}": {
"get": {
"summary": "Get specific values from a configuration for a specific project",
"operationId": "getProjectConfiguration",
"parameters": [
{
"name": "projectId",
"in": "path",
"description": "Project ID",
"required": true,
"schema": {
"type": "string",
"format": "string"
}
},
{
"name": "key",
"in": "query",
"description": "Obtains values corresponding to these keys from a project's configuration",
"schema": {
"type": "string",
"format": "string"
}
}
],
"responses": {
"200": {
"description": "Configuration for the specified project",
"content": {
"application/json": {
"schema": {
"type": "string",
"format": "string"
}
}
}
},
"403": {
"description": "Refusing access to requested resource, perhaps due to insufficient privilege"
},
"404": {
"description": "Requested resource was not found"
}
}
}
}
}
}
25 changes: 25 additions & 0 deletions core/test/martian/openapi_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,28 @@
(->> (filter #(= (:route-name %) :update-pet)))
first
(select-keys [:consumes :produces]))))))

(deftest openapi-parameters-test
(testing "parses parameters"
(is (= {:description nil,
:method :get,
:produces ["application/json"],
:path-schema {:projectId s/Str},
:query-schema {(s/optional-key :key) s/Str},
:form-schema {},
:path-parts ["/project/" :projectKey],
:headers-schema {},
:consumes [nil],
:summary "Get specific values from a configuration for a specific project",
:body-schema nil,
:route-name :get-project-configuration,
:response-schemas
[{:status (s/eq 200), :body s/Str}
{:status (s/eq 403), :body nil}
{:status (s/eq 404), :body nil}]}
(-> (parse-string (slurp (io/resource "openapi2.json")))
(openapi->handlers {:encodes ["application/json" "application/octet-stream"]
:decodes ["application/json" "application/octet-stream"]})
(->> (filter #(= (:route-name %) :get-project-configuration)))
first
(dissoc :openapi-definition))))))

0 comments on commit 28146b5

Please sign in to comment.