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

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

Open
5 of 6 tasks
sverch opened this issue Sep 13, 2019 · 4 comments

Comments

@sverch
Copy link

sverch commented Sep 13, 2019

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.

@auto-labeler
Copy link

auto-labeler bot commented Sep 13, 2019

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@wing328
Copy link
Member

wing328 commented Sep 15, 2019

Travis CI is using a local Petstore server for testing so we can avoid issues with bad data in the public petstore server.

@sverch
Copy link
Author

sverch commented Sep 20, 2019

That's good to know, thanks! It makes sense for reproducibility.

The reason I still consider this a bug is that I would expect it to be impossible to input bad data for servers that satisfy a given OpenAPI spec. So given your comment that probably means this is a bug in the petstore server itself. I don't know where the code for the public petstore lives though.

@p-alik
Copy link

p-alik commented Jun 18, 2021

It is possible there is a general issue with the url http://petstore.swagger.io/v2/swagger.json mentioned in WIKI.

Swagger/OpenAPI online validator failed to validate it.
My attempt to build go-server sample failed. But HTTPS comforted as online validator as generator.
Meaning no issue with

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
  -i https://petstore.swagger.io/v2/swagger.json \
  -g go-server \
  -o samples/server/petstore/go-server

I run my test with code based on 41afcd0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants