/// <summary>Generates the type.</summary> /// <param name="typeNameHint">The fallback type name.</param> /// <returns>The code.</returns> public override TypeGeneratorResult GenerateType(string typeNameHint) { var typeName = _resolver.GetOrGenerateTypeName(_schema, typeNameHint); if (_schema.IsEnumeration) { var model = new EnumTemplateModel(typeName, _schema, Settings); var template = Settings.TemplateFactory.CreateTemplate("TypeScript", "Enum", model); return(new TypeGeneratorResult { TypeName = typeName, Code = template.Render() }); } else { var model = new ClassTemplateModel(typeName, typeNameHint, Settings, _resolver, _schema, RootObject); var template = Settings.CreateTemplate(typeName, model); return(new TypeGeneratorResult { TypeName = typeName, BaseTypeName = model.BaseClass, Code = template.Render() }); } }
/// <summary>Generates the type.</summary> /// <param name="schema">The schema.</param> /// <param name="typeNameHint">The fallback type name.</param> /// <returns>The code.</returns> protected override CodeArtifact GenerateType(JsonSchema schema, string typeNameHint) { var typeName = _resolver.GetOrGenerateTypeName(schema, typeNameHint); if (schema.IsEnumeration) { var model = new EnumTemplateModel(typeName, schema, Settings); var template = Settings.TemplateFactory.CreateTemplate("TypeScript", "Enum", model); return(new CodeArtifact(typeName, CodeArtifactType.Enum, CodeArtifactLanguage.TypeScript, CodeArtifactCategory.Contract, template)); } else { var model = new ClassTemplateModel(typeName, typeNameHint, Settings, _resolver, schema, RootObject); var template = Settings.CreateTemplate(typeName, model); var type = Settings.TypeStyle == TypeScriptTypeStyle.Interface ? CodeArtifactType.Interface : CodeArtifactType.Class; return(new CodeArtifact(typeName, model.BaseClass, type, CodeArtifactLanguage.TypeScript, CodeArtifactCategory.Contract, template)); } }
/// <summary>Generates the type.</summary> /// <param name="schema">The schema.</param> /// <param name="typeNameHint">The fallback type name.</param> /// <returns>The code.</returns> protected override CodeArtifact GenerateType(JsonSchema schema, string typeNameHint) { var typeName = _resolver.GetOrGenerateTypeName(schema, typeNameHint); if (schema.IsEnumeration) { var model = new EnumTemplateModel(typeName, schema, Settings); string templateName; if (Settings.EnumStyle == TypeScriptEnumStyle.Enum) { templateName = nameof(TypeScriptEnumStyle.Enum); } else if (Settings.EnumStyle == TypeScriptEnumStyle.StringLiteral) { templateName = $"{nameof(TypeScriptEnumStyle.Enum)}.{nameof(TypeScriptEnumStyle.StringLiteral)}"; } else { throw new ArgumentOutOfRangeException(nameof(Settings.EnumStyle), Settings.EnumStyle, "Unknown enum style"); } var template = Settings.TemplateFactory.CreateTemplate("TypeScript", templateName, model); return(new CodeArtifact(typeName, CodeArtifactType.Enum, CodeArtifactLanguage.TypeScript, CodeArtifactCategory.Contract, template)); } else { var model = new ClassTemplateModel(typeName, typeNameHint, Settings, _resolver, schema, RootObject); var template = Settings.CreateTemplate(typeName, model); var type = Settings.TypeStyle == TypeScriptTypeStyle.Interface ? CodeArtifactType.Interface : CodeArtifactType.Class; return(new CodeArtifact(typeName, model.BaseClass, type, CodeArtifactLanguage.TypeScript, CodeArtifactCategory.Contract, template)); } }