Skip to content
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

incorrect rendering of s/tuple and vector? #327

Closed
carocad opened this issue Jul 24, 2017 · 5 comments
Closed

incorrect rendering of s/tuple and vector? #327

carocad opened this issue Jul 24, 2017 · 5 comments

Comments

@carocad
Copy link

carocad commented Jul 24, 2017

Hey guys,
I am using the alpha-5 version of compojure-api with spec-tools 0.3.0. It is a great tool. Thanks so much for it.

I think I found a bug in the way the response object is displayed in swager. In our case we have two specs definitions that include a s/tuple and a vector?. In both cases they are rendered as [{}].

In the case of a tuple, it should be rendered as [0 0].

In the case of vector? I think a simple [] would suffice.

Below are the specs definitions of the tuple and vector?

Here is a link to our swagger api. If you check the model tab you can also see that the elements that use the tuple and vector?, are rendered as inline-model-, not with their respective model names.

Thanks in advance and let me know if I can help you somehow. Hope it helps

@ikitommi
Copy link
Member

Hi,

and thanks for the detailed setup!

tuple

https://github.com/metosin/spec-tools/blob/5b4f7a8891f71ef93051ef74023e4465e504493e/src/spec_tools/swagger/core.cljc#L44-L48

As Swagger doesn't support heterogeneous lists, the current implementation converts to "array of anything" (with full info as vendor extension), which renders poorly on the UI. If all the tuple-elements are of same type, we could use that as the type. Also, as it could set the :minItems and :maxItems to the number of the elements in the tuple. Would you like to do PR of this for spec-tools?

vector?

Does not contain type information and as the type is mandatory in Swagger (https://swagger.io/specification/#itemsObject), we have to use "anything", which is {} in JSON Schema. To get typed arrays, you can use (s/* integer?) instead. Or actually (s/spec (s/* integer?)) to make it a real Spec instead of an RegEx.

hope this helps.

@ikitommi
Copy link
Member

One more thing, Swagger supports setting examples and spec-tools allows any extra data to be passed in to the generated JSON Schema with spec records with :json-schema prefix:

(st/spec
  {:spec (s/tuple int? int?)
   :json-schema/example [0 0]})

@carocad
Copy link
Author

carocad commented Jul 24, 2017

hi @ikitommi, I am not very familiar with the code of spec-tools. I will see what I can do but cannot promise much to be honest. Hopefully it is an easy fix :)

@ikitommi
Copy link
Member

No worries and ping if you have time for this and need help. My link to the code is a good place to start and most likely, the only place you need to touch besides the tests for it. Spec-tools has good test coverage, so after changing the code, the tests should guide you to write new ones. The children argument holds the transformed child values.

@ikitommi
Copy link
Member

Closing this one, added issue to spec-tools for the improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants