Skip to content

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

@DYukun

Description

@DYukun

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions