OpenAPITools / OpenAPITools/openapi-generator

[BUG][GO] Wrong interface type in generated client model when using oneof

Open
#8,769 1 comment 4 reactions 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

With certain kind of schema having oneOf with required field, the model generated for client does not have proper syntax for interface

type NFProfile struct {
        interface{} *interface{}
}
openapi-generator version

3.0.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:
  /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:
                  profile:
                    $ref: '#/components/schemas/NFProfile'
                minProperties: 1

components:
  schemas:
    NFProfile:
      description: Information of an NF Instance discovered by the NRF
      type: object
      required:
        - nfInstanceId
      anyOf:
        - required: [ fqdn ]
        - required: [ ipv4Addresses ]
        - required: [ ipv6Addresses ]
      properties:
        nfInstanceId:
          type: string
        nfInstanceName:
          type: string
        fqdn:
          type: string
        ipv4Addresses:
          type: string
        ipv6Addresses:
          type: string

Generation Details

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

Steps to reproduce

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

Related issues/PRs
Suggest a fix

Should had generated something like

type NFProfile struct {
        nfProfile *interface{}
}

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 OpenAPI declaration's NFProfile schema and reproduce the issue using the provided openapi-generator-cli command with the go generator. Trace how the oneOf/anyOf requirements are rendered in the generated NFProfile model; done means the generated interface field has valid Go syntax and the expected name and type.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.