OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.91k stars 6.58k forks source link

[BUG][Csharp-netcore] Spec generation with multipard-mixed endpoint #15688

Open Thorbenl opened 1 year ago

Thorbenl commented 1 year ago

Bug Report Checklist

Description

We are trying to generate a csharp-netcore client from our OpenAPI spec. The origin of the JSON spec is an ODATA SAP XML file. The resulting JSON looks fine to us, and also verifies in the Swagger validator.

The issue is, that the batch endpoint in SAP accepts a POST method with a request body of:

"requestBody": {
                "required": true,
                 "description": "Batch request",
                 "content": {
                    "multipart/mixed;boundary=request-separator": {
                         schema": {
                             "type": "string"
                        },
                        "example": "--request-separator\nContent-Type: application/http\nContent-Transfer-Encoding: binary\n\nGET ProdOrderDetailSet HTTP/1.1\nAccept: application/json\n\n\n--request-separator--"
                        }
                    }
                },

However, the generated dotnet client, does not have a parameter in the function, so we are not sure how we can use the generated class and its functions. See more in the repository here: https://github.com/Thorbenl/open-api-charp-sap-batch

openapi-generator version

latest, 2.6.0

OpenAPI declaration file content or url
openapi: 3.0.2
info:
  description: "This service is located at [https://localhost/service-root/](https://localhost/service-root/)"
  title: Service for namespace yadayada
  version: ""
servers:
- url: https://localhost/service-root
paths:
  /$batch:
    post:
      description: |-
        Group multiple requests into a single request payload, see [Batch Processing (OData Version 2.0)](https://www.odata.org/documentation/odata-version-2-0/batch-processing/).

        *Please note that "Try it out" is not supported for this request.*
      requestBody:
        content:
          multipart/mixed;boundary=request-separator:
            example: |-
              --request-separator
              Content-Type: application/http
              Content-Transfer-Encoding: binary

              GET ProdOrderDetailSet HTTP/1.1
              Accept: application/json

              --request-separator--
            schema:
              type: string
        description: Batch request
        required: true
      responses:
        "202":
          content:
            multipart/mixed:
              example: |-
                --response-separator
                Content-Type: application/http

                HTTP/1.1 200 OK
                Content-Type: application/json

                {...}
                --response-separator--
              schema:
                type: string
          description: Batch response
        "4XX":
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/error'
          description: Error
      summary: Send a group of requests
      tags:
      - Batch Requests
components:
  parameters: {}
  responses:
    error:
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/error'
      description: Error
  schemas:
    error:
      properties:
        error:
          $ref: '#/components/schemas/error_error'
      required:
      - error
      type: object
    error_error_message:
      properties:
        lang:
          type: string
        value:
          type: string
      required:
      - lang
      - value
      type: object
    error_error:
      properties:
        code:
          type: string
        message:
          $ref: '#/components/schemas/error_error_message'
        innererror:
          description: The structure of this object is service-specific
          type: object
      required:
      - code
      - message
      type: object
Generation Details
openapi-generator-cli -- generate -g csharp-netcore -c openapi-generator-client.config.yml -i openapi-spec-client.json -o test_client --skip-validate-spec 

with config

# https://openapi-generator.tech/docs/generators/csharp-netcore/
targetFramework: net6.0
library: httpclient
nullableReferenceTypes: true
disallowAdditionalPropertiesIfNotPresent: false
modelPropertyNaming: original
netCoreProjectFile: true
Steps to reproduce
  1. Clone https://github.com/Thorbenl/open-api-charp-sap-batch
  2. run npm i && npm run generate-client
  3. Navigate to path test_client/src/Org.OpenAPITools/Api/BatchRequestsApi.cs
  4. See the function param missing at the function BatchPostAsync

Expected a param for the request:

 /// <summary>
        /// Send a group of requests Group multiple requests into a single request payload, see [Batch Processing (OData Version 2.0)](https://www.odata.org/documentation/odata-version-2-0/batch-processing/).  *Please note that \&quot;Try it out\&quot; is not supported for this request.*
        /// </summary>
        /// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
        /// <returns>Task of string</returns>
        public async System.Threading.Tasks.Task<string> BatchPostAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
devhl-labs commented 1 year ago

@wing328 The CodegenOperation paramter does not appear in allParams. I looked in the DefaultCodegen fromOperation method. This variable is empty formParams = fromRequestBodyToFormParameters(requestBody, imports); Looks like the addProperties method should be returning something for this.