-
Notifications
You must be signed in to change notification settings - Fork 69
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
Improve swagger docs support #287
Conversation
I'll mark as draft, just because I would need to update doc but will only do so when we agree on the UI to build the swagger http4s route |
This looks great ! To improve the UX, we can use the
That wouldn't be breaking the sources of most current usage I think. |
ce53475
to
a372893
Compare
@@ -28,5 +28,5 @@ trait TestCompat { self: BaseIOSuite => | |||
} | |||
|
|||
def docs(path: String) = | |||
Docs[IO](service, path, swaggerUiPath = "swaggerui") | |||
Docs.multiple[IO](path, swaggerUiPath = "swaggerui")(service) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might as well remove the multiple
method altogether and just document the new way of wiring things up 😄
Also we might want to make the swaggerUiPath
configurable in the PartiallyApplied construct
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we might want to make the swaggerUiPath configurable in the PartiallyApplied construct
I started doing it, but I found that cumbersome. I figured, if someone needs to go all the way down and customize the swagger ui, they can use Docs.build[IO](path, swaggerUiPath = "swaggerui")(service)
like in this TestCompat
note build
is the new name I used instead of multiples`
will update the docs, but not much has changed from a user point of view
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will update the docs, but not much has changed from a user point of view
A screenshot of the drop-down menu added to the docs would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that
Updated docs: updated: see below |
Right, so great work 👍 , but I'm gonna nitpick at the fact that there are too many ways to create doc routes. Comments incoming |
@@ -50,21 +55,19 @@ private[smithy4s] object Compat { | |||
} | |||
|
|||
trait DocsCompanion extends SwaggerUiInit { | |||
def apply[F[_]]( | |||
hasId: HasId, | |||
def build[F[_]]( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should disappear plainly and simply in favour of "smart-setters" in the PartiallyApplied
construct.
val docs = Docs[F](hasId, path) | ||
docs.routes | ||
def docs: PartiallyAppliedDocs = new PartiallyAppliedDocs("docs") | ||
def atPath(path: String): PartiallyAppliedDocs = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should disappear plainly and simply in favour of "smart-setters" in the PartiallyApplied
construct.
def atPath(path: String): PartiallyAppliedDocs = | ||
new PartiallyAppliedDocs(path) | ||
|
||
class PartiallyAppliedDocs(path: String) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should receive smart setters to virtually "mutate" (read, immutable copy) of the path
value and the swaggerUiPath
value. The apply
method should be the last thing the user call and should create the HttpRoutes
Additionally, it'd be great if some tests could be added to exercise the smart setters, in order to ensure that the API is the same across CE versions. The only thing that needs specialisation (in tests) is the creation of the PartiallyApplied
, which should require a Blocker
in CE2. The rest can be CE-version-agnostic
PermanentRedirect( | ||
Location(Uri.unsafeFromString(s"/$path/index.html?url=/$jsonSpec")) | ||
) | ||
Found(Location(Uri.unsafeFromString(s"/$path/index.html"))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious (and also somewhat illiterate when it comes to 3xx statuses) : can you tl;dr the "why" of changing the status ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it because 308 is cached very aggressively (forever) and thus you can't change a redirect afterwards. But I can revert that, I don't have an opinion on the matter. On quick look at MDN suggest that it's mostly for SEO purposes.
In my case, it was annoying because I had run a smithy project locally before, accessed the docs (for say PizzaAdmin) and now my browser was always redirecting me to this old url with pizza spec in it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes total sense, thanks !
@daddykotex I made some changes to improve the UX a little, but it's great work 👍 |
@@ -520,32 +520,6 @@ lazy val `http4s-swagger` = projectMatrix | |||
) | |||
.http4sJvmPlatform(allJvmScalaVersions, jvmDimSettings) | |||
|
|||
lazy val `doc-check` = projectMatrix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh crap, I forgot to remove my test module loll
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no worries :)
Ahhh, two interesting things:
thanks |
Address: #150
Also address a security issue with the
url
query param that was previously required.The result looks like:
![Screen Shot 2022-06-30 at 10 41 39](https://user-images.githubusercontent.com/5230460/176761371-ca769700-aab5-4631-9f18-c64f7354f182.png)
![Screen Shot 2022-06-30 at 10 41 53](https://user-images.githubusercontent.com/5230460/176761372-1234a218-1b36-430f-89dd-64d83d2571a2.png)
![Screen Shot 2022-06-30 at 10 42 03](https://user-images.githubusercontent.com/5230460/176761373-a0403f4f-2e59-4973-af57-518d35c6cb7d.png)
I'm still unsure about the user experience around
smithy4s.http4s.swagger.multipleDocs[IO](HelloWorldService, PizzaAdminService)(path = "docs")
Let me know what you think