swagger-api / swagger-api/swagger-codegen

[Go] Empty Struct Generated Which Should be a Typealias

Open
#10,089 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

swagger-codegen does not create a correct GO representation for a OpenAPI 3.0 Model (from a schema definition) which would be ideally generated as a Go typealias.

Swagger-codegen version

This is the current version used in website: 3.0.10 (current tag)
openapi: 3.0.0

Swagger declaration file content or url

The following yaml snippet (openapi: 3.0.0) shows how the model is defined in section components/schemas:

components:
  schemas:
   Uint32:
      minimum: 0
      type: integer
      format: int32

This is basically a type integer which has a special format Uint32.

Command line used for generation

The code generator has been invoked from the Export feature from the website:

https://jdegre.github.io/

GenerateServer -> GoServer

Expected :
Go:

type ModelUint32 uint32

Actual:

/*
 * Nchf_ConvergedCharging
 *
 * ConvergedCharging Service    © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved. 
 *
 * API version: 3.0.0.alpha-2
 * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
 */
package swagger

type ModelUint32 struct {
}

As you can see, this is an empty struct and can not be used in any way.

Steps to reproduce

Well, this would require to setup a basic swagger spec and include the schema in the components section, then generate the code.

Related issues/PRs

Suggest a fix/enhancement

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 GoServer generator entry point and the components/schemas handling described in the issue, using the provided OpenAPI 3.0 schema and generation steps as a reproduction. Compare the generated ModelUint32 output with the expected Go typealias and verify that scalar schemas no longer produce an empty struct.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.