Skip to content
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

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

Open
5 of 6 tasks
vikashsparky opened this issue Feb 19, 2021 · 2 comments

Comments

@vikashsparky
Copy link

vikashsparky commented Feb 19, 2021

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
@auto-labeler
Copy link

auto-labeler bot commented Feb 19, 2021

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

@willh99
Copy link

willh99 commented Apr 13, 2023

We are seeing this issue as well as other syntactically wrong generation for the Go client. Examples:

components:
  schemas: 
   TestModel:
      properties:
        prop1:
          additionalProperties:
            anyOf:
            - {}
            - $ref: '#/components/schemas/OtherModel'
          type: object
      title: TestModel
      type: object

Results in the following struct:

type TestModel struct {
	OtherModel *OtherModel
	interface{} *interface{}
}

And the following response:

  /v1/thing/{thing_id}/start:
    post:
     ...
     requestBody:
     ...
      responses:
        '200':
          content:
            application/json:
              schema:
                anyOf:
                - $ref: '#/components/schemas/StartResponse'
                - type: object

Results in the model:

type ResponseThingStartPost struct {
	StartResponse *StartResponse
	map[string]interface{} *map[string]interface{}
}

These all seem to be constrained to the model_anyof.mustache template which is adding types as field names:

// {{classname}} {{{description}}}{{^description}}struct for {{{classname}}}{{/description}}
type {{classname}} struct {
	{{#anyOf}}
	{{{.}}} *{{{.}}}
	{{/anyOf}}
}

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

2 participants