Skip to content

C# Client Generation: Method accepting multiple request types defined oneOf accepts only first request type #5325

@nenadvicentic

Description

@nenadvicentic

Describe the bug

When we have service method accepting multiple request types, defined as, for example:

    V2_myRequest:
      type: object
      required:
      - type
      properties:
        type:
          type: string
          enum:
          - t1
          - t2
          - t3
          - t4
          description: |
            - `t1`: Type1
            - `t2`: Type2
            - `t3`: Type3
            - `t4`: Type4
      oneOf:
        - $ref: "#/components/schemas/V2_myRequest_t1"
        - $ref: "#/components/schemas/V2_myRequest_t2"
        - $ref: "#/components/schemas/V2_myRequest_t3"
        - $ref: "#/components/schemas/V2_myRequest_t4"

Generated method only accepts only the first type:

public myMethodAsync(Type1 value) {
    ...
}

Version 14.4.x was generating the method with object type, so all the request types could have been passed in. Something like:

public myMethodAsync(object value) {
   ...
}

NSwag.ApiDescription.Client generates C# client

14.6.x

With which versions did you encounter this behavior.

14.6.2

Expected behavior

Or generate for overload for the method, with each type:

myMethodAsync(Type1 value) {
   ....
}

myMethodAsync(Type2 value) {
    ....
}

or generate method with object type like in previous versions (14.4.x).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions