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] Enums generate invalid code if - (hyphen minus ) or + (plus sign) are possible values #444

Closed
vipw opened this issue Aug 8, 2022 · 3 comments · Fixed by #447
Closed
Assignees
Labels
bug Something isn't working Triage needed

Comments

@vipw
Copy link
Contributor

vipw commented Aug 8, 2022

Describe the bug
A json schema enumerated string type that has "-" as a possible value generates invalid code.

Generated code looks like this:

enum OrderStatus {
	@JsonValue('swaggerGeneratedUnknown')
  swaggerGeneratedUnknown,
	@JsonValue('placed')
	placed,
	@JsonValue('approved')
	approved,
	@JsonValue('+')
	,
	@JsonValue('-')
	$
}


	const $OrderStatusMap = {
		OrderStatus.placed: 'placed',
	OrderStatus.approved: 'approved',
	OrderStatus.: '+',
	OrderStatus.$: '-'
      };

To Reproduce
This can be easily reproduced by changing the petstore example: definitions->order->status:

        "status": {
          "type": "string",
          "description": "Order Status",
          "enum": [
            "placed",
            "approved",
            "delivered",
            "-",
            "+"
          ]
        },

Expected behavior
I think the variable names in the generated enum would be hard to be meaningful, but perhaps the unicode codepoints could be used: U002D for minus-hyphen and U002B for plus sign.

Swagger specification link
https://gist.github.com/vipw/afcbd1afb71217b39875a9b88f5096cf

Library version used:
master

Additional context
I assume there are many other symbols that can't be naively mapped to dart variable names, despite being valid json strings.

@vipw vipw added bug Something isn't working Triage needed labels Aug 8, 2022
@Vovanella95
Copy link
Collaborator

Hi @vipw , thanks for raising issue. Will take a look into it this week.

@Vovanella95
Copy link
Collaborator

@liemvu you can share it using private channel. vovanella95@mail.ru

@Vovanella95
Copy link
Collaborator

@vipw check swagger_dart_code_generator: ^2.7.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Triage needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants