springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.29k stars 499 forks source link

Swagger ui syntax highlighting configuration properties do not autocomplete #948

Closed AlexFalappa closed 3 years ago

AlexFalappa commented 3 years ago

While editing an application.properties file in an IDE I noticed that springdoc.swagger-ui.syntax gets completed into springdoc.swagger-ui.syntax-highlight but this is not enough it should propose springdoc.swagger-ui.syntax-highlight.theme and springdoc.swagger-ui.syntax-highlight.activate.

Infact the configuration properties metadata extracted by Spring Boot configuration processor is incomplete. I checked META-INF/spring-configuration-metadata.json in springdoc-openapi-common-1.5.0.jar and it contains only:

...
    {
      "name": "springdoc.swagger-ui.syntax-highlight",
      "type": "org.springdoc.core.AbstractSwaggerUiConfigProperties$SyntaxHighlight",
      "description": "The Syntax highlight.",
      "sourceType": "org.springdoc.core.SwaggerUiConfigProperties"
    },
...

The configuration properties class org.springdoc.core.AbstractSwaggerUiConfigProperties seems correct and the configuration processor should extract the metadata from org.springdoc.core.AbstractSwaggerUiConfigProperties$SyntaxHighlight inner class.

It would be useful to see why configuration metadata for the inner SyntaxHighlight class is not extracted.

AlexFalappa commented 3 years ago

Having a look at Spring Boot documentation on typesafe configuration properties I might suggest to try in AbstractSwaggerUiConfigProperties class:

protected final SyntaxHighlight syntaxHighlight = new SyntaxHighlight() ;

instead of

protected SyntaxHighlight syntaxHighlight;

and to remove the setter public void setSyntaxHighlight(SyntaxHighlight syntaxHighlight).

Maybe the processor navigates the oject hierarchy only if they are instanced.

AlexFalappa commented 3 years ago

Made a quick PR #949 for you to try.

Made trough GitHub web interface, did not build the project myself.

AlexFalappa commented 3 years ago

Noticed that the Csrf object in SwaggerUiConfigProperties is indeed instantiated and the csrf subproperties correctly extracted by the spring configuration processor.

You may want to apply the same pattern there too, that is private final Csrf csrf= new Csrf() and no setter public void setCsrf(Csrf csrf): it makes more clear that the inner object is fixed and only its properties are intended to be modified.