-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: navi does not support OpenApi operation anyOf
#9
Comments
Yeah navi as of now has support for basic types and their collections. The composite ones are a bit of a challenge to generate malli specs for, given the bit of complexity the openapi parser has. Will take a closer look soon, thanks for raising this! PRs are always welcome! |
thanks for instant response! Oh that would be super! I am also looking at it right now. Yes without this functionality navi is quite limited I suppose. Im looking at the paths right now (let [api-spec (slurp "newopenapispec.yaml") class Parameter {
name: version
in: null
description: Taxonomy version, either number that indicates the version, \"latest\" for latest release, or \"next\" for unpublished changes (requires admin rights)
required: false
deprecated: null
allowEmptyValue: null
style: form
explode: true
allowReserved: null
schema: class ComposedSchema {
class Schema {
type: null
format: null
$ref: null
description: null
title: null
multipleOf: null
maximum: null
exclusiveMaximum: null
minimum: null
exclusiveMinimum: null
maxLength: null
minLength: null
pattern: null
maxItems: null
minItems: null
uniqueItems: null
maxProperties: null
minProperties: null
required: null
not: null
properties: null
additionalProperties: null
nullable: null
readOnly: null
writeOnly: null
example: null
externalDocs: null
deprecated: null
discriminator: null
xml: null
}
}
examples: null
example: null
content: null
$ref: null
}
in: query and I dont see any metadata how to decide if its anyOf, oneOf or allOf, but perhaps I have not understood the problem correctly yet. Thanks again for reply! |
yeah, because there isn't a complete openapi parser for clojure, i need to rely on the java one and it has its non-trivial class structures to comprehend. i will try to see what would be a good way to solve this once i get a bit more time, struggling with work atm. |
Adding in some helpful context from my bit of digging:
|
The |
@taxonomy-man just pushed a4da2a9 with some initial support while i think more about it. Could you test it out? I'm not finalised on the impl details yet. |
This is now on main. |
@lispyclouds oh super nice! Did not think that you would be able to look at it that quick! I will try it out I have been working on this on my side also. I also found the getAllOf, etc and came up with this so far. (defn schema->spec [^Schema schema]
(if schema
(let [types (.getTypes schema)]
(if (= 1 (count types))
(spec schema)
(try
(->> (map (fn [type]
(.setTypes schema #{type})
(spec schema))
types)
(into [:or]))
(finally
(.setTypes schema types)))))
(throw (ex-info "Missing schema" {})))) and I came up with this, which seems to be working so far from my tests (defn schema->spec [^Schema schema]
(cond
(nil? schema)
(throw (ex-info "Missing schema" {}))
(instance? ComposedSchema schema)
(let [cs (cast ComposedSchema schema)
one-of (seq (.getOneOf cs))
any-of (seq (.getAnyOf cs))
all-of (seq (.getAllOf cs))]
(cond
one-of (into [:or] (mapv schema->spec one-of)) ; exactly one
any-of (into [:set] (mapv schema->spec any-of)) ; one or more
all-of (into [:and] (mapv schema->spec all-of)) ; all must match
:else (spec cs)))
(seq (.getTypes schema))
(let [types (.getTypes schema)]
(if (= 1 (count types))
(spec schema)
(try
(->> (map (fn [type]
(.setTypes schema #{type})
(spec schema))
types)
(into [:set])) ; Changed from :or to :set for multiple types
(finally
(.setTypes schema types)))))
:else
(spec schema))) |
Looks good! From what I think, |
I've left out the oneOf impl for now, lemme know if you have a need for it. From what I gather its rather an obscure one and bit weird to implement. Can do a release once you confirm it works for your cases. |
aha , yes you are right, I have not actually tried to run the generated reitit routes, just inspecting the output. Ok so then set Is not correct, as you say :) . Actually it was oneOf that I needed, but I suppose I can go with anyOf instead. Thanks again for your efforts! |
Yeah I'm not quite sure where one would use |
Released in 0.1.0 |
hi!
Thanks for sharing this project, I have the same use case so Im trying it out right now! 👍
I think I have found a bug, and It would be super nice to get it sorted out. I have case where it is possible to send in either a number or two string enums. From my understanding of openApi spec this is valid yaml. https://swagger.io/docs/specification/v3_0/data-models/oneof-anyof-allof-not/#oneof
but in my generated reitit routes the children (the schema options), and an exception is thrown if we try to start web server.
As you can see, the
:version
key here does just contain[:or]
,so when I start web server I get this error
The text was updated successfully, but these errors were encountered: