Skip to content

Add required keyword and nullable annotations to http-server-csharp model properties#9439

Open
aleksator wants to merge 2 commits intomicrosoft:mainfrom
aleksator:generate_required_property_with_nullable_annotations
Open

Add required keyword and nullable annotations to http-server-csharp model properties#9439
aleksator wants to merge 2 commits intomicrosoft:mainfrom
aleksator:generate_required_property_with_nullable_annotations

Conversation

@aleksator
Copy link

Hi folks!

Trying out TypeSpec with http-server-csharp generation in one of the projects - enjoying the generated code so far. Great job!

The most important improvement for me is to have required and nullable annotations for C# model properties as described in #7710, which this PR implements.

@aleksator
Copy link
Author

@microsoft-github-policy-service agree

@aleksator
Copy link
Author

I found that after adding required to exception properties for the definition like

@error
model ConflictError {
  @statusCode statusCode: 409;
  message: string;
}

creating an instance of the exception

throw new ConflictError("message");

produces error

Error CS9035 : Required member 'ConflictError.MessageProp' must be set in the object initializer or attribute constructor.

Fixed this by adding [SetsRequiredMembers] annotation to exception constructors.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants