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

[REQ] [ASPNETCORE] Add value types #18557

Open
evgenii-kuznetsov opened this issue May 2, 2024 · 3 comments
Open

[REQ] [ASPNETCORE] Add value types #18557

evgenii-kuznetsov opened this issue May 2, 2024 · 3 comments

Comments

@evgenii-kuznetsov
Copy link

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; }
@evgenii-kuznetsov
Copy link
Author

@wing328, I can create a PR for the proposed changes if required. Would you kindly take a look and give your approval?

@wing328
Copy link
Member

wing328 commented May 10, 2024

please file a PR to start with and we'll review the PR accordingly.

@evgenii-kuznetsov
Copy link
Author

I've created the PR with change.

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

No branches or pull requests

2 participants