swagger-api / swagger-api/swagger-codegen

Error parsing time with format "Y-m-d H:i:s" in generated go client

Open
#11,950 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I'm using swagger-codegen to generate go docs from Laravel project.

When using the generated go client, I keep getting error parsing time "2022-10-11 10:29:16" as "2006-01-02T15:04:05Z07:00" when trying to fill the model after calling an API
313931130_656216879425024_8040270276904435990_n313278347_653761633051714_414523623287948515_n

In the initial project, the annotation set for this field is
* @OA\Property(property="purchase_date",type="string", format="date-time")

In the generated go client by swagger, the field is
PurchaseDate time.Time json:"purchase_date,omitempty"``

Swagger-codegen version

3.0.34

Swagger declaration file content or url

snippet from yaml file

PurchaseResource:
      title: purchase_resource
      properties:
        id:
          type: integer
        external_id:
          type: string
        purchase_date:
          type: string
          format: date-time
Command line used for generation

swagger-codegen generate -i api-docs.json -l go --api-package SubscriptionsClient -o ./client-go

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 generated Go model's PurchaseDate field and the swagger-codegen generate command, then trace how the YAML date-time schema becomes time.Time. Reproduce the failure using the shown timestamp; done means the generated client handles the documented value consistently or the required input format is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, laravel
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.