Closed rtomyj closed 1 month ago
Quick note. If I reference the schema from an annotation (IE @Schema) the reference works with above code and annotation.
I removed .components(components())
, then it works well.it's a bug.
@rtomyj.
Add springdoc.remove-broken-reference-definitions=false
Describe the bug
Referencing Schemas results in error EG
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
/**
Configuration class for Swagger UI */ @Configuration class SwaggerConfig { /**
private fun components() = Components() // schemas .addSchemas("locale", Schema().type("string")
.example("en"))
.addSchemas("productID",
Schema().type("string")
.example("LOB"))
.addSchemas("skcErrorMessage", Schema().type("string")
.description("Error message"))
.addSchemas("skcErrorCode", Schema().type("string")
.description("Error code"))
// responses
.addResponses("badRequest", ApiResponse()
.description("Malformed request. Make sure request is valid JSON and data is using correct data types.")
.content(Content().addMediaType(APPLICATION_JSON_VALUE,
MediaType().schema(skcErrorSchema(SKCError(message = "Bad Request", code = "XXX"))))))
.addResponses("notFound", ApiResponse()
.description("No resource found for requested item.")
.content(Content().addMediaType(APPLICATION_JSON_VALUE,
MediaType()
.schema(skcErrorSchema(SKCError(message = "Requested resource was not found", code = "DB001"))))))
.addResponses("unprocessableEntity", ApiResponse()
.description("Request is using data that is wrong - for example using a card ID with 7 digits instead of 8.")
.content(Content().addMediaType(APPLICATION_JSON_VALUE,
MediaType()
.schema(skcErrorSchema(SKCError(message = "URL parameter, URL path parameter or data in body is not valid", code = "G001"))))))
.addResponses("internalServerError", ApiResponse()
.description("Server encountered an exception.")
.content(Content().addMediaType(APPLICATION_JSON_VALUE,
MediaType()
.schema(skcErrorSchema(SKCError(message = "Error occurred calling service", code = "DS001"))))))
// parameters
.addParameters("locale", Parameter()
.description("A locale denoting a geographical region. As of now the only locale available is \"en\" but in the future other locales can be added to support releases in other regions like Japan.")
.name("locale")
.required(true)
.().().
in
("path") .schema(Schema$ref
("locale"))) .addParameters("productID", Parameter() .description("Unique identifier each Yu-Gi-Oh! product has. It is the 3 or 4 alpha numeric string found on every card.") .name("productId") .required(true) .in
("path") .schema(Schema$ref
("productID")))private fun skcErrorSchema(example: SKCError) = Schema()
.type("object")
.description("Error response")
.properties(mapOf("message" to Schema().().
$ref
("skcErrorMessage"), "code" to Schema$ref
("skcErrorCode"))) .example(example) }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