OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Go] Generate client with default object miss

Open
#18,012 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 generated code contains a syntax error due to a missing type in value initialization.

// NewForecastMetricsConfigInput instantiates a new ForecastMetricsConfigInput object
// This constructor will assign default values to properties that have it defined,
// and makes sure properties required by API are set, but the set of arguments
// will change when the set of required properties is changed
func NewForecastMetricsConfigInput(instanceId int32, name string, help string) *ForecastMetricsConfigInput {
	this := ForecastMetricsConfigInput{}
	this.InstanceId = instanceId
	this.Name = name
	var query string = ""
	this.Query = &query
	this.Help = help
	var builtin int32 = 1
	this.Builtin = &builtin
	var parameter MetricsParameterInput = {"rolling_training_window_size":7,"predict_days":7,"up_limit":0,"down_limit":0,"prophet_parameter":{"changepoint_prior_scale":0.05,"changepoint_range":0.8,"daily_seasonality":4,"growth":"linear","seasonality_mode":"multiplicative","seasonality_prior_scale":10.0,"weekly_seasonality":4}}
	this.Parameter = &parameter
	var inuse bool = true
	this.Inuse = &inuse
	var state MetricStateType = TO_TRAINING
	this.State = &state
	var version int32 = 0
	this.Version = &version
	return &this
}
openapi-generator version

7.2.0

OpenAPI declaration file content or url

openapi.json

Generation Details
openapi-generator-cli generate --additional-properties useOneOfDiscriminatorLookup  -p generateInterfaces=true  -i openapi.json -g go -o ./forecastclientgo --package-name forecastclientgo --git-host yunqutech.gitlab.com --git-repo-id forecastclientgo --git-user-id agilex
Steps to reproduce

Try to use and compile the code. It will fail.

Related issues/PRs
Suggest a fix

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 by running the provided openapi-generator-cli command with openapi.json and inspect the generated ForecastMetricsConfigInput constructor, especially the default object initialization. Trace that output into the Go generator entry point or template responsible for default values, then verify that the generated client compiles without the missing type syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.