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

[csharp][java] Fix enum discriminator default value #19614

Merged

Conversation

david-marconis
Copy link
Contributor

@david-marconis david-marconis commented Sep 18, 2024

When you define a schema with an enum discriminator and you use allOf to include the parent schema in the child schema the current generated code fails to compile due to the generator thinking the discriminator is of type string instead of enum.

This is mentioned in some issues I could find which this PR should fix:
#12412 #16073 #16672 #19194 #19261

These PRs attempt to solve it, but they have some flaws.
#10959 #16394

This was tested with java and csharp generators which both have issues. Other generators might also have issues with this if they implement custom logic of handling default values of enums like the csharp generator currently does.

The issue in the code lied in the fact that when checking whether or not the discriminator is an enum it only checks the properties of the child schema, however the property might be defined in the referenced parent schema.

        // The schema here might not have the discriminator type property.
        if (schema.getProperties() != null &&
                schema.getProperties().get(discriminatorPropertyName) instanceof StringSchema) {
            StringSchema s = (StringSchema) schema.getProperties().get(discriminatorPropertyName);
            if (s.getEnum() != null && !s.getEnum().isEmpty()) { // it's an enum string
                discriminator.setIsEnum(true);
            }
        }

This can be verified by running the added tests against the current master and observe them fail.

The code was modified to return the referenced schema in addition to the discriminator when searching for it recursively and when checking for the property check both in the child schema and the schema that defines the discriminator.

I am unsure if it is possible to have a situation where the property is neither in the child schema or the schema with the discriminator, but in an intermediary in the ref chain. This would be uncommon and I am unsure if it is possible with the current code, but I don't understand it well enough to tell whether this is possible or if it is a valid spec. Perhaps it would be better to traverse up the allOf reference chain, but I an not familiar enough with how objects can be defined with combinations of allOf, anyOf and oneOf. At least this implementation avoids another recursive traversal of the schema tree. Let me know if this should be changed or if the new implementation is good enough.

I changed the code to check all parents and all descendants for the discriminator property. This should cover most if not all possible use cases. Here is the schema I used with a mix of anyOf, allOf and oneOf mappings:

