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

JavaDoc integration not working with SnakeCaseStrategy property naming #2484

Closed
joarobles opened this issue Jan 15, 2024 · 3 comments
Closed

Comments

@joarobles
Copy link

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.

@Heromyth
Copy link

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
Copy link

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)

@joarobles
Copy link
Author

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.

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

No branches or pull requests

2 participants