OpenAPITools / OpenAPITools/openapi-generator

[BUG] Description

Open
#18,295 0 comments 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
  • 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?
  • [may be] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

I am trying to generate the code for an endpoint that can accept json input and a multipart file upload

openapi-generator version

@openapitools/openapi-generator-cli": "^2.13.1"

OpenAPI declaration file content or url

If you post the code inline, please wrap it with

post:
  operationId: letter_create

  summary: create

  description: >-
    Creates a new letter given information

  tags:
    - Letters

  parameters:
    - $ref: "../shared/parameters/idempotency.yml#/idem-header"
    - $ref: "../shared/parameters/file.yml"

  requestBody:
    required: true
    content:
      application/json:
        schema:
          $ref: "models/letter_editable.yml"

      application/x-www-form-urlencoded:
        schema:
          $ref: "models/letter_editable.yml"
        encoding:
          to:
            style: deepObject
            explode: true
          from:
            style: deepObject
            explode: true
          merge_variables:
            style: deepObject
            explode: true
          metadata:
            style: deepObject
            explode: true

      multipart/form-data:
        schema:
          $ref: "models/letter_editable_with_file.yml"
        encoding:
          to:
            style: deepObject
            explode: true
          from:
            style: deepObject
            explode: true
          merge_variables:
            style: deepObject
            explode: true
          metadata:
            style: deepObject
            explode: true
          file:
            style: deepObject
            explode: true

  responses:
    "200":
      $ref: responses/post_letter.yml

    default:
      $ref: "../shared/responses/error_response.yml"

  x-template-config:
    upload_file: true
    test:
      create: true
      tests:
        - subject: regular_200
          success: true
        - subject: certified_200
          success: true
        - subject: registered_200
          success: true
        - subject: 422

(for YAML code) or

Generation Detail

I am generating ruby code for this, but it is only generating code when the request is application/json type not for the multipart one, actually if I put the multipart/form-data: block at the beginning it generates the code I need but now it does not generate the one for the application/json. This is weird because it is valid to have differente contents in the requestBody

this is the configuration I am using

{
  "packageName": "lob",
  "packageUrl": "https://github.com/lob/lob-ruby-sdk",
  "packageVersion": "1.0.0",
  "projectName": "lob-ruby-sdk",
  "withSeparateModelsAndApi": true,
  "developerName": "Lob",
  "developerEmail": "engineering@lob.com",
  "gemName": "lob",
  "hideGenerationTimestamp": true,
  "developerOrganizationUrl": "https://www.lob.com/developers",
  "files": {
    "CODE_SNIPPETS.md.mustache": {
      "destinationFilename": "CODE_SNIPPETS.md"
    }
  }
}

Steps to reproduce

The code generated for us to get this error is the following one https://github.com/lob/lob-ruby/blob/main/lib/lob/api/letters_api.rb#L109 this is the issure reported by one of our customers https://github.com/lob/lob-ruby/issues/211 where he is trying to use the sdk generated

Related issues/PRs

link

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 with the supplied OpenAPI requestBody declaration and the generated Ruby client at lib/lob/api/letters_api.rb#L109. Compare generation when application/json and multipart/form-data appear in different orders, then inspect the Ruby generator's handling of these requestBody content types. Done means the generated client supports both media types for the same endpoint.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, ruby
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.