Skip to content

[REQ] [ASPNETCORE] Add value types #18557

Open
@evgenii-kuznetsov

Description

@evgenii-kuznetsov

Is your feature request related to a problem? Please describe.

Generator name: aspnetcore
Generator cli version: 7.5.0

When generating a model with a UUID property, 'EmitDefaultValue' is set to 'false' if the field is required and not nullable. I think that in such case, it should be set to 'true'. For instance, an int property with the same configuration sets 'EmitDefaultValue' to 'true' because it is a value type. I believe that a Guid should also be considered a value type.

Describe the solution you'd like

I am wondering if it would be possible to extend the return values of the getValues function in AspNetServerCodegen.java to include "DateTime", "DateOnly", "DateTimeOffset", and "Guid". This suggestion is similar to the implementation in AbstractCSharpCodegen.java, where the code generator for C# client works as expected.

Describe alternatives you've considered

As a workaround, we have to override model.mustache by using x-csharp-value-type instead of x-is-value-type:
[DataMember(Name="{{baseName}}", EmitDefaultValue={{#isNullable}}true{{/isNullable}}{{^isNullable}}{{#vendorExtensions.x-csharp-value-type}}true{{/vendorExtensions.x-csharp-value-type}}{{^vendorExtensions.x-csharp-value-type}}false{{/vendorExtensions.x-csharp-value-type}}{{/isNullable}})], but we would like to use the standard template as much as possible.

Additional context

Script:

docker run --rm -v $(pwd):/app openapitools/openapi-generator-cli:v7.5.0 generate \
    --input-spec /app/schema.yml \
    --output /app/src \
    --model-name-suffix Dto \
    --generator-name aspnetcore \
    --additional-properties aspnetCoreVersion=5.0 \
    --additional-properties nullableReferenceTypes=true \

Schema:

openapi: 3.0.1
info:
  title: Test
  version: 1.0.0

paths:
  /test-endpoint:
    get:
      responses:
        200:
          description: Success

components:
  schemas:
    TestModel:
      type: object
      required:
        - test_id
      properties:
        test_id:
          type: string
          format: uuid

Output:

[Required]
[DataMember(Name="test_id", EmitDefaultValue=false)]
public Guid TestId { get; set; }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions