示例#1
0
        /// <summary>Generates the file.</summary>
        /// <param name="clientCode">The client code.</param>
        /// <param name="clientClasses">The client classes.</param>
        /// <param name="outputType">Type of the output.</param>
        /// <returns>The code.</returns>
        protected override string GenerateFile(string clientCode, IEnumerable <string> clientClasses, ClientGeneratorOutputType outputType)
        {
            var model    = new TypeScriptFileTemplateModel(clientCode, clientClasses, _document, _extensionCode, Settings, _resolver);
            var template = BaseSettings.CodeGeneratorSettings.TemplateFactory.CreateTemplate("TypeScript", "File", model);

            return(template.Render());
        }
示例#2
0
        /// <summary>
        /// for common function and dto
        /// </summary>
        /// <returns></returns>
        public string GenerateUtilities()
        {
            //var tempClientCode = "Placeholder Code For SwaggerException!";
            var tempClientCode = new List <CodeArtifact>();

            tempClientCode.Add(new CodeArtifact("tsException", CodeArtifactType.Undefined,
                                                CodeArtifactLanguage.TypeScript, CodeArtifactCategory.Undefined,
                                                "Placeholder Code For SwaggerException!"));
            tempClientCode.Add(new CodeArtifact("clientBaseClass", CodeArtifactType.Class,
                                                CodeArtifactLanguage.TypeScript, CodeArtifactCategory.Utility,
                                                $@"export class {_clientGeneratorSettings.ClientBaseClass} {{
                    public getBaseUrl(defaultUrl: string) {{
                        return process.env.VUE_APP_API_URL || defaultUrl;
                    }}
                }}"));
            var model = new TypeScriptFileTemplateModel(tempClientCode, new List <CodeArtifact>(), _openApiDocument,
                                                        _extensionCode, _clientGeneratorSettings, _resolver);
            var template =
                _clientGeneratorSettings.CodeGeneratorSettings.TemplateFactory.CreateTemplate("TypeScript", "File",
                                                                                              model);
            var utilitiesCode = template.Render();

            utilitiesCode = utilitiesCode.Replace("function ", "export function ")
                            .Replace("Placeholder Code For SwaggerException!", "");
            utilitiesCode = utilitiesCode.Replace("\n\n", "\n").Replace("\n\n", "\n").Replace("\n\n", "\n");
            return(utilitiesCode);
        }
示例#3
0
 public ClientMethodsTemplate(TypeScriptFileTemplateModel model)
 {
     Model = model;
 }
        /// <summary>Renders the client class helper methods.</summary>
        /// <param name="model">The model.</param>
        /// <param name="tabCount">The tab count.</param>
        /// <returns>The helper methods.</returns>
        public static string RenderClientMethodsCode(TypeScriptFileTemplateModel model, int tabCount = 0)
        {
            var tpl = new ClientMethodsTemplate(model);

            return(ConversionUtilities.Tab(tpl.Render(), tabCount));
        }