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.63k stars 6.53k forks source link

[BUG] [SPRING-CLOUD] UNKNOWN_BASE_TYPE when using multi-part content #4390

Open MelleD opened 4 years ago

MelleD commented 4 years ago

Bug Report Checklist

Description

When I swap out a multip part in a request body object, the interface is generated incorrectly with UNKNOWN BASE TYPE

openapi-generator version

4.2.0

OpenAPI declaration file content or url

This yaml works

---
openapi: 3.0.2
info:
  title: Test
  version: 'v1'
  description: Test
paths:
  /foo:
    post:
      summary: Test
      operationId: createFoo
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: array
                  items:
                    type: string
                    format: binary
      responses:
        '201':
          description: "Go"
    ResponseEntity<Void> createFoo(@ApiParam(value = "file detail") @RequestParam("file") MultipartFile file);

This yaml is not working

---
openapi: 3.0.2
info:
  title: Test
  version: 'v1'
  description: Test
paths:
  /foo:
    post:
      summary: Test
      operationId: createFoo
      requestBody:
        $ref: '#/components/requestBodies/MultiPartFile'
      responses:
        '201':
          description: "Go"
components:
  requestBodies:
    MultiPartFile:
      content:
        multipart/form-data:
          schema:
            type: object
            properties:
              file:
                type: array
                items:
                  type: string
                  format: binary
      description: Payload or user input is invalid. See error details in the payload for more information.
  ResponseEntity<Void> createFoo(@ApiParam(value = "Payload or user input is invalid. See error details in the payload for more information."  )  @Valid @RequestBody UNKNOWN_BASE_TYPE UNKNOWN_BASE_TYPE);
Command line used for generation
 <generatorName>spring</generatorName>
  <library>spring-cloud</library>
   <java8>true</java8>
matgnt commented 4 years ago

Same here:

[main] WARN  o.o.codegen.DefaultCodegen - codegenModel is null. Default to UNKNOWN_BASE_TYPE

I had this in my components: requestBodies:

components:
  requestBodies:
      hashFileBody:
          content:
              multipart/form-data:
                  schema:
                     type: object
                  ...

and used it in some post:requestBody as a $ref. It didn't work there. After moving it up to the post:requestBody: (meaning no $ref) it worked again. Then, I tried to move only the schema part down to components:schemas which worked without any problems.

At the same time, this one here works in components:requestBodies:

components:
  requestBodies:
      fileUpload:
        content:
            application/octet-stream:
                schema:
                    type: string
                    format: binary

To me it looks like the multipart/form-data does not work as a $ref to requestBodies.

Version: 4.3.0-SNAPSHOT Language: dart

I think this is not a "spring-cloud" only issue (as tagged in the title). it affects other languages too.