Skip to content

[BUG][GO] Patterned fields cause compile errors #7473

Open
@aschmahmann

Description

@aschmahmann

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

When using patterned fields https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#patterned-fields-1 for HTTP Status Codes such as 4XX we get a compile time error because the codegen spits out lines like localVarHTTPResponse.StatusCode == 4XX. This requires manually editing the codegen file in order to get things to compile.

openapi-generator version

5.0.0-beta2, although this is the case in 5.0.0-beta and 4.3.1 as well

OpenAPI declaration file content or url

https://github.com/ipfs/pinning-services-api-spec/blob/46f23fdea009244a49c12b586c06ef30c2ca982f/ipfs-pinning-service.yaml

(or alternatively, https://raw.githubusercontent.com/ipfs/pinning-services-api-spec/46f23fdea009244a49c12b586c06ef30c2ca982f/ipfs-pinning-service.yaml)

Generation Details
java -version
openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~20.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

java -jar openapi-generator-cli.jar generate -g go -i https://raw.githubusercontent.com/ipfs/pinning-services-api-spec/master/ipfs-pinning-service.yaml -o openapi
Steps to reproduce
go build
# github.com/GIT_USER_ID/GIT_REPO_ID
./api_pins.go:211:42: syntax error: unexpected XX, expecting {
./api_pins.go:221:42: syntax error: unexpected XX, expecting {
./api_pins.go:381:42: syntax error: unexpected XX, expecting {
./api_pins.go:391:42: syntax error: unexpected XX, expecting {
./api_pins.go:543:42: syntax error: unexpected XX, expecting {
./api_pins.go:553:42: syntax error: unexpected XX, expecting {
./api_pins.go:698:42: syntax error: unexpected XX, expecting {
./api_pins.go:708:42: syntax error: unexpected XX, expecting {
./api_pins.go:872:42: syntax error: unexpected XX, expecting {
./api_pins.go:882:42: syntax error: unexpected XX, expecting {
./api_pins.go:882:42: too many errors
Related issues/PRs
Suggest a fix
  1. Emit the same if statements we're already doing but put all the pattern matched ones at the end for if we haven't matched anything directly. Then order the patterns e.g. if statusCode >= 400 && statusCode < 410 .... if statusCode >= 410...
  2. Perhaps it's just my particular use case but I don't see any of the generated statusCode > 300 if statements doing anything particularly unique, perhaps just having all of the errors do the same thing would be sufficient here, but my understanding of the generator tools and OpenAPI spec creation is limited.

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