/// <summary>Initializes a new instance of the <see cref="SwaggerToCSharpClientGeneratorSettings"/> class.</summary>
 protected SwaggerToCSharpGeneratorSettings()
 {
     AdditionalNamespaceUsages = null;
     CSharpGeneratorSettings = new CSharpGeneratorSettings
     {
         Namespace = "MyNamespace"
     };
 }
예제 #2
0
        /// <summary>Creates a new resolver, adds the given schema definitions and registers an exception schema if available.</summary>
        /// <param name="settings">The settings.</param>
        /// <param name="definitions">The definitions.</param>
        public static SwaggerToCSharpTypeResolver CreateWithDefinitions(CSharpGeneratorSettings settings, IDictionary<string, JsonSchema4> definitions)
        {
            var exceptionSchema = definitions.ContainsKey("Exception") ? definitions["Exception"] : null;

            var resolver = new SwaggerToCSharpTypeResolver(settings, exceptionSchema);
            resolver.AddGenerators(definitions
                .Where(p => p.Value != exceptionSchema)
                .ToDictionary(p => p.Key, p => p.Value));

            return resolver;
        }
        /// <summary>Generates the JSON converters array code.</summary>
        /// <param name="settings">The settings.</param>
        /// <param name="additionalJsonConverters">The additional JSON converters.</param>
        /// <returns>The code.</returns>
        public static string GenerateJsonConvertersArrayCode(CSharpGeneratorSettings settings, IEnumerable <string> additionalJsonConverters)
        {
            var jsonConverters = GetJsonConverters(settings, additionalJsonConverters);

            return(GenerateConverters(jsonConverters, settings.JsonLibrary));
        }
예제 #4
0
 /// <summary>Initializes a new instance of the <see cref="CSharpTypeResolver"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 /// <param name="exceptionSchema">The exception type schema.</param>
 public CSharpTypeResolver(CSharpGeneratorSettings settings, JsonSchema4 exceptionSchema)
     : base(settings)
 {
     Settings        = settings;
     ExceptionSchema = exceptionSchema;
 }
 /// <summary>Initializes a new instance of the <see cref="CSharpDefaultValueGenerator" /> class.</summary>
 /// <param name="typeResolver">The type resolver.</param>
 /// <param name="settings">The settings.</param>
 public CSharpDefaultValueGenerator(ITypeResolver typeResolver, CSharpGeneratorSettings settings)
     : base(typeResolver, settings.EnumNameGenerator)
 {
     _settings = settings;
 }
예제 #6
0
 /// <summary>Initializes a new instance of the <see cref="CSharpTypeResolver"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 public CSharpTypeResolver(CSharpGeneratorSettings settings)
     : base(settings.TypeNameGenerator)
 {
     Settings = settings;
 }
예제 #7
0
 /// <summary>Initializes a new instance of the <see cref="CSharpTypeResolver"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 public CSharpTypeResolver(CSharpGeneratorSettings settings)
 {
     Settings = settings;
 }
예제 #8
0
 /// <summary>Initializes a new instance of the <see cref="CSharpTypeResolver"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 /// <param name="rootObject">The root object to search for JSON Schemas.</param>
 public CSharpTypeResolver(CSharpGeneratorSettings settings, object rootObject)
     : base(settings)
 {
     _rootObject = rootObject;
     Settings    = settings;
 }
예제 #9
0
 /// <summary>Initializes a new instance of the <see cref="CSharpGenerator"/> class.</summary>
 /// <param name="schema">The schema.</param>
 /// <param name="settings">The generator settings.</param>
 public CSharpGenerator(JsonSchema4 schema, CSharpGeneratorSettings settings)
     : this(schema, settings, new CSharpTypeResolver(settings))
 {
 }
예제 #10
0
 /// <summary>Initializes a new instance of the <see cref="CSharpTypeResolver" /> class.</summary>
 /// <param name="settings">The generator settings.</param>
 /// <param name="exceptionSchema">The exception type schema.</param>
 public SwaggerToCSharpTypeResolver(CSharpGeneratorSettings settings, JsonSchema4 exceptionSchema)
     : base(settings)
 {
     ExceptionSchema = exceptionSchema;
 }
예제 #11
0
 /// <summary>Initializes a new instance of the <see cref="CSharpValueGenerator" /> class.</summary>
 /// <param name="typeResolver">The type resolver.</param>
 /// <param name="settings">The settings.</param>
 public CSharpValueGenerator(TypeResolverBase typeResolver, CSharpGeneratorSettings settings)
     : base(typeResolver, settings.EnumNameGenerator)
 {
     _settings = settings;
 }
예제 #12
0
 /// <summary>Initializes a new instance of the <see cref="CSharpGenerator"/> class.</summary>
 /// <param name="rootObject">The root object to search for all JSON Schemas.</param>
 /// <param name="settings">The generator settings.</param>
 /// <param name="resolver">The resolver.</param>
 public CSharpGenerator(object rootObject, CSharpGeneratorSettings settings, CSharpTypeResolver resolver)
     : base(rootObject, resolver, settings)
 {
     _resolver = resolver;
     Settings  = settings;
 }
