OpenAPITools / OpenAPITools/openapi-generator

[BUG][C++][Pistache] Multipart/related is not handled. No code generated

Open
#4,396 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

The use of Multipart/related seems to be ignored by the generator. No code does reference to this content-type and the Json parser is called transparently without takin into account of the Multipart/related

The generated handler corresponding to the request looks like (but no reference to Multipart/related) :

void SMContextsCollectionApi::post_sm_contexts_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {

    // Getting the body param
    
    Inline_object inlineObject;
    
    try {
      nlohmann::json::parse(request.body()).get_to(inlineObject);
      this->post_sm_contexts(inlineObject, response);
    } catch (std::runtime_error & e) {
      //send a 400 error
      response.send(Pistache::Http::Code::Bad_Request, e.what());
      return;
    }
}
openapi-generator version

4.0.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 1.0.0
  title: Check generation of pistache
  description: Internal ref filename is check_multipart-related.yaml

servers:
  - url: http://localhost:8080

paths:
  /sm-contexts:
    post:
      summary:  Create SM Context
      tags:
        - SM contexts collection
      operationId: PostSmContexts
      requestBody:
        description: representation of the SM context to be created in the SMF
        required: true
        content:
          multipart/related:
            schema:
              type: object
              properties: # Request parts
                jsonData:
                  $ref: '#/components/schemas/SmContextCreateData'
                binaryDataN1SmMessage:
                  type: string
                  format: binary
            encoding:
              jsonData:
                contentType:  application/json
              binaryDataN1SmMessage:
                contentType:  application/vnd.3gpp.5gnas
                headers:
                  Content-Id:
                    schema:
                      type: string

      responses:
        '200':
          description: Everythings gonna be alright
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RespContent"
        default:
          description: unexpected error

components:
  schemas:
    RespContent:
      type: string

    SmContextCreateData:
      type: object
      properties:
        supi:
          $ref: '#/components/schemas/Supi'
        unauthenticatedSupi:
          type: boolean
          default:  false
    Supi:
      type: string

Command line used for generation

Generate :

openapi-generator-cli.sh generate -i ./openapi.yaml -g cpp-pistache-server -c ./config.json -o .
Steps to reproduce

Just generate and have a look to the file SMContextsCollectionApi.cpp (method post_sm_contexts_handler). See above also

Related issues/PRs

#3512

Suggest a fix

May be get inspiration with what is done in cpprestsdk to handle multipart/form-data see #3512

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

Generate the supplied OpenAPI document with cpp-pistache-server and inspect SMContextsCollectionApi.cpp, especially post_sm_contexts_handler; compare this behavior with the multipart/form-data handling discussed in related issue #3512. Trace the generator entry point for request-body content types, then verify that generated handlers account for multipart/related and preserve the existing JSON and binary parts.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.