OpenAPITools / OpenAPITools/openapi-generator

[BUG][GO] Syntactically wrong client code generated when uses one of taking param and list of param

Open
#8,765 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Go 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

Model generated for schema which takes one of object and array of object, does not compile. []Link in below code is not valid variable name.

// Link struct for Link
type Link struct {
        Href *string `json:"href,omitempty"`
}

// LinksValueSchema - struct for LinksValueSchema
type LinksValueSchema struct {
        Link *Link
        []Link *[]Link
}

openapi-generator version

3.0

OpenAPI declaration file content or url
openapi: 3.0.0

info:
  version: '1.1.2'
  title: 'Test Service'
  description: |
    Test Service.

servers:
  - url: '{apiRoot}/nfm/v1'
    variables:
      apiRoot:
        default: https://example.com

paths:
  /nf-instances:
    get:
      summary: Retrieves a collection of Instances
      operationId: GetInstances
      tags:
        - Instances (Store)
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time
          required: false
          schema:
            type: integer
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/3gppHal+json:
              schema:
                type: object
                properties:
                  _links:
                    type: object
                    description: 'List of the URI of instances. It has two members whose names are item and self.
                    additionalProperties:
                      $ref: '#/components/schemas/LinksValueSchema'
                minProperties: 1

components:
  schemas:
    Link:
      type: object
      properties:
        href:
          type: string
    LinksValueSchema:
      oneOf:
        - type: array
          items:
            $ref: '#/components/schemas/Link'
          minItems: 1
        - $ref: '#/components/schemas/Link'
Generation Details
Steps to reproduce

~/bin/openapitools/openapi-generator-cli generate -g go -o ~/test_dir/ -i test.yaml

Related issues/PRs
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

Run the provided openapi-generator CLI command with the supplied OpenAPI YAML and inspect the generated Go model for LinksValueSchema. Trace how the oneOf object and array schemas become field names, then verify that the generated client compiles and no invalid []Link identifier remains.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.