Skip to content

ScalaObjectMapper for the endpoint '/swagger.json` should use lowerCamelCase Strategy #82

@ndy2

Description

@ndy2

Hi. I found there is a bug related to ScalaObjectMapper in DocsController

For below SwaggerModule with termsOfService and SecurityRequirement

object RealworldSwaggerModule extends SwaggerModule {

  @Singleton
  @Provides
  def openAPI: OpenAPI = {
    val openAPI = new OpenAPI()

    val info = new Info()
      .description("The Student / Course management API, this is a sample for swagger document generation")
      .version("1.0.1")
      .title("Student / Course Management API")
      .termsOfService("http://swagger.io/terms/")
      .contact(
        new Contact()
          .name("Swagger API Team")
          .url("http://swagger.io")
          .email("deukyun.nam@ahnlab.com")
      )
    openAPI
      .info(info)
      .addServersItem(new Server()
        .url("https://api.example.com/v1")
        .description("Production Server"))
      .components(
        new Components()
          .addSecuritySchemes(
            "sampleBasic",
            new SecurityScheme()
              .`type`(io.swagger.v3.oas.models.security.SecurityScheme.Type.HTTP)
              .scheme("basic")
          )
      )
      .addSecurityItem(new SecurityRequirement().addList("sampleBasic", "basic"))
  }
}

with sample Main code in below

class Realworld extends HttpServer {

  override val name: String                   = "SampleApp"

  override protected def modules: Seq[Module] = Seq(RealworldSwaggerModule)

  override def configureHttp(router: HttpRouter): Unit = {
    router
      .filter[CommonFilters]
      .add[DocsController]
      .add[SampleController]
  }
  override protected def disableAdminHttpServer: Boolean = true
  override protected def defaultHttpPort: String         = ":8080"
}

object RealworldMain extends Realworld

The Swagger UI does not shows Terms of Service & the Authorize button

image

because what DocsController use is a default ScalaObjectMapper which gives snake_case converted swagger.json in endpoint /swagger.json

image
image

They should be camelCased instead.


I found that by overriding default jackson module to use camel case by adding belows, it fixed

// for RealworldMain
override protected def jacksonModule: Module = RealworldObjectMapperModule

// add RealworldObjectMapperModule
object RealworldObjectMapperModule extends ScalaObjectMapperModule {
  override val propertyNamingStrategy: PropertyNamingStrategy = PropertyNamingStrategy.LOWER_CAMEL_CASE
}

image

But it is not applicable for some use cases. (for me it is enough!)


I think fixing DocsController's object mapper to lowerCamelCase strategy is quite reasonable solution for this problem
By the way, thank you for maintaining this great opensource with great usability.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions