OpenAPITools / OpenAPITools/openapi-generator

[BUG][rust-server] date-time format generates invalid syntax

Open
#10,304 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

The rust-server generates a client example with invalid syntax when input is a date-time format.
In this case, the input type is chrono::DateTime::<chrono::Utc> but the example just puts a literal date-time in the function call:

let result = rt.block_on(client.set_pickup(
      2013-10-20T19:20:30+01:00
));

This is obviously not valid Rust code.

openapi-generator version

I tried the latest stable and two snapshots:

  1. 5.3.0-20210831.135320
  2. 6.0.0-20210901.065940
OpenAPI declaration file content
openapi: "3.0.0"
info:
  version: 1.0.0
  title: example
paths:
  /pickup:
    get:
      operationId: setPickup
      parameters:
        - name: when
          in: query
          required: true
          schema:
            type: string
            format: date-time # <- here is the problem
      responses:
        200:
          description: ok
Generation Details
java -jar ../openapi-generator-cli.jar generate -g rust-server -i exampledate.yaml -o example-server
Steps to reproduce
  1. Use the YAML above (I called it exampledate.yaml) and generate the code with the details above.
  2. Try building with cargo build --example client

The result is a confused compiler:

error: invalid suffix `T19` for number literal
  --> examples\client\main.rs:76:27
   |
76 |                   2013-10-20T19:20:30+01:00
   |                           ^^^^^ invalid suffix `T19`
   |
   = help: the suffix must be one of the numeric types (`u32`, `isize`, `f32`, etc.)

error: expected type, found `20`
  --> examples\client\main.rs:76:33
   |
76 |                   2013-10-20T19:20:30+01:00
   |                                -^^ expected type
   |                                |
   |                                tried to parse a type due to this

error: aborting due to 2 previous errors

error: could not compile `openapi_client`

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 with the rust-server generator output produced from the YAML example and the generated examples/client/main.rs entry point. Run the documented openapi-generator command, then cargo build --example client to reproduce the invalid date-time literal. Done means the generated client example compiles for a string parameter with format: date-time.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.