Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT export openapi spec generated with utoipa #61

Conversation

benjaminedwardwebb
Copy link
Contributor

@benjaminedwardwebb benjaminedwardwebb commented Nov 4, 2024

Export an openapi spec for the VTN server with the utoipa crate.


This is a draft commit that explores usage of the utoipa crate.

The utoipa crate is popular and well-maintained. It provides macros, traits, and types for maintaining openapi documentation.

This draft generates documentation for two operations

  • GET /vens/{venID}/resources
  • POST /vens/{venID}/resources

The document was exported to generated-openapi.yaml with

curl --silent http://localhost:3000/docs/openapi.json | yq --yaml-output . > generated-openapi.yaml

Some callouts

  • #[serde(flatten)] is supported, but the generated openapi json schema uses anyOf to combine the two structs (semantically equivalent but slightly surprising)
  • the effect of other serde attributes and validator constraints may need to be duplicated as ToSchema macro's schema attributes (not as bad as it might sound, since these duplicate definitions are placed essentially next to each other; also there is an issue to consider adding support for validator's attributes)
  • utoipa uses openapi version 3.1.0

Overall, the utoipa crate seems like a popular and safe choice. It requires a lot of macro boilerplate and there are some details to be aware relating to serde, but it's very easy to use and gets you 90% of the way there. And if the macros aren't working, you can always drop down into traits.

See https://docs.rs/utoipa/latest/utoipa/
and https://crates.io/crates/utoipa
and https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0

@benjaminedwardwebb benjaminedwardwebb changed the title TODO feat: export openapi spec generated with utoipa DRAFT export openapi spec generated with utoipa Nov 4, 2024
Export an openapi spec for the VTN server with the utoipa crate.

---

This is a draft commit that explores usage of the utoipa crate.

The utoipa crate is popular and well-maintained. It provides macros,
traits, and types for maintaining openapi documentation.

This draft generates documentation for two operations

- GET /vens/{venID}/resources
- POST /vens/{venID}/resources

The document was exported to generated-openapi.yaml with

    curl --silent http://localhost:3000/docs/openapi.json | yq --yaml-output . > generated-openapi.yaml

Some callouts

- #[serde(flatten)] is supported, but the generated openapi json schema
  uses anyOf to combine the two structs (semantically equivalent but
  slightly surprising)
- the effect of other serde attributes and validator constraints may
  need to be duplicated as ToSchema macro's schema attributes (not as
  bad as it might sound, since these duplicate definitions are placed
  essentially next to each other; also there is an issue to consider
  adding support for validator's attributes)
- utoipa uses openapi version 3.1.0

Overall, the utoipa crate seems like a popular and safe choice. It
requires a lot of macro boilerplate and there are some details to be
aware relating to serde, but it's very easy to use and gets you 90% of
the way there. And if the macros aren't working, you can always drop
down into traits.

See https://docs.rs/utoipa/latest/utoipa/
and https://crates.io/crates/utoipa
and https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
@benjaminedwardwebb benjaminedwardwebb force-pushed the benwebb/export-vtn-openapi-specification-utoipa branch from 3d9a469 to 004f91a Compare November 4, 2024 01:56
@benjaminedwardwebb
Copy link
Contributor Author

See discussion in #17

@benjaminedwardwebb benjaminedwardwebb deleted the benwebb/export-vtn-openapi-specification-utoipa branch November 5, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant