Skip to content

Generated client not compiled when x-go-name is specified #2892

@asv

Description

@asv

Problem statement

When using abbreviations (in my case PDF) and x-go-name, non-compiled code is generated.

Example: a parameter named pdf_extraction_mode (translated to a literal PdfExtractionMode) and its x-go-name PDFExtractionMode.

The code in the *Params structure is generated correctly (the name is the same as in x-go-name), however, in the generated SetDefaults code, the PdfExtractionMode literal is substituted, which breaks the compilation.

$ go build ./client/                                                                    
client/operations/extract_pdf_parameters.go:94:3: unknown field 'PdfExtractionMode' in struct literal of type ExtractPdfParams

Swagger specification

swagger: "2.0"
info:
  title: Sample API
  description: API description in Markdown.
  version: 1.0.0
host: api.example.com
basePath: /v1
schemes:
  - https
paths:
  /pdf:
    get:
      operationId: ExtractPdf
      parameters:
        - name: pdf_extraction_mode
          type: string
          enum:
            - fast
            - full
          x-go-name: PDFExtractionMode
          default: fast
          description: Lorem ipsum
          in: formData
      responses:
        200:
          description: OK

Steps to reproduce

  1. swagger generate client -q -A buggygen --spec example.yaml
  2. trying to build this code (go build ./client)

Environment

swagger version: 0.30.3
go version: 1.19
OS: MacOS Catalina

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions