Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum property values not hyphenated anymore in the configuration metadata #42514

Closed
ppalaga opened this issue Aug 13, 2024 · 12 comments · Fixed by #42522
Closed

Enum property values not hyphenated anymore in the configuration metadata #42514

ppalaga opened this issue Aug 13, 2024 · 12 comments · Fixed by #42522
Labels
area/config kind/bug Something isn't working
Milestone

Comments

@ppalaga
Copy link
Contributor

ppalaga commented Aug 13, 2024

Describe the bug

We have a config property in Quarkus CXF defined as follows:

    @WithDefault("Keep-Alive")
    @WithConverter(ConnectionTypeConverter.class)
    public ConnectionType connection();

Before the recent refactoring of quarkus-extension-processor, the metadata was produced with hyphenated enum values target/asciidoc/generated/config/all-configuration-roots-generated-doc/io.quarkiverse.cxf.CxfConfig:

  {
    "configDocKey": {
      "type": "org.apache.cxf.transports.http.configuration.ConnectionType",
      "key": "quarkus.cxf.client.\"client-name\".connection",
      "additionalKeys": [],
      "configDoc": "The connection disposition. If close the connection to the server is closed after each request/response dialog. If\nKeep-Alive the client requests the server to keep the connection open, and if the server honors the keep alive request,\nthe connection is reused. Many servers and proxies do not honor keep-alive requests.",
      "withinAMap": true,
      "defaultValue": "keep-alive",
      "javaDocSiteLink": "",
      "docMapKey": "connection",
      "configPhase": "RUN_TIME",
      "acceptedValues": [
        "`close`",
        "`keep-alive`"
      ],
      "optional": false,
      "list": false,
      "passThroughMap": false,
      "withinAConfigGroup": true,
      "topLevelGrouping": "quarkus.cxf",
      "since": "2.2.3",
      "environmentVariable": "QUARKUS_CXF_CLIENT__CLIENT_NAME__CONNECTION",
      "enum": true
    }
  },

After the refactoring, the enum values in target/quarkus-config-doc/quarkus-config-model.yaml are present verbatim:

  - !<io.quarkus.annotation.processor.documentation.config.model.ConfigProperty>
    enum: true
    sourceClass: "io.quarkiverse.cxf.CxfClientConfig"
    sourceName: "connection"
    path: "quarkus.cxf.client.\"client-name\".connection"
    type: "org.apache.cxf.transports.http.configuration.ConnectionType"
    phase: "RUN_TIME"
    environmentVariable: "QUARKUS_CXF_CLIENT__CLIENT_NAME__CONNECTION"
    typeDescription: "ConnectionType"
    withinMap: true
    converted: true
    enumAcceptedValues:
      qualifiedName: "org.apache.cxf.transports.http.configuration.ConnectionType"
      values:
        CLOSE:
          configValue: "CLOSE"
        KEEP_ALIVE:
          configValue: "KEEP_ALIVE"
    defaultValue: "Keep-Alive"

Expected behavior

The enum values should be produced hyphenated, same as before quarkus-extension-processor refactoring.

I am aware of the following note in ConfigResolver

// if the property has a converter, we don't hyphenate the values (per historical rules, not exactly sure of the reason)
boolean hyphenateEnumValues = !discoveryConfigProperty.isConverted();

However my example proves that the rule to decide about hyphenation must have been complexer than just "if the property has a converter"

@ppalaga ppalaga added the kind/bug Something isn't working label Aug 13, 2024
Copy link

quarkus-bot bot commented Aug 13, 2024

/cc @radcortez (config)

@ppalaga
Copy link
Contributor Author

ppalaga commented Aug 13, 2024

cc @gsmet

@gsmet
Copy link
Member

gsmet commented Aug 13, 2024

Yeah, I have ported this rule from the existing code base.
It kinda makes sense because when you have a converter, you have no idea how it will convert things and if the hyphenated value is a valid input.

Now what I don't understand is why you had the previous behavior. I'll have a look later today.

@gsmet
Copy link
Member

gsmet commented Aug 13, 2024

