glideapps / glideapps/quicktype
[C#] Multiple classes generated for shared $ref definition
- Dominant language
- TypeScript
- Stars
- 13.9k
- Forks
- 1.2k
- Avg merge
- 8h 53m
- Merged PRs (30d)
- 369
Description
Where there is an object type defined in a definitions section, whether in the same file or in an external one, every usage of that shared object definitions gets a separate class named after the property that references it. This makes it really hard to do things like have a custom JSON converter for that type, because there's not a single class, there are lots of classes with identical fields but different names.
Schema
```json
{
"$schema": "https://json-schema.org/draft/2019-09/schema#",
"description": "Demo of multiple classes from one definition.",
"type": "object",
"properties": {
"foo": {
"type": "object",
"description": "The Foo",
"$ref": "#/definitions/corge"
},
"bar": {
"type": "object",
"description": "A high Bar",
"$ref": "#/definitions/corge"
},
"baz": {
"type": "object",
"description": "Bazalicious",
"$ref": "#/definitions/corge"
}
},
"definitions": {
"corge": {
"type": "object",
"description": "Corgeous",
"properties": {
"name": {
"type": "string"
},
"something": {
"type": "string"
}
}
}
}
}
```
C#
```
namespace Quux
{
///
/// Demo of multiple classes from one definition.
///
public partial class DefDemo
{
///
/// A high Bar
///
public Bar Bar { get; set; }
///
/// Bazalicious
///
public Baz Baz { get; set; }
///
/// The Foo
///
public Foo Foo { get; set; }
}
///
/// A high Bar
///
/// Corgeous
///
public partial class Bar
{
public string Name { get; set; }
public string Something { get; set; }
}
///
/// Bazalicious
///
/// A high Bar
///
/// Corgeous
///
public partial class Baz
{
public string Name { get; set; }
public string Something { get; set; }
}
///
/// The Foo
///
/// A high Bar
///
/// Corgeous
///
public partial class Foo
{
public string Name { get; set; }
public string Something { get; set; }
}
}
```
I'm assuming this is deliberate, but can we have an option to just have a single class that is reused?
```
///
/// Demo of multiple classes from one definition.
///
public partial class DefDemo
{
///
/// A high Bar
///
public Corge Bar { get; set; }
///
/// Bazalicious
///
public Corge Baz { get; set; }
///
/// The Foo
///
public Corge Foo { get; set; }
}
///
/// Corgeous
///
public partial class Corge
{
public string Name { get; set; }
public string Something { get; set; }
}
```
As an aside, what's going on with the comments? There are descriptions from multiple properties appearing in multiple places.
Contributor guide
Assessment
This issue has not been assessed yet.