Openapi-specification: handling a property of Anything

Created on 4 Apr 2014  路  7Comments  路  Source: OAI/OpenAPI-Specification

hi.

With clojure, it's possible to use Any as a field type. How should this be modeled for Swagger?

a pure clojure Schema looks like:

(def Pizza {:id    Long
            :name  String
            :meta  Any}

valid values for Pizza are for example:

{:id 1 :name "kikka" :meta 1}
{:id 2 :name "kukka" :meta nil}
{:id 3 :name "kakka" :meta {:more "stuff" :even {:more "here"}}}

for documentation purposes, it would be great to be able to say for return values "there will be something coming behind property :meta", but don't want to break the swagger-gen-clients if there is no way they can understand it.

All 7 comments

@ikitommi - I think in Swagger 2.0 you can emulate this using the "additionalProperties" attribute of the schema. Does this satisfy your suggestion?

yes, this is how to handle it. thanks!

Could you please paste here some example how it could be modelized in swagger? Maybe I just overlooked something but I still really can't see how to have under one property (in that case called "meta") data with different data type (integer, string, object, ...).

type: object is how you make it "anything".

Hurray, thanks! It's friday afternoon => time to stop thinking and go home...

Hmm, it is a bit strange to assume that type : object allows strings, numbers and booleans, which are not objects in JSON.

(I think swagger-codegen maps this to java.lang.Object, which in deed is "anything".)

My assumption would have been that an empty schema is "anything".

Was this page helpful?
0 / 5 - 0 ratings

Related issues

niquola picture niquola  路  5Comments

muhmud picture muhmud  路  5Comments

john1452 picture john1452  路  5Comments

Prasanthmv picture Prasanthmv  路  4Comments

nomadtechie picture nomadtechie  路  4Comments