OpenAPITools / OpenAPITools/openapi-generator

[BUG] [scala-akka-http-server] Datetime query parameters are mapped to String instead of OffsetDateTime

Open
#20,262 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating code with scala-akka-http-server, a query parameter with type=string and format=date-time is mapped to a Scala String instead of OffsetDateTime.

openapi-generator version

7.10.0

OpenAPI declaration file content or url

Example query parameter definition:

- name: createdFrom
  in: query
  description: "Only return `Files` that were created after this date and time, expressed in ISO 8601 format."
  required: false
  schema:
    type: string
    format: date-time
Generation Details
openapi-generator generate -g scala-akka-http-server -i https://api.swaggerhub.com/apis/pagero-api/file-api/1.1.0/swagger.yaml\?resolved\=true -o out
Steps to reproduce

The generated file out/src/main/scala/org/openapitools/server/api/FileApi.scala contains the following:

    path("files") { 
      get { 
        parameters("companyId".as[String].?, "sendMode".as[String].?, "documentType".as[String].?, "senderReference".as[String].?, "createdFrom".as[String].?, "createdTo".as[String].?, "expand".as[String].?, "offset".as[Int].?(0), "limit".as[Int].?(10)) { (companyId, sendMode, documentType, senderReference, createdFrom, createdTo, expand, offset, limit) => 
            fileService.filesGet(companyId = companyId, sendMode = sendMode, documentType = documentType, senderReference = senderReference, createdFrom = createdFrom, createdTo = createdTo, expand = expand, offset = offset, limit = limit)
        }
      }
    } ~

In the code above, the query parameters createdFrom and createdTo should have the type OffsetDateTime.

Related issues/PRs

None found

Suggest a fix

The reason seems to be that in ScalaAkkaHttpServerCodegen.java->fromParameter (Line 294), param.dataType is always set to String for all non-primitive parameter types.

I'm new to openapi-generator so I can't really tell whether this is "by design". Perhaps since scala-akka-http-server is still in Beta, support for non-primitive data types in query parameters may not yet have been added?

Perhaps @Bouillie or @chameleon82 who seem to have been involved with creating this generator could shed some light on this? I'd be happy to contribute but would need some pointers on where to start in implementing this.

I'm also wondering what the current status of the scala-akka-http-server generator is. It seems to have been in beta for a while now.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ScalaAkkaHttpServerCodegen.java at fromParameter, identified around line 294, and reproduce the issue with the supplied scala-akka-http-server generation command. Verify that the createdFrom and createdTo query parameters in FileApi.scala are generated as OffsetDateTime rather than String.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, scala
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.