OpenAPITools / OpenAPITools/openapi-generator

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

Open
#15,688 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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))

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by cloning the linked reproduction repository, running npm i && npm run generate-client, and inspecting test_client/src/Org.OpenAPITools/Api/BatchRequestsApi.cs, especially BatchPostAsync. Compare the generated method with the request body in the supplied OpenAPI document; done means the generated C# client exposes the batch request parameter and the reproduction output matches the expected signature.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.