Skip to content

Conversation

chizhanov
Copy link
Contributor

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)

@kuhnroyal
Copy link
Contributor

kuhnroyal commented Jun 3, 2025

Do we have this in one of the samples? Probably not...

@chizhanov
Copy link
Contributor Author

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);

@barryguvenkaya
Copy link

@ahmednfwela would be great to get this reviewed ASAP please because it affects us too.

@ahmednfwela
Copy link
Contributor

@wing328 can this case be added to any of the samples we use? unfortunately they are all shared with other generators

@wing328
Copy link
Member

wing328 commented Jul 3, 2025

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

@wing328
Copy link
Member

wing328 commented Jul 3, 2025

i just merged #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

@chizhanov
Copy link
Contributor Author

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

@chizhanov chizhanov force-pushed the fix-20495 branch 2 times, most recently from 1bb620e to 09c61e4 Compare July 11, 2025 11:09
@wing328 wing328 merged commit f632ab7 into OpenAPITools:master Jul 17, 2025
16 checks passed
@wing328
Copy link
Member

wing328 commented Jul 17, 2025

PR merged

thanks for the contribution

@bw-flagship
Copy link

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

@chizhanov
Copy link
Contributor Author

@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?

@bw-flagship
Copy link

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants