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

Build docs with rapi docs and swagger docs features enabled #64

Merged
merged 1 commit into from
Nov 30, 2021

Conversation

ThouCheese
Copy link
Contributor

It is useful to display the structs and functions in the swagger and rapi doc modules on docs.rs. I also added an example to the rapi-docs module and fixed a couple of typos in Cargo.toml.

@Sollimann
Copy link

Is it possible to generate a openapi.json or openapi.yaml file that will be saved to file inside of the folder, so that I can copy it and re-use for autogenerate stubs for e.g python-api-client-sdk ? Right now, it just host the swagger-page using the openapi.json file, but I also want to be able to have the file itself. @ThouCheese

@ralpha
Copy link
Collaborator

ralpha commented Nov 30, 2021

Is it possible to generate a openapi.json or openapi.yaml file that will be saved to file inside of the folder, so that I can copy it and re-use for autogenerate stubs for e.g python-api-client-sdk ? Right now, it just host the swagger-page using the openapi.json file, but I also want to be able to have the file itself.

Although not related to this PR. But yes this is possible, but is easiest to do since version 0.8.0-rc.1. You can do this by using:
https://docs.rs/rocket_okapi/0.8.0-rc.1/rocket_okapi/macro.openapi_spec.html

This macro will return an OpenApi struct which implements Serialize and can thus be used with all Serde libraries, like serde_json or serde_yaml

let settings = rocket_okapi::settings::OpenApiSettings::new();
let spec = rocket_okapi::openapi_spec![get_message, post_message](settings);
let json_string = serde_json::to_string(&spec)?;
let yaml_string = serde_yaml::to_string(&spec)?;
// Just write this String to file.

Copy link
Collaborator

@ralpha ralpha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks good

@ralpha ralpha merged commit b21a118 into GREsau:master Nov 30, 2021
@Sollimann
Copy link

Sollimann commented Dec 2, 2021

@ralpha thank you! :) ps, sorry for hijacking the PR

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.

None yet

3 participants