Bug Report Checklist
Description
Given the following schema in OpenAPI the generator does not actually generate a map with nullable values.
LabelPatch:
type: object
description: "Object that represents the labels of an object."
additionalProperties:
type: string
nullable: true
example:
foo: "bar"
- Actual behavior: It generates a field of type
*map[string]*string.
- Expected behavior: A field of type
*map[string]*string is generated.
openapi-generator version
I'm using v7.22.0, but the issue is also present on the latest main branch.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: Minimal Example API
version: 1.0.0
paths:
/resources/{id}:
patch:
summary: Update a resource
parameters:
- name: id
in: path
required: true
schema:
type: string
requestBody:
description: Payload to update resource attributes, including labels.
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ResourceUpdate'
responses:
'200':
description: Resource updated successfully
components:
schemas:
ResourceUpdate:
type: object
description: Payload for updating a resource.
properties:
description:
type: string
description: A new description for the resource.
labels:
$ref: '#/components/schemas/LabelPatch'
LabelPatch:
type: object
description: "Object that represents the labels of an object."
additionalProperties:
type: string
nullable: true
example:
foo: "bar"
Generation Details
- I'm using the Golang client generator
Steps to reproduce
# build openapi generator from source
./mvnw clean install
# generate go code
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate --generator-name go --input-spec openapi.yaml --output "output"
The generated code in output/model_resource_update.go looks like this:
// ResourceUpdate Payload for updating a resource.
type ResourceUpdate struct {
// A new description for the resource.
Description *string `json:"description,omitempty"`
// Object that represents the labels of an object.
Labels *map[string]string `json:"labels,omitempty"`
}
Related issues/PRs
Couldn't find any.
Suggest a fix
The generated code should look like this:
// ResourceUpdate Payload for updating a resource.
type ResourceUpdate struct {
// A new description for the resource.
Description *string `json:"description,omitempty"`
// Object that represents the labels of an object.
- Labels *map[string]string `json:"labels,omitempty"`
+ Labels *map[string]*string `json:"labels,omitempty"`
}
Can be done by adjusting the AbstractGoCodegen.getTypeDeclaration implementation. Will contribute it soon :)
Bug Report Checklist
Description
Given the following schema in OpenAPI the generator does not actually generate a map with nullable values.
*map[string]*string.*map[string]*stringis generated.openapi-generator version
I'm using v7.22.0, but the issue is also present on the latest main branch.
OpenAPI declaration file content or url
Generation Details
Steps to reproduce
The generated code in
output/model_resource_update.golooks like this:Related issues/PRs
Couldn't find any.
Suggest a fix
The generated code should look like this:
// ResourceUpdate Payload for updating a resource. type ResourceUpdate struct { // A new description for the resource. Description *string `json:"description,omitempty"` // Object that represents the labels of an object. - Labels *map[string]string `json:"labels,omitempty"` + Labels *map[string]*string `json:"labels,omitempty"` }Can be done by adjusting the AbstractGoCodegen.getTypeDeclaration implementation. Will contribute it soon :)