-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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] [PYTHON] Malformed type hints on 6.3.0-SNAPSHOT with 303 status response #14009
Comments
Copy of the minimal reproduction from the gist: {
"openapi": "3.0.0",
"info": {
"title": "API Documentation",
"description": "Test documentation",
"contact": {
"name": "Support",
"email": "[email protected]"
},
"version": "v4",
"x-logo": {
"url": "https://example.com/logo.png"
}
},
"servers": [
{
"url": "https://app.example.com/api/v4",
"description": "Server"
}
],
"paths": {
"/things/{id}/download.json": {
"get": {
"tags": [
"Things"
],
"summary": "Download the Thing",
"operationId": "Thing#download",
"description": "Download the completed Thing",
"parameters": [
{
"name": "id",
"in": "path",
"description": "The unique identifier for the Thing",
"required": true,
"schema": {
"type": "integer",
"format": "int64"
}
}
],
"responses": {
"303": {
"description": "See Other"
},
"400": {
"description": "Bad Request",
"content": {
"application/json": {}
}
},
"401": {
"description": "Unauthorized",
"content": {
"application/json": {}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {}
}
},
"429": {
"description": "Too Many Requests",
"content": {
"application/json": {}
}
}
}
}
}
},
"tags": [
{
"name": "Things",
"description": "A bunch of things"
}
]
} |
Hi there. This is happening because this endpoint does not have any 2XX response status code. Some ways to fix this are:
Some more context here: We have open issues on redirects in other generators also: |
Thanks spacether, I'm reaching out to the upstream API provider to find out whether this is an oversight or whether there is really no 2xx response for this endpoint. |
Welcome :) |
I heard back from the API provider. 303 is the appropriate code for these operations. The 303 response provides an AWS URL which the client must follow to receive the requested download. AWS then provides a 200 response code when the file is downloaded. |
Okay, so do you want to add a dummy 200 response, or write a PR to handle the 3XX responses? Note: The 3XX response issue is already tracked in my separate repo also, openapi-json-schema-tools/openapi-json-schema-generator#23 |
This is for work, so unfortunately I don't think it's realistic for me to change scope into Java to write a PR. The upstream spec changes daily, so I can't just write a patch for it that will stay current. The solution for me might be to freeze one of the dailies of the spec, edit in the responses, and only update when absolutely necessary. |
You could write a python file that opens the spec, finds the path and response and writes a new spec with the additional 200 response. Or you can write a post processing program that fixes the client and pass it in to the generate command as a post-processing step |
@spacether I have the exact same issue but my upstream API has 204 instead of 200 |
@abhi1693 can you please include a minimal spec to reproduce your issue?
I get this code:
Using the current master branch. So I am unable to replicate your issue. |
@spacether You can use the spec defined at https://demo.netbox.dev/api/docs/?format=openapi. My command looks like config.json {
"generateAliasAsModel": "true",
"packageAuthor": "Abhimanyu Saharan",
"packageDescription": "NetBox Client is a Python library for interacting with the NetBox API.",
"packageName": "netbox_client",
"packageVersion": "0.0.1",
"useInlineModelResolver": "true"
} curl -s -o ./openapi.json https://demo.netbox.dev/api/docs/?format=openapi
openapi-generator-cli generate --config config.json --generator-name python --input-spec openapi.json One of class that generated the incorrect type @dataclass
class ApiResponseFor204(api_client.ApiResponse):
response: urllib3.HTTPResponse
body: typing.Union[
]
headers: schemas.Unset = schemas.unset |
FYI this is now working in the v2 release of openapi-json-schema-generator.
See a working test of http status code 303 response deserialization here
Note: ranged response redirection deserialization also works for 3XX per this other test |
Bug Report Checklist
Description
Clients are generated with syntax errors using the spec provided.
Sample of code with syntax errors:
It is not valid for this
typing.Union
to be empty, as shown at import time:openapi-generator version
OpenAPI declaration file content or url
Gist: https://gist.github.com/syntaxaire/9e584c63ac4ce71c7eda882a4d6837dc
Generation Details
java -jar openapi-generator-cli.jar generate --global-property skipFormModel=false -i empty-union.json -g python -o empty-union
Steps to reproduce
The text was updated successfully, but these errors were encountered: