@charlietango/react-docs-net
Advanced tools
Comparing version
// | ||
@@ -48,2 +48,6 @@ const upperFirst = require('lodash/fp/upperFirst'); | ||
function isEnumNumbers(types ) { | ||
return types.elements.every(el => !isNaN(parseInt(el.value))); | ||
} | ||
function buildPropFlags(description ) { | ||
@@ -66,3 +70,4 @@ const [, type] = description.match(/@type (\S+)/) || []; | ||
ns, | ||
isEnumNumbers, | ||
buildPropFlags, | ||
}; |
@@ -10,2 +10,3 @@ // | ||
const upperFirst = require('lodash/fp/upperFirst'); | ||
const isEnumNumbers = require('../helpers').isEnumNumbers; | ||
const ns = require('../helpers').ns; | ||
@@ -17,4 +18,5 @@ const camelCase = require('lodash/fp/camelCase'); | ||
function injectEnums(element , name , indent = 0) { | ||
return element.elements | ||
function injectEnums(types , name , indent = 0) { | ||
const onlyNumbers = isEnumNumbers(types); | ||
return types.elements | ||
.map((el, i) => { | ||
@@ -29,8 +31,15 @@ let response = []; | ||
if (plain) { | ||
if (!isNaN(number)) { | ||
if (!onlyNumbers) { | ||
// Not all values are numbers, so convert the number to string for JSON parsing. C# can't handle mixed value types. | ||
response.push(`[EnumMemberValue="${number}")]`); | ||
response.push(`${upperFirst(camelCase(name))}_${number},`); | ||
} else { | ||
response.push( | ||
`${upperFirst(camelCase(name))}_${number} = ${number},` | ||
); | ||
} | ||
} else { | ||
response.push(`[EnumMember(Value="${plain}")]`); | ||
response.push(`${upperFirst(camelCase(plain || 'Empty'))},`); | ||
} else if (number) { | ||
response.push(`[EnumMemberValue="${number}")]`); | ||
response.push(`${upperFirst(camelCase(name))}_${number},`); | ||
} | ||
@@ -37,0 +46,0 @@ } |
@@ -10,2 +10,3 @@ // | ||
const createSubViewModel = require('./sub-view-model'); | ||
const isEnumNumbers = require('../helpers').isEnumNumbers; | ||
const ns = require('../helpers').ns; | ||
@@ -68,6 +69,7 @@ const createEnum = require('./enum-model'); | ||
if (!!header) output += `\n${header}`; | ||
if (type.model && type.model.types) | ||
if (type.model && type.model.types && !isEnumNumbers(type.model.types)) { | ||
output += `${' '.repeat( | ||
indent | ||
)}[JsonConverter(typeof(StringEnumConverter))]\n`; | ||
} | ||
output += `${' '.repeat(indent)}public virtual ${type.type} ${upperFirst( | ||
@@ -89,7 +91,8 @@ name | ||
const propsResult = injectProps(model.displayName || name, model.props, 8); | ||
const hasTypes = propsResult.models.some(model => !!model.types); | ||
const fileSource = `using System.Collections.Generic; | ||
${ | ||
hasTypes | ||
? `using Newtonsoft.Json; | ||
const hasEnumTypes = propsResult.models.some( | ||
model => !!model.types && !isEnumNumbers(model.types) | ||
); | ||
const fileSource = `using System.Collections.Generic;${ | ||
hasEnumTypes | ||
? `\nusing Newtonsoft.Json; | ||
using Newtonsoft.Json.Converters;` | ||
@@ -96,0 +99,0 @@ : '' |
{ | ||
"name": "@charlietango/react-docs-net", | ||
"description": "Package and publish a NuGet package to a custom feed.", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"main": "lib/index.js", | ||
@@ -6,0 +6,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43281
3.36%733
2.23%