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.04k stars 6.38k forks source link

[BUG][KOTLIN] Model not generated when used as $ref in multipart/form-data requestBody #10396

Open whiemstra opened 2 years ago

whiemstra commented 2 years ago

Bug Report Checklist

Description

When using openApiGenerate with a yaml, model is not generated when used as a $ref inside a multipart/form-data requestBody.

If multipart/form-data is changed to application/json, the model will be generated.

openapi-generator version

5.2.0

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: YAML for bug report
  version: '1.0'
  title: Bug report
tags:
  - name: Test
    description: Test
paths:

  /test/create:
    post:
      tags:
        - Test
      summary: Summary
      description: Description
      operationId: testCreate
      responses:
        '200':
          description: Successful operation
        '400':
          description: Invalid request
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required:
                - file
                - json
              properties:
                file:
                  type: string
                  format: binary
                json:
                  $ref: '#/components/schemas/SomeRefObject'

components:
  schemas:
    SomeRefObject:
      description: 'Some Ref Object'
      type: object
      required:
        - id
      properties:
        id:
          type: string
          description: 'Some ID'
Generation Details

Gradle: 7.2 Kotlin: 1.5.30 Java: 11

Also tested with: SerializationLibrary: jackson (2.12.3)

Steps to reproduce

Create a gradle file with dependencies and the org.openapi.generator plugin

Execute: gradle openApiGenerate

sensi-shane commented 2 years ago

Just ran into this myself and was able to resolve. --global-property skipFormModel=true fixes the issue

I'm using npm package "@openapitools/openapi-generator-cli": "2.4.2", openapitools.json file looks like this:

{
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "5.2.0",
    "generators": {
      "standard": {
        "generatorName": "typescript-axios",
        "output": "#{cwd}/src/api/generated-files",
        "glob": "openapi.yaml",
        "skipValidateSpec": true,
        "additionalProperties": {
          "supportsEs6": "true",
          "useSingleRequestParameter": true
        },
        "globalProperty": {
          "skipFormModel": false
        }
      }
    }
  }
}
whiemstra commented 2 years ago

Amazing, that is a fix indeed thx @sensi-shane! But is this the desired behavior?

sensi-shane commented 2 years ago

@whiemstra you're welcome! I believe so. I found it on this page of docs. You can do a search on the page for skipFormModel https://openapi-generator.tech/docs/customization/