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

Trouble getting javalin-openapi to produce any output? #214

Closed mikera closed 4 months ago

mikera commented 7 months ago

Hi, I'm hoping to use javalin-openapi 6.0.1 to document / test a REST API

This issue I am having is that whenever I go to the swagger page at http://localhost:8080/swagger all I get is an error message saying "No API Definition provided".

If I go to http://localhost:8080/openapi all I get is response is some empty JSON {}

No doubt I am doing something wrong, but it is very unclear what the problem is?

I have a (working) Javalin endpoint annotated as follows:

    @OpenApi(
        path = ROUTE+"data/{hash}",
        methods = HttpMethod.POST,
            operationId = "data",
            pathParams = {
              @OpenApiParam(
                      name = "hash", 
                      description = "Data hash as a hex string. Leading '0x' is optional but discouraged.", 
                      required = true, 
                      type = String.class,
                      example = "0x1234567812345678123456781234567812345678123456781234567812345678")
    })

Any help / pointers much appreciated!

dzikoysk commented 6 months ago

Hey, could you share your Gradle/Maven config? It looks like misconfigured annotation processor.

mikera commented 6 months ago

Thanks for looking at it! Sounds like a plausible diagnosis :-)

The pom file is here: https://github.com/Convex-Dev/convex/blob/develop/convex-restapi/pom.xml

FWIW, I'm building on Windows using Eclipse and Maven 3.9.4

And here is what I believe is the relevant annotation processor plugin:

    <build>
        <plugins>
            ....
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.12.1</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                    <annotationProcessorPaths>
                        <annotationProcessorPath>
                            <groupId>io.javalin.community.openapi</groupId>
                            <artifactId>openapi-annotation-processor</artifactId>
                            <version>${javalin.version}</version>
                        </annotationProcessorPath>
                    </annotationProcessorPaths>
                </configuration>
            </plugin>
        </plugins>
    </build>
mikera commented 6 months ago

I'm not entirely clear where the openapi json is supposed to be put by default?

The Javalin server isn't particularly complex, though it does have a static file handler and a few API endpoints set up as well as the OpenAPI plugin with ReDoc and Swagger.

dzikoysk commented 6 months ago

Hey, sorry, I totally missed the notification as I have quite a lot of them 😔 Just cloned your project and it looks fine for me:

obraz

I think the issue here is probably Eclipse - I assume that you're probably launching your app via some sort of their custom app runner, where annotation processing is disabled by default, so I'd start looking there. I guess you can start from something like this:

mikera commented 6 months ago

Thanks for checking @dzikoysk ! Will see if I can figure out what Eclipse is doing....