Skip to content

[BUG] [Go-server] invalid composite literal type string #17373

@Tomer-L

Description

@Tomer-L

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

Generating the following yaml spec you will get code that does not compile with the following errors:

Error 1: invalid composite literal type string

api_test_api.go on line 63

bodyParam := string{}

Expected code ->

bodyParam := ""

Error 2: "github.com/gorilla/mux" imported and not used

Second compilation error is on file api_test_api.go line 17
There are at least 3 open issues:
#8847
#5153
#11097

openapi-generator version

latest stable 7.1.0

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: test
  description: API specification
  version: 1.0.0
servers:
  - url: /api/v1
paths:
  /collection/test:
    post:
      summary: POST a test batch
      operationId: postTest
      tags:
        - test api
      requestBody:
        $ref: '#/components/requestBodies/TestBody'
      responses:
        '200':
          $ref: '#/components/responses/SuccessfulOp'

components:
  responses:
    SuccessfulOp:
      description: Successful Operation
      content:
        application/json:
          schema:
            type: bool

  requestBodies:
    TestBody:
      description: Test body
      required: true
      content:
        text/plain:
          schema:
            type: string
            format: byte
Generation Details

I used the following command:

java -jar  generate --additional-properties=packageName=test,sourceFolder=test -i collection_test.yaml -g go-server
Steps to reproduce
  1. copy yaml content into a new file
  2. generate using -i file_name.yaml -g go-server
Related issues/PRs

Could not find issues related to "invalid composite literal type string" error

Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions