Fork me on GitHub
#reitit
<
2021-03-09
>
Matheus Moreira13:03:03

Hello! When using reitit + malli (coercion) + Swagger integration, is there a way to tell Swagger what is the type of a certain schema attribute? I used to have models with optional attributes defined like [:map [:attribute {:optional true} string?]] and that showed as expected on the Swagger ui (i.e. attribute is not required and has type string). But I had to change the attribute definition to [:map [:attribute [:or nil? string?]]] and now the attribute type is not showed as string anymore on Swagger ui. Is there a way to say what type should appear on the ui, something like [:map [:attribute {:type string} [:or nil? string?]]]?

mynomoto15:03:56

This is an interesting question, not sure of how smart the swagger generator can be.

juhoteperi17:03:31

Not sure if this was answered yet.

(json-schema/transform [:or {:json-schema/type "string"} int? string?]  )
  ;; => {:anyOf [{:type "integer", :format "int64"} {:type "string"}],
  ;;     :type "string"}
Though in this case [:maybe string?] would be more precise than :or. But not sure if it works any better with SwaggerUI. :or generates anyOf json-schema, :maybe generates oneOf.

👍 6
juhoteperi17:03:05

Any properties from schema options with json-schema namespaces are lifted to the resulting json-schema, and override the automatic properties.

Matheus Moreira09:03:45

@U061V0GG2 What is the practical difference between oneOf and anyOf ?

juhoteperi09:03:44

In this case, probably nothing