[BUG] Request body form parameters do not support complex composed schema use cases
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Request body form parameters do not support complex composed schema use cases When we handle request body form parameters here: https://github.com/OpenAPITools/openapi-generator/blob/fdb13c3e2e5fa96523102d7c92ae2a6b409c47d4/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L6001 Our code traverses composed schemas and pools all properties inside objects into the returned properties map. This will not work when:
- two schemas define a property with the same name and different types
- we have oneOf or anyOf schemas where some properties should be included and others shouldn’t
This code path is used when request bodies are content-type application/x-www-form-urlencoded, or content-type starts with multipart
openapi-generator version
5.2.1
OpenAPI declaration file content or url
openapi: 3.0.1
info:
version: '1.0.0'
title: the title
paths:
'/users/me':
post:
description: Change user password.
operationId: changeCurrentUserPassword
requestBody:
required: true
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/ChangePasswordRequest'
responses:
'200':
description: Successful operation
content: {}
components:
schemas:
CommonPasswordRequest:
type: object
required: [ password, passwordConfirmation ]
properties:
password:
type: string
format: password
passwordConfirmation:
type: string
format: password
ChangePasswordRequest:
type: object
allOf:
- $ref: '#/components/schemas/CommonPasswordRequest'
- type: object
required: [ oldPassword ]
properties:
oldPassword:
type: string
format: password
Generation Details
Steps to reproduce
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/10396
Suggest a fix
Update this code to return a single CodegenParameter which represents the composed schema in these cases. Then the generator will require than an instance of the model that this refers to is passed in. This fix should only be done for generators which support full composition. For now our code only handles object schema and pure allOf with no colliding property definitions.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top GitHub Comments
Same issue with 5.3.1 of the plugin (java). Models are not generated when
ref$
is used. I got message like “Model XXX not generated since it’s marked as unused (due to form parameters) andskipFormModel
(global property) set to true (default)” in my console"Here is my workaround but this should not be the fix as skipFormModel should be true only for OA2 as I understand. The problem I think is related to the fact it’s “marked as unused (due to form parameters)”
This has been fixed in the new python-experimental generator (added in 5.4.0) which supports Inline schemas anywhere. One can see it working in this PR in 6.0.0.