Closed bodiam closed 1 year ago
It seems a workaround for it can be found here (for Spring Boot, but applies to Micronaut too):
Annotating the method and explicitly naming the parameters, and then removing the request parameter does it:
@Parameter(`in` = ParameterIn.PATH, name = "restaurantId", schema = Schema(type = "string"))
@Parameter(`in` = ParameterIn.PATH, name = "partySize", schema = Schema(type = "int32"))
fun checkAvailability(@Parameter(hidden = true) availabilityRequest: AvailabilityRequest): Availability {
}
Generates:
get:
tags:
- availability
summary: Availability check
description: Returns the available timeslots
operationId: checkAvailability
parameters:
- name: partySize
in: path
required: true
schema: {}
- name: restaurantId
in: path
required: true
schema: {}
It's not pretty, but it works. It would be great if this works out of the box though (this has been fixed in Spring Boot / SpringDoc too)
@bodiam I fixed it in #853
Expected Behavior
It seems the generation of OpenAPI specifications doesn't take RFC-6570 URI template specification into account.
I have a method in Micronaut which looks like this:
fun checkAvailability(availabilityRequest: AvailabilityRequest): Availability {
My request looks like this:
However, I don't want to pass in a request, I'd like to pass in the individual parameters, such as:
http://localhost/availability?restaurantId=1&partySize=2&visittime=whenever
To do this, I annotated the controller method with this annotation:
@Get("/{?availabilityRequest*}")
(based on the info I found here: https://dzone.com/articles/micronaut-mastery-binding-request-parameters-to-po)
This works well, and all good. But now I want to generate an OpenAPI specification based on the above, and the generation doesn't seem to take the
?availabilityRequest*
into account. Instead, it still thinks the availabilityRequest is a parameter, which makes my mocks fail.The generated OpenAPI spec looks like this:
While I expected the OpenAPI spec to look more like this:
Actual Behaviour
See above
Steps To Reproduce
Create a new app with a complex type as input for a Get method (maybe also Post?) Enable openapi Build the spec
Environment Information
MacOS
Example Application
No response
Version
3.7.4