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

openapi-annotation-processor generates swagger file with no doc info #197

Closed franck-malka closed 1 year ago

franck-malka commented 1 year ago

Hi

I noticed that the openapi-annotation-processor generates a swagger json with no doc info

{ "openapi": "3.0.3", "info": { "title": "", "version": "" }, "paths": { "/api-invovation-logs/v1/{aefId}/logs": { "post": {

is there a way to add at least doc title and doc version using the plugin or an annotation in the code?

dzikoysk commented 1 year ago

Yup, these properties are configured in plugin configuration:

franck-malka commented 1 year ago

Then it's not working.

In my code i set

OpenApiPluginConfiguration openApiConfiguration = new OpenApiPluginConfiguration() .withDocumentationPath("/swagger") .withDefinitionConfiguration((version, definition) -> definition .withOpenApiInfo((openApiInfo) -> { openApiInfo.setTitle("CAPIF Core Function"); openApiInfo.setVersion("1.1.5"); openApiInfo.setDescription("3GPP TS 29.222 V18.0.0 Common API Framework for 3GPP Northbound APIs");
OpenApiContact contact = new OpenApiContact(); contact.setName("Slicce"); contact.setEmail("support@slicce.co"); contact.setUrl("https://www.slicce.co/api-terms-of-service"); openApiInfo.setContact(contact); }));

        config.plugins.register(new OpenApiPlugin(openApiConfiguration));

and the json generated is

{ "openapi": "3.0.3", "info": { "title": "", "version": "" }, "paths": { "/api-invovation-logs/v1/{aefId}/logs": { "post": {

I mean the json generated at compile time in target/classes/openapi-plugin/openapi-default.json

dzikoysk commented 1 year ago

Plugin configuration only applies changes to the loaded scheme, so it should be available at "http://localhost/openapi". Currently, there's no option to provide this value at compile time (maybe with Groovy script). Do you consume your openapi schemes at compile time? (with e.g. Gradle build)

franck-malka commented 1 year ago

Yes, it is available at http://localhost/openapi But,

I have several projects exposing APIs and one consuming all the APIs. And i want the consuming API project to automatically load the updated swagger json of the exposing projects at compile time And when i use tthe openapi-annotation-processor output, it misses the title, so all the APIs have no name

dzikoysk commented 1 year ago

I think we could inject these values though annotation processor flags that can be defined in ap/kapt task configuration in Maven/Gradle. Do you think such solution would work for your use-case?

franck-malka commented 1 year ago

It would mean we need to insert the values in the pom file, right? It's good enough for me but it's not cool to set these values twice.

dzikoysk commented 1 year ago

Once you set it in pom.xml, then you don't have to do that in plugin configuration. Alright I'll try to take a look at it in the evening/tomorrow.

dzikoysk commented 1 year ago

You should be able to inject these values through these 2 flags:

-Aopenapi.info.title=App
-Aopenapi.info.version=1.0.0

In pom.xml:

<configuration>
    <annotationProcessorPaths>
        [...]
    </annotationProcessorPaths>
    <compilerArgs>
        <compilerArg>-Aopenapi.info.title=App</compilerArg>
    </compilerArgs>
</configuration>
franck-malka commented 1 year ago

with what version this should work? it doesn't seems to work with version 5.4.2

franck-malka commented 1 year ago

neither with 5.6.2

dzikoysk commented 1 year ago

https://github.com/javalin/javalin-openapi/releases/tag/5.6.2-1