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

Plugin generates OpenAPI output that doesn't match spec #180

Closed dennisameling closed 1 year ago

dennisameling commented 1 year ago

Hi! Consider the following OpenApiInfo configuration:

      javalinConfig.plugins.register(
            OpenApiPlugin(
                OpenApiPluginConfiguration()
                    .withDefinitionConfiguration { version: String, definition: DefinitionConfiguration ->
                        definition
                            .withOpenApiInfo { openApiInfo: OpenApiInfo ->
                                openApiInfo.title = "Demo"
                                openApiInfo.description = "This is a demo description."
                                openApiInfo.version = version
                            }
                    }
            )
        )

... which generates this output:

{
  "openapi" : "3.0.3",
  "info" : {
    "title" : "Demo API",
    "summary" : null,
    "description" : "This is a demo description.",
    "terms_of_service" : null,
    "contact" : null,
    "license" : null,
    "version" : "default"
  }
}

When pasting this into https://editor.swagger.io for example (or any OpenAPI spec validator), it fails on these things:

image

I'd expect the null values to be left out completely. Am I doing something wrong in my implementation?

Thanks!

dzikoysk commented 1 year ago

To be fair, I don't remember why we have these properties. I think it might be a good idea to filter them from scheme.

dzikoysk commented 1 year ago

It looks like those summary & termsOfService are a part of 3.1.0:

But terms_of_service should be termsOfService. It seems like you're using different configuration of ObjectMapper in Javalin, because by default it's in a proper form:

obraz

dennisameling commented 1 year ago

Ah sorry, my bad indeed! Thanks a lot for looking into it 😊