예제 #13
0
 /// <summary>Initializes a new instance of the <see cref="CSharpGenerator"/> class.</summary>
 /// <param name="rootObject">The root object to search for all JSON Schemas.</param>
 /// <param name="settings">The generator settings.</param>
 public CSharpGenerator(object rootObject, CSharpGeneratorSettings settings)
     : this(rootObject, settings, new CSharpTypeResolver(settings))
 {
 }
 private static List <string> GetJsonConverters(CSharpGeneratorSettings settings, IEnumerable <string> additionalJsonConverters)
 {
     return((settings.JsonConverters ?? new string[0]).Concat(additionalJsonConverters ?? new string[0]).ToList());
 }
 /// <summary>Initializes a new instance of the <see cref="SwaggerToCSharpGeneratorSettings"/> class.</summary>
 public SwaggerToCSharpGeneratorSettings()
 {
     ClassName = "{controller}Client";
     AdditionalNamespaceUsages = null;
     CSharpGeneratorSettings = new CSharpGeneratorSettings();
 }
예제 #16
0
 internal SwaggerToCSharpGenerator(SwaggerService service, CSharpGeneratorSettings settings)
 {
     Resolver = new SwaggerToCSharpTypeResolver(settings, service.Definitions);
 }
예제 #17
0
 /// <summary>Initializes a new instance of the <see cref="CSharpValueGenerator" /> class.</summary>
 /// <param name="settings">The settings.</param>
 public CSharpValueGenerator(CSharpGeneratorSettings settings)
     : base(settings)
 {
     _settings = settings;
 }
예제 #18
0
 /// <summary>Initializes a new instance of the <see cref="CSharpGenerator"/> class.</summary>
 /// <param name="schema">The schema.</param>
 /// <param name="settings">The generator settings.</param>
 /// <param name="resolver">The resolver.</param>
 public CSharpGenerator(JsonSchema4 schema, CSharpGeneratorSettings settings, CSharpTypeResolver resolver)
 {
     _schema   = schema;
     _resolver = resolver;
     Settings  = settings;
 }
예제 #19
0
 /// <summary>Initializes a new instance of the <see cref="CSharpTypeResolver"/> class.</summary>
 /// <param name="settings">The generator settings.</param>
 public CSharpTypeResolver(CSharpGeneratorSettings settings)
     : this(settings, null)
 {
 }
예제 #20
0
 public JsonSchemaToCSharpCommand()
 {
     Settings = new CSharpGeneratorSettings();
 }
예제 #21
0
 /// <summary>Initializes a new instance of the <see cref="CSharpTypeResolver" /> class.</summary>
 /// <param name="definition">The definition.</param>
 /// <param name="settings">The generator settings.</param>
 public SwaggerToCSharpTypeResolver(CSharpGeneratorSettings settings, IDictionary<string, JsonSchema4> definition)
     : base(settings, definition.Where(p => p.Key != "Exception").Select(p => p.Value).ToArray())
 {
     _exceptionSchema = definition.ContainsKey("Exception") ? definition["Exception"] : null;
 }
예제 #22
0
 /// <summary>Initializes a new instance of the <see cref="CSharpGenerator"/> class.</summary>
 /// <param name="schema">The schema.</param>
 /// <param name="settings">The generator settings.</param>
 public CSharpGenerator(JsonSchema4 schema, CSharpGeneratorSettings settings)
     : this(schema, settings, new CSharpTypeResolver(settings))
 {
 }
예제 #23
0
 /// <summary>Initializes a new instance of the <see cref="CSharpGenerator"/> class.</summary>
 /// <param name="schema">The schema.</param>
 /// <param name="settings">The generator settings.</param>
 /// <param name="resolver">The resolver.</param>
 public CSharpGenerator(JsonSchema4 schema, CSharpGeneratorSettings settings, CSharpTypeResolver resolver)
 {
     _schema = schema;
     _resolver = resolver;
     Settings = settings;
 }
예제 #24
-1
 public override async Task RunAsync(CommandLineProcessor processor, IConsoleHost host)
 {
     var settings = new CSharpGeneratorSettings
     {
         Namespace = Namespace,
         RequiredPropertiesMustBeDefined = RequiredPropertiesMustBeDefined,
         DateTimeType = DateTimeType
     };
     
     var schema = JsonSchema4.FromJson(InputJson);
     var generator = new CSharpGenerator(schema, settings);
     var code = generator.GenerateFile();
     WriteOutput(host, code);
 }
예제 #25
-1
 private static CSharpGenerator CreateGenerator()
 {
     var schema = JsonSchema4.FromType<Teacher>();
     var schemaData = schema.ToJson();
     var settings = new CSharpGeneratorSettings();
     settings.Namespace = "MyNamespace";
     var generator = new CSharpGenerator(schema, settings);
     return generator;
 }