Skip to content

Commit

Permalink
Simplify model generation (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
openactive-bot authored Mar 2, 2021
1 parent e00e020 commit f39d508
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
7 changes: 3 additions & 4 deletions OpenActive.NET.Generator/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ function augmentWithExtension(extModelGraph, models, extensionUrl, extensionPref
],
"example": node.example,
"extensionPrefix": extensionPrefix,
"deprecated": !!node.supersededBy,
"deprecationGuidance": node.supersededBy ? `This term has graduated from the beta namespace and is highly likely to be removed in future versions of this library, please use \`${getPropNameFromFQP(node.supersededBy)}\` instead.` : null
};
node.domainIncludes.forEach(function (prop) {
Expand Down Expand Up @@ -547,13 +546,13 @@ function createPropertyFromField(field, models, enumMap, hasBaseClass) {
var propertyName = convertToCamelCase(field.fieldName);
var propertyType = createTypeString(field, models, enumMap, isExtension);
var jsonConverter = renderJsonConverter(field, propertyType);
var deprecated = field.deprecated ? `\n [Obsolete("${field.deprecationGuidance}", false)]` : "";
var obsolete = field.deprecationGuidance ? `\n [Obsolete("${field.deprecationGuidance}", false)]` : "";
var defaultContent = field.defaultContent ?
(Number.isInteger(field.defaultContent) ? ` = ${field.defaultContent};` : ` = "${field.defaultContent.replace(/"/g, '\\"')}";`)
: "";
return !field.obsolete ? `
/// ${createDescriptionWithExample(field).replace(/\n/g, '\n /// ')}
[DataMember(Name = "${memberName}", EmitDefaultValue = false, Order = ${isExtension ? 1000 + field.order : field.order})]${jsonConverter}${deprecated}
[DataMember(Name = "${memberName}", EmitDefaultValue = false, Order = ${isExtension ? 1000 + field.order : field.order})]${jsonConverter}${obsolete}
public ${field.override ? "override" : !isExtension && hasBaseClass && (isNew || field.override) ? "new virtual" : "virtual"} ${propertyType} ${propertyName} { get; set; }${defaultContent}
` : `
[Obsolete("This property is disinherited in this type, and must not be used.", true)]
Expand Down Expand Up @@ -610,7 +609,7 @@ function createDescriptionWithExample(field) {
if (field.requiredContent) {
return "Must always be present and set to " + renderCode(field.requiredContent, field.fieldName, field.requiredType);
} else {
var deprecationNotice = field.deprecated ? `[DEPRECATED: ${field.deprecationGuidance}]\n` : "";
var deprecationNotice = field.deprecationGuidance ? `[DEPRECATED: ${field.deprecationGuidance}]\n` : "";
var propertyWarning = EXTENSIONS[field.extensionPrefix] ? EXTENSIONS[field.extensionPrefix].propertyWarning + "\n" : "";
return `<summary>\n${deprecationNotice ? deprecationNotice : propertyWarning}${field.description.join(" \n")}\n</summary>`
+ (field.example ? "\n<example>\n" + renderCode(field.example, field.fieldName, field.requiredType) + "\n</example>" : "");
Expand Down
6 changes: 3 additions & 3 deletions OpenActive.NET.Generator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion OpenActive.NET.Generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"author": "Nick Evans",
"license": "MIT",
"dependencies": {
"@openactive/data-models": "^2.0.180",
"@openactive/data-models": "^2.0.181",
"fs-extra": "^7.0.1",
"sync-request": "^6.0.0"
}
Expand Down
4 changes: 1 addition & 3 deletions OpenActive.NET/models/Offer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,15 @@ public override string ToString()


/// <summary>
/// [DEPRECATED: Use `ageRestriction` instead of `ageRange` within the `Offer` for cases where the `Offer` is age restricted.]
/// Indicates that an Offer is only applicable to a specific age range.
/// </summary>
[DataMember(Name = "ageRange", EmitDefaultValue = false, Order = 12)]
[JsonConverter(typeof(ValuesConverter))]
[Obsolete("Use `ageRestriction` instead of `ageRange` within the `Offer` for cases where the `Offer` is age restricted.", false)]
public virtual QuantitativeValue AgeRange { get; set; }


/// <summary>
/// Indicates that an Offer is only applicable to a specific age range. Specified as a QuantitativeValue with minValue and maxValue properties. This must be displayed prominently to the user when selecting an `Offer` or before booking.
/// Indicates that an Offer can only be purchased by participants within a specific age range. Specified as a QuantitativeValue with minValue and maxValue properties. This must be displayed prominently to the user when selecting an `Offer` or before booking.
/// </summary>
/// <example>
/// <code>
Expand Down

0 comments on commit f39d508

Please sign in to comment.