Skip to content

Conversation

melloware
Copy link
Contributor

Because this just uses the default priority = 1 and so does the Health API they can flicker back and forth in the generated OpenAPI docs.

cc @phillip-kruger

@melloware melloware requested a review from a team as a code owner May 9, 2025 15:16
@melloware
Copy link
Contributor Author

@MikeEdgar @phillip-kruger i wonder if I should open a quarkus ticket? It would be great if the OpenApiFilter annotation was in the SPI so i don't have to do what I am doing in this PR.

I think we need to give the SmallRye Health the same treatment. If all filters are 1 we get "flickering" OpenAPI generation so it looks like it changes on every build with no code changes.

Copy link

@MikeEdgar MikeEdgar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to give the SmallRye Health the same treatment. If all filters are 1 we get "flickering" OpenAPI generation so it looks like it changes on every build with no code changes.

Do you mean that they are running in random order because they have the same priority?

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi-spi</artifactId>
<artifactId>quarkus-smallrye-openapi-deployment</artifactId>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why deployment? @OpenApiFilter is in the runtime library.

Suggested change
<artifactId>quarkus-smallrye-openapi-deployment</artifactId>
<artifactId>quarkus-smallrye-openapi</artifactId>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deployment modules usually depend on other extension's deployment modules

@melloware
Copy link
Contributor Author

melloware commented May 9, 2025

Correct so I use both this extension and SmallRye Health which both add OASFilter with no annotation. So they get priority=1 and it looks like the Quarkus Extension just processes then in priority order which seems to "flicker" when they are all the same priority. Maybe it could secondarily by name?

private List<String> getUserDefinedFilters(IndexView index, OpenApiFilter.RunStage stage) {
        EnumSet<OpenApiFilter.RunStage> stages = EnumSet.of(OpenApiFilter.RunStage.BOTH, stage);
        Comparator<Object> comparator = Comparator
                .comparing(x -> ((AnnotationInstance) x).valueWithDefault(index, "priority").asInt())
                .reversed();
        return index
                .getAnnotations(OpenApiFilter.class)
                .stream()
                .filter(ai -> stages.contains(OpenApiFilter.RunStage.valueOf(ai.valueWithDefault(index).asEnum())))
                .sorted(comparator)
                .map(ai -> ai.target().asClass())
                .filter(c -> c.interfaceNames().contains(DotName.createSimple(OASFilter.class.getName())))
                .map(c -> c.name().toString())
                .collect(Collectors.toCollection(ArrayList::new));
    }

@MikeEdgar
Copy link

Maybe it could secondarily by name?

Yeah, adding the fully-qualified class name to that comparator seems reasonable to me.

@melloware
Copy link
Contributor Author

OK that would be better than me hacking around! Let me submit a PR to Quarkus

@melloware
Copy link
Contributor Author

PR submitted: quarkusio/quarkus#47779

@melloware melloware closed this May 10, 2025
@melloware melloware deleted the openapi-enforce-order branch May 10, 2025 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants