-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[PHP] Generator doesn't respect the optional parameters in request body when content type is application/x-www-form-urlencoded #11129
Comments
Nothing? :( |
I'm getting this problem as well, with the "python" generator. I'm not really familiar with the swagger-codegen code, but after a quick dig I think the problem is here. This if statement seems to add form body properties to the "requiredParams" list if the body is required, not if the individual property itself is required. This can be verified by removing the A fix might be to add a check for |
These two issues also seem to be related:
|
Hmm, based on the tests, this seems to be intentional behaviour.
It seems like there's no way to have a required form body, but some optional properties within that body? |
Looks like that test, and the code it is testing, was created as part of this PR ( swagger-api/swagger-codegen-generators#331 ), but I would be surprised if that interpretation of the 'required' property is correct. |
Description
We have a request body with a schema with "application/x-www-form-urlencoded" content type. There are some parameters which are set as required. One of the parameters is optional. Swagger UI renders everything correctly and there are no issues there. However, when we generate PHP client with the swagger-codegen, we see that all the parameters are required... even the optional one. This basically makes the generated client useless.
Swagger-codegen version
3.0.26, 3.0.27
Swagger declaration file content or url
This is the definition:
And this is the schema of the requestBody:
Full specs can be found here: https://api.tuningfiles.com/swagger.json
As you can see from the above, only
message
,display_name
anddisplay_email
are required from the request body.attachments[]
is optional. However generated php code looks like this:As you can see from the code above,
$attachments
are also required , but it shouldn't.Command line used for generation
swagger-codegen generate -i https://api.tuningfiles.com/swagger.json -l php -o /output_dir -c config.json
config.json:
Steps to reproduce
Using the schema from https://api.tuningfiles.com/swagger.json and
config.json
from above, use the following command to generate php client (replace the output dir with your own directory):swagger-codegen generate -i https://api.tuningfiles.com/swagger.json -l php -o /output_dir -c config.json
protected function supportCreateMessageRequest
function (around line 596) and you will see that all the parameters are required. Even the$attachments
parameter. No matter that it's not included into the required params in the specification.Related issues/PRs
I can't find anything related.
Suggest a fix/enhancement
N/A
The text was updated successfully, but these errors were encountered: