mirror of
https://github.com/axllent/mailpit.git
synced 2026-04-26 16:56:00 +03:00
[GH-ISSUE #65] OpenAPI / Swagger schema #40
Labels
No labels
awaiting feedback
bug
docker
documentation
enhancement
github_actions
invalid
pull-request
question
stale
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/mailpit#40
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @PaoloC68 on GitHub (Mar 13, 2023).
Original GitHub issue: https://github.com/axllent/mailpit/issues/65
One of the reason for which I arrived to this project is because I was frustrated by the fact that after having built a client for Mailhog based on the schema file I had to discover that the provided schema was in no way matching the reality, making me just waste time.
I am not a go programmer, I mostly use Python and Django and as such I find very convenient the automated schema generation. It seems that there is something similar for Go projects that generates the schema parsing the code as explained here.
Maybe somebody can take a look. It would help a lot such schema so automatically could be generated API clients for MailPit in the most wide range of programming languages.
Here an example on how to comment the code so that the schema can be generated and kept in sync with the code.
@axllent commented on GitHub (Mar 14, 2023):
Hi. Does the existing API documentation not provide you with the information you require? I realize that you would prefer something you can import to save you time, however a) that would take me hours to learn, b) take me hours to create, and c) I don't use swagger so I could not test / verify it.
I welcome a PR from anyone with knowledge of swagger who is willing to spend a lot of time (re)documenting inline all the methods and responses, but I won't be writing it myself, sorry.
@PaoloC68 commented on GitHub (Mar 14, 2023):
I totally understand your point, as you know in our area you never stop to learn.
As a fellow programmer I strongly recommend you to have a look into the OpenAPI specs which are also followed by swagger.
Allow me to quote the brief description of what are the OpenAPI Specifications:
I think that is fair to say that nowadays every project that exposes an API should expose an OpenAPI schema. I understand that you may not have time at the moment, just keep it in mind whenever it happens to you to do some API work.
I hope that you don't take that as a critique but is just a friendly and respectful suggestion.
Cheers!
@axllent commented on GitHub (Mar 19, 2023):
Thank you for your input. As I expected, it has taken me several (far more than I'd like to admit) hours to try understand and generate the swagger JSON & yaml configs (not yet committed to git), but I need some input before I push my changes. Given your request for this, I assume you use swagger often, and so you should be able to answer the following questions I have:
How is a swagger config file supposed to be accessed / loaded? Is it simply accessed via a Github repo, or should it be accessed via the Mailpit server (eg:
http://localhost:8025/swagger.json)?Is there a default location within a repository for the swagger configs?
Although I am able to generate a config of all API routes and models (using go-swagger / inline comments), which can be parsed without errors using the official swagger-editor, I must admit that the built in swagger-editor's "generate client" (Swagger Codegen) functionality produces a lot more code than I was expecting, but maybe that's the side-effect of a one-show-fits-all solution like swagger. Your mileage may vary of course, and who knows, maybe this is expected.... With this said, once I can get a better understanding of where I'm supposed to put the configs, I'm likely going to need you to do some testing and provide feedback before any of this makes it way into production.
So if you can please give me some info re: my questions above that would be great, thank you.
@axllent commented on GitHub (Mar 25, 2023):
@PaoloC68 Would you mind please getting back to me on my previous questions? Thank you.
@nosovk commented on GitHub (Mar 29, 2023):
Unfortunately "generate client" is almost never used, but in common swagger is a good way to document your's API.
You can get something like https://rapidocweb.com/ and get https://app.mailcheck.co/docs in 10 lines of code
@axllent commented on GitHub (Mar 29, 2023):
Thanks @nosovk . I guess what has me most confused at this point is that these Swagger web UIs have a "try" button, however Mailpit is presumably (but not necessarily) running local. Does this mean that the swagger.json file should be included in the HTTP server and accessed via (for example)
http://localhost:8025/swagger.json, or are they simply loaded by a developer regardless where in the source code the swagger.json is located, and developers don't usually use the "try" feature because it doesn't work most of the time?You see, I just don't know what "swagger users" expect exactly. Sure I can create a swagger.json, but if it isn't implemented in a useful manner then there is no point. I am just trying to get some clarity (some of which you already provided, so thank you).
@nosovk commented on GitHub (Mar 29, 2023):
You are correct when say that swagger.json should be served as a static file from an included HTTP server. In most cases we expect good documentation with examples (is you use open API v3 there could be some examples inside doc, like typical request\response etc).
Good reference is a doc link I mentioned before. There are static openapi.json and nice web ui to read it.
@axllent commented on GitHub (Mar 30, 2023):
I'm afraid to say it, but I'm still quite lost as to "what next". I am currently using go-swagger locally to generate a Swagger 2 / OpenAPI 2.0 file - that appears to work fine, and outputs a valid swagger.json (and yml) file based off code comments I have in my local branch. I can then open that physical spec file successfully via swagger-editor (using their Docker image), and that results in the following:

It contains the methods, the required and optional parameters, and expected response structures.
I have then tried serving the swagger.json via the Mailpit HTTP server, and I can access that file via my browser without issues, however I cannot seem to load it successfully via any of the tools (that I have tried) because that appears to expect the http server to be publicly available (internet) which it obviously isn't. I also can't "test" ("try") the API via swagger-editor because it keeps trying "localhost" on the same port as the swagger-editor is running. If I try load http://:8025/swagger.json` using swagger-editor (or swagger-ui) I get generic errors.
So I have generated the schema, but I am really not sure what to do now, if anything. I guess my question is, do I really need to do anything? As I mentioned in previous messages here, I do not use swagger myself (nor do I plan to), so this is new to me. I am just trying to satisfy users such as yourselves by providing documentation as to how to use the API (ie: swagger), but I feel I'm either missing something, or there is now a lot more I need to do in order for anyone to actually use this.
I have the spec json/yaml file, it can be served via the Mailpit server - what now? I am not looking to create more work for myself, but I'd like this to usable by developers such as yourself (else all the hours I have put in was all for nothing).
@nosovk commented on GitHub (Mar 30, 2023):
Try to add something like that doc.html into server near the swagger.
You may see that it will consume /swagger.json from local go http server
@axllent commented on GitHub (Mar 31, 2023):
@nosovk thank you so much, this helps more than you can imagine! I have it working very nicely via the base of the API route (
http://0.0.0.0:8025/api/v1/), and it is able to "try" all the endpoints successfully (provided they can valid parameters of course). This is awesome, thank you for your help. I will release a new version soon that will include this.@axllent commented on GitHub (Mar 31, 2023):
Swagger / OpenAPI documentation has now been released as part of v1.5.0. Please give it a test and let me know if this is suitable? Thank you.
@PaoloC68 commented on GitHub (Apr 2, 2023):
@axllent Sorry for not getting back ton you earlier, I was really busy, I appreciate the effort you have done and as soon as tt will fit in my schedule I will give a try!
Thank you!
@axllent commented on GitHub (Apr 21, 2023):
I'm closing this issue as it has been three weeks since the swagger documentation was released.