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

Add unit test to demonstrate interaction of ClassNameHint with other hints #54

Merged
2 commits merged into from
Oct 18, 2018

Conversation

ghost
Copy link

@ghost ghost commented Oct 17, 2018

In this scenario, the code generator isn't as easy to use as it should be. You need to file any hints that affect the renamed class under the new class name. For example, your CodeGenHints.json might look like this:

  "exception": [
    {
      "kind": "ClassNameHint",
      "arguments": {
        "className": "ExceptionData"
      }
    }
  ],
  "exceptionData": [
    {
      "kind": "BaseTypeHint",
      "arguments": {
        "baseTypeNames": [
          "PropertyBagHolder"
        ]
      }
    }
  ],

Another nit in the design is that the renamed class has to appear in camelCase in the hints file. In the example above, note that the dictionary key is exceptionData, even though the renamed class is ExceptionData.

This PR just adds a unit test to demonstrate this usage.

}
}
}
}",
Copy link
Author

@ghost ghost Oct 17, 2018

Choose a reason for hiding this comment

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

The schema defines a root object with a single property named file of type file. #ByDesign

""className"": ""FileData""
}
}
],
Copy link
Author

@ghost ghost Oct 17, 2018

Choose a reason for hiding this comment

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

The ClassNameHint says that the generated class is named FileData. #ByDesign

""PropertyBagHolder""
]
}
}
Copy link
Author

@ghost ghost Oct 17, 2018

Choose a reason for hiding this comment

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

The BaseTypeHint says that the renamed class has a base class PropertyBagHolder. #ByDesign

{
[DataContract]
[GeneratedCode(""Microsoft.Json.Schema.ToDotNet"", """ + VersionConstants.FileVersion + @""")]
public partial class FileData : PropertyBagHolder
Copy link
Author

@ghost ghost Oct 17, 2018

Choose a reason for hiding this comment

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

PropertyBagHolder [](start = 36, length = 17)

The renamed class has the correct base type. #ByDesign

}

return true;
}
Copy link
Author

@ghost ghost Oct 17, 2018

Choose a reason for hiding this comment

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

} [](start = 8, length = 1)

Now this is a separate, existing, bug, which I will file. The generated equality comparer doesn't compare the base classes! #Pending

Copy link
Author

@ghost ghost Oct 17, 2018

Choose a reason for hiding this comment

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

@michaelcfanning Microsoft/jschema#55, "Equality comparer doesn't compare base types".


In reply to: 226104727 [](ancestors = 226104727)

@ghost ghost merged commit 1eb23ab into develop Oct 18, 2018
@ghost ghost deleted the users/lgolding/52 branch October 18, 2018 21:02
michaelcfanning added a commit that referenced this pull request Dec 29, 2018
* Remove dependency on RuleMessageId (shortly to be deprecated) (#24)

* Release 0.57.0

* Todotnet package (#30)

* Add utilities to validation and todotnet packages

* Update nuget.exe. Add success message for nuspec-driven package creation.

* Update signing scripts

* Release 0.58.0 (#32)

* Address PR feedback from 0.58.0 release (#33)

Also:
* Build the `develop` branch in AppVeyor.

* Add dotnet publish step to build. (#34)

Also:
- Use `.CommandLine`, not `.Cli` in the command line tool namespaces.

* Disable appveyor email notifications (#36)

* Update to latest SARIF SDK + JSON.NET downgrade (#38)

* Fix ToDotNet.Cli project file so resources can be found. (#40)

When you run the ToDotNet command line app, it fails because it can't find the resource stream. Somehow the `.resx` and the `.Resources.designer` files got separated in the project file. Fix the project file to connect the resources back up.

* Rewrite top-level README in preparation for documenting each component. (#47)

An almost complete rewrite.

* Fix #41: Document Json.Pointer (#48)

* embed resx resources (#53)

* Add unit test to demonstrate interaction of ClassNameHint with other hints (#54)

* Start codegen README (#59)

* Fix #57, fix #58: Emit initializers and attributes for default values (#60)

#57: When a schema property declares a default value, assign that value to the property in the default constructor. This ensures that the property has the correct default even if you construct the object by hand rather than by deserializing it from JSON.

#58: When a schema property declares a default value, decorate the property with a `System.ComponentModel.DefaultValue` attribute. This avoids your having to specify those attributes in the CodeGenHints.json file, which is error-prone.

Also:
- Fix a bug where the generated doc comments for properties had an extra space: `cref="P: propName`" → `cref="P:propName`".
- Address some hygiene-related IDE messages by marking some properties `readonly`, and by inlining the declarations of some `out` parameters.

* Fix #61: Generate JsonProperty attribute for properties with defaults (#62)

* Add final release note in advance of shipping 0.59.0
michaelcfanning added a commit that referenced this pull request Dec 30, 2018
* Remove dependency on RuleMessageId (shortly to be deprecated) (#24)

* Release 0.57.0

* Todotnet package (#30)

* Add utilities to validation and todotnet packages

* Update nuget.exe. Add success message for nuspec-driven package creation.

* Update signing scripts

* Release 0.58.0 (#32)

* Address PR feedback from 0.58.0 release (#33)

Also:
* Build the `develop` branch in AppVeyor.

* Add dotnet publish step to build. (#34)

Also:
- Use `.CommandLine`, not `.Cli` in the command line tool namespaces.

* Disable appveyor email notifications (#36)

* Update to latest SARIF SDK + JSON.NET downgrade (#38)

* Fix ToDotNet.Cli project file so resources can be found. (#40)

When you run the ToDotNet command line app, it fails because it can't find the resource stream. Somehow the `.resx` and the `.Resources.designer` files got separated in the project file. Fix the project file to connect the resources back up.

* Rewrite top-level README in preparation for documenting each component. (#47)

An almost complete rewrite.

* Fix #41: Document Json.Pointer (#48)

* embed resx resources (#53)

* Add unit test to demonstrate interaction of ClassNameHint with other hints (#54)

* Start codegen README (#59)

* Fix #57, fix #58: Emit initializers and attributes for default values (#60)

#57: When a schema property declares a default value, assign that value to the property in the default constructor. This ensures that the property has the correct default even if you construct the object by hand rather than by deserializing it from JSON.

#58: When a schema property declares a default value, decorate the property with a `System.ComponentModel.DefaultValue` attribute. This avoids your having to specify those attributes in the CodeGenHints.json file, which is error-prone.

Also:
- Fix a bug where the generated doc comments for properties had an extra space: `cref="P: propName`" → `cref="P:propName`".
- Address some hygiene-related IDE messages by marking some properties `readonly`, and by inlining the declarations of some `out` parameters.

* Fix #61: Generate JsonProperty attribute for properties with defaults (#62)

* Add final release note in advance of shipping 0.59.0

* Update licensing reference to satisfy NuGet improvements in this area. (#65)
This pull request was closed.
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.

0 participants