-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Tags side menu with markdown and object description #681
Tags side menu with markdown and object description #681
Conversation
Brilliant! Would love for this to get merged. But could it make more sense to use e.g. |
The That is why it not prefixed with an Additionally, sub-menus are created out of markdown headings so you could create richer endpoint menus with additional info beside endpoints. Frankly, I don't know if tags are rendered if there are no endpoints inside them, but that should be an easy fix. I am open to suggestions proposals n how to make this more useful. |
Can you give an example of how the tag/object is rendered? |
You could clone this branch and run the demo. They render as the same way as responses, not unlike what stripe does. :) |
Sorry, I'm not proficient in JS development. I have node installed, but I have no idea how to run the demo. If it's just a matter of running a few commands, could you give me the commands to run? |
Sure, here is a step-by-step guide : # clone ( my fork ) repository
git clone https://github.com/eCollect/ReDoc
# change to repository directory
cd ReDoc
# switch to this feature branch
git checkout tags-side-menu-and-object-description
# in case you don't have it, install yarn globally
npm i -g yarn
# install project dependencies - might take a minute or so
yarn install
# run the demo - might take a minute or so
yarn run start Then you open your browser at http://localhost:9090. Under Pet and Store you could see submenus "The Pet Object" and "The Store Object", this is more or less it. I know notice an annoying spacing issue on the menu side which should be fixed, but the idea is pretty much the same. |
I get an error on
|
Ah, Windows... :/ I guess you have an old node version. I am not sure about how one may update his node on windows ( just downloading binaries ? ), an update ( and reopening terminal ) should do it. |
Sorry for not looking into this. Super busy recent days 🙀 |
Other build problems occurred. Likely nothing that can't easily be fixed, but I'll pass on the demo from this PR as it's only to satisfy my curiosity. I'm super looking forward to this being merged/implemented in some form or another; I can probably shave my yaml files in half since I currently have duplicated the schema definitions as manual markdown tables in the tag descriptions. |
I've deployed an online demo. |
Wow, thanks! It looks very good. Does it also render the object description, if any? |
Also, what does it do regarding properties that are read-only and write-only? I suggest it should show both (since they're part of the object and it's rendered outside any request/response context), but that the members should be marked read-only or write-only. |
To answer your both questions. Does it also render the object description, if any? As it is injected with markdown, you could write any description you wish ( actually rendering the root object description might be an idea, need to take a look ). What does it do regarding properties that are read-only and write-only? It renders the same thing, as if this schema is used in response, this means it is omitting write-only options ( a those are, normally, a prat of the request, not the model ). |
Thanks! I suggest allowing the user to render both read-only and write-only properties, if desired. I really need that in order to use this feature. As you say, normally that property would be part of a request and not a model, but there are exceptions, such as when following the JSON-API standard which is fairly strict about everything needing to be part of a resource. A good example of a write-only property is a (One could argue exactly how to represent password changes in an API and how the choice of JSON-API vs. another standard influences that; that is besides the point here. I'm just saying there are valid use-cases requiring write-only properties as part of the conceptual model, which should be shown in the model rendering. And for APIs already in production, the discussion would be a moot point anyway.) Furthermore, I strongly suggest that read-only and write-only properties are marked in some way, e.g. in the same way as |
So I have added showReadOnly and showWriteOnly options ( the default is to show readOnly and not to show writeOnly ). |
Brilliant, thanks! Really looking forward to this 😊 |
The ability to print an object would be amazingly useful to me. Hopefully @RomanGotsiy can get to it soon! |
It would be useful to not only have a tag where I can specify one object to be rendered but also a tag (maybe "just" without What do you think and do you think that this should be part of this PR or a separate one? :) |
Technically it is not a problem to implement this, the question which exact "objects" ( ie. schemas ) should the tag render. As the "components/schemas" section contains all the schemas ( including ones that are only referenced by others but not used directly, or even unused ones ), the list of the schemas is really specific. Additionally you may want those schemas in a certain order, which again needs to be setup somehow. I think it is a lot easier, and makes more sense, to get this generated programmatically on side that generates the specification, or be done manually. |
Aside from the assumedly trivial |
@RomanGotsiy Is this waiting for anything in particular? |
@RomanGotsiy any change of merging this soon? |
+1 for this. It gives exactly the result I'm after. Just a thought. Any reason why doing it this way round, rather than putting a custom extension on the schema of the form x-schema-tags or whatever that then causes it to be rendered like an operation would? I need the result that this gives me though, so I'll use a fork with this in it for now. |
@tomq42 Could you explain you idea more in detail, as I am not really sure I get it. My idea was to leave it as free as possible in order to give the user ( ie. schema owner ) the freedom to structure his documentation as needed. |
@nanov What I had looked for when I didn't realise I could do this to start with, was the ability to just put a tag on a schema. So the normal "operations" part of the output is built by listing the paths and method to get the operations, and then matching the "tag" values on each of those with the tags definition list (don't know which way round it goes, but my guess is it lists through /tags, then for each one lists through /paths and the contained operations and renders any that have a matching tag in their tags array). What I naively tried was to do exactly the same, but put a tag on a schema in /components/schemas. However, the OpenAPI spec doesn't allow tag on a schema, but does allow extensions, so you could use a custom extension "x-schema-tag" or whatever. This seems to most closely follow the way that the operations are rendered. My guess is that within each tag section it would render operations first, then render schemas. It would just list through /components/schemas in the same way it lists through /paths, and render the schemas that are tagged with the current tag in the same way it renders the operations tagged with the current tag. I can then choose to create a tag for just schemas, or I can mix then with the relevant operations. |
I am more in favor of the existing approach in this PR, which allows placing a tag exactly where one wants it in any description (e.g. in a tag description). |
@RomanHotsiy let me know if you need any assistance ;) |
@nanov I am thinking about renaming the component.
? Personally, I prefer |
In my opinion it should definitely be something with I would say |
Great job @nanov! Sorry for so huuuge delay! It will be released later this week. |
Fantastic, can't wait! Will you add a note to the readme also on how it can be used? |
Accidentally released it with wrong component name in rc.11 🙈 Fixed it in I will add docs later. Although, PR with README docs would be appreciated 🙏 |
@nanov Could you just briefly describe basic usage? |
Sure! We could basically split it into two parts. Adding submenus inside tag descriptionsOne could build richer menus by adding (markdown) headings into tag descriptions. Basically it's the same functionality as in the main Example usage: - name: store_model
x-displayName: The Order Object
description: |
The order objects contains all the needed information about your orders
## Late Orders
Late orders are marked with a dedicated flag Injecting Schema DefinitionsThe ability to inject desired schema (model/object) definitions into tag descriptions trough a dedicated The tag accepts the following properties :
Example usage:minimal:
full
|
Thanks, it's working great! Would it be possible to add an option for auto-expanding child objects to some desired level? Even just one level would work great for e.g. JSON-API resources, since then the attribute, relationship, and link names would be visible and searchable by Ctrl-F (I know our API client devs use Ctrl-F to find stuff in the docs, which won't work if it's not expanded). |
I am afraid this is out of the scope of this ( already merged ) PR, but I think you'll find a solution here. |
@RomanHotsiy , @nanov - I'm not sure if this is addressed anywhere, but schemas with an external reference in allOf are not displaying (they show up blank). Can you let me know who I need to talk to on this? Thanks! |
@wyau7 could you post your schema, or in ideally a repro. |
@nanov - here's an example schema (located in a file called producer.yaml). I couldn't get the format to work in the comment, but the formatting is correct in the file. :) Producer: |
could you share your full schema? ** EDIT ** |
|
@nanov - let me know if you need more information - thanks! |
Thanks. Is there any way of doing this by inputting JSON instead of YAML? |
I noticed that the description of the schema object itself (the description at the root level of the schema) is not rendered when using the Would it be possible to add this? If I (as a user) am looking at the existing schemas in the API, I would also want to see the descriptions for them. Right now, as a workaround, I am copy-pasting the description in question next to the Maybe another option for the tag could be added for this? Something like EDIT: |
@Blacklands this is tracked in #720 |
@RomanHotsiy Apologies, I completely missed this issue. I even checked for other issues about this but I managed to overlook this one. Thank you! |
What is the current intended way to display models in generated docs without using React component? |
Is there an example of how this can be used with a json schema? Really new to redoc, but I'd love to have this feature added to a project. (never mind I just took the petstore example yaml file and converted it to json. You can see how it's used that way). |
I had the exact same issue, and I've cracked it. You need to escape the quotes with
|
Pretty quick workaround to be able to add additional side menu sections to tags, in the same manner it is done in the info description object.
Also an component was added which prints a referenced object/schema, and optionally a referenced example.
Combining both one may achieve similar structure to the one Stripe uses for their own documentation.