javalin / javalin-openapi

Annotation processor for compile-time OpenAPI & JsonSchema, with out-of-the-box support for Javalin 5.x, Swagger & ReDoc
https://github.com/javalin/javalin-openapi/wiki
Apache License 2.0
45 stars 17 forks source link

Examples in OpenApiResponse #213

Closed mzielinski closed 7 months ago

mzielinski commented 7 months ago

Describe the feature

It would be good to have possibility to define example response for each of OpenApiResponse

 responses = [
        OpenApiResponse(
            status = "200",
            description = "SUCCESS",
            content = [OpenApiContent(Response::class)]
        ),
        OpenApiResponse(
            status = "500",
            description = "UNEXPECTED_ERROR",
            content = [OpenApiContent(Response::class)]
        ),
        OpenApiResponse(
            status = "503",
            description = "SERVICE_UNAVAILABLE",
            content = [OpenApiContent(Response::class)]
        )
    ],

I have such content in OpenAPI specification:

image

It would be nice to have possibly to define examples and finally have such output

image

To achieve that, we need to inject example into content part

 "500": {
     "description": "UNEXPECTED_ERROR",
     "content": {
         "application/json": {
             "schema": {
                 "$ref": "#/components/schemas/Response"
            },
            "example": {
                "statusCode": "500",
                 "subStatusCode:": "ERROR-CODE-500-1",
                 "statusMessage": "Unexpected Error"
            }
        }
    }
},
dzikoysk commented 7 months ago

Yes, I already had a conversation about this particular feature on our Discord server today, and it was reported an hour ago in #212 :) It should be implemented by the end of this week.