OpenAPITools / OpenAPITools/openapi-generator

[BUG] [GO] Empty Struct generated for top-level "additionalProperties" when "generateAliasAsModel=true"

Open
#14,829 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

In go generator, empty Struct generated for top-level "additionalProperties" when "generateAliasAsModel=true".

openapi-generator version

tested 5.3.1, 6.4.0

OpenAPI declaration file content or url
swagger: '2.0'
info:
  title: Harbor API
  description: These APIs provide services for manipulating Harbor project.
  version: '2.0'
host: localhost
schemes:
  - http
  - https
basePath: /api/v2.0
produces:
  - application/json
consumes:
  - application/json
securityDefinitions:
  basic:
    type: basic
security:
  - basic: []
  - {}
paths:
  /health:
    get:
      summary: Check the status of Harbor components
      description: Check the status of Harbor components
      tags:
        - health
      operationId: getHealth
      parameters:
      responses:
        '200':
          description: The health status of Harbor components
          schema:
            $ref: '#/definitions/Annotations'
definitions:
  Annotations:
    type: object
    additionalProperties:
      type: string
Generation Details

swagger yaml contains a top level object with additionalProperties(in this case, Annotations). For generation argument, generateAliasAsModel is set to true to make it an individual model.

Expected to get the model with a map field for the additionalProperties. However, an empty struct is generated.

example code generated:

/*
Harbor API

These APIs provide services for manipulating Harbor project.

API version: 2.0
*/

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.

package openapi

import (
	"encoding/json"
)

// checks if the Annotations type satisfies the MappedNullable interface at compile time
var _ MappedNullable = &Annotations{}

// Annotations struct for Annotations
type Annotations struct {
}

// Code below has been omitted
// ...
Steps to reproduce
openapi-generator-cli generate -i ./swagger_tmp.yaml -g go --generate-alias-as-model -o ./tmp_client
Related issues/PRs

#391, #1296, #1729

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 with the swagger_tmp.yaml reproduction and run the documented openapi-generator-cli command using the Go generator and --generate-alias-as-model. Trace how the top-level Annotations schema is handled, then verify that generated Annotations contains a map field for additionalProperties rather than an empty struct.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.