210 Commits
v0.1.0 ... main

Author SHA1 Message Date
Federico Maggi
ef1ac5fd7e Upgrade version to v0.10.1 2025-10-06 15:34:42 +02:00
Federico Maggi
fc597bec00 bump kin openapi version CVE-2025-30153 (#169) 2025-10-06 15:30:34 +02:00
Federico Maggi
eb3c4d9c98 refactor: rename swagger to oas in errors (#165) 2024-11-08 19:52:34 +01:00
Davide Bianchi
3563d41c0f feat: add support to multiple params (#162) 2024-08-07 16:24:59 +02:00
dependabot[bot]
1802f29ad3 chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.4 to 2.52.5 (#159)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.52.4 to 2.52.5.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.52.4...v2.52.5)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-07-01 11:01:28 +02:00
dependabot[bot]
56651d1029 chore(deps): bump github.com/getkin/kin-openapi from 0.124.0 to 0.125.0 (#158)
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.124.0 to 0.125.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.124.0...v0.125.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-11 09:31:31 +02:00
Stefano Del Tufo
91f50dd0e4 Added test using enum in request body schema (#157) 2024-04-23 14:29:05 +02:00
dependabot[bot]
a98a205453 chore(deps): bump github.com/labstack/echo/v4 from 4.11.4 to 4.12.0 (#156)
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.11.4 to 4.12.0.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.11.4...v4.12.0)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-23 11:45:47 +02:00
dependabot[bot]
3720da7606 chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.2 to 2.52.4 (#154)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.52.2 to 2.52.4.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.52.2...v2.52.4)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-23 10:27:01 +02:00
dependabot[bot]
fb94293412 chore(deps): bump github.com/getkin/kin-openapi from 0.123.0 to 0.124.0 (#155)
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.123.0 to 0.124.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.123.0...v0.124.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-08 14:11:34 +02:00
dependabot[bot]
d1f6294d95 chore(deps): bump github.com/stretchr/testify from 1.8.4 to 1.9.0 (#152)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.4 to 1.9.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.4...v1.9.0)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-04 10:38:22 +01:00
dependabot[bot]
a828758065 chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.1 to 2.52.2 (#151)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.52.1 to 2.52.2.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.52.1...v2.52.2)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-03-04 10:38:14 +01:00
Davide Bianchi
09e3bd484e Upgrade version to v0.10.0 2024-02-28 11:31:55 +01:00
dependabot[bot]
617c44900c chore(deps): bump github.com/getkin/kin-openapi from 0.120.0 to 0.123.0 (#148)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Federico Maggi <federico.maggi@mia-platform.eu>
2024-02-28 11:30:55 +01:00
dependabot[bot]
1cd88c70bb chore(deps): bump github.com/gofiber/fiber/v2 from 2.52.0 to 2.52.1 (#150)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.52.0 to 2.52.1.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.52.0...v2.52.1)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-22 14:47:13 +01:00
dependabot[bot]
d3bbc528ac chore(deps): bump github.com/labstack/echo/v4 from 4.11.3 to 4.11.4 (#146)
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.11.3 to 4.11.4.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.11.3...v4.11.4)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-15 10:58:23 +01:00
dependabot[bot]
91c15b79b1 chore(deps): bump github.com/gofiber/fiber/v2 from 2.50.0 to 2.52.0 (#147)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.50.0 to 2.52.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.50.0...v2.52.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-02-15 10:13:15 +01:00
Federico Maggi
bd884cb1de ci: fix coveralls parallel job (#149) 2024-02-15 09:53:23 +01:00
dependabot[bot]
b776ccf233 chore(deps): bump github.com/gorilla/mux from 1.8.0 to 1.8.1 (#141)
Bumps [github.com/gorilla/mux](https://github.com/gorilla/mux) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/gorilla/mux/releases)
- [Commits](https://github.com/gorilla/mux/compare/v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: github.com/gorilla/mux
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-08 12:51:06 +01:00
dependabot[bot]
0d75c2cb5e chore(deps): bump github.com/labstack/echo/v4 from 4.11.2 to 4.11.3 (#142)
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.11.2 to 4.11.3.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.11.2...v4.11.3)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-08 12:48:17 +01:00
dependabot[bot]
2354daa4a9 chore(deps): bump github.com/gofiber/fiber/v2 from 2.49.2 to 2.50.0 (#140)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.49.2 to 2.50.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.49.2...v2.50.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-17 17:31:30 +02:00
dependabot[bot]
8d05c61745 chore(deps): bump github.com/labstack/echo/v4 from 4.11.1 to 4.11.2 (#139)
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.11.1 to 4.11.2.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.11.1...v4.11.2)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-10-13 00:42:29 +02:00
Davide Bianchi
9a6b0b9b16 upgrade jsonschema (#138) 2023-10-07 17:50:16 +02:00
Davide Bianchi
dd94c5cd25 Merge pull request #130 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.120.0 2023-10-03 09:00:20 +02:00
dependabot[bot]
8047e54eac chore(deps): bump github.com/getkin/kin-openapi from 0.118.0 to 0.120.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.118.0 to 0.120.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.118.0...v0.120.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-09-18 09:29:41 +00:00
dependabot[bot]
e6adc34cee chore(deps): bump github.com/gofiber/fiber/v2 from 2.49.1 to 2.49.2 (#132)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.49.1 to 2.49.2.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.49.1...v2.49.2)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-18 11:28:22 +02:00
Davide Bianchi
2b87521135 Merge pull request #131 from davidebianchi/use-invopop-jsonschema-lib 2023-09-11 18:46:07 +02:00
Davide Bianchi
d095403a23 docs: update CHANGELOG 2023-09-10 19:14:19 +02:00
Davide Bianchi
526265eda9 feat: update deps 2023-09-10 18:58:03 +02:00
dependabot[bot]
88bbf2f41c chore(deps): bump github.com/gofiber/fiber/v2 from 2.49.0 to 2.49.1 (#129)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.49.0 to 2.49.1.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.49.0...v2.49.1)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-04 09:16:51 +02:00
dependabot[bot]
6a1bd1cd19 chore(deps): bump github.com/gofiber/fiber/v2 from 2.48.0 to 2.49.0 (#127)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.48.0 to 2.49.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.48.0...v2.49.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-28 18:47:18 +02:00
Davide Bianchi
c44efeed6e Merge pull request #125 from davidebianchi/dependabot/go_modules/github.com/labstack/echo/v4-4.11.1 2023-08-02 14:33:23 +02:00
dependabot[bot]
4b06c26421 chore(deps): bump github.com/labstack/echo/v4 from 4.10.2 to 4.11.1
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.10.2 to 4.11.1.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.10.2...v4.11.1)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-07-18 11:01:55 +00:00
dependabot[bot]
7a48480545 chore(deps): bump github.com/gofiber/fiber/v2 from 2.47.0 to 2.48.0 (#124)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.47.0 to 2.48.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.47.0...v2.48.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-18 13:00:13 +02:00
dependabot[bot]
bbc469d26d chore(deps): bump github.com/gofiber/fiber/v2 from 2.46.0 to 2.47.0 (#123)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.46.0 to 2.47.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.46.0...v2.47.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-20 14:52:23 +02:00
dependabot[bot]
be8a1de244 chore(deps): bump github.com/getkin/kin-openapi from 0.117.0 to 0.118.0 (#122)
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.117.0 to 0.118.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.117.0...v0.118.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-06-08 09:29:01 +02:00
Davide Bianchi
39f8f916d1 Update README.md 2023-06-01 16:23:37 +02:00
dependabot[bot]
9fac1c3a4f chore(deps): bump github.com/stretchr/testify from 1.8.3 to 1.8.4 (#119)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.3 to 1.8.4.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.3...v1.8.4)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-31 09:41:52 +02:00
Davide Bianchi
d5e740ecac Merge pull request #118 from davidebianchi/dependabot/go_modules/github.com/gofiber/fiber/v2-2.46.0 2023-05-22 06:11:45 +02:00
dependabot[bot]
5f24f99c89 chore(deps): bump github.com/gofiber/fiber/v2 from 2.45.0 to 2.46.0
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.45.0 to 2.46.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.45.0...v2.46.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-22 03:58:58 +00:00
dependabot[bot]
19e6e6e888 chore(deps): bump github.com/getkin/kin-openapi from 0.116.0 to 0.117.0 (#117)
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.116.0 to 0.117.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.116.0...v0.117.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-19 09:43:48 +02:00
dependabot[bot]
449ee873f8 chore(deps): bump github.com/stretchr/testify from 1.8.2 to 1.8.3 (#116)
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.2 to 1.8.3.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.2...v1.8.3)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-19 09:43:00 +02:00
dependabot[bot]
8d08ab4e88 chore(deps): bump github.com/gofiber/fiber/v2 from 2.44.0 to 2.45.0 (#115)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.44.0 to 2.45.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.44.0...v2.45.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-05-09 09:14:28 +02:00
dependabot[bot]
e4154d1870 chore(deps): bump github.com/getkin/kin-openapi from 0.115.0 to 0.116.0 (#114)
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.115.0 to 0.116.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.115.0...v0.116.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-04-19 11:24:35 +02:00
Davide Bianchi
34f6bc882e Upgrade version to v0.9.0 2023-04-17 10:25:18 +02:00
Davide Bianchi
bb30bcbb18 Merge pull request #112 from davidebianchi/add-new-oas-fields-to-definition 2023-04-17 10:24:07 +02:00
Davide Bianchi
e3bf8ad397 Merge pull request #111 from davidebianchi/dependabot/go_modules/github.com/gofiber/fiber/v2-2.44.0 2023-04-17 10:21:39 +02:00
Davide Bianchi
36c6f8b159 feat: add new fields to definition struct 2023-04-17 10:20:59 +02:00
dependabot[bot]
4cb82ead72 chore(deps): bump github.com/gofiber/fiber/v2 from 2.43.0 to 2.44.0
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.43.0 to 2.44.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.43.0...v2.44.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-04-17 03:58:01 +00:00
dependabot[bot]
5851dbec22 chore(deps): bump github.com/gofiber/fiber/v2 from 2.42.0 to 2.43.0 (#110)
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.42.0 to 2.43.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.42.0...v2.43.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-03-27 10:00:45 +02:00
Davide Bianchi
7eabb18dd1 Merge pull request #109 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.115.0
chore(deps): bump github.com/getkin/kin-openapi from 0.114.0 to 0.115.0
2023-03-14 08:33:18 +01:00
dependabot[bot]
b50cc86f43 chore(deps): bump github.com/getkin/kin-openapi from 0.114.0 to 0.115.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.114.0 to 0.115.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.114.0...v0.115.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-14 03:58:20 +00:00
Davide Bianchi
8330d20f23 Merge pull request #108 from malta895/patch-1 2023-03-07 09:34:15 +01:00
Luca Maltagliati
68cc1ddbf1 Add Fiber path parameter example 2023-03-07 09:09:01 +01:00
Davide Bianchi
5f67ad2aad Merge pull request #107 from davidebianchi/upgrade-kin-openapi
update kin-openapi to 0.114.0
2023-03-05 22:10:20 +01:00
Davide Bianchi
0676ab69a8 docs: update CHANGELOG 2023-03-05 21:12:48 +01:00
Davide Bianchi
838f862067 update kin-openapi to 0.114.0 2023-03-05 21:12:34 +01:00
Davide Bianchi
48371417ce Merge pull request #102 from davidebianchi/dependabot/go_modules/github.com/gofiber/fiber/v2-2.42.0 2023-03-05 12:45:09 +01:00
dependabot[bot]
3e11724cd9 chore(deps): bump github.com/gofiber/fiber/v2 from 2.41.0 to 2.42.0
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.41.0 to 2.42.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.41.0...v2.42.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-05 11:41:31 +00:00
Davide Bianchi
85a65a69aa Merge pull request #105 from davidebianchi/dependabot/go_modules/github.com/stretchr/testify-1.8.2 2023-03-05 12:40:50 +01:00
dependabot[bot]
0b3a79b0b5 chore(deps): bump github.com/stretchr/testify from 1.8.1 to 1.8.2
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.1 to 1.8.2.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.1...v1.8.2)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-27 04:00:09 +00:00
dependabot[bot]
83cb8c6301 chore(deps): bump github.com/labstack/echo/v4 from 4.10.1 to 4.10.2 (#104)
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.10.1 to 4.10.2.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.10.1...v4.10.2)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-02-22 17:10:45 +01:00
Davide Bianchi
a605011038 Merge pull request #103 from davidebianchi/dependabot/go_modules/github.com/labstack/echo/v4-4.10.1
chore(deps): bump github.com/labstack/echo/v4 from 4.9.1 to 4.10.1
2023-02-21 08:34:57 +01:00
dependabot[bot]
4f18946fab chore(deps): bump github.com/labstack/echo/v4 from 4.9.1 to 4.10.1
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.9.1 to 4.10.1.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.9.1...v4.10.1)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-02-21 03:57:37 +00:00
Federico Maggi
8ea5444777 Merge pull request #99 from davidebianchi/dependabot/go_modules/github.com/gofiber/fiber/v2-2.41.0
chore(deps): bump github.com/gofiber/fiber/v2 from 2.40.1 to 2.41.0
2023-01-05 07:58:30 +01:00
dependabot[bot]
e6e53be7d8 chore(deps): bump github.com/gofiber/fiber/v2 from 2.40.1 to 2.41.0
Bumps [github.com/gofiber/fiber/v2](https://github.com/gofiber/fiber) from 2.40.1 to 2.41.0.
- [Release notes](https://github.com/gofiber/fiber/releases)
- [Commits](https://github.com/gofiber/fiber/compare/v2.40.1...v2.41.0)

---
updated-dependencies:
- dependency-name: github.com/gofiber/fiber/v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-01-04 03:02:29 +00:00
Davide Bianchi
a503dd54db Upgrade version to v0.8.0 2022-12-24 16:31:31 +01:00
Davide Bianchi
231f0b5b65 Merge pull request #97 from davidebianchi/fix-different-params 2022-12-24 16:02:36 +01:00
Davide Bianchi
6d81ef8469 update changelog 2022-12-24 16:00:38 +01:00
Davide Bianchi
f6c98d97cc docs: update CHANGELOG 2022-12-23 21:06:02 +01:00
Davide Bianchi
4587271bc2 fix: fix different params configuration 2022-12-23 21:03:53 +01:00
Davide Bianchi
17f9235abd Merge pull request #95 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.112.0 2022-12-23 10:22:32 +01:00
dependabot[bot]
e81a74c306 chore(deps): bump github.com/getkin/kin-openapi from 0.111.0 to 0.112.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.111.0 to 0.112.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.111.0...v0.112.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-23 03:02:29 +00:00
Davide Bianchi
48e22b5674 Upgrade version to v0.7.0 2022-12-22 19:36:46 +01:00
Davide Bianchi
a1df7c966e docs: update CHANGELOG 2022-12-22 19:33:13 +01:00
Davide Bianchi
6e38c8b9ea Merge pull request #93 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.111.0 2022-12-22 19:26:41 +01:00
Davide Bianchi
40ea80b890 Merge pull request #94 from davidebianchi/support-fiber 2022-12-22 19:26:30 +01:00
Davide Bianchi
1daad04aab feat: change GenerateAndExposeSwagger fn name 2022-12-22 19:23:37 +01:00
Davide Bianchi
77e080c587 docs: update CHANGELOG 2022-12-22 19:15:33 +01:00
Davide Bianchi
00d9267cf8 feat: improve README 2022-12-22 19:11:37 +01:00
Davide Bianchi
efab680870 docs: update CHANGELOG 2022-12-22 18:43:13 +01:00
Davide Bianchi
fa4fd37f17 feat: add first class support to echo router 2022-12-22 18:42:41 +01:00
Davide Bianchi
74baec392e feat: move gorilla integration under gorilla folder 2022-12-22 18:27:57 +01:00
Davide Bianchi
a48fb550df feat: drop support golang below v1.17 2022-12-22 15:37:14 +01:00
Davide Bianchi
76d2e514e1 feat: add strong types on Route 2022-12-22 15:35:56 +01:00
Davide Bianchi
aeb5680612 feat: add fiber support 2022-12-22 12:44:55 +01:00
Davide Bianchi
10a5f64f5c feat: change apirouter implementation to support multiple type of handler 2022-12-22 11:29:13 +01:00
Davide Bianchi
fca6b6910d feat: move gorilla under support 2022-12-22 10:03:20 +01:00
Davide Bianchi
da751837df upgrade to go 19 2022-12-22 09:54:37 +01:00
dependabot[bot]
cbe3488c8d chore(deps): bump github.com/getkin/kin-openapi from 0.108.0 to 0.111.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.108.0 to 0.111.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.108.0...v0.111.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-12-19 03:03:15 +00:00
Davide Bianchi
315cd103a7 Merge pull request #88 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.108.0 2022-11-17 09:35:44 +01:00
Davide Bianchi
d7b5134200 Upgrade version to v0.6.1 2022-11-17 09:34:39 +01:00
Davide Bianchi
31e40cedfd Merge pull request #90 from davidebianchi/fix/remove-deprecated-lib 2022-11-17 09:34:11 +01:00
Davide Bianchi
6f3dcc578c update go version in github actions 2022-11-17 09:32:13 +01:00
Davide Bianchi
45cf385dec docs: update CHANGELOG 2022-11-17 09:30:28 +01:00
Davide Bianchi
e5f3c438b4 fix: remove use of the deprecated io/ioutil lib 2022-11-17 09:29:43 +01:00
Federico Maggi
047317ef17 Merge pull request #89 from FilippoRezzonico/fix/RJMR-254-jsonschema-lib-without-patternProperties
Fix/rjmr 254 jsonschema lib without pattern properties
2022-11-16 18:40:44 +01:00
filippo.rezzonico
b007e57092 updated changelog 2022-11-16 18:27:28 +01:00
filippo.rezzonico
6c9d0e579f added test 2022-11-16 18:24:10 +01:00
filippo.rezzonico
f84327d424 changed jsonschema 2022-11-16 18:22:24 +01:00
dependabot[bot]
3a598c0726 chore(deps): bump github.com/getkin/kin-openapi from 0.107.0 to 0.108.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.107.0 to 0.108.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.107.0...v0.108.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-11-10 03:05:07 +00:00
Davide Bianchi
085abe98d1 Merge pull request #83 from davidebianchi/dependabot/go_modules/github.com/stretchr/testify-1.8.1 2022-11-06 12:08:46 +01:00
Davide Bianchi
c5fff8f982 Merge pull request #84 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.107.0 2022-11-06 12:08:37 +01:00
Davide Bianchi
fee2444c96 Merge pull request #80 from davidebianchi/dependabot/go_modules/github.com/labstack/echo/v4-4.9.1 2022-11-06 12:08:21 +01:00
Davide Bianchi
24dfb293ea Upgrade version to v0.6.0 2022-11-04 15:15:01 +01:00
Davide Bianchi
a5b9bd3dc4 Merge pull request #86 from davidebianchi/feat/tags-support-in-add-routes 2022-11-04 15:10:02 +01:00
Federico Maggi
7f7c92eaca feat: tags support 2022-11-04 15:01:26 +01:00
dependabot[bot]
2939f1027d chore(deps): bump github.com/getkin/kin-openapi from 0.103.0 to 0.107.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.103.0 to 0.107.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.103.0...v0.107.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-28 03:10:41 +00:00
dependabot[bot]
3a4118844e chore(deps): bump github.com/stretchr/testify from 1.8.0 to 1.8.1
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.8.0 to 1.8.1.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.8.0...v1.8.1)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-24 03:11:45 +00:00
dependabot[bot]
3e72099700 chore(deps): bump github.com/labstack/echo/v4 from 4.9.0 to 4.9.1
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.9.0 to 4.9.1.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.9.0...v4.9.1)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-10-13 03:09:18 +00:00
Davide Bianchi
9fac38a162 fix 2022-10-03 09:18:13 +02:00
Davide Bianchi
424779a7d8 Upgrade version to v0.5.1 2022-10-03 09:17:33 +02:00
Davide Bianchi
d6a528ea28 fix: changelog 2022-10-03 09:17:25 +02:00
Davide Bianchi
909c58608a upgrade deps 2022-10-03 09:17:02 +02:00
Davide Bianchi
43c6e37a47 Merge pull request #78 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.103.0 2022-10-03 09:14:37 +02:00
dependabot[bot]
b9dc8ff83c chore(deps): bump github.com/getkin/kin-openapi from 0.102.0 to 0.103.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.102.0 to 0.103.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.102.0...v0.103.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-22 03:20:06 +00:00
Davide Bianchi
1b95853d11 Merge pull request #77 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.102.0 2022-09-20 21:44:58 +02:00
Davide Bianchi
e8369933fc Merge pull request #74 from davidebianchi/dependabot/go_modules/github.com/labstack/echo/v4-4.9.0 2022-09-20 21:44:24 +02:00
dependabot[bot]
89d668771a chore(deps): bump github.com/getkin/kin-openapi from 0.98.0 to 0.102.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.98.0 to 0.102.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.98.0...v0.102.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-19 03:08:43 +00:00
dependabot[bot]
0039a3f74f chore(deps): bump github.com/labstack/echo/v4 from 4.7.2 to 4.9.0
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.7.2 to 4.9.0.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.7.2...v4.9.0)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-09-05 13:15:57 +00:00
Davide Bianchi
b29887d15f docs: update CHANGELOG 2022-08-05 17:56:20 +02:00
Davide Bianchi
e03aeb51c2 update deps 2022-08-05 17:55:39 +02:00
Davide Bianchi
a3cb8e3775 Merge pull request #68 from davidebianchi/dependabot/go_modules/github.com/invopop/jsonschema-0.6.0 2022-08-05 17:54:31 +02:00
Davide Bianchi
995c3d97a2 Merge pull request #70 from davidebianchi/autofill-path-params 2022-08-05 17:52:46 +02:00
Davide Bianchi
d376b5411e Update README.md 2022-08-05 17:48:09 +02:00
Davide Bianchi
b187bd716f docs: update CHANGELOG 2022-08-05 17:44:50 +02:00
Davide Bianchi
d07b9c96f5 feat: autofill path params 2022-08-05 17:35:30 +02:00
dependabot[bot]
3c8cffc622 chore(deps): bump github.com/invopop/jsonschema from 0.5.0 to 0.6.0
Bumps [github.com/invopop/jsonschema](https://github.com/invopop/jsonschema) from 0.5.0 to 0.6.0.
- [Release notes](https://github.com/invopop/jsonschema/releases)
- [Commits](https://github.com/invopop/jsonschema/compare/v0.5.0...v0.6.0)

---
updated-dependencies:
- dependency-name: github.com/invopop/jsonschema
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-04 03:12:40 +00:00
Davide Bianchi
c5e3219f7a docs: update CHANGELOG 2022-08-02 09:15:52 +02:00
Davide Bianchi
d9c105585b Merge pull request #53 from davidebianchi/upgrade-deps 2022-08-02 09:13:59 +02:00
Davide Bianchi
3f7d09cc36 improve changelog 2022-08-02 09:11:28 +02:00
Davide Bianchi
57842cf39d upgrade deps 2022-08-02 09:08:04 +02:00
Davide Bianchi
3e359451c8 Merge pull request #66 from davidebianchi/dependabot/go_modules/github.com/stretchr/testify-1.8.0 2022-08-01 08:58:28 +02:00
dependabot[bot]
7896d8efd3 chore(deps): bump github.com/stretchr/testify from 1.7.5 to 1.8.0
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.5 to 1.8.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.5...v1.8.0)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-30 03:16:40 +00:00
Davide Bianchi
ac9ae09ff9 Merge pull request #57 from davidebianchi/dependabot/go_modules/github.com/labstack/echo/v4-4.7.2
chore(deps): bump github.com/labstack/echo/v4 from 4.6.3 to 4.7.2
2022-06-25 08:29:04 +02:00
dependabot[bot]
42bfc9c9a6 chore(deps): bump github.com/labstack/echo/v4 from 4.6.3 to 4.7.2
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.6.3 to 4.7.2.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.6.3...v4.7.2)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-25 06:23:31 +00:00
Davide Bianchi
32233b0a6b Merge pull request #65 from davidebianchi/dependabot/go_modules/github.com/stretchr/testify-1.7.5
chore(deps): bump github.com/stretchr/testify from 1.7.2 to 1.7.5
2022-06-25 08:22:06 +02:00
dependabot[bot]
ab052edbe2 chore(deps): bump github.com/stretchr/testify from 1.7.2 to 1.7.5
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.2 to 1.7.5.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.2...v1.7.5)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-24 03:09:17 +00:00
Davide Bianchi
90b7305b57 Merge pull request #62 from davidebianchi/dependabot/go_modules/github.com/stretchr/testify-1.7.2
chore(deps): bump github.com/stretchr/testify from 1.7.0 to 1.7.2
2022-06-18 23:53:57 +02:00
dependabot[bot]
0a6ddb22c3 chore(deps): bump github.com/stretchr/testify from 1.7.0 to 1.7.2
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.7.0 to 1.7.2.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.7.0...v1.7.2)

---
updated-dependencies:
- dependency-name: github.com/stretchr/testify
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-06-07 03:11:22 +00:00
Davide Bianchi
e884893fd5 chore: remove support to go 1.15 2022-03-26 18:34:24 +01:00
Davide Bianchi
1aaf503686 upgrade deps 2022-03-26 18:20:16 +01:00
Davide Bianchi
f109edd60a feat: upgrade deps 2022-03-12 19:13:02 +01:00
Davide Bianchi
d187894847 Merge pull request #49 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.89.0 2022-02-04 09:52:46 +01:00
dependabot[bot]
6eeb5ab409 chore(deps): bump github.com/getkin/kin-openapi from 0.88.0 to 0.89.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.88.0 to 0.89.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.88.0...v0.89.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-04 03:12:31 +00:00
Davide Bianchi
8efc400a2f Merge pull request #48 from davidebianchi/dependabot/go_modules/github.com/labstack/echo/v4-4.6.3 2022-02-02 22:41:50 +01:00
dependabot[bot]
5c5d02c68e chore(deps): bump github.com/labstack/echo/v4 from 4.6.1 to 4.6.3
Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.6.1 to 4.6.3.
- [Release notes](https://github.com/labstack/echo/releases)
- [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md)
- [Commits](https://github.com/labstack/echo/compare/v4.6.1...v4.6.3)

---
updated-dependencies:
- dependency-name: github.com/labstack/echo/v4
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-11 03:16:28 +00:00
Davide Bianchi
e5b47a772a Merge pull request #46 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.88.0 2022-01-05 18:25:13 +01:00
dependabot[bot]
fa6f33399b chore(deps): bump github.com/getkin/kin-openapi from 0.87.0 to 0.88.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.87.0 to 0.88.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.87.0...v0.88.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-01-05 03:13:39 +00:00
Davide Bianchi
786a5ed67d Merge pull request #45 from davidebianchi/echo-integration-example 2022-01-04 15:40:12 +01:00
Davide Bianchi
8f8ca16724 test: add subrouter test 2021-12-27 19:45:53 +01:00
Davide Bianchi
e1e3e95d80 feat: add test of integration of echo router 2021-12-22 19:13:18 +01:00
Davide Bianchi
1f550922b6 Merge pull request #44 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.87.0 2021-12-21 22:57:20 +01:00
dependabot[bot]
55cfa361ce chore(deps): bump github.com/getkin/kin-openapi from 0.86.0 to 0.87.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.86.0 to 0.87.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.86.0...v0.87.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-21 03:09:22 +00:00
Davide Bianchi
0c867d2839 fix: change test name 2021-12-20 20:32:39 +01:00
Davide Bianchi
68fdf59cdb change go version to 1.17 and update workflow to support from go version 1.15 to 1.17 2021-12-20 20:31:46 +01:00
Davide Bianchi
ebb8822041 Merge pull request #42 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.86.0 2021-12-20 20:28:23 +01:00
Davide Bianchi
491f683807 fix: update CHANGELOG 2021-12-20 20:25:58 +01:00
Davide Bianchi
122be38154 Merge pull request #39 from danibix95/fix/align-code-docs 2021-12-20 20:21:53 +01:00
dependabot[bot]
a0ea89ed92 chore(deps): bump github.com/getkin/kin-openapi from 0.85.0 to 0.86.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.85.0 to 0.86.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.85.0...v0.86.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-13 03:14:25 +00:00
Davide Bianchi
f21942de1b Merge pull request #41 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.85.0 2021-12-06 22:34:19 +01:00
dependabot[bot]
b1b7025862 chore(deps): bump github.com/getkin/kin-openapi from 0.79.0 to 0.85.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.79.0 to 0.85.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.79.0...v0.85.0)

---
updated-dependencies:
- dependency-name: github.com/getkin/kin-openapi
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-12-06 03:12:57 +00:00
danibix95
3d21dece34 Set method as first parameter of AddRoute function in Router interface 2021-11-23 23:19:52 +01:00
Davide Bianchi
715c554482 docs: update README 2021-11-10 11:26:34 +01:00
Davide Bianchi
d35432abaf test: add integration test 2021-11-10 11:19:12 +01:00
Davide Bianchi
ffb0e6b3f7 docs: update CHANGELOG 2021-11-10 10:41:38 +01:00
Davide Bianchi
94abd8f4bf docs: update README 2021-11-10 10:39:59 +01:00
Davide Bianchi
7232d5d823 feat: add coverage report 2021-11-10 10:34:38 +01:00
Davide Bianchi
b26ddbeecf Update test-builds.yml 2021-11-10 10:30:40 +01:00
Davide Bianchi
3374e2bd80 Merge pull request #36 from davidebianchi/feat/subrouter-path-prefix 2021-11-10 10:27:22 +01:00
Davide Bianchi
33d81e9cdd docs: update CHANGELOG 2021-11-10 10:23:17 +01:00
Davide Bianchi
a7a671be5a test: add route with path equal to prefix path 2021-11-10 10:22:45 +01:00
Davide Bianchi
239a70a1a0 test: more simple test 2021-11-10 10:15:55 +01:00
Davide Bianchi
8c0aacb68c fix: remove GetSwaggerSchema fn 2021-11-10 10:13:51 +01:00
Davide Bianchi
d145c6ca5d feat: add SubRouter method 2021-11-10 10:12:26 +01:00
Davide Bianchi
a8c5be8870 feat: add SubRouter method 2021-11-10 10:02:32 +01:00
Davide Bianchi
8fda85d9d3 docs: update CHANGELOG 2021-11-09 22:36:56 +01:00
Davide Bianchi
a872dd02b7 feat: add support to subrouter, handle path prefix 2021-11-09 22:35:17 +01:00
Davide Bianchi
7615365291 docs: update CHANGELOG 2021-10-16 21:59:57 +02:00
Davide Bianchi
6411ef6e66 Merge branch 'main' of github.com:davidebianchi/gswagger 2021-10-16 21:59:03 +02:00
Davide Bianchi
49fd48c375 docs: update README 2021-10-16 21:58:54 +02:00
Davide Bianchi
9f3698cf59 Update README.md 2021-10-16 21:54:37 +02:00
Davide Bianchi
98ed6678e6 Update README.md 2021-10-16 21:54:28 +02:00
Davide Bianchi
0075df7fc4 Update README.md 2021-10-16 21:39:21 +02:00
Davide Bianchi
66b593f3f6 Update README.md 2021-10-16 21:38:58 +02:00
Davide Bianchi
30bf3ec60e docs: change readme 2021-10-16 21:01:59 +02:00
Davide Bianchi
ff30e87701 Merge pull request #33 from davidebianchi/support-router-interface 2021-10-16 21:00:23 +02:00
Davide Bianchi
07568cabc0 test: fix test 2021-10-16 20:59:27 +02:00
Davide Bianchi
2cffb94971 feat: improve documentation 2021-10-16 20:56:15 +02:00
Davide Bianchi
ec86fe1571 docs: improved docs 2021-10-16 20:12:39 +02:00
Davide Bianchi
5d1b1b795d fix: remove first level export of new router 2021-10-16 20:03:18 +02:00
Davide Bianchi
b964b3c3ca feat: support custom router interface 2021-10-16 20:00:52 +02:00
Davide Bianchi
4e8ccbd66d fix: fix warning in test 2021-10-16 19:27:48 +02:00
Davide Bianchi
9aaf041909 Merge pull request #32 from davidebianchi/upgrade-deps 2021-10-16 19:25:27 +02:00
Davide Bianchi
b1dc480411 run go mod tidy 2021-10-16 19:24:31 +02:00
Davide Bianchi
3d9ad0fb5f feat: upgrade deps 2021-10-16 19:23:52 +02:00
Davide Bianchi
5f07fcb394 Update README.md 2021-10-16 19:05:25 +02:00
Davide Bianchi
985e3dfd03 Update dependabot.yml 2021-10-16 19:04:21 +02:00
Davide Bianchi
67073bb3bb Merge pull request #30 from davidebianchi/dependabot/add-v2-config-file
Upgrade to GitHub-native Dependabot
2021-05-18 21:44:48 +02:00
dependabot-preview[bot]
ba069411b1 Upgrade to GitHub-native Dependabot 2021-04-29 16:07:20 +00:00
Davide Bianchi
a950dcc879 Merge pull request #28 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.60.0
chore(deps): bump github.com/getkin/kin-openapi from 0.53.0 to 0.60.0
2021-04-26 18:54:00 +02:00
dependabot-preview[bot]
1fe64517bd chore(deps): bump github.com/getkin/kin-openapi from 0.53.0 to 0.60.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.53.0 to 0.60.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.53.0...v0.60.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-04-26 06:34:55 +00:00
Davide Bianchi
651f2d0478 Merge pull request #25 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.53.0
chore(deps): bump github.com/getkin/kin-openapi from 0.48.0 to 0.53.0
2021-04-03 18:57:28 +02:00
dependabot-preview[bot]
22cf8cdbc4 chore(deps): bump github.com/getkin/kin-openapi from 0.48.0 to 0.53.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.48.0 to 0.53.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.48.0...v0.53.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-24 06:58:26 +00:00
Davide Bianchi
2d310b15e1 Merge pull request #21 from davidebianchi/dependabot/go_modules/github.com/getkin/kin-openapi-0.48.0
chore(deps): bump github.com/getkin/kin-openapi from 0.39.0 to 0.48.0
2021-03-07 18:14:05 +01:00
dependabot-preview[bot]
b77a71d0e4 chore(deps): bump github.com/getkin/kin-openapi from 0.39.0 to 0.48.0
Bumps [github.com/getkin/kin-openapi](https://github.com/getkin/kin-openapi) from 0.39.0 to 0.48.0.
- [Release notes](https://github.com/getkin/kin-openapi/releases)
- [Commits](https://github.com/getkin/kin-openapi/compare/v0.39.0...v0.48.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-03-05 07:01:19 +00:00
Davide Bianchi
7f240250d5 Create CHANGELOG.md 2021-02-07 18:19:23 +01:00
Davide Bianchi
3b0f5b33eb Merge pull request #15 from davidebianchi/dependabot/go_modules/github.com/stretchr/testify-1.7.0
chore(deps): bump github.com/stretchr/testify from 1.6.1 to 1.7.0
2021-02-07 18:17:45 +01:00
dependabot-preview[bot]
6c8a4b5cdf chore(deps): bump github.com/stretchr/testify from 1.6.1 to 1.7.0
Bumps [github.com/stretchr/testify](https://github.com/stretchr/testify) from 1.6.1 to 1.7.0.
- [Release notes](https://github.com/stretchr/testify/releases)
- [Commits](https://github.com/stretchr/testify/compare/v1.6.1...v1.7.0)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2021-02-07 17:04:21 +00:00
Davide Bianchi
04774f8ed5 update deps 2021-02-07 18:02:52 +01:00
50 changed files with 2598 additions and 433 deletions

7
.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10

View File

@@ -5,28 +5,46 @@ on:
push:
jobs:
tests:
name: Test on go ${{ matrix.go_version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
go_version: [1.15]
os: [macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v1
- name: Use golang ${{ matrix.go_version }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go_version }}
name: Test on go ${{ matrix.go_version }} os ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
go_version: ['1.24', '1.25']
os: [ubuntu-latest]
include:
- go_version: '1.25'
os: macos-latest
steps:
- uses: actions/checkout@v1
- name: Use golang ${{ matrix.go_version }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go_version }}
- name: Go version
run: |
go version
- name: Go get dependencies
run: |
go get -v -t -d ./...
- name: Run tests
run: |
go test ./... -count=1 -race -cover
- name: Build
run: |
go build -v .
- name: Go version
run: |
go version
- name: Go get dependencies
run: |
go get -v -t -d ./...
- name: Run tests
run: |
go test ./... -count=1 -race -cover -coverprofile cover.out
- name: Build
run: |
go build -v .
- name: Send the coverage output
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: cover.out
flag-name: Go-${{ matrix.go_version }}
parallel: true
post-tests:
runs-on: ubuntu-latest
needs: tests
steps:
- name: Close coverage report
uses: shogo82148/actions-goveralls@v1
with:
parallel-finished: true

151
CHANGELOG.md Normal file
View File

@@ -0,0 +1,151 @@
# Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
## 0.10.1 - 06-10-2025
### Refactor
- renamed swagger to openapi in error messages
## 0.10.0 - 28-02-2024
### BREAKING CHANGES
- remove support to golang 1.19
### Updated
- change jsonschema lib to use again `invopop/jsonschema` one, since now it support additionalProperties instead of patternProperties
## 0.9.0 - 17-04-2023
### Added
- add new fields to Definition:
- Security
- Tags
- Summary
- Description
- Deprecated
- Extensions
### Updated
- update kin-openapi to 0.114.0: this change removes components from exposed oas (if not manually set). In this update of kin-openapi, there is a breaking change with the T struct, which now accepts component as pointer.
## 0.8.0 - 23-12-2022
### BREAKING CHANGES
- add `TransformPathToOasPath(path string) string` method to apirouter.Router interface to handle different types of paths parameters. If you use one of the supported routers, you should do nothing;
## 0.7.0 - 22-12-2022
This is a big major release. The main achievement is to increase the usability of this library to all the routers.
Below are listed the breaking changes you should care when update the version.
### BREAKING CHANGES
- `apirouter.NewGorillaMuxRouter` is now `gorilla.NewRouter` (exposed by package `github.com/davidebianchi/gswagger/support/gorilla`).
- removed `apirouter.HandlerFunc`. Now it is exposed by `gorilla.HandlerFunc`
- changed `apirouter.Router` interface:
- now it accept a generics `HandlerFunc` to define the handler function
- add method `SwaggerHandler(contentType string, json []byte) HandlerFunc`
- `NewRouter` function now accept `HandlerFunc` as generics
- drop support to golang <= 1.17
- `GenerateAndExposeSwagger` renamed to `GenerateAndExposeOpenapi`
### Feature
- support to different types of routers
- add [fiber](https://github.com/gofiber/fiber) support
- add [echo](https://echo.labstack.com/) support
## 0.6.1 - 17-11-2022
### Changed
- change jsonschema lib to `mia-platform/jsonschema v0.1.0`. This update removes the `patternProperties` with `additionalProperties` from all schemas
- remove use of deprecated io/ioutil lib
## 0.6.0 - 04-11-2022
### Added
- Tags support to `router.AddRoute` accepted definition
## 0.5.1 - 03-10-2022
### Fixed
- upgrade deps
## v0.5.0 - 05-08-2022
### Added
- path params are auto generated if not set
## v0.4.0 - 02-08-2022
### Changed
- change jsonschema lib to `invopop/jsonschema v0.5.0`. This updates remove the `additionalProperties: true` from all the schemas, as it is the default value
### BREAKING CHANGES
- modified Router interface by sorting addRoute arguments in a different manner: first method and then path
To migrate, all the router implementation must be updated with the Router interface change.
Before:
```go
type Router interface {
AddRoute(path, method string, handler HandlerFunc) Route
}
```
After:
```go
type Router interface {
AddRoute(method, path string, handler HandlerFunc) Route
}
```
### Updates
- kin-openapi@v0.98.0
- go-openapi/swag@v0.21.1
- labstack/echo/v4@v4.7.2
## v0.3.0 - 10-11-2021
### Added
- handle router with path prefix
- add SubRouter method to use a new sub router
## v0.2.0 - 16-10-2021
### BREAKING CHANGES
Introduced the `apirouter.Router` interface, which abstract the used router.
Changed function are:
- Router struct now support `apirouter.Router` interface
- NewRouter function accepted router is an `apirouter.Router`
- AddRawRoute now accept `apirouter.Handler` iterface
- AddRawRoute returns an interface instead of *mux.Router. This interface is the Route returned by specific Router
- AddRoute now accept `apirouter.Handler` iterface
- AddRoute returns an interface instead of *mux.Router. This interface is the Route returned by specific Router
## v0.1.0
Initial release

23
Makefile Normal file
View File

@@ -0,0 +1,23 @@
VERSION ?= latest
# Create a variable that contains the current date in UTC
# Different flow if this script is running on Darwin or Linux machines.
ifeq (Darwin,$(shell uname))
NOW_DATE = $(shell date -u +%d-%m-%Y)
else
NOW_DATE = $(shell date -u -I)
endif
all: test
.PHONY: test
test:
go test ./... -coverprofile coverage.out
.PHONY: version
version:
sed -i.bck "s|## Unreleased|## Unreleased\n\n## ${VERSION} - ${NOW_DATE}|g" "CHANGELOG.md"
rm -fr "CHANGELOG.md.bck"
git add "CHANGELOG.md"
git commit -m "Upgrade version to v${VERSION}"
git tag v${VERSION}

108
README.md
View File

@@ -1,34 +1,51 @@
<div align="center">
[![Build Status][github-actions-svg]][github-actions]
[![Coverage Status](https://coveralls.io/repos/github/davidebianchi/gswagger/badge.svg?branch=main)](https://coveralls.io/github/davidebianchi/gswagger?branch=main)
[![Go Report Card][go-report-card]][go-report-card-link]
[![GoDoc][godoc-svg]][godoc-link]
# Gorilla Swagger
# gswagger
</div>
Generate a swagger dynamically based on the types used to handle request and response.
Generate an openapi spec dynamically based on the types used to handle request and response.
It works with [gorilla-mux](https://github.com/gorilla/mux) and uses [kin-openapi]
to automatically generate and serve a swagger file.
It works with any router, it is simple to add support to your router implementing the [apirouter](apirouter/router.go) interface.
The routers supported out of the box are:
- [gorilla-mux](https://github.com/gorilla/mux)
- [fiber](https://github.com/gofiber/fiber)
- [echo](https://echo.labstack.com/)
This lib uses [kin-openapi] to automatically generate and serve a swagger file.
To convert struct to schemas, we use [jsonschema] library.
The struct must contains the appropriate struct tags to be inserted in json schema to generate the schema dynamically.
It is always possible to add a totally custom swagger schema using [kin-openapi]
It is always possible to add a totally custom swagger schema using [kin-openapi].
## Install
To use it, install with
```sh
go get github.com/davidebianchi/gswagger
```
## Usage
An example usage of this lib:
An example usage of this lib with gorilla mux:
```go
context := context.Background()
r := mux.NewRouter()
router, _ := swagger.NewRouter(r, gswagger.Options{
muxRouter := mux.NewRouter()
router, _ := swagger.NewRouter(gorilla.NewRouter(muxRouter), swagger.Options{
Context: context,
Openapi: &openapi3.Swagger{
Openapi: &openapi3.T{
Info: &openapi3.Info{
Title: "my swagger title",
Title: "my title",
Version: "1.0.0",
},
},
@@ -39,20 +56,30 @@ okHandler := func(w http.ResponseWriter, req *http.Request) {
w.Write([]byte("OK"))
}
router.AddRoute(http.MethodPost, "/users", okHandler, Definitions{
RequestBody: &gswagger.ContentValue{
Content: gswagger.Content{
type User struct {
Name string `json:"name" jsonschema:"title=The user name,required" jsonschema_extras:"example=Jane"`
PhoneNumber int `json:"phone" jsonschema:"title=mobile number of user"`
Groups []string `json:"groups,omitempty" jsonschema:"title=groups of the user,default=users"`
Address string `json:"address" jsonschema:"title=user address"`
}
type errorResponse struct {
Message string `json:"message"`
}
router.AddRoute(http.MethodPost, "/users", okHandler, swagger.Definitions{
RequestBody: &swagger.ContentValue{
Content: swagger.Content{
"application/json": {Value: User{}},
},
},
Responses: map[int]gswagger.ContentValue{
Responses: map[int]swagger.ContentValue{
201: {
Content: gswagger.Content{
Content: swagger.Content{
"text/html": {Value: ""},
},
},
401: {
Content: gswagger.Content{
Content: swagger.Content{
"application/json": {Value: &errorResponse{}},
},
Description: "invalid request",
@@ -60,11 +87,11 @@ router.AddRoute(http.MethodPost, "/users", okHandler, Definitions{
},
})
router.AddRoute(http.MethodGet, "/users", okHandler, Definitions{
Responses: map[int]ContentValue{
router.AddRoute(http.MethodGet, "/users", okHandler, swagger.Definitions{
Responses: map[int]swagger.ContentValue{
200: {
Content: Content{
"application/json": {Value: &Users{}},
Content: swagger.Content{
"application/json": {Value: &[]User{}},
},
},
},
@@ -79,9 +106,41 @@ operation := swagger.NewOperation()
operation.AddRequestBody(requestBody)
router.AddRawRoute(http.MethodPost, "/cars", okHandler, operation)
router.GenerateAndExposeOpenapi()
```
This configuration will output the schema shown [here](testdata/users_employees.json)
This configuration will output the schema shown [here](./support/gorilla/testdata/examples-users.json).
## Auto generated path params schema
The path params, if not set in schema, are auto generated from the path.
The format of the path parameters depends on the router library you are using, as explained below.
### Gorilla Mux
Gorilla Mux supports the path parameters as `{someParam}`, for example as in `/users/{userId}`.
Here is the [example test](./support/gorilla/examples_test.go).
The generated oas schema will contains `userId`, `carId` and `driverId` as path params set to string.
If only one params is set, you must specify manually all the path params.
The generated OAS for this test case is visible [here](./support/gorilla/testdata/examples-users.json).
### Fiber
Fiber supports the path parameters as `:someParam`, for example as in `/users/:userId`.
Here is the [example test](./support/fiber/integration_test.go)
## SubRouter
It is possible to create a new sub router from the swagger.Router.
It is possible to add a prefix to all the routes created under the specific router (instead of use the router specific methods, if given, or repeat the prefix for every route).
It could also be useful if you need a sub router to create a group of APIs which use the same middleware (for example,this could be achieved by the SubRouter features of gorilla mux, for example).
To see the SubRouter example, please see the integration test of one of the supported routers.
### FAQ
@@ -101,7 +160,7 @@ You can create manually a swagger with `oneOf` using the `AddRawRoute` method, o
*Formats*:
* `uuid` is unsupported by [kin-openapi]
- `uuid` is unsupported by [kin-openapi]
## Versioning
@@ -110,10 +169,11 @@ see the [tags on this repository](https://github.com/davidebianchi/gswagger/tags
<!-- Reference -->
[kin-openapi]: https://github.com/getkin/kin-openapi
[jsonschema]: https://github.com/alecthomas/jsonschema
[jsonschema]: https://github.com/mia-platform/jsonschema
[github-actions]: https://github.com/davidebianchi/gswagger/actions
[github-actions-svg]: https://github.com/davidebianchi/gswagger/workflows/Test%20and%20build/badge.svg
[godoc-svg]: https://godoc.org/github.com/davidebianchi/gswagger?status.svg
[godoc-link]: https://godoc.org/github.com/davidebianchi/gswagger
[go-report-card]: https://goreportcard.com/badge/github.com/davidebianchi/gswagger
[go-report-card-link]: https://goreportcard.com/report/github.com/davidebianchi/gswagger
[semver]: https://semver.org/

7
apirouter/router.go Normal file
View File

@@ -0,0 +1,7 @@
package apirouter
type Router[HandlerFunc any, Route any] interface {
AddRoute(method string, path string, handler HandlerFunc) Route
SwaggerHandler(contentType string, blob []byte) HandlerFunc
TransformPathToOasPath(path string) string
}

View File

@@ -0,0 +1,15 @@
package apirouter
import (
"strings"
)
func TransformPathParamsWithColon(path string) string {
pathParams := strings.Split(path, "/")
for i, param := range pathParams {
if strings.HasPrefix(param, ":") {
pathParams[i] = strings.Replace(param, ":", "{", 1) + "}"
}
}
return strings.Join(pathParams, "/")
}

View File

@@ -0,0 +1,59 @@
package apirouter
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestTransformPathParamsWithColon(t *testing.T) {
testCases := []struct {
name string
path string
expectedPath string
}{
{
name: "only /",
path: "/",
expectedPath: "/",
},
{
name: "without params",
path: "/foo",
expectedPath: "/foo",
},
{
name: "without params ending with /",
path: "/foo/",
expectedPath: "/foo/",
},
{
name: "with params",
path: "/foo/:par1",
expectedPath: "/foo/{par1}",
},
{
name: "with params ending with /",
path: "/foo/:par1/",
expectedPath: "/foo/{par1}/",
},
{
name: "with multiple params",
path: "/:par1/:par2/:par3",
expectedPath: "/{par1}/{par2}/{par3}",
},
{
name: "with multiple params ending with /",
path: "/:par1/:par2/:par3/",
expectedPath: "/{par1}/{par2}/{par3}/",
},
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
actual := TransformPathParamsWithColon(test.path)
require.Equal(t, test.expectedPath, actual)
})
}
}

48
go.mod
View File

@@ -1,13 +1,47 @@
module github.com/davidebianchi/gswagger
go 1.15
go 1.24
require (
github.com/alecthomas/jsonschema v0.0.0-20201129101101-7b852d451add
github.com/getkin/kin-openapi v0.35.0
github.com/getkin/kin-openapi v0.131.0
github.com/ghodss/yaml v1.0.0
github.com/go-openapi/swag v0.19.13 // indirect
github.com/gorilla/mux v1.8.0
github.com/iancoleman/orderedmap v0.1.0 // indirect
github.com/stretchr/testify v1.6.1
github.com/gofiber/fiber/v2 v2.52.5
github.com/gorilla/mux v1.8.1
github.com/invopop/jsonschema v0.12.0
github.com/labstack/echo/v4 v4.12.0
github.com/stretchr/testify v1.9.0
)
require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

127
go.sum
View File

@@ -1,61 +1,92 @@
github.com/alecthomas/jsonschema v0.0.0-20201129101101-7b852d451add h1:UWj2AVW7oygpatGgJRy6rvNBcl+J7u8vl6qTV+XNWzA=
github.com/alecthomas/jsonschema v0.0.0-20201129101101-7b852d451add/go.mod h1:/n6+1/DWPltRLWL/VKyUxg6tzsl5kHUCcraimt4vr60=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk=
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/getkin/kin-openapi v0.35.0 h1:YoJusew7Es36hSpnEx3gRL2DGj/82T3j3Akbs9VIXDQ=
github.com/getkin/kin-openapi v0.35.0/go.mod h1:ZJSfy1PxJv2QQvH9EdBj3nupRTVvV42mkW6zKUlRBwk=
github.com/getkin/kin-openapi v0.131.0 h1:NO2UeHnFKRYhZ8wg6Nyh5Cq7dHk4suQQr72a4pMrDxE=
github.com/getkin/kin-openapi v0.131.0/go.mod h1:3OlG51PCYNsPByuiMB0t4fjnNlIDnaEDsjiKUV8nL58=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.13 h1:233UVgMy1DlmCYYfOiFpta6e2urloh+sEs5id6lyzog=
github.com/go-openapi/swag v0.19.13/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 h1:i462o439ZjprVSFSZLZxcsoAe592sZB1rci2Z8j4wdk=
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/iancoleman/orderedmap v0.1.0 h1:2orAxZBJsvimgEBmMWfXaFlzSG2fbQil5qzP3F6cCkg=
github.com/iancoleman/orderedmap v0.1.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
github.com/invopop/jsonschema v0.12.0 h1:6ovsNSuvn9wEQVOyc72aycBMVQFKz7cPdMJn10CvzRI=
github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/klauspost/compress v1.17.0 h1:Rnbp4K9EjcDuVuHtd0dgA4qNuv9yKDYKK1ulpJwgrqM=
github.com/klauspost/compress v1.17.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0=
github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM=
github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw=
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c=
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o=
github.com/perimeterx/marshmallow v1.1.5 h1:a2LALqQ1BlHM8PZblsDdidgv1mWi1DgC2UmX50IvK2s=
github.com/perimeterx/marshmallow v1.1.5/go.mod h1:dsXbUu8CRzfYP5a87xpp0xq9S3u0Vchtcl8we9tYaXw=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.3.1-0.20190311161405-34c6fa2dc709/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -1,88 +0,0 @@
package swagger
import (
"context"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
)
const (
swaggerOpenapiTitle = "test swagger title"
swaggerOpenapiVersion = "test swagger version"
)
func TestIntegration(t *testing.T) {
t.Run("router works correctly", func(t *testing.T) {
muxRouter := setupSwagger(t)
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "OK", body)
t.Run("and generate swagger", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, DefaultJSONDocumentationPath, nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "{\"components\":{},\"info\":{\"title\":\"test swagger title\",\"version\":\"test swagger version\"},\"openapi\":\"3.0.0\",\"paths\":{\"/hello\":{\"get\":{\"responses\":{\"default\":{\"description\":\"\"}}}}}}", body)
})
})
}
func readBody(t *testing.T, requestBody io.ReadCloser) string {
t.Helper()
body, err := ioutil.ReadAll(requestBody)
require.NoError(t, err)
return string(body)
}
func setupSwagger(t *testing.T) *mux.Router {
t.Helper()
context := context.Background()
muxRouter := mux.NewRouter()
router, err := NewRouter(muxRouter, Options{
Context: context,
Openapi: &openapi3.Swagger{
Info: &openapi3.Info{
Title: swaggerOpenapiTitle,
Version: swaggerOpenapiVersion,
},
},
})
require.NoError(t, err)
handler := func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`OK`))
}
operation := Operation{}
_, err = router.AddRawRoute(http.MethodGet, "/hello", handler, operation)
require.NoError(t, err)
err = router.GenerateAndExposeSwagger()
require.NoError(t, err)
return muxRouter
}

128
main.go
View File

@@ -7,50 +7,60 @@ import (
"net/http"
"strings"
"github.com/davidebianchi/gswagger/apirouter"
"github.com/getkin/kin-openapi/openapi3"
"github.com/ghodss/yaml"
"github.com/gorilla/mux"
)
var (
// ErrGenerateSwagger throws when fails the marshalling of the swagger struct.
ErrGenerateSwagger = errors.New("fail to generate swagger")
// ErrValidatingSwagger throws when given swagger params are not correct.
ErrValidatingSwagger = errors.New("fails to validate swagger")
// ErrGenerateOAS throws when fails the marshalling of the swagger struct.
ErrGenerateOAS = errors.New("fail to generate openapi")
// ErrValidatingOAS throws when given openapi params are not correct.
ErrValidatingOAS = errors.New("fails to validate openapi")
// Deprecated: ErrGenerateSwagger has been deprecated, use ErrGenerateOAS instead.
ErrGenerateSwagger = ErrGenerateOAS
// Deprecated: ErrValidatingSwagger has been deprecated, use ErrValidatingOAS instead.
ErrValidatingSwagger = ErrValidatingOAS
)
const (
// DefaultJSONDocumentationPath is the path of the swagger documentation in json format.
// DefaultJSONDocumentationPath is the path of the openapi documentation in json format.
DefaultJSONDocumentationPath = "/documentation/json"
// DefaultYAMLDocumentationPath is the path of the swagger documentation in yaml format.
// DefaultYAMLDocumentationPath is the path of the openapi documentation in yaml format.
DefaultYAMLDocumentationPath = "/documentation/yaml"
defaultOpenapiVersion = "3.0.0"
)
// Router handle the gorilla mux router and the swagger schema
type Router struct {
router *mux.Router
swaggerSchema *openapi3.Swagger
// Router handle the api router and the openapi schema.
// api router supported out of the box are:
// - gorilla mux
type Router[HandlerFunc, Route any] struct {
router apirouter.Router[HandlerFunc, Route]
swaggerSchema *openapi3.T
context context.Context
jsonDocumentationPath string
yamlDocumentationPath string
pathPrefix string
}
// Options to be passed to create the new router and swagger
type Options struct {
Context context.Context
Openapi *openapi3.Swagger
Openapi *openapi3.T
// JSONDocumentationPath is the path exposed by json endpoint. Default to /documentation/json.
JSONDocumentationPath string
// YAMLDocumentationPath is the path exposed by yaml endpoint. Default to /documentation/yaml.
YAMLDocumentationPath string
// Add path prefix to add to every router path.
PathPrefix string
}
// NewRouter generate new router with swagger. Default to OpenAPI 3.0.0
func NewRouter(router *mux.Router, options Options) (*Router, error) {
swagger, err := generateNewValidSwagger(options.Openapi)
// NewRouter generate new router with openapi. Default to OpenAPI 3.0.0
func NewRouter[HandlerFunc, Route any](router apirouter.Router[HandlerFunc, Route], options Options) (*Router[HandlerFunc, Route], error) {
openapi, err := generateNewValidOpenapi(options.Openapi)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrValidatingSwagger, err)
return nil, fmt.Errorf("%w: %s", ErrValidatingOAS, err)
}
var ctx = options.Context
@@ -74,65 +84,73 @@ func NewRouter(router *mux.Router, options Options) (*Router, error) {
jsonDocumentationPath = options.JSONDocumentationPath
}
return &Router{
return &Router[HandlerFunc, Route]{
router: router,
swaggerSchema: swagger,
swaggerSchema: openapi,
context: ctx,
yamlDocumentationPath: yamlDocumentationPath,
jsonDocumentationPath: jsonDocumentationPath,
pathPrefix: options.PathPrefix,
}, nil
}
func generateNewValidSwagger(swagger *openapi3.Swagger) (*openapi3.Swagger, error) {
if swagger == nil {
return nil, fmt.Errorf("swagger is required")
}
if swagger.OpenAPI == "" {
swagger.OpenAPI = defaultOpenapiVersion
}
if swagger.Paths == nil {
swagger.Paths = openapi3.Paths{}
}
if swagger.Info == nil {
return nil, fmt.Errorf("swagger info is required")
}
if swagger.Info.Title == "" {
return nil, fmt.Errorf("swagger info title is required")
}
if swagger.Info.Version == "" {
return nil, fmt.Errorf("swagger info version is required")
}
return swagger, nil
type SubRouterOptions struct {
PathPrefix string
}
// GenerateAndExposeSwagger creates a /documentation/json route on router and
func (r Router[HandlerFunc, Route]) SubRouter(router apirouter.Router[HandlerFunc, Route], opts SubRouterOptions) (*Router[HandlerFunc, Route], error) {
return &Router[HandlerFunc, Route]{
router: router,
swaggerSchema: r.swaggerSchema,
context: r.context,
jsonDocumentationPath: r.jsonDocumentationPath,
yamlDocumentationPath: r.yamlDocumentationPath,
pathPrefix: opts.PathPrefix,
}, nil
}
func generateNewValidOpenapi(openapi *openapi3.T) (*openapi3.T, error) {
if openapi == nil {
return nil, fmt.Errorf("openapi is required")
}
if openapi.OpenAPI == "" {
openapi.OpenAPI = defaultOpenapiVersion
}
if openapi.Paths == nil {
openapi.Paths = &openapi3.Paths{}
}
if openapi.Info == nil {
return nil, fmt.Errorf("openapi info is required")
}
if openapi.Info.Title == "" {
return nil, fmt.Errorf("openapi info title is required")
}
if openapi.Info.Version == "" {
return nil, fmt.Errorf("openapi info version is required")
}
return openapi, nil
}
// GenerateAndExposeOpenapi creates a /documentation/json route on router and
// expose the generated swagger
func (r Router) GenerateAndExposeSwagger() error {
func (r Router[_, _]) GenerateAndExposeOpenapi() error {
if err := r.swaggerSchema.Validate(r.context); err != nil {
return fmt.Errorf("%w: %s", ErrValidatingSwagger, err)
return fmt.Errorf("%w: %s", ErrValidatingOAS, err)
}
jsonSwagger, err := r.swaggerSchema.MarshalJSON()
if err != nil {
return fmt.Errorf("%w json marshal: %s", ErrGenerateSwagger, err)
return fmt.Errorf("%w json marshal: %s", ErrGenerateOAS, err)
}
r.router.HandleFunc(r.jsonDocumentationPath, func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(jsonSwagger)
}).Methods(http.MethodGet)
r.router.AddRoute(http.MethodGet, r.jsonDocumentationPath, r.router.SwaggerHandler("application/json", jsonSwagger))
yamlSwagger, err := yaml.JSONToYAML(jsonSwagger)
if err != nil {
return fmt.Errorf("%w yaml marshal: %s", ErrGenerateSwagger, err)
return fmt.Errorf("%w yaml marshal: %s", ErrGenerateOAS, err)
}
r.router.HandleFunc(r.yamlDocumentationPath, func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.WriteHeader(http.StatusOK)
w.Write(yamlSwagger)
}).Methods(http.MethodGet)
r.router.AddRoute(http.MethodGet, r.yamlDocumentationPath, r.router.SwaggerHandler("text/plain", yamlSwagger))
return nil
}

View File

@@ -3,45 +3,48 @@ package swagger
import (
"context"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
"github.com/davidebianchi/gswagger/support/gorilla"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
)
func TestNewRouter(t *testing.T) {
mRouter := mux.NewRouter()
muxRouter := mux.NewRouter()
mAPIRouter := gorilla.NewRouter(muxRouter)
info := &openapi3.Info{
Title: "my title",
Version: "my version",
}
openapi := &openapi3.Swagger{
openapi := &openapi3.T{
Info: info,
Paths: openapi3.Paths{},
Paths: &openapi3.Paths{},
}
t.Run("not ok - invalid Openapi option", func(t *testing.T) {
r, err := NewRouter(mRouter, Options{})
r, err := NewRouter(mAPIRouter, Options{})
require.Nil(t, r)
require.EqualError(t, err, fmt.Sprintf("%s: swagger is required", ErrValidatingSwagger))
require.EqualError(t, err, fmt.Sprintf("%s: openapi is required", ErrValidatingOAS))
})
t.Run("ok - with default context", func(t *testing.T) {
r, err := NewRouter(mRouter, Options{
r, err := NewRouter(mAPIRouter, Options{
Openapi: openapi,
})
require.NoError(t, err)
require.Equal(t, &Router{
require.Equal(t, &Router[gorilla.HandlerFunc, gorilla.Route]{
context: context.Background(),
router: mRouter,
router: mAPIRouter,
swaggerSchema: openapi,
jsonDocumentationPath: DefaultJSONDocumentationPath,
yamlDocumentationPath: DefaultYAMLDocumentationPath,
@@ -51,15 +54,15 @@ func TestNewRouter(t *testing.T) {
t.Run("ok - with custom context", func(t *testing.T) {
type key struct{}
ctx := context.WithValue(context.Background(), key{}, "value")
r, err := NewRouter(mRouter, Options{
r, err := NewRouter(mAPIRouter, Options{
Openapi: openapi,
Context: ctx,
})
require.NoError(t, err)
require.Equal(t, &Router{
require.Equal(t, &Router[gorilla.HandlerFunc, gorilla.Route]{
context: ctx,
router: mRouter,
router: mAPIRouter,
swaggerSchema: openapi,
jsonDocumentationPath: DefaultJSONDocumentationPath,
yamlDocumentationPath: DefaultYAMLDocumentationPath,
@@ -69,7 +72,7 @@ func TestNewRouter(t *testing.T) {
t.Run("ok - with custom docs paths", func(t *testing.T) {
type key struct{}
ctx := context.WithValue(context.Background(), key{}, "value")
r, err := NewRouter(mRouter, Options{
r, err := NewRouter(mAPIRouter, Options{
Openapi: openapi,
Context: ctx,
JSONDocumentationPath: "/json/path",
@@ -77,9 +80,9 @@ func TestNewRouter(t *testing.T) {
})
require.NoError(t, err)
require.Equal(t, &Router{
require.Equal(t, &Router[gorilla.HandlerFunc, gorilla.Route]{
context: ctx,
router: mRouter,
router: mAPIRouter,
swaggerSchema: openapi,
jsonDocumentationPath: "/json/path",
yamlDocumentationPath: "/yaml/path",
@@ -89,7 +92,7 @@ func TestNewRouter(t *testing.T) {
t.Run("ko - json documentation path does not start with /", func(t *testing.T) {
type key struct{}
ctx := context.WithValue(context.Background(), key{}, "value")
r, err := NewRouter(mRouter, Options{
r, err := NewRouter(mAPIRouter, Options{
Openapi: openapi,
Context: ctx,
JSONDocumentationPath: "json/path",
@@ -103,7 +106,7 @@ func TestNewRouter(t *testing.T) {
t.Run("ko - yaml documentation path does not start with /", func(t *testing.T) {
type key struct{}
ctx := context.WithValue(context.Background(), key{}, "value")
r, err := NewRouter(mRouter, Options{
r, err := NewRouter(mAPIRouter, Options{
Openapi: openapi,
Context: ctx,
JSONDocumentationPath: "/json/path",
@@ -116,50 +119,50 @@ func TestNewRouter(t *testing.T) {
}
func TestGenerateValidSwagger(t *testing.T) {
t.Run("not ok - empty swagger info", func(t *testing.T) {
swagger := &openapi3.Swagger{}
t.Run("not ok - empty openapi info", func(t *testing.T) {
openapi := &openapi3.T{}
swagger, err := generateNewValidSwagger(swagger)
require.Nil(t, swagger)
require.EqualError(t, err, "swagger info is required")
openapi, err := generateNewValidOpenapi(openapi)
require.Nil(t, openapi)
require.EqualError(t, err, "openapi info is required")
})
t.Run("not ok - empty info title", func(t *testing.T) {
swagger := &openapi3.Swagger{
openapi := &openapi3.T{
Info: &openapi3.Info{},
}
swagger, err := generateNewValidSwagger(swagger)
require.Nil(t, swagger)
require.EqualError(t, err, "swagger info title is required")
openapi, err := generateNewValidOpenapi(openapi)
require.Nil(t, openapi)
require.EqualError(t, err, "openapi info title is required")
})
t.Run("not ok - empty info version", func(t *testing.T) {
swagger := &openapi3.Swagger{
openapi := &openapi3.T{
Info: &openapi3.Info{
Title: "title",
},
}
swagger, err := generateNewValidSwagger(swagger)
require.Nil(t, swagger)
require.EqualError(t, err, "swagger info version is required")
openapi, err := generateNewValidOpenapi(openapi)
require.Nil(t, openapi)
require.EqualError(t, err, "openapi info version is required")
})
t.Run("ok - custom swagger", func(t *testing.T) {
swagger := &openapi3.Swagger{
t.Run("ok - custom openapi", func(t *testing.T) {
openapi := &openapi3.T{
Info: &openapi3.Info{},
}
swagger, err := generateNewValidSwagger(swagger)
require.Nil(t, swagger)
require.EqualError(t, err, "swagger info title is required")
openapi, err := generateNewValidOpenapi(openapi)
require.Nil(t, openapi)
require.EqualError(t, err, "openapi info title is required")
})
t.Run("not ok - swagger is required", func(t *testing.T) {
swagger, err := generateNewValidSwagger(nil)
require.Nil(t, swagger)
require.EqualError(t, err, "swagger is required")
t.Run("not ok - openapi is required", func(t *testing.T) {
openapi, err := generateNewValidOpenapi(nil)
require.Nil(t, openapi)
require.EqualError(t, err, "openapi is required")
})
t.Run("ok", func(t *testing.T) {
@@ -167,30 +170,30 @@ func TestGenerateValidSwagger(t *testing.T) {
Title: "my title",
Version: "my version",
}
swagger := &openapi3.Swagger{
openapi := &openapi3.T{
Info: info,
}
swagger, err := generateNewValidSwagger(swagger)
openapi, err := generateNewValidOpenapi(openapi)
require.NoError(t, err)
require.Equal(t, &openapi3.Swagger{
require.Equal(t, &openapi3.T{
OpenAPI: defaultOpenapiVersion,
Info: info,
Paths: openapi3.Paths{},
}, swagger)
Paths: &openapi3.Paths{},
}, openapi)
})
}
func TestGenerateAndExposeSwagger(t *testing.T) {
t.Run("fails swagger validation", func(t *testing.T) {
t.Run("fails openapi validation", func(t *testing.T) {
mRouter := mux.NewRouter()
router, err := NewRouter(mRouter, Options{
Openapi: &openapi3.Swagger{
router, err := NewRouter(gorilla.NewRouter(mRouter), Options{
Openapi: &openapi3.T{
Info: &openapi3.Info{
Title: "title",
Version: "version",
},
Components: openapi3.Components{
Components: &openapi3.Components{
Schemas: map[string]*openapi3.SchemaRef{
"&%": {},
},
@@ -199,22 +202,23 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
})
require.NoError(t, err)
err = router.GenerateAndExposeSwagger()
err = router.GenerateAndExposeOpenapi()
require.Error(t, err)
require.True(t, strings.HasPrefix(err.Error(), fmt.Sprintf("%s:", ErrValidatingSwagger)))
require.True(t, strings.HasPrefix(err.Error(), fmt.Sprintf("%s:", ErrValidatingOAS)))
})
t.Run("correctly expose json documentation from loaded swagger file", func(t *testing.T) {
t.Run("correctly expose json documentation from loaded openapi file", func(t *testing.T) {
mRouter := mux.NewRouter()
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromFile("testdata/users_employees.json")
openapi, err := openapi3.NewLoader().LoadFromFile("testdata/users_employees.json")
require.NoError(t, err)
router, err := NewRouter(mRouter, Options{
Openapi: swagger,
router, err := NewRouter(gorilla.NewRouter(mRouter), Options{
Openapi: openapi,
})
require.NoError(t, err)
err = router.GenerateAndExposeSwagger()
err = router.GenerateAndExposeOpenapi()
require.NoError(t, err)
w := httptest.NewRecorder()
@@ -225,23 +229,24 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
body := readBody(t, w.Result().Body)
actual, err := ioutil.ReadFile("testdata/users_employees.json")
actual, err := os.ReadFile("testdata/users_employees.json")
require.NoError(t, err)
require.JSONEq(t, string(actual), body)
})
t.Run("correctly expose json documentation from loaded swagger file - custom path", func(t *testing.T) {
t.Run("correctly expose json documentation from loaded openapi file - custom path", func(t *testing.T) {
mRouter := mux.NewRouter()
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromFile("testdata/users_employees.json")
openapi, err := openapi3.NewLoader().LoadFromFile("testdata/users_employees.json")
require.NoError(t, err)
router, err := NewRouter(mRouter, Options{
Openapi: swagger,
router, err := NewRouter(gorilla.NewRouter(mRouter), Options{
Openapi: openapi,
JSONDocumentationPath: "/custom/path",
})
require.NoError(t, err)
err = router.GenerateAndExposeSwagger()
err = router.GenerateAndExposeOpenapi()
require.NoError(t, err)
w := httptest.NewRecorder()
@@ -252,22 +257,23 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
body := readBody(t, w.Result().Body)
actual, err := ioutil.ReadFile("testdata/users_employees.json")
actual, err := os.ReadFile("testdata/users_employees.json")
require.NoError(t, err)
require.JSONEq(t, string(actual), body)
})
t.Run("correctly expose yaml documentation from loaded swagger file", func(t *testing.T) {
t.Run("correctly expose yaml documentation from loaded openapi file", func(t *testing.T) {
mRouter := mux.NewRouter()
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromFile("testdata/users_employees.json")
openapi, err := openapi3.NewLoader().LoadFromFile("testdata/users_employees.json")
require.NoError(t, err)
router, err := NewRouter(mRouter, Options{
Openapi: swagger,
router, err := NewRouter(gorilla.NewRouter(mRouter), Options{
Openapi: openapi,
})
require.NoError(t, err)
err = router.GenerateAndExposeSwagger()
err = router.GenerateAndExposeOpenapi()
require.NoError(t, err)
w := httptest.NewRecorder()
@@ -278,23 +284,24 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "text/plain"))
body := readBody(t, w.Result().Body)
expected, err := ioutil.ReadFile("testdata/users_employees.yaml")
expected, err := os.ReadFile("testdata/users_employees.yaml")
require.NoError(t, err)
require.YAMLEq(t, string(expected), body, string(body))
})
t.Run("correctly expose yaml documentation from loaded swagger file - custom path", func(t *testing.T) {
t.Run("correctly expose yaml documentation from loaded openapi file - custom path", func(t *testing.T) {
mRouter := mux.NewRouter()
swagger, err := openapi3.NewSwaggerLoader().LoadSwaggerFromFile("testdata/users_employees.json")
openapi, err := openapi3.NewLoader().LoadFromFile("testdata/users_employees.json")
require.NoError(t, err)
router, err := NewRouter(mRouter, Options{
Openapi: swagger,
router, err := NewRouter(gorilla.NewRouter(mRouter), Options{
Openapi: openapi,
YAMLDocumentationPath: "/custom/path",
})
require.NoError(t, err)
err = router.GenerateAndExposeSwagger()
err = router.GenerateAndExposeOpenapi()
require.NoError(t, err)
w := httptest.NewRecorder()
@@ -305,8 +312,132 @@ func TestGenerateAndExposeSwagger(t *testing.T) {
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "text/plain"))
body := readBody(t, w.Result().Body)
expected, err := ioutil.ReadFile("testdata/users_employees.yaml")
expected, err := os.ReadFile("testdata/users_employees.yaml")
require.NoError(t, err)
require.YAMLEq(t, string(expected), body, string(body))
})
t.Run("ok - subrouter", func(t *testing.T) {
mRouter := mux.NewRouter()
router, err := NewRouter(gorilla.NewRouter(mRouter), Options{
Openapi: &openapi3.T{
Info: &openapi3.Info{
Title: "test openapi title",
Version: "test openapi version",
},
},
JSONDocumentationPath: "/custom/path",
})
require.NoError(t, err)
router.AddRoute(http.MethodGet, "/foo", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}, Definitions{})
mSubRouter := mRouter.NewRoute().Subrouter()
subrouter, err := router.SubRouter(gorilla.NewRouter(mSubRouter), SubRouterOptions{
PathPrefix: "/prefix",
})
require.NoError(t, err)
_, err = subrouter.AddRoute(http.MethodGet, "/taz", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}, Definitions{})
require.NoError(t, err)
t.Run("add route with path equal to prefix path", func(t *testing.T) {
_, err = subrouter.AddRoute(http.MethodGet, "", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}, Definitions{})
require.NoError(t, err)
})
err = router.GenerateAndExposeOpenapi()
require.NoError(t, err)
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/custom/path", nil)
mRouter.ServeHTTP(w, req)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
body := readBody(t, w.Result().Body)
actual, err := os.ReadFile("testdata/subrouter.json")
require.NoError(t, err)
require.JSONEq(t, string(actual), body)
t.Run("test request /prefix", func(t *testing.T) {
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/prefix", nil)
mRouter.ServeHTTP(w, req)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
})
t.Run("test request /prefix/taz", func(t *testing.T) {
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/prefix/taz", nil)
mRouter.ServeHTTP(w, req)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
})
t.Run("test request /foo", func(t *testing.T) {
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/foo", nil)
mRouter.ServeHTTP(w, req)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
})
})
t.Run("ok - new router with path prefix", func(t *testing.T) {
mRouter := mux.NewRouter()
router, err := NewRouter(gorilla.NewRouter(mRouter), Options{
Openapi: &openapi3.T{
Info: &openapi3.Info{
Title: "test openapi title",
Version: "test openapi version",
},
},
JSONDocumentationPath: "/custom/path",
PathPrefix: "/prefix",
})
require.NoError(t, err)
router.AddRoute(http.MethodGet, "/foo", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("ok"))
}, Definitions{})
err = router.GenerateAndExposeOpenapi()
require.NoError(t, err)
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, "/custom/path", nil)
mRouter.ServeHTTP(w, req)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
require.True(t, strings.Contains(w.Result().Header.Get("content-type"), "application/json"))
body := readBody(t, w.Result().Body)
actual, err := os.ReadFile("testdata/router_with_prefix.json")
require.NoError(t, err)
require.JSONEq(t, string(actual), body, body)
})
}
func readBody(t *testing.T, requestBody io.ReadCloser) string {
t.Helper()
body, err := io.ReadAll(requestBody)
require.NoError(t, err)
return string(body)
}

View File

@@ -28,7 +28,7 @@ func (o *Operation) AddRequestBody(requestBody *openapi3.RequestBody) {
// but it is always possible to add it manually.
func (o *Operation) AddResponse(status int, response *openapi3.Response) {
if o.Responses == nil {
o.Responses = make(openapi3.Responses)
o.Responses = &openapi3.Responses{}
}
if response.Description == nil {
// a description is required by kin openapi, so we set an empty description
@@ -37,3 +37,12 @@ func (o *Operation) AddResponse(status int, response *openapi3.Response) {
}
o.Operation.AddResponse(status, response)
}
func (o *Operation) addSecurityRequirements(securityRequirements SecurityRequirements) {
if securityRequirements != nil && o.Security == nil {
o.Security = openapi3.NewSecurityRequirements()
}
for _, securityRequirement := range securityRequirements {
o.Security.With(openapi3.SecurityRequirement(securityRequirement))
}
}

View File

@@ -27,7 +27,7 @@ func TestNewOperation(t *testing.T) {
operation.Responses = openapi3.NewResponses()
return operation
},
expectedJSON: `{"components":{},"info":{"title":"test swagger title","version":"test swagger version"},"openapi":"3.0.0","paths":{"/":{"post":{"requestBody":{"content":{"application/json":{"schema":{"properties":{"bar":{"maximum":15,"minimum":5,"type":"integer"},"foo":{"type":"string"}},"type":"object"}}}},"responses":{"default":{"description":""}}}}}}`,
expectedJSON: `{"info":{"title":"test openapi title","version":"test openapi version"},"openapi":"3.0.0","paths":{"/":{"post":{"requestBody":{"content":{"application/json":{"schema":{"properties":{"bar":{"maximum":15,"minimum":5,"type":"integer"},"foo":{"type":"string"}},"type":"object"}}}},"responses":{"default":{"description":""}}}}}}`,
},
{
name: "add response",
@@ -36,19 +36,19 @@ func TestNewOperation(t *testing.T) {
operation.AddResponse(200, response)
return operation
},
expectedJSON: `{"components":{},"info":{"title":"test swagger title","version":"test swagger version"},"openapi":"3.0.0","paths":{"/":{"post":{"responses":{"200":{"content":{"application/json":{"schema":{"properties":{"bar":{"maximum":15,"minimum":5,"type":"integer"},"foo":{"type":"string"}},"type":"object"}}},"description":""}}}}}}`,
expectedJSON: `{"info":{"title":"test openapi title","version":"test openapi version"},"openapi":"3.0.0","paths":{"/":{"post":{"responses":{"200":{"content":{"application/json":{"schema":{"properties":{"bar":{"maximum":15,"minimum":5,"type":"integer"},"foo":{"type":"string"}},"type":"object"}}},"description":""}}}}}}`,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
swagger := getBaseSwagger(t)
swagger.OpenAPI = "3.0.0"
openapi := getBaseSwagger(t)
openapi.OpenAPI = "3.0.0"
operation := test.getOperation(t, NewOperation())
swagger.AddOperation("/", http.MethodPost, operation.Operation)
openapi.AddOperation("/", http.MethodPost, operation.Operation)
data, _ := swagger.MarshalJSON()
data, _ := openapi.MarshalJSON()
jsonData := string(data)
require.JSONEq(t, test.expectedJSON, jsonData, "actual json data: %s", jsonData)
})

124
route.go
View File

@@ -3,12 +3,13 @@ package swagger
import (
"errors"
"fmt"
"net/http"
"path"
"regexp"
"sort"
"strings"
"github.com/alecthomas/jsonschema"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gorilla/mux"
"github.com/invopop/jsonschema"
)
var (
@@ -22,17 +23,14 @@ var (
ErrQuerystring = errors.New("errors generating querystring schema")
)
// Handler is the http type handler
type Handler func(w http.ResponseWriter, req *http.Request)
// AddRawRoute add route to router with specific method, path and handler. Add the
// router also to the swagger schema, after validating it
func (r Router) AddRawRoute(method string, path string, handler Handler, operation Operation) (*mux.Route, error) {
// router also to the openapi schema, after validating it
func (r Router[HandlerFunc, Route]) AddRawRoute(method string, routePath string, handler HandlerFunc, operation Operation) (Route, error) {
op := operation.Operation
if op != nil {
err := operation.Validate(r.context)
if err != nil {
return nil, err
return getZero[Route](), err
}
} else {
op = openapi3.NewOperation()
@@ -40,12 +38,12 @@ func (r Router) AddRawRoute(method string, path string, handler Handler, operati
op.Responses = openapi3.NewResponses()
}
}
r.swaggerSchema.AddOperation(path, method, op)
pathWithPrefix := path.Join(r.pathPrefix, routePath)
oasPath := r.router.TransformPathToOasPath(pathWithPrefix)
r.swaggerSchema.AddOperation(oasPath, method, op)
return r.router.HandleFunc(path, func(w http.ResponseWriter, req *http.Request) {
// Handle, when content-type is json, the request/response marshalling? Maybe with a specific option.
handler(w, req)
}).Methods(method), nil
// Handle, when content-type is json, the request/response marshalling? Maybe with a specific option.
return r.router.AddRoute(method, pathWithPrefix, handler), nil
}
// Content is the type of a content.
@@ -58,28 +56,58 @@ type Schema struct {
AllowAdditionalProperties bool
}
// ParameterValue is the struct containing the schema or the content information.
// If content is specified, it takes precedence.
type ParameterValue map[string]struct {
type Parameter struct {
Content Content
Schema *Schema
Description string
}
// ParameterValue is the struct containing the schema or the content information.
// If content is specified, it takes precedence.
type ParameterValue map[string]Parameter
// ContentValue is the struct containing the content information.
type ContentValue struct {
Content Content
Description string
}
type SecurityRequirements []SecurityRequirement
type SecurityRequirement map[string][]string
// Definitions of the route.
// To see how to use, refer to https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md
type Definitions struct {
// Specification extensions https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions
Extensions map[string]interface{}
// Optional field for documentation
Tags []string
Summary string
Description string
Deprecated bool
// PathParams contains the path parameters. If empty is autocompleted from the path
PathParams ParameterValue
Querystring ParameterValue
Headers ParameterValue
Cookies ParameterValue
RequestBody *ContentValue
Responses map[int]ContentValue
Security SecurityRequirements
}
func newOperationFromDefinition(schema Definitions) Operation {
operation := NewOperation()
operation.Responses = &openapi3.Responses{}
operation.Tags = schema.Tags
operation.Extensions = schema.Extensions
operation.addSecurityRequirements(schema.Security)
operation.Description = schema.Description
operation.Summary = schema.Summary
operation.Deprecated = schema.Deprecated
return operation
}
const (
@@ -89,45 +117,45 @@ const (
cookieParamType = "cookie"
)
// AddRoute add a route with json schema inferted by passed schema.
func (r Router) AddRoute(method string, path string, handler Handler, schema Definitions) (*mux.Route, error) {
operation := NewOperation()
operation.Responses = make(openapi3.Responses)
// AddRoute add a route with json schema inferred by passed schema.
func (r Router[HandlerFunc, Route]) AddRoute(method string, path string, handler HandlerFunc, schema Definitions) (Route, error) {
operation := newOperationFromDefinition(schema)
err := r.resolveRequestBodySchema(schema.RequestBody, operation)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrRequestBody, err)
return getZero[Route](), fmt.Errorf("%w: %s", ErrRequestBody, err)
}
err = r.resolveResponsesSchema(schema.Responses, operation)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrResponses, err)
return getZero[Route](), fmt.Errorf("%w: %s", ErrResponses, err)
}
err = r.resolveParameterSchema(pathParamsType, schema.PathParams, operation)
oasPath := r.router.TransformPathToOasPath(path)
err = r.resolveParameterSchema(pathParamsType, getPathParamsAutoComplete(schema, oasPath), operation)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrPathParams, err)
return getZero[Route](), fmt.Errorf("%w: %s", ErrPathParams, err)
}
err = r.resolveParameterSchema(queryParamType, schema.Querystring, operation)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrPathParams, err)
return getZero[Route](), fmt.Errorf("%w: %s", ErrPathParams, err)
}
err = r.resolveParameterSchema(headerParamType, schema.Headers, operation)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrPathParams, err)
return getZero[Route](), fmt.Errorf("%w: %s", ErrPathParams, err)
}
err = r.resolveParameterSchema(cookieParamType, schema.Cookies, operation)
if err != nil {
return nil, fmt.Errorf("%w: %s", ErrPathParams, err)
return getZero[Route](), fmt.Errorf("%w: %s", ErrPathParams, err)
}
return r.AddRawRoute(method, path, handler, operation)
}
func (r Router) getSchemaFromInterface(v interface{}, allowAdditionalProperties bool) (*openapi3.Schema, error) {
func (r Router[_, _]) getSchemaFromInterface(v interface{}, allowAdditionalProperties bool) (*openapi3.Schema, error) {
if v == nil {
return &openapi3.Schema{}, nil
}
@@ -135,10 +163,11 @@ func (r Router) getSchemaFromInterface(v interface{}, allowAdditionalProperties
reflector := &jsonschema.Reflector{
DoNotReference: true,
AllowAdditionalProperties: allowAdditionalProperties,
Anonymous: true,
}
jsonSchema := reflector.Reflect(v)
jsonschema.Version = ""
jsonSchema.Version = ""
// Empty definitions. Definitions are not valid in openapi3, which use components.
// In the future, we could add an option to fill the components in openapi spec.
jsonSchema.Definitions = nil
@@ -157,7 +186,7 @@ func (r Router) getSchemaFromInterface(v interface{}, allowAdditionalProperties
return schema, nil
}
func (r Router) resolveRequestBodySchema(bodySchema *ContentValue, operation Operation) error {
func (r Router[_, _]) resolveRequestBodySchema(bodySchema *ContentValue, operation Operation) error {
if bodySchema == nil {
return nil
}
@@ -176,7 +205,7 @@ func (r Router) resolveRequestBodySchema(bodySchema *ContentValue, operation Ope
return nil
}
func (r Router) resolveResponsesSchema(responses map[int]ContentValue, operation Operation) error {
func (r Router[_, _]) resolveResponsesSchema(responses map[int]ContentValue, operation Operation) error {
if responses == nil {
operation.Responses = openapi3.NewResponses()
}
@@ -195,7 +224,7 @@ func (r Router) resolveResponsesSchema(responses map[int]ContentValue, operation
return nil
}
func (r Router) resolveParameterSchema(paramType string, paramConfig ParameterValue, operation Operation) error {
func (r Router[_, _]) resolveParameterSchema(paramType string, paramConfig ParameterValue, operation Operation) error {
var keys = make([]string, 0, len(paramConfig))
for k := range paramConfig {
keys = append(keys, k)
@@ -246,7 +275,7 @@ func (r Router) resolveParameterSchema(paramType string, paramConfig ParameterVa
return nil
}
func (r Router) addContentToOASSchema(content Content) (openapi3.Content, error) {
func (r Router[_, _]) addContentToOASSchema(content Content) (openapi3.Content, error) {
oasContent := openapi3.NewContent()
for k, v := range content {
var err error
@@ -258,3 +287,30 @@ func (r Router) addContentToOASSchema(content Content) (openapi3.Content, error)
}
return oasContent, nil
}
func getPathParamsAutoComplete(schema Definitions, path string) ParameterValue {
if schema.PathParams == nil {
re := regexp.MustCompile(`\{([^}]+)\}`)
segments := strings.Split(path, "/")
for _, segment := range segments {
params := re.FindAllStringSubmatch(segment, -1)
if len(params) == 0 {
continue
}
if schema.PathParams == nil {
schema.PathParams = make(ParameterValue)
}
for _, param := range params {
schema.PathParams[param[1]] = Parameter{
Schema: &Schema{Value: ""},
}
}
}
}
return schema.PathParams
}
func getZero[T any]() T {
var result T
return result
}

View File

@@ -3,11 +3,12 @@ package swagger
import (
"context"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/davidebianchi/gswagger/support/gorilla"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
@@ -16,8 +17,9 @@ import (
const jsonType = "application/json"
const formDataType = "multipart/form-data"
func TestAddRoutes(t *testing.T) {
type TestRouter = Router[gorilla.HandlerFunc, gorilla.Route]
func TestAddRoutes(t *testing.T) {
type User struct {
Name string `json:"name" jsonschema:"title=The user name,required" jsonschema_extras:"example=Jane"`
PhoneNumber int `json:"phone" jsonschema:"title=mobile number of user"`
@@ -46,6 +48,7 @@ func TestAddRoutes(t *testing.T) {
FirstName string `json:"firstName" jsonschema:"title=user first name"`
LastName string `json:"lastName" jsonschema:"title=user last name"`
Metadata interface{} `json:"metadata,omitempty" jsonschema:"title=custom properties,oneof_type=string;number"`
UserType string `json:"userType,omitempty" jsonschema:"title=type of user,enum=simple,enum=advanced"`
}
okHandler := func(w http.ResponseWriter, req *http.Request) {
@@ -55,19 +58,19 @@ func TestAddRoutes(t *testing.T) {
tests := []struct {
name string
routes func(t *testing.T, router *Router)
routes func(t *testing.T, router *TestRouter)
fixturesPath string
testPath string
testMethod string
}{
{
name: "no routes",
routes: func(t *testing.T, router *Router) {},
routes: func(t *testing.T, router *TestRouter) {},
fixturesPath: "testdata/empty.json",
},
{
name: "empty route schema",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodPost, "/", okHandler, Definitions{})
require.NoError(t, err)
},
@@ -77,7 +80,7 @@ func TestAddRoutes(t *testing.T) {
},
{
name: "multiple real routes",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodPost, "/users", okHandler, Definitions{
RequestBody: &ContentValue{
Content: Content{
@@ -127,7 +130,7 @@ func TestAddRoutes(t *testing.T) {
},
{
name: "multipart request body",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodPost, "/files", okHandler, Definitions{
RequestBody: &ContentValue{
Content: Content{
@@ -156,7 +159,7 @@ func TestAddRoutes(t *testing.T) {
},
{
name: "schema with params",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
var number = 0
_, err := router.AddRoute(http.MethodGet, "/users/{userId}", okHandler, Definitions{
PathParams: ParameterValue{
@@ -183,9 +186,30 @@ func TestAddRoutes(t *testing.T) {
testPath: "/users/12",
fixturesPath: "testdata/params.json",
},
{
name: "schema without explicit params autofill them",
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/users/{userId}", okHandler, Definitions{
Querystring: ParameterValue{
"query": {
Schema: &Schema{Value: ""},
},
},
})
require.NoError(t, err)
_, err = router.AddRoute(http.MethodGet, "/cars/{carId}/drivers/{driverId}", okHandler, Definitions{})
require.NoError(t, err)
_, err = router.AddRoute(http.MethodGet, "/files/{name}.{extension}", okHandler, Definitions{})
require.NoError(t, err)
},
testPath: "/files/myid.yaml",
fixturesPath: "testdata/params-autofill.json",
},
{
name: "schema with querystring",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/projects", okHandler, Definitions{
Querystring: ParameterValue{
"projectId": {
@@ -201,7 +225,7 @@ func TestAddRoutes(t *testing.T) {
},
{
name: "schema with headers",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/projects", okHandler, Definitions{
Headers: ParameterValue{
"foo": {
@@ -220,7 +244,7 @@ func TestAddRoutes(t *testing.T) {
},
{
name: "schema with cookies",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/projects", okHandler, Definitions{
Cookies: ParameterValue{
"debug": {
@@ -239,7 +263,7 @@ func TestAddRoutes(t *testing.T) {
},
{
name: "schema defined without value",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodPost, "/{id}", okHandler, Definitions{
RequestBody: &ContentValue{
Description: "request body without schema",
@@ -268,7 +292,7 @@ func TestAddRoutes(t *testing.T) {
},
{
name: "allOf schema",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
schema := openapi3.NewAllOfSchema()
schema.AllOf = []*openapi3.SchemaRef{
{
@@ -313,7 +337,7 @@ func TestAddRoutes(t *testing.T) {
},
{
name: "anyOf schema",
routes: func(t *testing.T, router *Router) {
routes: func(t *testing.T, router *TestRouter) {
schema := openapi3.NewAnyOfSchema()
schema.AnyOf = []*openapi3.SchemaRef{
{
@@ -356,8 +380,8 @@ func TestAddRoutes(t *testing.T) {
fixturesPath: "testdata/anyof.json",
},
{
name: "oneOf support on properties",
routes: func(t *testing.T, router *Router) {
name: "oneOf and enum are supported on properties",
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodPost, "/user-profile", okHandler, Definitions{
RequestBody: &ContentValue{
Content: Content{
@@ -403,6 +427,77 @@ func TestAddRoutes(t *testing.T) {
testMethod: http.MethodPost,
fixturesPath: "testdata/oneOf.json",
},
{
name: "schema with tags",
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/users", okHandler, Definitions{
Tags: []string{"Tag1", "Tag2"},
})
require.NoError(t, err)
},
testPath: "/users",
fixturesPath: "testdata/tags.json",
},
{
name: "schema with security",
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/users", okHandler, Definitions{
Security: SecurityRequirements{
SecurityRequirement{
"api_key": []string{},
"auth": []string{
"resource.write",
},
},
},
})
require.NoError(t, err)
},
testPath: "/users",
fixturesPath: "testdata/security.json",
},
{
name: "schema with extension",
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/users", okHandler, Definitions{
Extensions: map[string]interface{}{
"x-extension-field": map[string]string{
"foo": "bar",
},
},
})
require.NoError(t, err)
},
testPath: "/users",
fixturesPath: "testdata/extension.json",
},
{
name: "invalid extension - not starts with x-",
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/", okHandler, Definitions{
Extensions: map[string]interface{}{
"extension-field": map[string]string{
"foo": "bar",
},
},
})
require.EqualError(t, err, "extra sibling fields: [extension-field]")
},
fixturesPath: "testdata/empty.json",
},
{
name: "schema with summary, description, deprecated and operationID",
routes: func(t *testing.T, router *TestRouter) {
_, err := router.AddRoute(http.MethodGet, "/users", okHandler, Definitions{
Summary: "small description",
Description: "this is the long route description",
Deprecated: true,
})
require.NoError(t, err)
},
testPath: "/users",
fixturesPath: "testdata/users-deprecated-with-description.json",
},
}
for _, test := range tests {
@@ -410,7 +505,7 @@ func TestAddRoutes(t *testing.T) {
context := context.Background()
r := mux.NewRouter()
router, err := NewRouter(r, Options{
router, err := NewRouter(gorilla.NewRouter(r), Options{
Context: context,
Openapi: getBaseSwagger(t),
})
@@ -420,7 +515,7 @@ func TestAddRoutes(t *testing.T) {
// Add routes to test
test.routes(t, router)
err = router.GenerateAndExposeSwagger()
err = router.GenerateAndExposeOpenapi()
require.NoError(t, err)
if test.testPath != "" {
@@ -438,7 +533,7 @@ func TestAddRoutes(t *testing.T) {
require.Equal(t, "OK", body)
}
t.Run("and generate swagger documentation in json", func(t *testing.T) {
t.Run("and generate openapi documentation in json", func(t *testing.T) {
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, DefaultJSONDocumentationPath, nil)
@@ -447,7 +542,7 @@ func TestAddRoutes(t *testing.T) {
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
expected, err := ioutil.ReadFile(test.fixturesPath)
expected, err := os.ReadFile(test.fixturesPath)
require.NoError(t, err)
require.JSONEq(t, string(expected), body, "actual json data: %s", body)
})
@@ -589,8 +684,7 @@ func TestResolveRequestBodySchema(t *testing.T) {
"type":"object",
"properties": {
"id": {"type": "string"}
},
"additionalProperties": true
}
}
}
}
@@ -601,7 +695,7 @@ func TestResolveRequestBodySchema(t *testing.T) {
}
mux := mux.NewRouter()
router, err := NewRouter(mux, Options{
router, err := NewRouter(gorilla.NewRouter(mux), Options{
Openapi: getBaseSwagger(t),
})
require.NoError(t, err)
@@ -627,6 +721,14 @@ func TestResolveResponsesSchema(t *testing.T) {
type TestStruct struct {
Message string `json:"message,omitempty"`
}
type NestedTestStruct struct {
Notification string `json:"notification"`
NestedMapOfStructs map[string]TestStruct `json:"nestedMapOfStructs,omitempty"`
}
type ComplexTestStruct struct {
Communication string `json:"communication"`
MapOfStructs map[string]NestedTestStruct `json:"mapOfStructs,omitempty"`
}
tests := []struct {
name string
responsesSchema map[int]ContentValue
@@ -669,6 +771,79 @@ func TestResolveResponsesSchema(t *testing.T) {
}
}`,
},
{
name: "with complex schema",
responsesSchema: map[int]ContentValue{
200: {
Content: Content{
jsonType: {Value: &ComplexTestStruct{
Communication: "myCommunication",
MapOfStructs: map[string]NestedTestStruct{
"myProperty": {
Notification: "myNotification",
NestedMapOfStructs: map[string]TestStruct{
"myNestedProperty": {
Message: "myMessage",
},
},
},
},
}},
},
},
},
expectedErr: nil,
expectedJSON: `{
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"properties": {
"communication": {
"type": "string"
},
"mapOfStructs": {
"additionalProperties": {
"additionalProperties": false,
"properties": {
"nestedMapOfStructs": {
"additionalProperties": {
"additionalProperties": false,
"properties": {
"message": {
"type": "string"
}
},
"type": "object"
},
"type": "object"
},
"notification": {
"type": "string"
}
},
"required": [
"notification"
],
"type": "object"
},
"type": "object"
}
},
"required": [
"communication"
],
"type": "object"
}
}
},
"description": ""
}
}
}`,
},
{
name: "with more status codes",
responsesSchema: map[int]ContentValue{
@@ -744,7 +919,7 @@ func TestResolveResponsesSchema(t *testing.T) {
}
mux := mux.NewRouter()
router, err := NewRouter(mux, Options{
router, err := NewRouter(gorilla.NewRouter(mux), Options{
Openapi: getBaseSwagger(t),
})
require.NoError(t, err)
@@ -752,7 +927,7 @@ func TestResolveResponsesSchema(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
operation := NewOperation()
operation.Responses = make(openapi3.Responses)
operation.Responses = &openapi3.Responses{}
err := router.resolveResponsesSchema(test.responsesSchema, operation)
@@ -914,7 +1089,7 @@ func TestResolveParametersSchema(t *testing.T) {
}
mux := mux.NewRouter()
router, err := NewRouter(mux, Options{
router, err := NewRouter(gorilla.NewRouter(mux), Options{
Openapi: getBaseSwagger(t),
})
require.NoError(t, err)
@@ -936,13 +1111,71 @@ func TestResolveParametersSchema(t *testing.T) {
}
}
func getBaseSwagger(t *testing.T) *openapi3.Swagger {
func getBaseSwagger(t *testing.T) *openapi3.T {
t.Helper()
return &openapi3.Swagger{
return &openapi3.T{
Info: &openapi3.Info{
Title: swaggerOpenapiTitle,
Version: swaggerOpenapiVersion,
Title: "test openapi title",
Version: "test openapi version",
},
}
}
func TestGetPathParamsAutoComplete(t *testing.T) {
testCases := map[string]struct {
schemaDefinition Definitions
path string
expected ParameterValue
}{
"no path params": {
schemaDefinition: Definitions{},
path: "/users",
expected: nil,
},
"with path params": {
schemaDefinition: Definitions{},
path: "/users/{userId}",
expected: ParameterValue{
"userId": {
Schema: &Schema{Value: ""},
},
},
},
"with multiple path params": {
schemaDefinition: Definitions{},
path: "/foo/{bar}.{taz}",
expected: ParameterValue{
"bar": {
Schema: &Schema{Value: ""},
},
"taz": {
Schema: &Schema{Value: ""},
},
},
},
"with nested multiple path params": {
schemaDefinition: Definitions{},
path: "/foo/{bar}.{taz}/{baz}/ok",
expected: ParameterValue{
"bar": {
Schema: &Schema{Value: ""},
},
"taz": {
Schema: &Schema{Value: ""},
},
"baz": {
Schema: &Schema{Value: ""},
},
},
},
}
for name, test := range testCases {
t.Run(name, func(t *testing.T) {
actual := getPathParamsAutoComplete(test.schemaDefinition, test.path)
require.Equal(t, test.expected, actual)
})
}
}

36
support/echo/echo.go Normal file
View File

@@ -0,0 +1,36 @@
package echo
import (
"github.com/davidebianchi/gswagger/apirouter"
"net/http"
"github.com/labstack/echo/v4"
)
type Route = *echo.Route
type echoRouter struct {
router *echo.Echo
}
func (r echoRouter) AddRoute(method string, path string, handler echo.HandlerFunc) Route {
return r.router.Add(method, path, handler)
}
func (r echoRouter) SwaggerHandler(contentType string, blob []byte) echo.HandlerFunc {
return func(c echo.Context) error {
c.Response().Header().Add("Content-Type", contentType)
return c.JSONBlob(http.StatusOK, blob)
}
}
func (r echoRouter) TransformPathToOasPath(path string) string {
return apirouter.TransformPathParamsWithColon(path)
}
func NewRouter(router *echo.Echo) apirouter.Router[echo.HandlerFunc, Route] {
return echoRouter{
router: router,
}
}

65
support/echo/echo_test.go Normal file
View File

@@ -0,0 +1,65 @@
package echo
import (
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/davidebianchi/gswagger/apirouter"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/require"
)
func TestGorillaMuxRouter(t *testing.T) {
echoRouter := echo.New()
ar := NewRouter(echoRouter)
t.Run("create a new api router", func(t *testing.T) {
require.Implements(t, (*apirouter.Router[echo.HandlerFunc, Route])(nil), ar)
})
t.Run("add new route", func(t *testing.T) {
route := ar.AddRoute(http.MethodGet, "/foo", func(c echo.Context) error {
return c.String(http.StatusOK, "")
})
require.IsType(t, route, &echo.Route{})
t.Run("router exposes correctly api", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/foo", nil)
echoRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
})
t.Run("router exposes api only to the specific method", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodPost, "/foo", nil)
echoRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusMethodNotAllowed, w.Result().StatusCode)
})
})
t.Run("create openapi handler", func(t *testing.T) {
handlerFunc := ar.SwaggerHandler("text/html", []byte("some data"))
echoRouter.GET("/oas", handlerFunc)
t.Run("responds correctly to the API", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/oas", nil)
echoRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
require.Equal(t, "text/html", w.Result().Header.Get("Content-Type"))
body, err := io.ReadAll(w.Result().Body)
require.NoError(t, err)
require.Equal(t, "some data", string(body))
})
})
}

View File

@@ -0,0 +1,170 @@
package echo_test
import (
"context"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
oasEcho "github.com/davidebianchi/gswagger/support/echo"
swagger "github.com/davidebianchi/gswagger"
"github.com/getkin/kin-openapi/openapi3"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/require"
)
const (
swaggerOpenapiTitle = "test openapi title"
swaggerOpenapiVersion = "test openapi version"
)
type echoSwaggerRouter = swagger.Router[echo.HandlerFunc, *echo.Route]
func TestEchoIntegration(t *testing.T) {
t.Run("router works correctly - echo", func(t *testing.T) {
echoRouter, oasRouter := setupEchoSwagger(t)
err := oasRouter.GenerateAndExposeOpenapi()
require.NoError(t, err)
t.Run("/hello", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
echoRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "OK", body)
})
t.Run("/hello/:value", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodPost, "/hello/something", nil)
echoRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "OK", body)
})
t.Run("and generate swagger", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, swagger.DefaultJSONDocumentationPath, nil)
echoRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.JSONEq(t, readFile(t, "../testdata/integration.json"), body)
})
})
t.Run("works correctly with subrouter - handles path prefix - echo", func(t *testing.T) {
eRouter, oasRouter := setupEchoSwagger(t)
subRouter, err := oasRouter.SubRouter(oasEcho.NewRouter(eRouter), swagger.SubRouterOptions{
PathPrefix: "/prefix",
})
require.NoError(t, err)
_, err = subRouter.AddRoute(http.MethodGet, "/foo", okHandler, swagger.Definitions{})
require.NoError(t, err)
err = oasRouter.GenerateAndExposeOpenapi()
require.NoError(t, err)
t.Run("correctly call /hello", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
eRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "OK", body)
})
t.Run("correctly call sub router", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/prefix/foo", nil)
eRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "OK", body)
})
t.Run("and generate swagger", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, swagger.DefaultJSONDocumentationPath, nil)
eRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.JSONEq(t, readFile(t, "../testdata/intergation-subrouter.json"), body, body)
})
})
}
func readBody(t *testing.T, requestBody io.ReadCloser) string {
t.Helper()
body, err := io.ReadAll(requestBody)
require.NoError(t, err)
return string(body)
}
func setupEchoSwagger(t *testing.T) (*echo.Echo, *echoSwaggerRouter) {
t.Helper()
context := context.Background()
e := echo.New()
router, err := swagger.NewRouter(oasEcho.NewRouter(e), swagger.Options{
Context: context,
Openapi: &openapi3.T{
Info: &openapi3.Info{
Title: swaggerOpenapiTitle,
Version: swaggerOpenapiVersion,
},
},
})
require.NoError(t, err)
operation := swagger.Operation{}
_, err = router.AddRawRoute(http.MethodGet, "/hello", okHandler, operation)
require.NoError(t, err)
_, err = router.AddRoute(http.MethodPost, "/hello/:value", okHandler, swagger.Definitions{})
require.NoError(t, err)
return e, router
}
func okHandler(c echo.Context) error {
return c.String(http.StatusOK, "OK")
}
func readFile(t *testing.T, path string) string {
t.Helper()
fileContent, err := os.ReadFile(path)
require.NoError(t, err)
return string(fileContent)
}

34
support/fiber/fiber.go Normal file
View File

@@ -0,0 +1,34 @@
package fiber
import (
"github.com/davidebianchi/gswagger/apirouter"
"github.com/gofiber/fiber/v2"
)
type HandlerFunc = fiber.Handler
type Route = fiber.Router
type fiberRouter struct {
router fiber.Router
}
func NewRouter(router fiber.Router) apirouter.Router[HandlerFunc, Route] {
return fiberRouter{
router: router,
}
}
func (r fiberRouter) AddRoute(method string, path string, handler HandlerFunc) Route {
return r.router.Add(method, path, handler)
}
func (r fiberRouter) SwaggerHandler(contentType string, blob []byte) HandlerFunc {
return func(c *fiber.Ctx) error {
c.Set("Content-Type", contentType)
return c.Send(blob)
}
}
func (r fiberRouter) TransformPathToOasPath(path string) string {
return apirouter.TransformPathParamsWithColon(path)
}

View File

@@ -0,0 +1,63 @@
package fiber
import (
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/davidebianchi/gswagger/apirouter"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/require"
)
func TestFiberRouterSupport(t *testing.T) {
fiberRouter := fiber.New()
ar := NewRouter(fiberRouter)
t.Run("create a new api router", func(t *testing.T) {
require.Implements(t, (*apirouter.Router[HandlerFunc, Route])(nil), ar)
})
t.Run("add new route", func(t *testing.T) {
route := ar.AddRoute(http.MethodGet, "/foo", func(c *fiber.Ctx) error {
return c.SendStatus(http.StatusOK)
})
require.IsType(t, route, fiber.New())
t.Run("router exposes correctly api", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/foo", nil)
resp, err := fiberRouter.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
})
t.Run("router exposes api only to the specific method", func(t *testing.T) {
r := httptest.NewRequest(http.MethodPost, "/foo", nil)
resp, err := fiberRouter.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusMethodNotAllowed, resp.StatusCode)
})
})
t.Run("create openapi handler", func(t *testing.T) {
handlerFunc := ar.SwaggerHandler("text/html", []byte("some data"))
fiberRouter.Get("/oas", handlerFunc)
t.Run("responds correctly to the API", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/oas", nil)
resp, err := fiberRouter.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
require.Equal(t, "text/html", resp.Header.Get("Content-Type"))
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
require.Equal(t, "some data", string(body))
})
})
}

View File

@@ -0,0 +1,165 @@
package fiber_test
import (
"context"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
swagger "github.com/davidebianchi/gswagger"
oasFiber "github.com/davidebianchi/gswagger/support/fiber"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gofiber/fiber/v2"
"github.com/stretchr/testify/require"
)
type SwaggerRouter = swagger.Router[oasFiber.HandlerFunc, oasFiber.Route]
const (
swaggerOpenapiTitle = "test openapi title"
swaggerOpenapiVersion = "test openapi version"
)
func TestFiberIntegration(t *testing.T) {
t.Run("router works correctly", func(t *testing.T) {
router, oasRouter := setupSwagger(t)
err := oasRouter.GenerateAndExposeOpenapi()
require.NoError(t, err)
t.Run("/hello", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
resp, err := router.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
body := readBody(t, resp.Body)
require.Equal(t, "OK", body)
})
t.Run("/hello/:value", func(t *testing.T) {
r := httptest.NewRequest(http.MethodPost, "/hello/something", nil)
resp, err := router.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
body := readBody(t, resp.Body)
require.Equal(t, "OK", body)
})
t.Run("and generate swagger", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, swagger.DefaultJSONDocumentationPath, nil)
resp, err := router.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
body := readBody(t, resp.Body)
require.JSONEq(t, readFile(t, "../testdata/integration.json"), body, body)
})
})
t.Run("works correctly with subrouter - handles path prefix - gorilla mux", func(t *testing.T) {
fiberRouter, oasRouter := setupSwagger(t)
subRouter, err := oasRouter.SubRouter(oasFiber.NewRouter(fiberRouter), swagger.SubRouterOptions{
PathPrefix: "/prefix",
})
require.NoError(t, err)
_, err = subRouter.AddRoute(http.MethodGet, "/foo", okHandler, swagger.Definitions{})
require.NoError(t, err)
err = oasRouter.GenerateAndExposeOpenapi()
require.NoError(t, err)
t.Run("correctly call /hello", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
resp, err := fiberRouter.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
body := readBody(t, resp.Body)
require.Equal(t, "OK", body)
})
t.Run("correctly call sub router", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/prefix/foo", nil)
resp, err := fiberRouter.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
body := readBody(t, resp.Body)
require.Equal(t, "OK", body)
})
t.Run("and generate swagger", func(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, swagger.DefaultJSONDocumentationPath, nil)
resp, err := fiberRouter.Test(r)
require.NoError(t, err)
require.Equal(t, http.StatusOK, resp.StatusCode)
body := readBody(t, resp.Body)
require.JSONEq(t, readFile(t, "../testdata/intergation-subrouter.json"), body, body)
})
})
}
func setupSwagger(t *testing.T) (*fiber.App, *SwaggerRouter) {
t.Helper()
context := context.Background()
fiberRouter := fiber.New()
router, err := swagger.NewRouter(oasFiber.NewRouter(fiberRouter), swagger.Options{
Context: context,
Openapi: &openapi3.T{
Info: &openapi3.Info{
Title: swaggerOpenapiTitle,
Version: swaggerOpenapiVersion,
},
},
})
require.NoError(t, err)
operation := swagger.Operation{}
_, err = router.AddRawRoute(http.MethodGet, "/hello", okHandler, operation)
require.NoError(t, err)
_, err = router.AddRoute(http.MethodPost, "/hello/:value", okHandler, swagger.Definitions{})
require.NoError(t, err)
return fiberRouter, router
}
func okHandler(c *fiber.Ctx) error {
c.Status(http.StatusOK)
return c.SendString("OK")
}
func readBody(t *testing.T, requestBody io.ReadCloser) string {
t.Helper()
body, err := io.ReadAll(requestBody)
require.NoError(t, err)
return string(body)
}
func readFile(t *testing.T, path string) string {
t.Helper()
fileContent, err := os.ReadFile(path)
require.NoError(t, err)
return string(fileContent)
}

View File

@@ -0,0 +1,118 @@
package gorilla_test
import (
"context"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
swagger "github.com/davidebianchi/gswagger"
"github.com/davidebianchi/gswagger/support/gorilla"
"github.com/stretchr/testify/require"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gorilla/mux"
)
func TestExample(t *testing.T) {
context := context.Background()
muxRouter := mux.NewRouter()
router, _ := swagger.NewRouter(gorilla.NewRouter(muxRouter), swagger.Options{
Context: context,
Openapi: &openapi3.T{
Info: &openapi3.Info{
Title: "my title",
Version: "1.0.0",
},
},
})
okHandler := func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
}
type User struct {
Name string `json:"name" jsonschema:"title=The user name,required" jsonschema_extras:"example=Jane"`
PhoneNumber int `json:"phone" jsonschema:"title=mobile number of user"`
Groups []string `json:"groups,omitempty" jsonschema:"title=groups of the user,default=users"`
Address string `json:"address" jsonschema:"title=user address"`
}
type errorResponse struct {
Message string `json:"message"`
}
router.AddRoute(http.MethodPost, "/users", okHandler, swagger.Definitions{
RequestBody: &swagger.ContentValue{
Content: swagger.Content{
"application/json": {Value: User{}},
},
},
Responses: map[int]swagger.ContentValue{
201: {
Content: swagger.Content{
"text/html": {Value: ""},
},
},
401: {
Content: swagger.Content{
"application/json": {Value: &errorResponse{}},
},
Description: "invalid request",
},
},
})
router.AddRoute(http.MethodGet, "/users", okHandler, swagger.Definitions{
Responses: map[int]swagger.ContentValue{
200: {
Content: swagger.Content{
"application/json": {Value: &[]User{}},
},
},
},
})
carSchema := openapi3.NewObjectSchema().WithProperties(map[string]*openapi3.Schema{
"foo": openapi3.NewStringSchema(),
"bar": openapi3.NewIntegerSchema().WithMax(15).WithMin(5),
})
requestBody := openapi3.NewRequestBody().WithJSONSchema(carSchema)
operation := swagger.NewOperation()
operation.AddRequestBody(requestBody)
router.AddRawRoute(http.MethodPost, "/cars", okHandler, operation)
_, err := router.AddRoute(http.MethodGet, "/users/{userId}", okHandler, swagger.Definitions{
Querystring: swagger.ParameterValue{
"query": {
Schema: &swagger.Schema{Value: ""},
},
},
})
require.NoError(t, err)
_, err = router.AddRoute(http.MethodGet, "/cars/{carId}/drivers/{driverId}", okHandler, swagger.Definitions{})
require.NoError(t, err)
router.GenerateAndExposeOpenapi()
t.Run("correctly exposes documentation", func(t *testing.T) {
w := httptest.NewRecorder()
req := httptest.NewRequest(http.MethodGet, swagger.DefaultJSONDocumentationPath, nil)
muxRouter.ServeHTTP(w, req)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
require.Equal(t, "application/json", w.Result().Header.Get("Content-Type"))
body, err := io.ReadAll(w.Result().Body)
require.NoError(t, err)
expected, err := os.ReadFile("./testdata/examples-users.json")
require.NoError(t, err)
require.JSONEq(t, string(expected), string(body), "actual json data: %s", body)
})
}

View File

@@ -0,0 +1,39 @@
package gorilla
import (
"github.com/davidebianchi/gswagger/apirouter"
"net/http"
"github.com/gorilla/mux"
)
// HandlerFunc is the http type handler used by gorilla/mux
type HandlerFunc func(w http.ResponseWriter, req *http.Request)
type Route = *mux.Route
type gorillaRouter struct {
router *mux.Router
}
func (r gorillaRouter) AddRoute(method string, path string, handler HandlerFunc) Route {
return r.router.HandleFunc(path, handler).Methods(method)
}
func (r gorillaRouter) SwaggerHandler(contentType string, blob []byte) HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", contentType)
w.WriteHeader(http.StatusOK)
w.Write(blob)
}
}
func (r gorillaRouter) TransformPathToOasPath(path string) string {
return path
}
func NewRouter(router *mux.Router) apirouter.Router[HandlerFunc, Route] {
return gorillaRouter{
router: router,
}
}

View File

@@ -0,0 +1,66 @@
package gorilla
import (
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/davidebianchi/gswagger/apirouter"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
)
func TestGorillaMuxRouter(t *testing.T) {
muxRouter := mux.NewRouter()
ar := NewRouter(muxRouter)
t.Run("create a new api router", func(t *testing.T) {
require.Implements(t, (*apirouter.Router[HandlerFunc, Route])(nil), ar)
})
t.Run("add new route", func(t *testing.T) {
route := ar.AddRoute(http.MethodGet, "/foo", func(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
w.Write(nil)
})
require.IsType(t, route, &mux.Route{})
t.Run("router exposes correctly api", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/foo", nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
})
t.Run("router exposes api only to the specific method", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodPost, "/foo", nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusMethodNotAllowed, w.Result().StatusCode)
})
})
t.Run("create openapi handler", func(t *testing.T) {
handlerFunc := ar.SwaggerHandler("text/html", []byte("some data"))
muxRouter.HandleFunc("/oas", handlerFunc).Methods(http.MethodGet)
t.Run("responds correctly to the API", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/oas", nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
require.Equal(t, "text/html", w.Result().Header.Get("Content-Type"))
body, err := io.ReadAll(w.Result().Body)
require.NoError(t, err)
require.Equal(t, "some data", string(body))
})
})
}

View File

@@ -0,0 +1,157 @@
package gorilla_test
import (
"context"
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
swagger "github.com/davidebianchi/gswagger"
"github.com/davidebianchi/gswagger/support/gorilla"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gorilla/mux"
"github.com/stretchr/testify/require"
)
const (
swaggerOpenapiTitle = "test openapi title"
swaggerOpenapiVersion = "test openapi version"
)
type SwaggerRouter = swagger.Router[gorilla.HandlerFunc, gorilla.Route]
func TestGorillaIntegration(t *testing.T) {
t.Run("router works correctly", func(t *testing.T) {
muxRouter, oasRouter := setupSwagger(t)
err := oasRouter.GenerateAndExposeOpenapi()
require.NoError(t, err)
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "OK", body)
t.Run("and generate swagger", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, swagger.DefaultJSONDocumentationPath, nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.JSONEq(t, readFile(t, "../testdata/integration.json"), body)
})
})
t.Run("works correctly with subrouter - handles path prefix - gorilla mux", func(t *testing.T) {
muxRouter, oasRouter := setupSwagger(t)
muxSubRouter := muxRouter.NewRoute().Subrouter()
subRouter, err := oasRouter.SubRouter(gorilla.NewRouter(muxSubRouter), swagger.SubRouterOptions{
PathPrefix: "/prefix",
})
require.NoError(t, err)
_, err = subRouter.AddRoute(http.MethodGet, "/foo", okHandler, swagger.Definitions{})
require.NoError(t, err)
err = oasRouter.GenerateAndExposeOpenapi()
require.NoError(t, err)
t.Run("correctly call router", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/hello", nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "OK", body)
})
t.Run("correctly call sub router", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, "/prefix/foo", nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.Equal(t, "OK", body)
})
t.Run("and generate swagger", func(t *testing.T) {
w := httptest.NewRecorder()
r := httptest.NewRequest(http.MethodGet, swagger.DefaultJSONDocumentationPath, nil)
muxRouter.ServeHTTP(w, r)
require.Equal(t, http.StatusOK, w.Result().StatusCode)
body := readBody(t, w.Result().Body)
require.JSONEq(t, readFile(t, "../testdata/intergation-subrouter.json"), body, body)
})
})
}
func readBody(t *testing.T, requestBody io.ReadCloser) string {
t.Helper()
body, err := io.ReadAll(requestBody)
require.NoError(t, err)
return string(body)
}
func setupSwagger(t *testing.T) (*mux.Router, *SwaggerRouter) {
t.Helper()
context := context.Background()
muxRouter := mux.NewRouter()
router, err := swagger.NewRouter(gorilla.NewRouter(muxRouter), swagger.Options{
Context: context,
Openapi: &openapi3.T{
Info: &openapi3.Info{
Title: swaggerOpenapiTitle,
Version: swaggerOpenapiVersion,
},
},
})
require.NoError(t, err)
operation := swagger.Operation{}
_, err = router.AddRawRoute(http.MethodGet, "/hello", okHandler, operation)
require.NoError(t, err)
_, err = router.AddRoute(http.MethodPost, "/hello/{value}", okHandler, swagger.Definitions{})
require.NoError(t, err)
return muxRouter, router
}
func okHandler(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`OK`))
}
func readFile(t *testing.T, path string) string {
t.Helper()
fileContent, err := os.ReadFile(path)
require.NoError(t, err)
return string(fileContent)
}

View File

@@ -0,0 +1,185 @@
{
"info": {
"title": "my title",
"version": "1.0.0"
},
"openapi": "3.0.0",
"paths": {
"/cars/{carId}/drivers/{driverId}": {
"get": {
"parameters": [
{
"in": "path",
"name": "carId",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "path",
"name": "driverId",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"description": ""
}
}
}
},
"/users": {
"get": {
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"items": {
"additionalProperties": false,
"properties": {
"address": {
"title": "user address",
"type": "string"
},
"groups": {
"default": [
"users"
],
"items": {
"type": "string"
},
"title": "groups of the user",
"type": "array"
},
"name": {
"example": "Jane",
"title": "The user name",
"type": "string"
},
"phone": {
"title": "mobile number of user",
"type": "integer"
}
},
"required": [
"name",
"phone",
"address"
],
"type": "object"
},
"type": "array"
}
}
},
"description": ""
}
}
},
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"properties": {
"address": {
"title": "user address",
"type": "string"
},
"groups": {
"default": [
"users"
],
"items": {
"type": "string"
},
"title": "groups of the user",
"type": "array"
},
"name": {
"example": "Jane",
"title": "The user name",
"type": "string"
},
"phone": {
"title": "mobile number of user",
"type": "integer"
}
},
"required": [
"name",
"phone",
"address"
],
"type": "object"
}
}
}
},
"responses": {
"201": {
"content": {
"text/html": {
"schema": {
"type": "string"
}
}
},
"description": ""
},
"401": {
"content": {
"application/json": {
"schema": {
"additionalProperties": false,
"properties": {
"message": {
"type": "string"
}
},
"required": [
"message"
],
"type": "object"
}
}
},
"description": "invalid request"
}
}
}
},
"/users/{userId}": {
"get": {
"parameters": [
{
"in": "path",
"name": "userId",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "query",
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"description": ""
}
}
}
}
}
}

37
support/testdata/integration.json vendored Normal file
View File

@@ -0,0 +1,37 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/hello": {
"get": {
"responses": {
"default": {
"description": ""
}
}
}
},
"/hello/{value}": {
"post": {
"parameters": [
{
"in": "path",
"name": "value",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"description": ""
}
}
}
}
}
}

View File

@@ -0,0 +1,46 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/hello": {
"get": {
"responses": {
"default": {
"description": ""
}
}
}
},
"/hello/{value}": {
"post": {
"parameters": [
{
"in": "path",
"name": "value",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"description": ""
}
}
}
},
"/prefix/foo": {
"get": {
"responses": {
"default": {
"description": ""
}
}
}
}
}
}

5
testdata/allof.json vendored
View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {

5
testdata/anyof.json vendored
View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {

View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {

View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {

5
testdata/empty.json vendored
View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {}

21
testdata/extension.json vendored Normal file
View File

@@ -0,0 +1,21 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/users": {
"get": {
"responses": {
"default": {
"description": ""
}
},
"x-extension-field": {
"foo": "bar"
}
}
}
}
}

View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {

View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
@@ -14,13 +13,11 @@
"multipart/form-data": {
"schema": {
"type": "object",
"additionalProperties": true,
"properties": {
"id": {
"type": "string"
},
"address": {
"additionalProperties": true,
"type": "object",
"properties": {
"street": {

11
testdata/oneOf.json vendored
View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
@@ -70,7 +69,6 @@
"type": "string"
},
"metadata": {
"additionalProperties": true,
"oneOf": [
{
"type": "string"
@@ -80,6 +78,11 @@
}
],
"title": "custom properties"
},
"userType": {
"title": "type of user",
"type": "string",
"enum": ["simple", "advanced"]
}
},
"required": [

89
testdata/params-autofill.json vendored Normal file
View File

@@ -0,0 +1,89 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/cars/{carId}/drivers/{driverId}": {
"get": {
"parameters": [
{
"in": "path",
"name": "carId",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "path",
"name": "driverId",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"description": ""
}
}
}
},
"/users/{userId}": {
"get": {
"parameters": [
{
"in": "path",
"name": "userId",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "query",
"name": "query",
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"description": ""
}
}
}
},
"/files/{name}.{extension}": {
"get": {
"parameters": [
{
"in": "path",
"name": "extension",
"required": true,
"schema": {
"type": "string"
}
},
{
"in": "path",
"name": "name",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"default": {
"description": ""
}
}
}
}
}
}

View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {

5
testdata/query.json vendored
View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {

18
testdata/router_with_prefix.json vendored Normal file
View File

@@ -0,0 +1,18 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/prefix/foo": {
"get": {
"responses": {
"default": {
"description": ""
}
}
}
}
}
}

View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
@@ -32,6 +31,7 @@
}
],
"requestBody": {
"content": {},
"description": "request body without schema"
},
"responses": {

26
testdata/security.json vendored Normal file
View File

@@ -0,0 +1,26 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/users": {
"get": {
"responses": {
"default": {
"description": ""
}
},
"security": [
{
"api_key": [],
"auth": [
"resource.write"
]
}
]
}
}
}
}

36
testdata/subrouter.json vendored Normal file
View File

@@ -0,0 +1,36 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/foo": {
"get": {
"responses": {
"default": {
"description": ""
}
}
}
},
"/prefix/taz": {
"get": {
"responses": {
"default": {
"description": ""
}
}
}
},
"/prefix": {
"get": {
"responses": {
"default": {
"description": ""
}
}
}
}
}
}

19
testdata/tags.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/users": {
"get": {
"tags": ["Tag1", "Tag2"],
"responses": {
"default": {
"description": ""
}
}
}
}
}
}

View File

@@ -0,0 +1,21 @@
{
"info": {
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {
"/users": {
"get": {
"deprecated": true,
"description": "this is the long route description",
"responses": {
"default": {
"description": ""
}
},
"summary": "small description"
}
}
}
}

View File

@@ -1,8 +1,7 @@
{
"components": {},
"info": {
"title": "test swagger title",
"version": "test swagger version"
"title": "test openapi title",
"version": "test openapi version"
},
"openapi": "3.0.0",
"paths": {

View File

@@ -1,7 +1,6 @@
components: {}
info:
title: test swagger title
version: test swagger version
title: test openapi title
version: test openapi version
openapi: 3.0.0
paths:
/employees: