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

Add examples to @OpenApiResponse #212

Closed gordonjb closed 7 months ago

gordonjb commented 7 months ago

Actual behavior (the bug) You can't add examples to responses where the endpoint just returns a String, e.g.:

    @OpenApi(
        summary = "xxxxxx",
        description = "xxxxxx",
        operationId = "xxxxxx",
        path = "/xxxxxx/:id",
        methods = HttpMethod.PUT,
        pathParams = {@OpenApiParam(name = "id", type = String.class, description = "xxxxxx")},
        requestBody = @OpenApiRequestBody(content = {@OpenApiContent(from = DTOClass.class)}),
        responses = {
            @OpenApiResponse(status = "200", content = {@OpenApiContent(from = String.class)}, description = "A string is returned describing changes."),
            @OpenApiResponse(status = "400", content = {@OpenApiContent(from = String.class)}, description = "Returned if JSON was malformed")
        }
    )
    @OpenApiExample(objects = {
        @OpenApiExampleProperty(value="example 1"),
        @OpenApiExampleProperty(value="example 2"),
        @OpenApiExampleProperty(value="example 3"),
        @OpenApiExampleProperty(value="example 4")
    })
    private void xxxxxx(Context context) {
    ...
    }

similarly,

@OpenApiExample("example 1")
private void xxxxxx(Context context) {
...
}

also doesn't work. The "Example Value" section in swagger UI just shows string

Expected behavior Examples can be displayed in the "Example Value" section

To Reproduce Example config given above

Additional context dzikoysk — Today at 17:13 Yeah, I think we miss that particular field - it should be on OpenApiContent to reflect Media Type Object: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#fixed-fields-12