springdoc / springdoc-openapi

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

Referencing Schema from Parameter Gives Error: Could not resolve reference: Could not resolve pointer #2735

Closed rtomyj closed 1 month ago

rtomyj commented 1 month ago

Describe the bug

Referencing Schemas results in error EG

Could not resolve reference: Could not resolve pointer: /components/schemas/skcErrorMessage does not exist in document

This is when using schema in a parameter and referencing the parameter in Annotation/Controller

To Reproduce Steps to reproduce the behavior:

import com.rtomyj.skc.exception.SKCError import com.rtomyj.skc.util.constant.AppConstants import io.swagger.v3.oas.models.Components import io.swagger.v3.oas.models.ExternalDocumentation import io.swagger.v3.oas.models.OpenAPI import io.swagger.v3.oas.models.info.Info import io.swagger.v3.oas.models.info.License import io.swagger.v3.oas.models.media.Content import io.swagger.v3.oas.models.media.MediaType import io.swagger.v3.oas.models.media.Schema import io.swagger.v3.oas.models.parameters.Parameter import io.swagger.v3.oas.models.responses.ApiResponse import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration import org.springframework.http.MediaType.APPLICATION_JSON_VALUE

/**

// referencing parameter from controller - this works but the schema referenced by parameter does not
@ApiResponse(responseCode = "400", ref = "badRequest")
@ApiResponse(responseCode = "404", ref = "notFound")
@ApiResponse(responseCode = "422", ref = "unprocessableEntity")

Expected behavior

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

Additional context Add any other context about the problem here.

I am using Kotlin, not Java to write the API

rtomyj commented 1 month ago

Quick note. If I reference the schema from an annotation (IE @Schema) the reference works with above code and annotation.

suningnet commented 1 month ago

I removed .components(components()), then it works well.it's a bug.

bnasslahsen commented 1 month ago

@rtomyj.

Add springdoc.remove-broken-reference-definitions=false