OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Rust] Rust-reqwest client fails because of null values in tags arrays from petstore.swagger.io

Open
#3,885 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Rust Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

The rust-reqwest client fails on the current contents of petstore.swagger.io because of null values in the tags array of some pets.

openapi-generator version

4.1.2-SNAPSHOT

OpenAPI declaration file content or url

See http://petstore.swagger.io/v2/swagger.json

Command line used for generation
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
Steps to reproduce
  1. Generate the client as above.
  2. Use it to call find_pets_by_status.
  3. See the following error.
result = Err(Reqwest(Error(Json(Error("invalid type: null, expected struct Tag", line: 1, column: 2807)))))

Also, this is currently in the petstore api:

$ curl -X GET "https://petstore.swagger.io/v2/pet/findByStatus?status=pending" -H  "accept: application/json" | jq ".[].tags"
...
[
  null
]
...

And this is the relevant spec section:

$ 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"
  }
}
Related issues/PRs

No related issues found.

Suggest a fix

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>>>,

Although I don't know whether those nulls should have even been allowed in the first place.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided Docker generation command against the petstore.swagger.io spec, then call find_pets_by_status with the generated rust-reqwest client. Compare the generated Pet model's tags field with the response containing null entries. Done means the generated client handles that response without the null-deserialization error and remains consistent with the tags schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, rust
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.