Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #10836
Closed
Open
Issue created Nov 11, 2021 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

Go Generator Incorrectly handles string with decimal format

Created by: zhangbanger

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 handling properties with

type: string
format: decimal

the golang generator incorrectly assumes a JSON float/numeric type. This causes an Unmarshall error when encountering a string in the API response.

openapi-generator version

5.3.0

OpenAPI declaration file content or url

https://raw.githubusercontent.com/alpacahq/bkdocs/564d49f52bc91bb180b15b2b900253a1e7c53846/assets/openapi.yaml

Generation Details
Steps to reproduce

Start a new golang project in go 1.16 or higher. Run go mod init in the project Create a folder for the openapi package and cd to the folder Run

openapi-generator-cli generate -g go -i https://raw.githubusercontent.com/alpacahq/bkdocs/564d49f52bc91bb180b15b2b900253a1e7c53846/assets/openapi.yaml -o .

Then go mod tidy

IF you have an Alpaca Broker account, then you can reproduce this fully. Otherwise, here is what happens:

You make an API call that would return fields annotated as above. You will get an Unmarshall error because you are attempting to Unmarshall a string into a float64.

One thing to note - generating for akka-scala seems to build in the correct conversions. BigDecimal is used, but it correctly parses a string response from the API.

Related issues/PRs

Could not find anything.

Suggest a fix

Fixing the struct tag should do the trick -

from

DollarBills float64 `json:"dollarBills"` 

to

DollarBills float64 `json:"dollarBills,string"` 

Can this be modified in the template or generator logic?

Assignee
Assign to
Time tracking