Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning and missing response description when generating specs for file upload #1418

Closed
tcrespog opened this issue Feb 5, 2024 · 5 comments · Fixed by #1419
Closed

Warning and missing response description when generating specs for file upload #1418

tcrespog opened this issue Feb 5, 2024 · 5 comments · Fixed by #1419

Comments

@tcrespog
Copy link

tcrespog commented Feb 5, 2024

Expected Behavior

Response description should be present without warnings.

Actual Behaviour

Given a controller method such as:

    @Post(value = "/", consumes = MediaType.MULTIPART_FORM_DATA)
    @Status(HttpStatus.NO_CONTENT)
    @Operation(
            operationId = 'UploadFile',
            summary = 'Upload a file',
            requestBody = @RequestBody(
                    description = 'File request',
                    content = @Content(mediaType = MediaType.MULTIPART_FORM_DATA, schema = @Schema(type = 'object'))
            ),
            responses = [
                    @ApiResponse(responseCode = '204', description = 'OK'),
            ]
    )
    void uploadFile(CompletedFileUpload file) {
        assert file.bytes
    }

A warning is shown when generating the OpenAPI specs:

WARNING: Error converting  [{"summary":"Upload a file","operationId":"UploadFile","responses":{"204":{"description":"OK","responseCode":"204"}},"requestBody":{"description":"File request","content":{"schema":{"anyOf":[],"allOf":[],"oneOf":[],"type":"object"},"mediaType":"multipart/form-data"}}}]: to class io.swagger.v3.oas.models.Operation: Cannot construct instance of `io.swagger.v3.oas.models.media.MediaType` (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('multipart/form-data')
 at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: io.swagger.v3.oas.models.Operation["requestBody"]->io.swagger.v3.oas.models.parameters.RequestBody["content"]->io.swagger.v3.oas.models.media.Content["mediaType"])

Although the generated specs seem to look okay, the desired description for the response is missing (might be related to the warning?):

openapi: 3.0.1
info:
  title: mn-openapi-content
  version: "0.0"
paths:
  /file:
    post:
      operationId: uploadFile # <----- Why is it uncapitalized?
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
            encoding:
              file:
                contentType: application/octet-stream
        required: true
      responses:
        "204":
          description: uploadFile 204 response # <----- this should be just 'OK'

Steps To Reproduce

  1. Download the sample project.
  2. Run ./gradlew compileGroovy
  3. The warning is shown.
  4. Although the specs are generated, the response description is not as expected.

Environment Information

  • Micronaut + Groovy.
  • Ubuntu 22.04.
  • Java 17.

Example Application

https://github.com/tcrespog/mn-openapi-content

Version

4.2.3

@altro3
Copy link
Collaborator

altro3 commented Feb 5, 2024

It's already fixed. Just use latest version of micronaut-openapi.

Latest version generate this:

openapi: 3.0.1
paths:
  /api:
    post:
      summary: Upload a file
      operationId: UploadFile
      requestBody:
        description: File request
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
            encoding:
              file:
                contentType: application/octet-stream
      responses:
        "204":
          description: OK

@altro3 altro3 closed this as completed Feb 5, 2024
@tcrespog
Copy link
Author

tcrespog commented Feb 5, 2024

I'm sorry, but I've just upgraded the sample project to version 6.5.1 and still seeing the same behaviour. Am I doing something wrong?

@altro3
Copy link
Collaborator

altro3 commented Feb 5, 2024

try to replace this:

    compileOnly platform("io.micronaut.openapi:micronaut-openapi-bom:6.5.1")
    compileOnly("io.micronaut.openapi:micronaut-openapi")
    compileOnly("io.micronaut.openapi:micronaut-openapi-annotations")

to this:

    compileOnly("io.micronaut.openapi:micronaut-openapi:6.5.1!!")

@altro3 altro3 reopened this Feb 5, 2024
@altro3
Copy link
Collaborator

altro3 commented Feb 5, 2024

Hm... looks like a bug with groovy only... Ok, I'll check it tomorrow

@altro3
Copy link
Collaborator

altro3 commented Feb 6, 2024

I fixed it, but for you know: this is bug with jackson with groovy. With kotlin and java all wors fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants