sourcey / spectacle

Beautiful static documentation generator for OpenAPI/Swagger 2.0
https://sourcey.com/spectacle
Other
1.27k stars 337 forks source link

fix example rendering #198

Closed Damokl3s closed 4 years ago

Damokl3s commented 4 years ago

This fixes an issue we were seeing where large schemas would have missing properties in the examples.

Previously, because options are shared between recursive calls, only a maximum of 100 properties would be rendered in total. (It would be less if $ref are used, because the indirection counts towards the limit).

Since the fix in #190 prevents circular examples from ending in an infinite loop, I removed the "depth" check. I've tested it with the referenced billing.yaml example and it works fine. If you prefer I can leave it in, though since it now truly checks for depth, 100 would be a pretty high limit, so I don't think it adds anything.

Also if the same $ref is used multiple times in the same schema, even if not recursive, it would previously only render the first occurrence.

Here's an example of billing.yaml before and after:

Bildschirmfoto 2020-01-30 um 09 12 11

Notice that id was missing in a lot of places because it is a $ref and is used on the top level already, so it was not render it in nested objects.

Recursive examples like this still work: (Service object which contains a nested Service object + ServicePeriod which has nested ServicePeriod)

Bildschirmfoto 2020-01-30 um 09 13 04
auscaster commented 4 years ago

Looks good, sorry for the wait! Merging now :)

Damokl3s commented 4 years ago

Thanks! No worries.

Would be awesome if you could push an updated version to npm :)

auscaster commented 4 years ago

Just pushed 1.1.0

Damokl3s commented 4 years ago

Awesome, thank you very much!