openapi: 3.0.3
info:
title: Test schema with enum discriminator
version: v1
paths:
"/animal":
get:
responses:
'200':
description: OK
content:
application/json:
schema:
"$ref": "#/components/schemas/Animal"
components:
schemas:
Animal:
type: object
properties:
# Inline enum type
petType:
type: string
enum:
- Dog
- Catty
- Gecko
- Camo
discriminator:
propertyName: petType
# Mapping with implicit (Dog, Gecko), explicit ref (Catty -> Cat), and explicit schema name (Camo -> Chameleon)
mapping:
Catty: '#/components/schemas/Cat'
Camo: 'Chameleon'
required:
- petType
Cat:
type: object
allOf:
- $ref: '#/components/schemas/Animal'
properties:
meow:
type: string
Dog:
type: object
allOf:
- $ref: '#/components/schemas/Animal'
properties:
bark:
type: string
Lizard:
oneOf:
- $ref: '#/components/schemas/Gecko'
- $ref: '#/components/schemas/Chameleon'
Gecko:
type: object
allOf:
- $ref: '#/components/schemas/Animal'
properties:
lovesRocks:
type: string
Chameleon:
type: object
allOf:
- $ref: '#/components/schemas/Animal'
properties:
currentColor:
type: string
# Car inheritance tree: Car -> Truck -> SUV
# Car -> Van -> MiniVan
# Car -> Van -> CargoVan
# Car -> Sedan
Car:
type: object
required:
- carType
# Discriminator carType not defined in Car properties, but in child properties
discriminator:
propertyName: carType
CarType:
type: string
enum:
- Truck
- SUV
- Sedan
- MiniVan
- CargoVan
Truck:
type: object
allOf:
- $ref: '#/components/schemas/Car'
properties:
carType:
$ref: '#/components/schemas/CarType'
required:
- carType
SUV:
type: object
# SUV gets its discriminator property from Truck
allOf:
- $ref: '#/components/schemas/Truck'
Sedan:
type: object
allOf:
- $ref: '#/components/schemas/Car'
required:
- carType
properties:
carType:
$ref: '#/components/schemas/CarType'
Van:
oneOf:
- $ref: '#/components/schemas/MiniVan'
- $ref: '#/components/schemas/CargoVan'
MiniVan:
type: object
allOf:
- $ref: '#/components/schemas/Car'
properties:
carType:
$ref: '#/components/schemas/CarType'
required:
- carType
CargoVan:
type: object
allOf:
- $ref: '#/components/schemas/Car'
properties:
carType:

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh ./bin/configs/*.yaml
    ./bin/utils/export_docs_generators.sh
    
    (For Windows users, please run the script in Git BASH)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.6.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

@david-marconis david-marconis force-pushed the feature/fix-enum-discriminator branch from 4bd0ec3 to 9c0a126 Compare September 26, 2024 13:55
@david-marconis
Copy link
Contributor Author

This has been sitting for a month, so I'll ping the technical committee for csharp and java:

@mandrean (2017/08) @shibayan (2020/02) @Blackclaws (2021/03) @lucamazzanti (2021/05) @iBicha (2023/07)

@bbdouglas (2017/07) @sreeshas (2017/08) @jfiala (2017/08) @lukoyanov (2017/09) @cbornet (2017/09) @jeff9finger (2018/01) @karismann (2019/03) @Zomzog (2019/04) @lwlee2608 (2019/10) @martin-mfg (2023/08)

@martin-mfg
Copy link
Contributor

Hi @david-marconis, thanks for the PR!
This PR solves the compiler problem by not initializing the discriminator field anymore. But isn't this undesired behaviour? Wouldn't it be good to have the discriminator field initialized properly?

Using Dog as an example, the old constructor was

  public Dog() {
    this.petType = this.getClass().getSimpleName();
  }

The new constructor is now

  public Dog() {
  }

Instead, shouldn't we do either this:

  public Dog() {
    this.petType = PetTypeEnum.DOG;
  }

... or this?

  public Dog() {
    this.petType=PetTypeEnum.fromValue("Dog");
  }

@david-marconis
Copy link
Contributor Author

Hi @david-marconis, thanks for the PR! This PR solves the compiler problem by not initializing the discriminator field anymore. But isn't this undesired behaviour? Wouldn't it be good to have the discriminator field initialized properly?

Using Dog as an example, the old constructor was

  public Dog() {
    this.petType = this.getClass().getSimpleName();
  }

The new constructor is now

  public Dog() {
  }

Instead, shouldn't we do either this:

  public Dog() {
    this.petType = PetTypeEnum.DOG;
  }

... or this?

  public Dog() {
    this.petType=PetTypeEnum.fromValue("Dog");
  }

That is a fair point and this is actually solved in the c# codegen, but not Java. I'll have a stab at it when I get the time.

@david-marconis
Copy link
Contributor Author

@martin-mfg I tried my hand at fixing it and it wasn't as straight forward as I wanted. I utilized the same solution as C# in order to solve the case for Java as well (setting defaultValue of the readWriteVar element which has isDiscriminator set). I only set it for AbstractJavcaCodegen and not DefaultCodegen because it had some undesired side effects for bash, cpp and php.

I also discovered that there is still one bug where it will not set the isEnum properly on the CodegenDiscriminator which is this case:

    GrandparentAnimal:
      type: object
      required:
        - pet_type
      properties:
        pet_type:
          type: string
      discriminator:
        propertyName: pet_type
    ParentPet:
      type: object
      allOf:
        - $ref: '#/components/schemas/GrandparentAnimal'
    ChildCat:
      allOf:
        - $ref: '#/components/schemas/ParentPet'
        - type: object
          properties:
            name:
              type: string
            pet_type:
              x-enum-as-string: true
              type: string
              enum:
              - ChildCat
              default: ChildCat
          required:
          - pet_type

This won't work, because the property pet_type in ChildCat will actually point to the property pet_type from GrandparentAnimal which will not include the enum list because it is not an enum. This is probably due to some property caching. IDK if this is intentional or not and I don't know if or how to fix it. I think this case can be ignored for now though as it is an unusual case.

Let me know if this is a good solution or if we should try to solve it in a different way. Perhaps with a new property instead of utilizing defaultValue of a readWriteVar.

Copy link
Contributor

@martin-mfg martin-mfg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this case can be ignored for now though as it is an unusual case.

Yes, I agree.

Let me know if this is a good solution or if we should try to solve it in a different way. Perhaps with a new property instead of utilizing defaultValue of a readWriteVar.

Generally I don't see a problem with the current approach. But please take care of the following "Nonnull" issue, as well as the inline comment below:

Using your added example input spec, here's how this PR's changes affect the generated code: https://gist.github.com/martin-mfg/d4e28b386eab99e53374eef866cc1a50 . Besides the desired enum initialization changes, it's also removing some @javax.annotation.Nonnull annotations. I guess this change was not intended and should be avoided/reverted. [PS: The "Nonnull" change is caused by unrelated commits on the master branch.]

protected static String getEnumValueForProperty(
String modelName, CodegenDiscriminator discriminator, CodegenProperty var) {
if (!discriminator.getIsEnum() && !var.isEnum) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, I guess we shouldn't override the defaultValue at all. But currently we're overriding it with null. In line 3125. Or am I wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I changed it to use the existing defaultValue instead of null.

If I set defaultValue to the enum discriminator in DefaultCodegen then there is only this change to dart-dio when I generate the samples:

diff --git a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ChildWithNullable.md b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/
doc/ChildWithNullable.md
index 770494fcf4c..d3e5b182076 100644
--- a/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ChildWithNullable.md
+++ b/samples/openapi3/client/petstore/dart-dio/petstore_client_lib_fake/doc/ChildWithNullable.md
@@ -8,7 +8,7 @@ import 'package:openapi/api.dart';
 ## Properties
 Name | Type | Description | Notes
 ------------ | ------------- | ------------- | -------------
-**type** | **String** |  | [optional]
+**type** | **String** |  | [optional] [default to ChildWithNullableTypeEnum.childWithNullable]
 **nullableProperty** | **String** |  | [optional]
 **otherProperty** | **String** |  | [optional]

I am not sure if this change is fine or if I should just keep it to Java and C# for now, but this could also be a problem that needs to be solved for other languages.

@martin-mfg
Copy link
Contributor

And just for the record I want to mention two more things. They don't need to be fixed here though.

  • Running OpenAPI Generator on the added input spec with generator=java prints [main] INFO org.openapitools.codegen.DefaultGenerator - Model Car not generated since it's a free-form object and the generated output doesn't compile, due to class Car missing.
  • Also, running OpenAPI Generator as described prints several warnings like this: [main] WARN org.openapitools.codegen.DefaultCodegen - 'Lizard' defines discriminator 'petType', but the referenced schema 'Gecko' is incorrect. petType is missing from the schema, define it as required and type string.

@david-marconis
Copy link
Contributor Author

david-marconis commented Oct 24, 2024

And just for the record I want to mention two more things. They don't need to be fixed here though.

  • Running OpenAPI Generator on the added input spec with generator=java prints [main] INFO org.openapitools.codegen.DefaultGenerator - Model Car not generated since it's a free-form object and the generated output doesn't compile, due to class Car missing.

I'm not quite sure how to fix this. It has to do with this method:

    public static boolean shouldGenerateFreeFormObjectModel(String name, CodegenConfig config) {
        // there are 3 free form use cases
        // 1. free form with no validation that is not allOf included in any composed schemas
        // 2. free form with validation
        // 3. free form that is allOf included in any composed schemas
        //      this use case arises when using interface schemas
        // generators may choose to make models for use case 2 + 3
        Schema refSchema = new Schema();
        refSchema.set$ref("#/components/schemas/" + name);
        Schema unaliasedSchema = config.unaliasSchema(refSchema);
        return unaliasedSchema.get$ref() != null;
    }

But it is unclear to me how it should be modified and what further implications that would cause.
As you say though, it doesn't need to be fixed in this PR, but it does in fact create uncompilable code for the spec created.

  • Also, running OpenAPI Generator as described prints several warnings like this: [main] WARN org.openapitools.codegen.DefaultCodegen - 'Lizard' defines discriminator 'petType', but the referenced schema 'Gecko' is incorrect. petType is missing from the schema, define it as required and type string.

I investigated this issue and found a few bugs in the discriminatorFound recursive method:

  • The discriminator schema wasn't properly dereferenced if it was a part of the properties.
  • It wasn't actually recursing, because it used the composedSchemaName for its visited set, which is always the same so it would stop recursing on the second call. I fixed this by instead using the schema name of the sc schema passed in. However not all schemas passed in here has a name, so I look for the schemaName in this order:
    1. Passed in composedSchemaName
    2. refSchema.getName()
    3. sc.get$ref() converted to simpleref
    4. toString()
      If all methods of finding the name fail, then revert to using toString(), this didn't occur in my test, but some other test cases failed without it. Could possibly just return null instead if the name wasn't found. WDYT?

This eliminates the warnings seen in the logs and probably fixes these issues:
#17893
#17985

After I fixed these two bugs, I saw that I could actually set the isEnum on the returned CodegenProperty for the discriminator and reuse this method instead of my previous solution for finding the discriminator.

Copy link
Contributor

@martin-mfg martin-mfg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the additional effort regarding the warnings!

This eliminates the warnings seen in the logs

I actually still get the following warnings:

[main] WARN  org.openapitools.codegen.utils.ModelUtils - Failed to get the schema name: null
[main] WARN  org.openapitools.codegen.DefaultCodegen - 'Lizard' defines discriminator 'petType', but the referenced OneOf schema 'Chameleon' is missing petType

Is the behaviour different for you?

Since the PR already looks good to me, I'll approve it now.

You are of course very welcome to have another look at the above warnings and improve the situation there if you want. Possibly in a new PR if this one here gets merged.

@david-marconis
Copy link
Contributor Author

david-marconis commented Oct 25, 2024

Thanks for the additional effort regarding the warnings!

This eliminates the warnings seen in the logs

I actually still get the following warnings:

[main] WARN  org.openapitools.codegen.utils.ModelUtils - Failed to get the schema name: null
[main] WARN  org.openapitools.codegen.DefaultCodegen - 'Lizard' defines discriminator 'petType', but the referenced OneOf schema 'Chameleon' is missing petType

Is the behaviour different for you?

Since the PR already looks good to me, I'll approve it now.

You are of course very welcome to have another look at the above warnings and improve the situation there if you want. Possibly in a new PR if this one here gets merged.

Whack one down and another resurfaces 😅. I have fixed it again; now there should be no more warnings.
Confirmed with build log: https://github.com/OpenAPITools/openapi-generator/actions/runs/11515327595/job/32055773044?pr=19614#step:7:28515

There was another bug in the discriminatorFound method where it would try to revisit the same tree multiple times, but if it had already visited it before it would not visit it again because of the visitedSchemas set. I just copied the set so each oneOf/anyOf will have its own set. It could probably be made better by utilizing a cache of the found properties, but I think it's an ok solution.

Also the "Failed to get schema" was an error on my part, I left in a useless line of code.

@david-marconis
Copy link
Contributor Author

@martin-mfg, @wing328: Any chance of getting this merged soon?

@karataydev
Copy link

hey, any update on this PR?

@martin-mfg
Copy link
Contributor

hey, any update on this PR?

No; it's waiting to be merged by the project maintainer when he has time.

@david-marconis
Copy link
Contributor Author

@wing328 Can you please have a look at this. It has been approved for almost two months now. If there is anything else I need to add or do, please let me know.

@wing328
Copy link
Member

wing328 commented Dec 17, 2024

@david-marconis Hi David, thanks for the PR and sorry for the delay in reviewing as we've got many many PRs from the awesome community.

I'll review this week and let you know if I've any questions or simply merge if I don't spot anything.

@wing328
Copy link
Member

wing328 commented Dec 23, 2024

I tested with

 java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g csharp -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/1f8b90c4a660c8e6c6a7732847b2b964b5997c99/modules/openapi-generator/src/test/resources/3_0/enum_discriminator_inheritance.yaml -o /tmp/csharp23 --additional-properties targetFramework=net8.0

but got errors when running dotnet build in the output folder:

Build FAILED.

C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Cat.cs(94,49): warning CS0108: 'Cat.BaseValidate(ValidationContext)' hides inherited member 'Animal.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Chameleon.cs(94,49): warning CS0108: 'Chameleon.BaseValidate(ValidationContext)' hides inherited member 'Animal.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Dog.cs(94,49): warning CS0108: 'Dog.BaseValidate(ValidationContext)' hides inherited member 'Animal.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Gecko.cs(94,49): warning CS0108: 'Gecko.BaseValidate(ValidationContext)' hides inherited member 'Animal.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\SUV.cs(85,49): warning CS0108: 'SUV.BaseValidate(ValidationContext)' hides inherited member 'Truck.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\CargoVan.cs(33,37): error CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\MiniVan.cs(33,36): error CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Truck.cs(35,34): error CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Sedan.cs(33,34): error CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
    5 Warning(s)
    4 Error(s)

Does it build without issues for your locally using the test included in this PR?

@wing328
Copy link
Member

wing328 commented Dec 23, 2024

cc @OpenAPITools/generator-core-team

@david-marconis
Copy link
Contributor Author

I tested with

 java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g csharp -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/1f8b90c4a660c8e6c6a7732847b2b964b5997c99/modules/openapi-generator/src/test/resources/3_0/enum_discriminator_inheritance.yaml -o /tmp/csharp23 --additional-properties targetFramework=net8.0

but got errors when running dotnet build in the output folder:

Build FAILED.

C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Cat.cs(94,49): warning CS0108: 'Cat.BaseValidate(ValidationContext)' hides inherited member 'Animal.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Chameleon.cs(94,49): warning CS0108: 'Chameleon.BaseValidate(ValidationContext)' hides inherited member 'Animal.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Dog.cs(94,49): warning CS0108: 'Dog.BaseValidate(ValidationContext)' hides inherited member 'Animal.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Gecko.cs(94,49): warning CS0108: 'Gecko.BaseValidate(ValidationContext)' hides inherited member 'Animal.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\SUV.cs(85,49): warning CS0108: 'SUV.BaseValidate(ValidationContext)' hides inherited member 'Truck.BaseValidate(ValidationContext)'. Use the new keyword if hiding was intended. [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\CargoVan.cs(33,37): error CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\MiniVan.cs(33,36): error CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Truck.cs(35,34): error CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Model\Sedan.cs(33,34): error CS0246: The type or namespace name 'Car' could not be found (are you missing a using directive or an assembly reference?) [C:\Users\wing3\AppData\Local\Temp\csharp23\src\Org.OpenAPITools\Org.OpenAPITools.csproj]
    5 Warning(s)
    4 Error(s)

Does it build without issues for your locally using the test included in this PR?

No. it fails on my end as well. I discussed this issue in this comment and I am unsure on how to fix it. This issue is not really related to the discriminator being an enum, as it fails if I remove the enum block from the CarType, and this issue is also present in the repo before this PR. So I think it could be filed as an issue and be solved in another PR instead of this one.

@wing328 wing328 modified the milestones: 7.11.0, 7.12.0 Jan 20, 2025
@wing328
Copy link
Member

wing328 commented Jan 20, 2025

thanks for the explanation. will try to get this merged this week

@wing328 wing328 merged commit c75fbb3 into OpenAPITools:master Jan 21, 2025
85 checks passed
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.

4 participants