Skip to content

Strict interface with reserved Go keywords as property yield invalid generated code #993

@reinkrul

Description

@reinkrul

When generating a strict (Echo) interface for an API that contains properties that are reserved Go keywords, the generated code is invalid.

YAML spec:

openapi: 3.0.0

info:
  title: api
  description: sample api
  version: "0.0.0"

paths:
  /endpoint/{type}:
    get:
      parameters:
        - in: path
          name: type
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: string

YAML config:

package: pr
generate:
  echo-server: true
  models: true
  strict-server: true

Generated code:

type GetEndpointTypeRequestObject struct {
	Type string `json:"type"`
}

func (sh *strictHandler) GetEndpointType(ctx echo.Context, pType string) error {
	var request GetEndpointTypeRequestObject

	request.PType = pType // compilation error, should've been request.Type = pType
	// etc
}

(see https://github.com/reinkrul/oapi-codegen/tree/reserved-keywords-bug/pr)

Probably related to #30

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