/// <summary>Initializes a new instance of the <see cref="CSharpRefitOperationModel" /> class.</summary> /// <param name="operation">The operation.</param> /// <param name="settings">The settings.</param> /// <param name="generator">The generator.</param> /// <param name="resolver">The resolver.</param> public CSharpRefitOperationModel(OpenApiOperation operation, CSharpRefitGeneratorSettings settings, CSharpRefitGenerator generator, CSharpTypeResolver resolver) : base(operation, settings, generator, resolver) { _operation = operation; _generator = generator; _resolver = resolver; _settings = settings; }
static void Main(string[] args) { var swagger = "baseUrl"; var result = OpenApiDocument.FromUrlAsync(swagger).Result; var clientSettings = new CSharpRefitGeneratorSettings { UseActionResultType = true, WrapResponses = false, OperationNameGenerator = new MultipleClientsFromFirstTagAndOperationIdGenerator() }; clientSettings.CodeGeneratorSettings.TemplateFactory = new RefitTemplateFactory(clientSettings.CSharpGeneratorSettings, new Assembly[3] { typeof(CSharpGeneratorSettings).GetTypeInfo().Assembly, typeof(CSharpGeneratorBaseSettings).GetTypeInfo().Assembly, typeof(CSharpRefitGeneratorSettings).GetTypeInfo().Assembly }); clientSettings.CSharpGeneratorSettings.Namespace = "Cms"; clientSettings.CSharpGeneratorSettings.ArrayType = "List"; clientSettings.CSharpGeneratorSettings.ArrayInstanceType = "List"; clientSettings.ResponseArrayType = "ICollection"; clientSettings.ResponseDictionaryType = "IDictionary"; clientSettings.ParameterArrayType = "IEnumerable"; clientSettings.ParameterDictionaryType = "IDictionary"; var clientGenerator = new CSharpRefitGenerator(result, clientSettings); var data = clientGenerator.GetAllClientType(); var models = clientGenerator.GetAllGenerateDtoType(); var dir = Path.Combine("output", clientSettings.CSharpGeneratorSettings.Namespace); var apisPath = Path.Combine(dir, "HttpApis"); var modelsPath = Path.Combine(dir, "HttpModels"); Directory.CreateDirectory(apisPath); Directory.CreateDirectory(modelsPath); foreach (var api in data) { var file = Path.Combine(apisPath, $"{api.TypeName}.cs"); File.WriteAllText(file, api.Code, Encoding.UTF8); Console.WriteLine($"输出接口文件:{file}"); } foreach (var model in models) { var file = Path.Combine(modelsPath, $"{model.TypeName}.cs"); File.WriteAllText(file, model.Code, Encoding.UTF8); Console.WriteLine($"输出模型文件:{file}"); } Console.WriteLine("Hello World!"); }
/// <summary>Initializes a new instance of the <see cref="CSharpRefitTemplateModel" /> class.</summary> /// <param name="controllerName">Name of the controller.</param> /// <param name="operations">The operations.</param> /// <param name="document">The document.</param> /// <param name="settings">The settings.</param> public CSharpRefitTemplateModel( string controllerName, IEnumerable <CSharpOperationModel> operations, OpenApiDocument document, CSharpRefitGeneratorSettings settings) : base(controllerName, settings) { _document = document; _settings = settings; Class = controllerName; Operations = operations; BaseClass = _settings.ControllerBaseClass?.Replace("{controller}", controllerName); NameSpace = _settings.CSharpGeneratorSettings.Namespace; }