public NSwagStudioOptions(INSwagStudioOptions options = null) : base(options) { try { if (options == null) { options = GetFromDialogPage(); } GenerateResponseClasses = options.GenerateResponseClasses; GenerateJsonMethods = options.GenerateJsonMethods; RequiredPropertiesMustBeDefined = options.RequiredPropertiesMustBeDefined; GenerateDefaultValues = options.GenerateDefaultValues; GenerateDataAnnotations = options.GenerateDataAnnotations; } catch (Exception e) { Trace.WriteLine(e); Trace.WriteLine(Environment.NewLine); Trace.WriteLine("Error reading user options. Reverting to default values"); Trace.WriteLine("GenerateResponseClasses = true"); Trace.WriteLine("GenerateJsonMethods = true"); Trace.WriteLine("RequiredPropertiesMustBeDefined = true"); Trace.WriteLine("GenerateDefaultValues = true"); Trace.WriteLine("GenerateDataAnnotations = true"); GenerateResponseClasses = true; GenerateJsonMethods = true; RequiredPropertiesMustBeDefined = true; GenerateDefaultValues = true; GenerateDataAnnotations = true; } }
public static async Task <string> CreateNSwagStudioFileAsync( EnterOpenApiSpecDialogResult enterOpenApiSpecDialogResult, INSwagStudioOptions options = null, string outputNamespace = null) { var specifications = enterOpenApiSpecDialogResult.OpenApiSpecification; var outputFilename = enterOpenApiSpecDialogResult.OutputFilename; var url = enterOpenApiSpecDialogResult.Url; var openApiDocument = url.EndsWith("yaml") || url.EndsWith("yml") ? await OpenApiYamlDocument.FromUrlAsync(url) : await OpenApiDocument.FromJsonAsync(specifications); var className = options?.UseDocumentTitle ?? true ? openApiDocument.GenerateClassName() : outputFilename; return(new { Runtime = "Default", SwaggerGenerator = new { FromSwagger = GetFromSwagger(enterOpenApiSpecDialogResult, specifications) }, CodeGenerators = new { SwaggerToCSharpClient = new { ClassName = className, InjectHttpClient = options?.InjectHttpClient ?? true, GenerateClientInterfaces = options?.GenerateClientInterfaces ?? true, GenerateDtoTypes = options?.GenerateDtoTypes ?? true, UseBaseUrl = options?.UseBaseUrl ?? false, OperationGenerationMode = "MultipleClientsFromOperationId", GenerateResponseClasses = options?.GenerateResponseClasses ?? true, GenerateJsonMethods = options?.GenerateJsonMethods ?? true, RequiredPropertiesMustBeDefined = options?.RequiredPropertiesMustBeDefined ?? true, ClassStyle = options?.ClassStyle ?? CSharpClassStyle.Poco, GenerateDefaultValues = options?.GenerateDefaultValues ?? true, GenerateDataAnnotations = options?.GenerateDataAnnotations ?? true, Namespace = outputNamespace ?? "GeneratedCode", Output = $"{className}.cs" } } } .ToJson()); }
public static async Task <string> CreateNSwagStudioFileAsync( string swaggerJson, string url, INSwagStudioOptions options = null, string outputNamespace = null) { var openApiDocument = await OpenApiDocument.FromJsonAsync(swaggerJson); var className = options?.UseDocumentTitle ?? true?openApiDocument.GenerateClassName() : "GeneratedCode.cs"; return(new { Runtime = "Default", SwaggerGenerator = new { FromSwagger = new { Json = swaggerJson, url } }, CodeGenerators = new { SwaggerToCSharpClient = new { ClassName = className, InjectHttpClient = options?.InjectHttpClient ?? true, GenerateClientInterfaces = options?.GenerateClientInterfaces ?? true, GenerateDtoTypes = options?.GenerateDtoTypes ?? true, UseBaseUrl = options?.UseBaseUrl ?? false, OperationGenerationMode = "MultipleClientsFromOperationId", GenerateResponseClasses = options?.GenerateResponseClasses ?? true, GenerateJsonMethods = options?.GenerateJsonMethods ?? true, RequiredPropertiesMustBeDefined = options?.RequiredPropertiesMustBeDefined ?? true, ClassStyle = options?.ClassStyle ?? CSharpClassStyle.Poco, GenerateDefaultValues = options?.GenerateDefaultValues ?? true, GenerateDataAnnotations = options?.GenerateDataAnnotations ?? true, Namespace = outputNamespace ?? "GeneratedCode", Output = $"{className}.cs" } } } .ToJson()); }
public NSwagStudioOptionsTests() { var mock = new Mock <INSwagStudioOptions>(); options = mock.Object; }
public void Init() { var mock = new Mock <INSwagStudioOptions>(); options = mock.Object; }