0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

はじめに

趣味のプログラミングでrustをつかったwebサーバーを作成しています🦀

その際、utoipaを使ってopenapiのスキーマ出力 ⇒ openapi-generatorによるTSクライアント出力をしていたのですが、
deployするときにTSクライアントのbaseUrlを変えたかったので、openapiのserversスキーマ指定する方法をとることにしました

utoipa::openapi::Serverを使用するとよいです

サンプル

    // ドキュメントのオブジェクト生成
    let mut doc = ApiDoc::openapi();

    // 環境変数から","区切りのURL取得
    std::env::var("SERVERS").ok().map(|servers| {
        doc.servers = Some(
            servers
                .split(',')
+               .map(|x| utoipa::openapi::Server::new(x))
                .collect()
        );
    });

utoipa::openapi::Server::new()を使用して生成しないとコンパイルエラーになります

new()を使用しないといけないのに気付かず詰まった

#[non_exhaustive]が設定されているので
cannot create non-exhaustive struct using struct expression
というエラーが、、

cargo checkの実行結果によると
For more information about this error, try 'rustc --explain E0639'.
ということなので、実行してみると、new()使ってみなよとあったので無事解決した運びでした

rustcのexplainは親切でわかりやすいですね!

ちなみに…マクロを使ったserversの指定ができるのかよくわからないんですよね、、
あえて目をつむります🙈

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?