/// <summary>Initializes a new instance of the <see cref="CSharpOperationModel" /> 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 CSharpOperationModel( SwaggerOperation operation, SwaggerToCSharpGeneratorSettings settings, SwaggerToCSharpGeneratorBase generator, SwaggerToCSharpTypeResolver resolver) : base(resolver.ExceptionSchema, operation, resolver, generator, settings) { _settings = settings; _operation = operation; _generator = generator; _resolver = resolver; var parameters = _operation.ActualParameters.ToList(); if (settings.GenerateOptionalParameters) { parameters = parameters.OrderBy(p => !p.IsRequired).ToList(); } Parameters = parameters.Select(parameter => new CSharpParameterModel(parameter.Name, GetParameterVariableName(parameter, _operation.Parameters), ResolveParameterType(parameter), parameter, parameters, _settings.CodeGeneratorSettings, _generator)) .ToList(); }
public DotvvmSwaggerToCSharpClientGenerator(SwaggerDocument document, SwaggerToCSharpClientGeneratorSettings settings, SwaggerToCSharpTypeResolver resolver) : base(document, settings, resolver) { this.document = document; this.resolver = resolver; }
/// <summary>Initializes a new instance of the <see cref="FileTemplateModel" /> class.</summary> /// <param name="clientCode"></param> /// <param name="outputType"></param> /// <param name="service">The service.</param> /// <param name="settings">The settings.</param> /// <param name="resolver">The resolver.</param> public FileTemplateModel(string clientCode, ClientGeneratorOutputType outputType, SwaggerService service, SwaggerToCSharpGeneratorSettings settings, SwaggerToCSharpTypeResolver resolver) { _clientCode = clientCode; _outputType = outputType; _service = service; _settings = settings; _resolver = resolver; }
/// <summary>Initializes a new instance of the <see cref="FileTemplateModel" /> class.</summary> /// <param name="clientCode">The client code.</param> /// <param name="outputType">Type of the output.</param> /// <param name="document">The Swagger document.</param> /// <param name="clientGeneratorBase">The client generator base.</param> /// <param name="settings">The settings.</param> /// <param name="resolver">The resolver.</param> public FileTemplateModel(string clientCode, ClientGeneratorOutputType outputType, SwaggerDocument document, ClientGeneratorBase clientGeneratorBase, SwaggerToCSharpGeneratorSettings settings, SwaggerToCSharpTypeResolver resolver) { _clientCode = clientCode; _outputType = outputType; _document = document; _clientGeneratorBase = clientGeneratorBase; _settings = settings; _resolver = resolver; }
/// <summary>Initializes a new instance of the <see cref="FileTemplateModel" /> class.</summary> /// <param name="clientCode">The client code.</param> /// <param name="outputType">Type of the output.</param> /// <param name="document">The Swagger document.</param> /// <param name="clientGeneratorBase">The client generator base.</param> /// <param name="settings">The settings.</param> /// <param name="resolver">The resolver.</param> public FileTemplateModel(string clientCode, ClientGeneratorOutputType outputType, SwaggerDocument document, ClientGeneratorBase clientGeneratorBase, SwaggerToCSharpGeneratorSettings settings, SwaggerToCSharpTypeResolver resolver) { _clientCode = clientCode; _outputType = outputType; _document = document; _clientGeneratorBase = clientGeneratorBase; _settings = settings; _resolver = resolver; }
public static (bool isSingleClient, string typeName) GenerateCSharp(SwaggerDocument document, ApiClientDefinition definition, bool promptOnFileOverwrite) { var className = Path.GetFileNameWithoutExtension(definition.CSharpClient); var settings = new SwaggerToCSharpClientGeneratorSettings() { GenerateSyncMethods = true, OperationNameGenerator = new CustomOperationNameGenerator(), GenerateOptionalParameters = true, CSharpGeneratorSettings = { ClassStyle = CSharpClassStyle.Poco, Namespace = definition.Namespace, ArrayType = "System.Collections.Generic.List", PropertyNameGenerator = new CustomPropertyNameGenerator(c => ConversionUtilities.ConvertToUpperCamelCase(c,true)), } }; // detect whether there will be multiple clients or just one var clientNames = document.Operations .Select(o => settings.OperationNameGenerator.GetClientName(document, o.Path, o.Method, o.Operation)) .Distinct() .ToArray(); definition.IsSingleClient = clientNames.Length == 1; if (definition.IsSingleClient) { // set the class name only when Swagger generates one client, otherwise all classes would have the same name settings.ClassName = className; } settings.CSharpGeneratorSettings.TypeNameGenerator = new DotvmmCSharpTypeNameGenerator(settings.CSharpGeneratorSettings, document); settings.CSharpGeneratorSettings.TemplateFactory = new DotvvmClientTemplateFactory(settings.CodeGeneratorSettings, new[] { typeof(CSharpGeneratorSettings).Assembly, typeof(SwaggerToCSharpGeneratorSettings).Assembly }); var resolver = SwaggerToCSharpTypeResolver.CreateWithDefinitions(settings.CSharpGeneratorSettings, document); var generator = new DotvvmSwaggerToCSharpClientGenerator(document, settings, resolver); var csharp = generator.GenerateFile(); if (definition.GenerateWrapperClass && !definition.IsSingleClient) { csharp = ApiClientUtils.InjectWrapperClass(csharp, className, clientNames); } FileSystemHelpers.WriteFile(definition.CSharpClient, csharp, promptOnFileOverwrite); return(definition.IsSingleClient, className); }
/// <summary>Initializes a new instance of the <see cref="CSharpFileTemplateModel" /> class.</summary> /// <param name="clientCode">The client code.</param> /// <param name="outputType">Type of the output.</param> /// <param name="document">The Swagger document.</param> /// <param name="settings">The settings.</param> /// <param name="generator">The client generator base.</param> /// <param name="resolver">The resolver.</param> public CSharpFileTemplateModel( string clientCode, ClientGeneratorOutputType outputType, SwaggerDocument document, SwaggerToCSharpGeneratorSettings settings, SwaggerToCSharpGeneratorBase generator, SwaggerToCSharpTypeResolver resolver) { _clientCode = clientCode; _outputType = outputType; _document = document; _generator = generator; _settings = settings; _resolver = resolver; Classes = GenerateDtoTypes(); }
public static (bool isSingleClient, string typeName) GenerateCSharp(SwaggerDocument document, ApiClientDefinition definition) { var settings = new SwaggerToCSharpClientGeneratorSettings() { GenerateSyncMethods = true, OperationNameGenerator = new CustomOperationNameGenerator(), GenerateOptionalParameters = true, CSharpGeneratorSettings = { ClassStyle = CSharpClassStyle.Poco, Namespace = definition.Namespace, ArrayType = "System.Collections.Generic.List", PropertyNameGenerator = new CustomPropertyNameGenerator(c => ConversionUtilities.ConvertToUpperCamelCase(c,true)), } }; settings.CSharpGeneratorSettings.TypeNameGenerator = new DotvmmCSharpTypeNameGenerator(settings.CSharpGeneratorSettings, document); settings.CSharpGeneratorSettings.TemplateFactory = new DotvvmClientTemplateFactory(settings.CodeGeneratorSettings, new[] { typeof(CSharpGeneratorSettings).Assembly, typeof(SwaggerToCSharpGeneratorSettings).Assembly }); var resolver = SwaggerToCSharpTypeResolver.CreateWithDefinitions(settings.CSharpGeneratorSettings, document); var generator = new DotvvmSwaggerToCSharpClientGenerator(document, settings, resolver); var csharp = generator.GenerateFile(); var newClient = ApiClientUtils.InjectWrapperClass(csharp, Path.GetFileNameWithoutExtension(definition.CSharpClient), document, settings.OperationNameGenerator, out var isSingleClient, out var wrapperTypeName); definition.IsSingleClient = isSingleClient; if (definition.GenerateWrapperClass) { csharp = newClient; } File.WriteAllText(definition.CSharpClient, csharp); return(isSingleClient, wrapperTypeName); }
public DotvvmCSharpOperationModel(SwaggerOperation operation, SwaggerToCSharpGeneratorSettings settings, SwaggerToCSharpGeneratorBase generator, SwaggerToCSharpTypeResolver resolver) : base(operation, settings, generator, resolver) { RewriteParameters(operation, settings, generator); }