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] Patterned fields cause compile errors #7473

Open
5 of 6 tasks
aschmahmann opened this issue Sep 21, 2020 · 4 comments
Open
5 of 6 tasks

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

aschmahmann opened this issue Sep 21, 2020 · 4 comments

Comments

@aschmahmann
Copy link

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

auto-labeler bot commented Sep 21, 2020

👍 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.

@lidel
Copy link

lidel commented Sep 22, 2020

Seems that this problem was bothering community for a while: #199, #6829, #5397, #5812, #5812, #1455

Good news is that there is a potential fix in #7381

@philippthiele
Copy link

@lidel the linked PR was closed and the replacement PR did not seem to fix the issue unfortunately: #9046

@dahu33
Copy link

dahu33 commented Oct 22, 2021

Any update on this? Is it blocked by another issue or is it waiting for someone to fix the template?

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

4 participants