Skip to content

[BUG] [swift] oneOf handling for form-url encoded requestBodies  #15511

Open
@Jonas1893

Description

@Jonas1893

Bug 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

When specifying a requestBody using application/x-www-form-urlencoded; charset=utf-8 encoding, oneOf does not work as expected. Instead of generating and using a model for each of the oneOf types as it is the case when using application/json, the generated API method just expects all parameters from all the oneOf types together and ignores the generated request models.
This was a problem even before 6.3.0, but with 6.4.0 and above it got worse as parameters that are only present in some and not in all of the oneOf types are now being generated non-optional which does not make sense.

Generated method signature with application/x-www-form-urlencoded; charset=utf-8

open class func asTokenOauth2Post(password: String, scope: String, username: String, clientId: String? = nil, grantType: APIGrantType_asTokenOauth2Post? = nil, refreshToken: String? = nil) -> AnyPublisher<APIAsTokenOauth2Post200Response, Error>

Generated method signature with application/json

open class func asTokenOauth2Post(aPIAsTokenOauth2PostRequest: APIAsTokenOauth2PostRequest) -> AnyPublisher<APIAsTokenOauth2Post200Response, Error>
openapi-generator version
  • broken in 6.4.0 - current
  • workaround with nilabel parameters in < 6.3.0
OpenAPI declaration file content or url

https://gist.github.com/Jonas1893/baf6076647cc302e4eb7014025977663

Generation Details

Used config

generatorName: swift5
outputDir: ./
library: alamofire
projectName: AuthClient
generateModelAdditionalProperties: false
additionalProperties:
  responseAs: Combine
  readonlyProperties: true
  nonPublicApi: false
  modelNamePrefix: API
  removeMigrationProjectNameClass: true
Steps to reproduce

Using the provided spec and config perform the generation. Also try a second generation run with application/json content-type for the requestBody and observe the behavior described above

Related issues/PRs
Suggest a fix

Content-Type application/x-www-form-urlencoded; charset=utf-8 should use the same approach of handling oneOfs in generated APIs as application/json

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions