OpenAPITools / OpenAPITools/openapi-generator

[REQ] Improve description for missing required properties errors in Go Models

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

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Missing required properties error only returns the required property name which can be time consuming to find for large and complex specs.

for _, requiredProperty := range(requiredProperties) {
		if _, exists := allProperties[requiredProperty]; !exists {
			return fmt.Errorf("no value given for required property %v", requiredProperty)
		}
	}

Describe the solution you'd like

Including the class name in the error message would be very helpful by modifying the Go Model template model_simple.mustache

for _, requiredProperty := range(requiredProperties) {
		{{#useDefaultValuesForRequiredVars}}
		if value, exists := allProperties[requiredProperty]; !exists || value == "" {
			if _, ok := defaultValueFuncMap[requiredProperty]; ok {
				allProperties[requiredProperty] = defaultValueFuncMap[requiredProperty]()
				defaultValueApplied = true
			}
		}
		if value, exists := allProperties[requiredProperty]; !exists || value == ""{
		{{/useDefaultValuesForRequiredVars}}
		{{^useDefaultValuesForRequiredVars}}
		if _, exists := allProperties[requiredProperty]; !exists {
		{{/useDefaultValuesForRequiredVars}}
+			return fmt.Errorf("no value given for required property %v in {{ classname }}", requiredProperty)
-			return fmt.Errorf("no value given for required property %v", requiredProperty)
		}
	}

Describe alternatives you've considered

Additional context

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 modules/openapi-generator/src/main/resources/go/model_simple.mustache and inspect the required-property validation shown in the issue. Update the generated error wording so it includes the model class name, then verify that generated Go models report both the missing property and its class.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java
Domain
api, tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.