Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public ClassTemplateModel(string typeName, CSharpGeneratorSettings settings,
.Select(property => new PropertyModel(this, property, _resolver, _settings))
.ToArray();

Id = _schema.Id;
Copy link
Owner

Choose a reason for hiding this comment

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

Use a derived/calculated property?

if (schema.InheritedSchema != null)
{
BaseClass = new ClassTemplateModel(BaseClassName, settings, resolver, schema.InheritedSchema, rootObject);
Expand All @@ -50,6 +51,11 @@ public ClassTemplateModel(string typeName, CSharpGeneratorSettings settings,
}
}

/// <summary>
/// Id for the class instance
/// </summary>
public string Id { get; set; }

/// <summary>Gets or sets the class name.</summary>
public override string ClassName { get; }

Expand Down
9 changes: 9 additions & 0 deletions src/NJsonSchema.CodeGeneration.CSharp/Models/PropertyModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ public PropertyModel(
_property = property;
_settings = settings;
_resolver = typeResolver;

Id = property.Id;
Copy link
Owner

Choose a reason for hiding this comment

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

Id = property.Id ?? property.ActualSchema.Id;

Can a property have its own id?
Maybe also use a derived property like the Name?

if (property.Reference != null && string.IsNullOrEmpty(Id))
Id = property.Reference.Id;
}

/// <summary>
/// Id for the property
/// </summary>
public string Id { get; }

/// <summary>Gets the name of the property.</summary>
public string Name => _property.Name;

Expand Down