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

Empty schema for responses #1420

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

Empty schema for responses #1420

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

Comments

@tcrespog
Copy link

tcrespog commented Feb 6, 2024

Expected Behavior

The generated schema field shouldn't be empty.

Actual Behaviour

Given the following controller method:

    @Post("/pet")
    @Operation(
            operationId = 'CreatePet',
            summary = 'Create a pet',
            requestBody = @RequestBody(description = 'Pet create request', content = @Content(schema = @Schema(implementation = CreatePetRequest))),
            responses = [
                    @ApiResponse(responseCode = '200', description = 'OK', content = @Content(schema = @Schema(implementation = CreatePetResponse))),
                    @ApiResponse(responseCode = '400', description = 'Bad request', content = @Content(schema = @Schema(implementation = ErrorResponse))),
                    @ApiResponse(responseCode = '403', description = 'Operation not allowed'),
                    @ApiResponse(responseCode = '409', description = 'Duplicated element', content = @Content(schema = @Schema(implementation = ErrorResponse)))
            ]
    )
    HttpResponse<CreatePetResponse> createPet(@Body CreatePetRequest body) {
        def respBody = new CreatePetResponse(pet: body.pet)

        return HttpResponse.ok(respBody)
    }

The generated specs contain empty schemas for responses:

openapi: 3.0.1
info:
  title: mn-openapi-empty-schema
  version: "0.0"
paths:
  /pet:
    post:
      summary: Create a pet
      operationId: CreatePet
      requestBody:
        description: Pet create request
        content:
          schema: {} # <----- empty schema here too, but the block below looks alright
          application/json:
            schema:
              $ref: '#/components/schemas/CreatePetRequest'
        required: true
      responses:
        "200":
          description: OK
          content:
            schema: {} # <---- empty schema for all responses
        "400":
          description: Bad request
          content:
            schema: {}
        "403":
          description: Operation not allowed
        "409":
          description: Duplicated element
          content:
            schema: {}
components:
  schemas:
    CreatePetRequest:
      type: object
      properties:
        pet:
          $ref: '#/components/schemas/Pet'
    Pet:
      type: object
      properties:
        name:
          type: string

The same method in Micronaut 3.x generates something such as the following:

      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreatePetResponse'

Steps To Reproduce

  1. Download the sample project.
  2. Run ./gradlew compileGroovy
  3. In the generated specs are generated, the schema for responses is empty.

Environment Information

  • Micronaut + Groovy (and Micronaut OpenAPI 6.5.1).
  • Ubuntu 22.04.
  • Java 17.

Example Application

https://github.com/tcrespog/mn-openapi-empty-schema

Version

4.2.3

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.

1 participant