-
Notifications
You must be signed in to change notification settings - Fork 427
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
Allow documentation for individual case class properties #247
Comments
I think an optional Then you could add a custom |
I'd love to see this feature implemented too. |
I want a Regarding |
It would also make sense to support several concrete types more like Furthermore it would be cool to support extracting information from possibly used refined types to fill the |
@leonardehrenfried did you start implementing this (it would greatly improve documentation quality for frontend devs)? |
I have not. As there are many ways in which this could be implemented, with a wide variety of compatibility and complexity concerns, I'd like to get a rough guide from the maintainers before I start an implementation. @lukoyanov I guess you can give this a go and see what the response to your suggestion is. A PR often stimulates the decision making progress. |
I don't have a good idea how to implement this yet. I'm sure it would bring in larger changes to the current Schema/SchemaFor structure. As it is now, a (we could add meta-data to Going even further, we could experiment with enriching schemas even more, so that we are able to generate whole codecs out of them. But that's more of a research topic :) |
Of course, would be great to hear other ideas! In the form of comments or PRs, though I can't promise they'll get merged ;) |
Caliban utilizes magnolia for schema derivation with support for class/field description via custom annotations: |
Here's my proposition. First, a definition:
A schema is one of the following: a basic schema (string, int, number, boolean, date, ...), an array, binary, object (product / coproduct / open product) or a reference to an object (for recursive schemas). The representation isn't far away from what we have today, with the main difference being that we get rid of Apart from the information that schema carries with its type, it contains:
So we would have, for example, a In case of custom wrapper types, e.g. Customising schemasTo customise schemas, all of the built-in implicits (including the ones generated by magnolia) would be wrapped in a So to customise a schema for a given type, you could do:
While you could add field-level customisations this way, it could be cumbersome. That's why we would also introduce a quicklens/diffx-style API for modifying a nested schema, e.g.:
Specifying the path would be a macro, which would translate this into the appropriate operations on the parent Relationship with validatorOne of the philosophical questions is, should the validator be part of the schema? Should we derive json encoders/decoders from the schema? Both sound tempting. But I think it's worth keeping the divide. On the "cons" side, we have the duplicate recursive logic of building up validators/schemas/encoders for composite types. On the "pro" side however, we have a clear division of responsibility:
Hence, a validator can influence the schema; the high-level description of the possible values can narrow down the format of the low-level representation, for example. However, not the other way round - it's not generally possible to derive a validator from a schema. Let's consider the Why not annotationsAdding |
Before we start implementing the above, would be great to hear if you see any show-stoppers in the above! |
I usually like annotations to add a description to each product member for ergonomics, but your proposal sounds great to provide a solid, composable ground first.
|
On a first glance I have no objections. I really like the idea of providing a "customisation api". On the other hand it might be sufficient (and may reduce implementation cost) to just provide documentation/instructions/examples on how to tackle such problems using optics. Currently I'm leveraging monocle for this but it ain't easy. |
@jan0sch yes, the path-based api would be a nicer syntax for optics. The problem here is that at the level of schemas we are dealing with string-based representation of the class (field maps: So the path would translate to navigating these structures and updating them appropriately. We can probably also provide a mid-level API as in diffx:https://github.com/softwaremill/diffx/blob/master/core/src/main/scala/com/softwaremill/diffx/Diff.scala#L14 |
It never ceases to amaze me how many really cool projects you softwaremill people have in the wild. :-) |
I've started working on this, see https://github.com/softwaremill/tapir/compare/schema2?expand=1 In the end the main abstraction is now |
Released in 0.12.0 (without the macro, yet - #295) |
Right now it is not possible to add descriptions to individual fields of JSON body responses.
To us that would be highly desirable as it would allow us to explain to the reader the meaning of the field and not just the OpenAPI type and format.
If you are not sure what I'm talking about, here is a screenshot of a Redoc-powered rendering of the OpenAPI YAML.
The red boxes show where the property's
description
would be rendered.I can imagine a couple of places were this information could be retrieved from:
@param
tags (probably not available but would nevertheless be great)Schema
implicit instance, but would have to add a data structure to put the information inIt's quite likely that if an implementation strategy is agreed, I can contribute this.
The text was updated successfully, but these errors were encountered: