[GH-ISSUE #442] Swagger JSON Causes Stack Overflow #285

Closed
opened 2026-03-15 13:40:49 +03:00 by kerem · 9 comments
Owner

Originally created by @melloware on GitHub (Feb 13, 2025).
Original GitHub issue: https://github.com/axllent/mailpit/issues/442

Verified with 1.22.0 and 1.22.2 with two different tools it causes Stack Overflow.

Test it for yourself here online with Kubb: https://kubb.dev/playground

works with 1.21.8: https://raw.githubusercontent.com/axllent/mailpit/refs/tags/v1.21.8/server/ui/api/v1/swagger.json

Fails with 1.22.0: https://raw.githubusercontent.com/axllent/mailpit/refs/tags/v1.22.0/server/ui/api/v1/swagger.json

See also OpenAPI Genertor: https://github.com/OpenAPITools/openapi-generator/issues/20607

Originally created by @melloware on GitHub (Feb 13, 2025). Original GitHub issue: https://github.com/axllent/mailpit/issues/442 Verified with 1.22.0 and 1.22.2 with two different tools it causes Stack Overflow. Test it for yourself here online with Kubb: https://kubb.dev/playground works with 1.21.8: https://raw.githubusercontent.com/axllent/mailpit/refs/tags/v1.21.8/server/ui/api/v1/swagger.json Fails with 1.22.0: https://raw.githubusercontent.com/axllent/mailpit/refs/tags/v1.22.0/server/ui/api/v1/swagger.json See also OpenAPI Genertor: https://github.com/OpenAPITools/openapi-generator/issues/20607
kerem closed this issue 2026-03-15 13:40:55 +03:00
Author
Owner

@melloware commented on GitHub (Feb 13, 2025):

I feel like the infinite loop is here:

    "Triggers": {
      "description": "Triggers for the Chaos configuration",
      "type": "object",
      "properties": {
        "Authentication": {
          "$ref": "#/definitions/Trigger"
        },
        "Recipient": {
          "$ref": "#/definitions/Trigger"
        },
        "Sender": {
          "$ref": "#/definitions/Trigger"
        }
      },
      "$ref": "#/definitions/Triggers"
    },

Triggers refs itself?

EDIT: if I remove the last "$ref": "#/definitions/Triggers" i can now build using both Kubb and OpenApiGenerator.

<!-- gh-comment-id:2657026283 --> @melloware commented on GitHub (Feb 13, 2025): I feel like the infinite loop is here: ```json "Triggers": { "description": "Triggers for the Chaos configuration", "type": "object", "properties": { "Authentication": { "$ref": "#/definitions/Trigger" }, "Recipient": { "$ref": "#/definitions/Trigger" }, "Sender": { "$ref": "#/definitions/Trigger" } }, "$ref": "#/definitions/Triggers" }, ``` Triggers refs itself? **EDIT:** if I remove the last `"$ref": "#/definitions/Triggers"` i can now build using both Kubb and OpenApiGenerator.
Author
Owner

@carolosf commented on GitHub (Feb 13, 2025):

Oddly this test didn't detect a problem:
https://github.com/axllent/mailpit/actions/runs/13219308646/job/36902383782#step:10:21

<!-- gh-comment-id:2657638766 --> @carolosf commented on GitHub (Feb 13, 2025): Oddly this test didn't detect a problem: https://github.com/axllent/mailpit/actions/runs/13219308646/job/36902383782#step:10:21
Author
Owner

@carolosf commented on GitHub (Feb 13, 2025):

Installing go swagger from here on darwin arm64:
https://github.com/go-swagger/go-swagger/releases/tag/v0.31.0

Also says its valid

swagger validate server/ui/api/v1/swagger.json
2025/02/13 20:47:45
The swagger spec at "server/ui/api/v1/swagger.json" is valid against swagger specification 2.0

Tried to generate it with the following but doesn't produce the same swagger.json file

cd mailpit
swagger generate spec -o swagger.json --scan-models --input server/apiv1/swagger-config.yml

@axllent please also document how to generate the swagger file / let us know in this issue

<!-- gh-comment-id:2657686570 --> @carolosf commented on GitHub (Feb 13, 2025): Installing go swagger from here on darwin arm64: https://github.com/go-swagger/go-swagger/releases/tag/v0.31.0 Also says its valid ``` swagger validate server/ui/api/v1/swagger.json 2025/02/13 20:47:45 The swagger spec at "server/ui/api/v1/swagger.json" is valid against swagger specification 2.0 ``` Tried to generate it with the following but doesn't produce the same swagger.json file ``` cd mailpit swagger generate spec -o swagger.json --scan-models --input server/apiv1/swagger-config.yml ``` @axllent please also document how to generate the swagger file / let us know in this issue
Author
Owner

@axllent commented on GitHub (Feb 14, 2025):

This is interesting, please bear with me...

I use the official https://editor.swagger.io/ confirm the swagger.json to validate the generated swagger file is valid (which it does), so this was not picked up as broken. I do however confirm that kubb (I've never used it before) breaks.

Personally I do not use swagger directly, however I do use it to document the API. To make my life a lot easier, I use a tool (go-swagger) to convert structured inline Go comments to swagger. I've often had to spend far more time than I like to admit trying to get the darn thing to work (structured correctly), but it's about the only metric I have to know if it's working and making sense, so I'm glad you reported this.

The downloadable releases of go-swagger are however a bit temperamental (I've had very mixed results), so I built a docker image with a working version of go-swagger which I use to generate the config (this at least gives me consistent results):

docker run --rm -it -u $(shell id -u):$(shell id -g) -v "${PWD}:/source" axllent/go-swagger generate spec -m -i ./server/apiv1/swagger-config.yml -o ./server/ui/api/v1/swagger.json

With hind sight I would have used a different tool from the beginning, however it's difficult to backtrack on all that work, not to mention the potential for breakage if I do, so we are where we are.

Anyway, with the information you have provided, I was able to identify where (not exactly why) the issue was coming from, and have just pushed an update which now validates on both tools. Could you please confirm for me that https://raw.githubusercontent.com/axllent/mailpit/refs/heads/develop/server/ui/api/v1/swagger.json works for you?

Thank you.

<!-- gh-comment-id:2658174309 --> @axllent commented on GitHub (Feb 14, 2025): This is interesting, please bear with me... I use the official https://editor.swagger.io/ confirm the swagger.json to validate the generated swagger file is valid (which it does), so this was not picked up as broken. I do however confirm that kubb (I've never used it before) breaks. Personally I do not use swagger directly, however I do use it to document the API. To make my life a lot easier, I use a tool ([go-swagger](https://github.com/go-swagger/go-swagger)) to convert structured inline Go comments to swagger. I've often had to spend far more time than I like to admit trying to get the darn thing to work (structured correctly), but it's about the only metric I have to know if it's working and making sense, so I'm glad you reported this. The downloadable releases of go-swagger are however a bit temperamental (I've had very mixed results), so I built a docker image with a **working version** of go-swagger which I use to generate the config (this at least gives me consistent results): ```shell docker run --rm -it -u $(shell id -u):$(shell id -g) -v "${PWD}:/source" axllent/go-swagger generate spec -m -i ./server/apiv1/swagger-config.yml -o ./server/ui/api/v1/swagger.json ``` With hind sight I would have used a different tool from the beginning, however it's difficult to backtrack on all that work, not to mention the potential for breakage if I do, so we are where we are. Anyway, with the information you have provided, I was able to identify where (not exactly why) the issue was coming from, and have just pushed an update which now validates on both tools. Could you please confirm for me that https://raw.githubusercontent.com/axllent/mailpit/refs/heads/develop/server/ui/api/v1/swagger.json works for you? Thank you.
Author
Owner

@carolosf commented on GitHub (Feb 14, 2025):

Thanks for the quick response and how to generate the swagger file!

It does seem to be working for quarkus-mailpit now thanks!

I've made this pull request - builds for me locally and in the PR build:
https://github.com/quarkiverse/quarkus-mailpit/pull/117

Have a great day

<!-- gh-comment-id:2658924800 --> @carolosf commented on GitHub (Feb 14, 2025): Thanks for the quick response and how to generate the swagger file! It does seem to be working for quarkus-mailpit now thanks! I've made this pull request - builds for me locally and in the PR build: https://github.com/quarkiverse/quarkus-mailpit/pull/117 Have a great day
Author
Owner

@axllent commented on GitHub (Feb 14, 2025):

Awesome. I'll release a new tagged version this weekend, so probably wisest you stick with those in case you end up with non-released features in the future.

<!-- gh-comment-id:2659143213 --> @axllent commented on GitHub (Feb 14, 2025): Awesome. I'll release a new tagged version this weekend, so probably wisest you stick with those in case you end up with non-released features in the future.
Author
Owner

@melloware commented on GitHub (Feb 14, 2025):

@axllent many thanks for your quick fix and attention to this!

<!-- gh-comment-id:2659357949 --> @melloware commented on GitHub (Feb 14, 2025): @axllent many thanks for your quick fix and attention to this!
Author
Owner

@axllent commented on GitHub (Feb 15, 2025):

This fix has now been released in v1.22.3. As I mentioned before, I would strongly suggest against linking to the develop branch as that contains often unreleased changes. If you want to always link to the latest released version, then use https://raw.githubusercontent.com/axllent/mailpit/refs/heads/master/server/ui/api/v1/swagger.json (ie: master branch).

Thanks for reporting the issue!

<!-- gh-comment-id:2661098891 --> @axllent commented on GitHub (Feb 15, 2025): This fix has now been released in [v1.22.3](https://github.com/axllent/mailpit/releases/tag/v1.22.3). As I mentioned before, I would strongly suggest _against_ linking to the develop branch as that contains often unreleased changes. If you want to always link to the latest released version, then use `https://raw.githubusercontent.com/axllent/mailpit/refs/heads/master/server/ui/api/v1/swagger.json` (ie: `master` branch). Thanks for reporting the issue!
Author
Owner

@melloware commented on GitHub (Feb 16, 2025):

Thank you!

<!-- gh-comment-id:2661198082 --> @melloware commented on GitHub (Feb 16, 2025): Thank you!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#285
No description provided.