-
Notifications
You must be signed in to change notification settings - Fork 6
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
Protect object property & enum member names #67
Conversation
@walsha2 openapi_spec/lib/src/generators/schema.dart Lines 964 to 987 in e4bf912
|
In the event that there is an empty enum value, there is no real good solution for how to name it. Take the following valid example spec: "StateLocation": {
"type": "string",
"enum": [
"",
"alabama",
"alaska",
"arizona",
"arkansas",
...
],
} The end user may be using In summary: the spec did not provide a name, we need to come up with one. The reason there are three options is just to cover the case where, for example, |
@walsha2 E.G
it would remove that leading digit.
This will result in invalid code.
|
Hmmm... Im not sure about this or why you are combining changes for a leading digit with changes to handle unescaped characters. These seem like two separate problems. For the first one, enum value starts with a digit. There should already be protections for this. Are you somehow not triggering this part of the code in your test? openapi_spec/lib/src/generators/schema.dart Lines 965 to 968 in 8c239f9
We should not be removing or moving values if we can help it. For example if the starting point is
The resulting Dart enums should/will be: enum SizeEnum {
v1x1,
v2x2,
v3x3,
} I think this is preferable than your solution. |
@walsha2 Agree.
This needs to be removed, we then can end up with duplicates and many empty values |
Correct, I want to add it to parameters too. |
What is this real world use case exactly where someone is using this Dart generator on an enum value if It seems like right now you are going through the OpenAPI examples and pulling out the most complicated/fringe cases to support in this repo, no? Do you actually have a use case that is being solved by adding this support to the generator? Just curious on the motivation for these code changes. |
The PR I'm adding will add a I does it without changing much of the codebase. Streamlines parts of it. |
Sounds good. I can take a look. I appreciate all the effort. One thing that I think needs to happen before we incorporate any of these overhaul type changes is to first add a bunch of unit tests to ensure these cases are covered. Right now the unit tests are not nearly comprehensive enough and I also need to take a second and add some infra to compare the output code of each generated file against some archived, golden, version. This is on my to-do list here soon. |
NowI agree this would be a big change. GoalThe user should never encounter a bug by themselves, the generator should warn them. Proposal: var spec = OpenApi.fromString(
source: rawSchemaText,
format: OpenApiFormat.fromExtention(fileExtension))
.centralizedSpec();
// New Function
checkSchemaAndWarn(spec )
await spec.generate( ); ExpectationsA generator that handles every valid schema would be too complex, and keeping the source code neat it a worthy tradeoff. Thanks! |
No description provided.