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

Rust-reqwest client fails because of null values in tags arrays from petstore.swagger.io #2003

Closed
sverch opened this issue Sep 13, 2019 · 2 comments

Comments

@sverch
Copy link

sverch commented Sep 13, 2019

Steps to Reproduce

1. Generate the rust-reqwest based client

docker run --rm -v ${PWD}:/local/out/rust/ openapitools/openapi-generator-cli generate     -i http://petstore.swagger.io/v2/swagger.json     -g rust     -o /local/out/rust/generated --additional-properties packageName=petstore_client --library=reqwest

2. Use it to call find_pets_by_status against petstore.swagger.io

use petstore_client;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let configuration = petstore_client::apis::configuration::Configuration::new();
    let apiclient = petstore_client::apis::client::APIClient::new(configuration);
    let status = vec![std::string::String::from("pending")];
    let result = apiclient.pet_api().find_pets_by_status(status);
    println!("result = {:?}", result);
    Ok(())
}

3. See error with null tags

result = Err(Reqwest(Error(Json(Error("invalid type: null, expected struct Tag", line: 1, column: 2807)))))

Background

I generated the rust-reqwest based client and tried to do a find_pets_by_status operation, but I got this error:

result = Err(Reqwest(Error(Json(Error("invalid type: null, expected struct Tag", line: 1, column: 2807)))))

Sure enough, when I hit the API directly I see that there are null values in the tags arrays for some pets:

$ curl -X GET "https://petstore.swagger.io/v2/pet/findByStatus?status=pending" -H  "accept: application/json" | jq ".[].tags"
...
[
  {
    "id": 0,
    "name": "string"
  }
]
[
  null
]
[
  null
]
[
  null
]
[
  {
    "id": 0,
    "name": "Asdasd"
  }
]
...

The spec that I generated this client from doesn't say anything about nulls being allowed:

$ curl --silent --output - http://petstore.swagger.io/v2/swagger.json | jq ".definitions.Pet.properties.tags"
{
  "type": "array",
  "xml": {
    "name": "tag",
    "wrapped": true
  },
  "items": {
    "$ref": "#/definitions/Tag"
  }
}

The spec doesn't mention null at all:

$ curl --silent --output - http://petstore.swagger.io/v2/swagger.json | jq "." | grep null
(nothing)

I'm not sure if nulls should be allowed in arrays and the client is wrong, or if they shouldn't and the server is wrong. I see this issue which makes me think null values being allowed wasn't intended to be the default.

To get it working, I had to change this line in the Pet model:

    pub tags: Option<Vec<crate::models::Tag>>,

To this:

    pub tags: Option<Vec<Option<crate::models::Tag>>>,

Thanks for your work on this project! Let me know if there's a better place I should file this.

@webron
Copy link
Member

webron commented Sep 13, 2019

This repository is for the spec alone and not any of the tools. Please file the ticket with the respective product.

@webron webron closed this as completed Sep 13, 2019
@sverch
Copy link
Author

sverch commented Sep 13, 2019

Ah, sorry @webron. I got this confused with the generator. I'll go file this there: https://github.com/OpenAPITools/openapi-generator/.

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

No branches or pull requests

2 participants