OpenAPITools / OpenAPITools/openapi-generator
[BUG] Default values, min, max, etc. are missing from generated Go models for object properties
Nobody has claimed this yet.
- 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)?
- What's the version of OpenAPI Generator used? -> 4.2.1
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
I defined an API with an object property that has default values, minimum, maximum, etc. The generated Go code lacks this information completely.
openapi-generator version
4.2.1
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
title: Configuration API
contact:
name: Corporation
url: https://corporation.com
email: nobody@corporation.com
description: Manage configuration
version: v2
servers:
- url: http://config/
paths:
/system/whatever:
get:
summary: Get whatever configuration
description: Get whatever configuration
operationId: getConfigWhatever
tags:
- system
responses:
200:
description: The current whatever configuration
content:
application/json:
schema:
$ref: '#/components/schemas/WhateverConfig'
default:
description: Unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
put:
summary: Set whatever configuration
description: Set whatever configuration
operationId: setConfigWhatever
tags:
- system
requestBody:
description: Whatever configuration to set
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/WhateverConfig'
responses:
200:
description: The whatever configuration was set
400:
description: Invalid swhatever configuration was specified
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
500:
description: Unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
delete:
summary: Delete the whatever configuration
description: Delete the whatever configuration and revert to defaults
operationId: deleteConfigWhatever
tags:
- system
responses:
200:
description: The whatever configuration was deleted
default:
description: Unexpected error
content:
application/json:
schema:
$ref: '#/components/schemas/APIError'
components:
schemas:
APIError:
description: An error has occurred
type: object
properties:
code:
type: integer
format: int32
message:
type: string
WhateverConfig:
title: Whatever Configuration
description: Whatever configuration
type: object
properties:
OutputDirectory:
type: string
title: Output directory
description: Output directory
default: "/var/log/whatever"
BooleanFalse:
type: boolean
title: A boolean property with default false
description: A boolean property with default false
default: false
BooleanTrue:
type: boolean
title: A boolean property with default true
description: A boolean property with default true
default: true
Integer13:
type: integer
title: An integer property with default 13, min 1, max 1000
description: An integer property with default 13, min 1, max 1000
default: 13
minimum: 1
maximum: 1000
Command line used for generation
java -jar openapi-generator-cli.jar generate -i example.yaml -o example-gen -g go
Steps to reproduce
Execute the above command. Search the generated code for default values, minimum, maximum, etc. In example-gen/model_whatever_config.go, find:
// WhateverConfig Whatever configuration
type WhateverConfig struct {
// Output directory
OutputDirectory string `json:"OutputDirectory,omitempty"`
// A boolean property with default false
BooleanFalse bool `json:"BooleanFalse,omitempty"`
// A boolean property with default true
BooleanTrue bool `json:"BooleanTrue,omitempty"`
// An integer property with default 13, min 1, max 1000
Integer13 int32 `json:"Integer13,omitempty"`
}
But no mention of the default values, minimum, maximum, etc. for any property.
Related issues/PRs
Suggest a fix
Not sure if this is a fix or a feature request. I don't understand why this information is missing from the generated Go code.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied example.yaml and run the documented openapi-generator-cli command using the go generator. Inspect example-gen/model_whatever_config.go and compare the generated WhateverConfig fields with the schema's default, minimum, and maximum values. Done means the generated Go model represents the reported property metadata, with generation output demonstrating the expected values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- backend-api-design, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100