theduke / crates-io-api

API client for crates.io, the Rust crate registry.
Apache License 2.0
72 stars 26 forks source link

License is None #50

Closed alenpaulvarghese closed 2 years ago

alenpaulvarghese commented 2 years ago

The License field of the struct Crate is always None

async fn asyncmain() {
    let client: AsyncClient = AsyncClient::new(
        "something (no@email.com)",
        std::time::Duration::from_millis(1500),
    )
    .unwrap();
    let mut cquery = CratesQuery::builder()
        .search("rand")
        .page_size(1)
        .sort(Sort::Relevance)
        .build();
    cquery.set_page(1);
    let result = client.crates(cquery).await.unwrap();
    println!("{:?}", result.crates[0].license);
}

output None

expected output MIT OR Apache-2.0

theduke commented 2 years ago

The API doesn't return the license on list queries, only when retrieving a crate directly.

The Crate::license field is actually always empty. I believe this might be a relic of previous API responses.

To get the license, you have to retrieve the crate via Client::get_crate and then inspect the Version::license field of the newest version.