https://github.com/quarkusio/quarkus/blob/3.13.2/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java#L232-L235

I think the only reason why it wasn't hyphenated is that when @ConfigMapping support was added, the @WithConvert annotation wasn't added at this place.

We are a lot more consistent now.

Not entirely sure what's best but really hyphenating when having a converter that is not the default is probably a bad idea.

Is there a reason why you have a converter here?

@ppalaga
Copy link
Contributor Author

ppalaga commented Aug 13, 2024

Is there a reason why you have a converter here?

Haha, yes, IIRC it's only because earlier it was not possible to persuade Quarkus not to hyphenate the enum values in the metadata so I had to introduce a way to map what users got in the docs to the real values.

Another detail that makes this case a bit harder is that the enum comes from CXF, so I cannot annotate it with @ConfigDocEnumValue.

It is only a single property on Quarkus CXF side having this issue (but I have not looked into Camel yet) and I actually agree not-hyphenating makes sense if there is @WithConverter.

It would be great to have a way to adjust the presented values somehow.

Maybe a new @ConfigDocEnumValues annotation like this?

    @WithDefault("Keep-Alive")
    @WithConverter(ConnectionTypeConverter.class)
    @ConfigDocEnumValues("KEEP_ALIVE:Keep-Alive,CLOSE:Close")
    public ConnectionType connection();

@gsmet
Copy link
Member

gsmet commented Aug 13, 2024

Maybe an annotation to force the hyphenation would be a bit more sustainable from a maintenance POV?

@ppalaga
Copy link
Contributor Author

ppalaga commented Aug 13, 2024

Maybe an annotation to force the hyphenation would be a bit more sustainable from a maintenance POV?

Yes, that would solve the current issue, but a general way to document accepted values (even for non-enums) would come in handy, wouldn't it?

How about this?

    @WithDefault("Keep-Alive")
    @WithConverter(ConnectionTypeConverter.class)
    @ConfigDocAcceptedValues({"Keep-Alive", "Close"})
    public ConnectionType connection();

@ppalaga
Copy link
Contributor Author

ppalaga commented Aug 13, 2024

I mean @ConfigDocAcceptedValues would be useful also for IDE content assist.

@ppalaga
Copy link
Contributor Author

ppalaga commented Aug 13, 2024

Anyway, if all the above is too complicated, given that I need this in just a single case, I can also workaround it by wrapping the CXF enum in a local one and use @ConfigDocEnumValue.

@ppalaga
Copy link
Contributor Author

ppalaga commented Aug 13, 2024

I can also workaround it by wrapping the CXF enum in a local one and use @ConfigDocEnumValue.

I did that right now and I'd be fine with closing this issue unless you see some value in handling this in a general manner?

@gsmet
Copy link
Member

gsmet commented Aug 13, 2024

@ConfigDocAcceptedValues({"Keep-Alive", "Close"}) is cute but I'm afraid it's going to be hard to maintain.

@ConfigDocEnumValues("KEEP_ALIVE:Keep-Alive,CLOSE:Close") is less cute but probably a bit more future-proof.
(whatever the name we give to it)

For now I think I would start with @ConfigDocEnum(hyphenateAcceptedValues = true) and see what we can come up with in the future.

@gsmet
Copy link
Member

gsmet commented Aug 13, 2024

I'm working on a patch.

gsmet added a commit to gsmet/quarkus that referenced this issue Aug 13, 2024
Also refactor things a bit to centralize the handling of the common
annotations.

Fixes quarkusio#42514
gsmet added a commit to gsmet/quarkus that referenced this issue Aug 13, 2024
Also refactor things a bit to centralize the handling of the common
annotations.

Fixes quarkusio#42514
@gsmet gsmet closed this as completed in c512e3d Aug 14, 2024
@quarkus-bot quarkus-bot bot added this to the 3.14 - main milestone Aug 14, 2024
danielsoro pushed a commit to danielsoro/quarkus that referenced this issue Sep 20, 2024
Also refactor things a bit to centralize the handling of the common
annotations.

Fixes quarkusio#42514
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants