oas3-gen 0.25.0

A rust type generator for OpenAPI v3.1.x specification.
use oas3::spec::{Info, Server};

use crate::generator::ast::StructToken;

const DEFAULT_BASE_URL: &str = "https://example.com/";

#[derive(Debug, Clone, Default)]
pub struct ClientRootNode {
  pub name: StructToken,
  pub title: String,
  pub version: String,
  pub description: Option<String>,
  pub base_url: String,
}

#[bon::bon]
impl ClientRootNode {
  #[builder]
  pub fn new(name: StructToken, info: &Info, servers: &[Server]) -> Self {
    Self {
      name,
      title: info.title.clone(),
      version: info.version.clone(),
      description: info.description.clone(),
      base_url: servers
        .first()
        .map_or_else(|| DEFAULT_BASE_URL.to_string(), |server| server.url.clone()),
    }
  }
}