Comments (13)
Hello,
Thanks for reporting this. Could you attach the edn and yaml files please?
Thanks
from martian.
Had to change the extensions of the files to .txt
to get github to allow the upload.
The internal oas-edn
was created by (yaml/parse-string (slurp "sponsored-products-yaml.txt"))
.
The edn file was created by (spit "sponsored-products-edn.txt" oas-edn)
.
sponsored-products-yaml.txt
sponsored-products-edn.txt
from martian.
On taking a closer look, it seems that the EDN that is generated from the YAML may be faulty.
For example, the following YAML snippet
/v2/sp/campaigns:
post:
tags:
- Campaigns
operationId: createCampaigns
summary: Creates one or more campaigns.
parameters:
- $ref: '#/components/parameters/clientHeader'
- $ref: '#/components/parameters/profileHeader'
requestBody:
description: An array of campaigns.
content:
application/json:
schema:
type: array
minItems: 0
maxItems: 100
items:
$ref: '#/components/schemas/CreateCampaign'
responses:
207:
description: Success.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/CampaignResponse'
401:
$ref: '#/components/responses/Unauthorized'
put:
tags:
- Campaigns
operationId: updateCampaigns
summary: Updates one or more campaigns.
parameters:
- $ref: '#/components/parameters/clientHeader'
- $ref: '#/components/parameters/profileHeader'
requestBody:
description: An array of campaigns with updated values.
content:
application/json:
schema:
type: array
minItems: 0
maxItems: 100
items:
$ref: '#/components/schemas/UpdateCampaign'
responses:
207:
description: Multi-status. An array of campaign response objects reflecting the same order as the request.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/CampaignResponse'
401:
$ref: '#/components/responses/Unauthorized'
get:
tags:
- Campaigns
operationId: listCampaigns
summary: Gets an array of campaigns.
parameters:
- $ref: '#/components/parameters/clientHeader'
- $ref: '#/components/parameters/profileHeader'
- $ref: '#/components/parameters/startIndex'
- $ref: '#/components/parameters/count'
- $ref: '#/components/parameters/stateFilter'
- $ref: '#/components/parameters/name'
- $ref: '#/components/parameters/portfolioIdFilter'
- $ref: '#/components/parameters/campaignIdFilter'
responses:
200:
description: Success.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Campaign'
401:
$ref: '#/components/responses/Unauthorized'
404:
$ref: '#/components/responses/NotFound'
results in the following EDN snippet
[:/v2/sp/campaigns
{:post
{:tags ["Campaigns"],
:operationId "createCampaigns",
:summary "Creates one or more campaigns.",
:parameters
[{:$ref "#/components/parameters/clientHeader"}
{:$ref "#/components/parameters/profileHeader"}],
:requestBody
{:description "An array of campaigns.",
:content
#:application{:json
{:schema
{:type "array",
:minItems 0,
:maxItems 100,
:items
{:$ref
"#/components/schemas/CreateCampaign"}}}}},
:responses {nil {:$ref "#/components/responses/Unauthorized"}}},
:put
{:tags ["Campaigns"],
:operationId "updateCampaigns",
:summary "Updates one or more campaigns.",
:parameters
[{:$ref "#/components/parameters/clientHeader"}
{:$ref "#/components/parameters/profileHeader"}],
:requestBody
{:description "An array of campaigns with updated values.",
:content
#:application{:json
{:schema
{:type "array",
:minItems 0,
:maxItems 100,
:items
{:$ref
"#/components/schemas/UpdateCampaign"}}}}},
:responses {nil {:$ref "#/components/responses/Unauthorized"}}},
:get
{:tags ["Campaigns"],
:operationId "listCampaigns",
:summary "Gets an array of campaigns.",
:parameters
[{:$ref "#/components/parameters/clientHeader"}
{:$ref "#/components/parameters/profileHeader"}
{:$ref "#/components/parameters/startIndex"}
{:$ref "#/components/parameters/count"}
{:$ref "#/components/parameters/stateFilter"}
{:$ref "#/components/parameters/name"}
{:$ref "#/components/parameters/portfolioIdFilter"}
{:$ref "#/components/parameters/campaignIdFilter"}],
:responses {nil {:$ref "#/components/responses/NotFound"}}}}]
Note that the response status codes are missing.
from martian.
Yes, those nil status codes correspond to the exception that's being thrown.
from martian.
Thanks. That addresses the NPE.
from martian.
I was able to generate EDN from the YAML that was acceptable to martian
. To help anyone wanting to add built-in YAML support for martian
, here is what I needed to do.
(require '[clj-yaml.core :as yaml])
(require '[martian.core :as martian])
(require '[martian.hato :as martian-http])
(require '[martian.openapi :as openapi])
(require '[clojure.walk :as w])
(defn cleanup
"Clean up the EDN returned by clj-commons/clj-yaml
to be compatible with what martian expects."
[edn]
(w/postwalk (fn [x]
(cond
;; replace all LazySeqs with Vectors
;; See https://github.com/clj-commons/clj-yaml/pull/18
(and (seq? x) (not (vector? x)))
(into [] x)
;; make sure all the keys of maps are keywords, including keys that were numbers
;; See https://github.com/clj-commons/clj-yaml/blob/master/src/clojure/clj_yaml/core.clj#L128-L129
(map? x)
(into {} (map (fn [[k v]] [(or (keyword k) (if (number? k) (keyword (str k)) k)) v]) x))
;; otherwise do nothing
:else
x))
edn))
(defn yaml->edn
"Convert a YAML OpenAPI Spec to EDN compatible with martian."
[url]
(-> url
(slurp)
(yaml/parse-string)
(cleanup)))
(let [sp-url "https://d3a0d0y2hgofx6.cloudfront.net/openapi/en-us/sponsored-products/2-0/openapi.yaml"
edn (yaml->edn sp-url)
base-url (openapi/base-url edn)
m (martian/bootstrap-openapi base-url edn martian-http/default-opts)]
(martian/explore m))
from martian.
If you'd like a PR that handles YAMP OpenAPI specs for just CLJ clients, I'm happy to make one based on the above comment.
from martian.
Hi @bombaywalla ,
Thanks for your work on this. I'd be happy to accept a PR, you could make a new namespace called martian.yaml
in the core/src directory.
Thanks
from martian.
I'm presuming you want a martian.yaml
cljc
file but one that will (currently) only work for CLJ.
If something different, let me know.
from martian.
Hi,
You might as well make it a clj file if it won't have any public cljs fns, makes it clearer how to use it.
Cheers
from martian.
Okay.
from martian.
Very keen to see yaml working. It seems many apis only publish yaml. Xero accounting api for example
https://raw.githubusercontent.com/XeroAPI/Xero-OpenAPI/master/xero_accounting.yaml
Converting such a huge api to edn seems like a lot of room for translation errors.
from martian.
Added in #132 and available in 0.1.21-SNAPSHOT
from martian.
Related Issues (20)
- Hato support HOT 2
- martian-httpkit defaults to async HOT 3
- Support OpenAPI 3 servers specification HOT 6
- Make schema backend pluggable too HOT 1
- disallowed-key / missing-required-key bipolar schema validation errors involving a path param HOT 9
- api list HOT 7
- pagination HOT 2
- `response-for` gives me `nil` HOT 2
- How do I set withCredentials header? HOT 3
- How to HOT 7
- no routes found for my swagger OpenApi 3.0 definition HOT 2
- parameter not found in specific url HOT 2
- Automatically handle application/vnd.blah.foo+json custom content types HOT 3
- Martian could be more specific in the schemas HOT 1
- Add support for string format "date-time" leaf schema HOT 3
- Custom `:parameter-aliases` HOT 2
- Not an issue with martian; just don't know what I'm doing. HOT 2
- Can't get `respond-with-generated` or `response-generator` to work. HOT 3
- `response-for` returns `nil` HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from martian.