[dart-dio] Fix compile error in enum properties with "default" values (#20495)
This PR solves the problem described in #20495.
I made this fix locally and on my openapi the issue was fixed and no new issues were found.
@jaumard (2018/09) @josh-burton (2019/12) @amondnet (2019/12) @sbu-WBT (2020/12) @kuhnroyal (2020/12) @agilob (2020/12) @ahmednfwela (2021/08)
Do we have this in one of the samples? Probably not...
Do we have this in one of the samples? Probably not...
I didn't see it, but we can try to add it:
OpenAPI spec:
{
"openapi": "3.1.0",
"info": {
"title": "Simple",
"version": "0.0.1"
},
"paths": {},
"components": {
"schemas": {
"TestEnum": {
"type": "string",
"enum": [
"",
"1",
"2"
],
"title": "TestEnum"
},
"TestItem": {
"properties": {
"test": {
"type": "integer",
"title": "test"
},
"testEmum": {
"$ref": "#/components/schemas/TestEnum",
"default": ""
}
},
"type": "object",
"required": [
"test"
],
"title": "TestItem"
}
}
},
"tags": []
}
And problem will be here:
@BuiltValueHook(initializeBuilder: true)
static void _defaults(TestItemBuilder b) => b
..testEmum = const ._(TestEnum.empty);
@ahmednfwela would be great to get this reviewed ASAP please because it affects us too.
@wing328 can this case be added to any of the samples we use? unfortunately they are all shared with other generators
@chizhanov did you test it locally to confirm it works for you?
i can add a test or 2 later using a dedicated for dart client tests.
i just merged https://github.com/OpenAPITools/openapi-generator/pull/21516 to the master to have dart dedicated test spec (fake petstore)
can you please merge the latest master into your branch and add a test schema with enum properties (with default values) and regenerate the samples (step 3 in pr checklist) when you've time?
dart test spec: modules/openapi-generator/src/test/resources/3_0/dart/petstore-with-fake-endpoints-models-for-testing.yaml
@wing328 Yes, I tested these changes and in my cases they fixed the problem and did not cause new ones.
I added a test to petstore as you asked.
PR merged
thanks for the contribution
@chizhanov Since this version, code generation broke for me, and I suspect this PR to be the rootcause. I have an enum called ProductTypeSetting in openapi. Before, the default-section was generated like this:
static void _defaults(SetIsPhysicalDeliveryWriteDtoBuilder b) => b
..productTypeSetting = const SetIsPhysicalDeliveryWriteDtoProductTypeSettingEnum._('physical');
After upgrading to 7.15, it is this:
static void _defaults(SetIsPhysicalDeliveryWriteDtoBuilder b) => b
..productTypeSetting = 'physical';
Which does not compile, because it tries to write a string to the enum value.
@bw-flagship I think you’re right — it looks like my PR broke this behavior. Could you please share a minimal OpenAPI specification so I can reproduce the issue?
@chizhanov I created a minimal spec to reproduce and put it in an issue: #22120 Let me know if I shall provide further info, thanks for looking into it!