RicoSuter / NJsonSchema

JSON Schema reader, generator and validator for .NET
http://NJsonSchema.org
MIT License
1.37k stars 529 forks source link

Property named '-1' generates wrong C# Property name #1710

Open bstordrup opened 2 months ago

bstordrup commented 2 months ago

The following definition

      "reaction-rollup": {
        "title": "Reaction Rollup",
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "format": "uri"
          },
          "total_count": {
            "type": "integer"
          },
          "+1": {
            "type": "integer"
          },
          "-1": {
            "type": "integer"
          },
          "laugh": {
            "type": "integer"
          }
        },

generates the C# property name Plus1 as expected, but _1 for the -1. I would expect it to become Minus1.

Also, the parameter names for the method are causing compilation errors - they should follow the Property name generation.

        public ReactionRollup(int @+1, int @1, int @laugh, int @total_count, System.Uri @url)

        {

            this.Url = @url;

            this.Total_count = @total_count;

            this.Plus1 = @+1;

            this._1 = @1;

            this.Laugh = @laugh;

        }

For the property names generation, I think it can be solve din the CSharpPropertyNameGenerator. Not sure about the parameter names though.