Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
4 of 6 tasks
DYukun opened this issue Feb 28, 2023 · 0 comments

Comments

@DYukun
Copy link

DYukun commented Feb 28, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant