springdoc-openapi icon indicating copy to clipboard operation
springdoc-openapi copied to clipboard

JavaDoc integration not working with SnakeCaseStrategy property naming

Open joarobles opened this issue 1 year ago • 3 comments

Describe the bug

When trying to generate Schema description from JavaDoc comments, it's not working as expected for fields that not match exactly with their JSON representation (camelCase to snake_case for example).

To Reproduce Steps to reproduce the behavior:

  • What version of spring-boot you are using? spring-boot: 3.2.1

  • What modules and versions of springdoc-openapi are you using? springdoc-openapi-starter-webmvc-ui: 2.3.0 therapi-runtime-javadoc: 0.15.0

  • What is the actual and the expected result using OpenAPI Description (yml or json)?

Actual:

{
    "SearchRequest": {
        "required": [
            "org_id",
            "organization_id"
        ],
        "type": "object",
        "properties": {
            "organization_id": {
                "type": "integer",
                "format": "int64"
            },
            "org_id": {
                "type": "integer",
                "description": "All search requests must specify an Organization to filter the results by (exact match). I.e.: <code>1234</code>",
                "format": "int64"
            }
        }
    }
}

Expected:

{
    "SearchRequest": {
        "required": [
            "org_id",
            "organization_id"
        ],
        "type": "object",
        "properties": {
            "organization_id": {
                "type": "integer",
                "description": "All search requests must specify an Organization to filter the results by (exact match). I.e.: <code>1234</code>",
                "format": "int64"
            },
            "org_id": {
                "type": "integer",
                "description": "All search requests must specify an Organization to filter the results by (exact match). I.e.: <code>1234</code>",
                "format": "int64"
            }
        }
    }
}
  • Provide with a sample code (HelloController) or Test that reproduces the problem
@Data
@Builder
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class SearchRequest {

  /**
   * All search requests must specify an Organization to filter the results by (exact match)
   * I.e.: <code>1234</code>
   */
  private @NotNull final Long organizationId;

  @Schema(description = "All search requests must specify an Organization to filter the results by (exact match). I.e.: <code>1234</code>")
  private @NotNull final Long orgId;

}

Expected behavior

  • A clear and concise description of what you expected to happen. I'd expect all fields to have the same schema description in the generated json.

  • What is the expected result using OpenAPI Description (yml or json)? I'd expect all fields to have the same schema description in the generated json.

Screenshots If applicable, add screenshots to help explain your problem. N/A

Additional context Add any other context about the problem here.

joarobles avatar Jan 15 '24 18:01 joarobles

It works well. I'm using these dependencies

		<!-- Springdoc -->
		<dependency>
			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
			<version>${springdoc.version}</version>
		</dependency>

		<dependency>
			<groupId>com.github.therapi</groupId>
			<artifactId>therapi-runtime-javadoc-scribe</artifactId>
			<version>0.15.0</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>com.github.therapi</groupId>
			<artifactId>therapi-runtime-javadoc</artifactId>
			<version>0.15.0</version>
		</dependency>

The output is here 图片

Heromyth avatar Jan 19 '24 04:01 Heromyth

However, there is a NullPointerException:

java.lang.NullPointerException: Cannot invoke "java.lang.reflect.Method.getDeclaringClass()" because "method" is null
	at com.github.therapi.runtimejavadoc.RuntimeJavadoc.getJavadoc(RuntimeJavadoc.java:165)
	at com.github.therapi.runtimejavadoc.RuntimeJavadoc.getJavadoc(RuntimeJavadoc.java:161)
	at org.springdoc.core.providers.SpringDocJavadocProvider.getMethodJavadocDescription(SpringDocJavadocProvider.java:90)
	at org.springdoc.core.customizers.JavadocPropertyCustomizer.lambda$setJavadocDescription$6(JavadocPropertyCustomizer.java:169)
	at java.base/java.util.Optional.ifPresent(Optional.java:178)
	at org.springdoc.core.customizers.JavadocPropertyCustomizer.lambda$setJavadocDescription$7(JavadocPropertyCustomizer.java:168)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at org.springdoc.core.customizers.JavadocPropertyCustomizer.setJavadocDescription(JavadocPropertyCustomizer.java:159)
	at org.springdoc.core.customizers.JavadocPropertyCustomizer.resolve(JavadocPropertyCustomizer.java:109)
	at org.springdoc.core.converters.PageableOpenAPIConverter.resolve(PageableOpenAPIConverter.java:93)
	at org.springdoc.core.converters.SortOpenAPIConverter.resolve(SortOpenAPIConverter.java:83)
	at io.swagger.v3.core.converter.ModelConverterContextImpl.resolve(ModelConverterContextImpl.java:97)
	at io.swagger.v3.core.jackson.ModelResolver.resolve(ModelResolver.java:477)
	at org.springdoc.core.converters.WebFluxSupportConverter.resolve(WebFluxSupportConverter.java:86)
	at org.springdoc.core.converters.AdditionalModelsConverter.resolve(AdditionalModelsConverter.java:155)
	at org.springdoc.core.converters.FileSupportConverter.resolve(FileSupportConverter.java:69)

Heromyth avatar Jan 19 '24 04:01 Heromyth

It works well. I'm using these dependencies

		<!-- Springdoc -->
		<dependency>
			<groupId>org.springdoc</groupId>
			<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
			<version>${springdoc.version}</version>
		</dependency>

		<dependency>
			<groupId>com.github.therapi</groupId>
			<artifactId>therapi-runtime-javadoc-scribe</artifactId>
			<version>0.15.0</version>
			<scope>provided</scope>
		</dependency>

		<dependency>
			<groupId>com.github.therapi</groupId>
			<artifactId>therapi-runtime-javadoc</artifactId>
			<version>0.15.0</version>
		</dependency>

The output is here 图片

But as far as I can see you are not using SnakeCaseStrategy, your attributes are all in camel case.

joarobles avatar Jan 22 '24 11:01 joarobles