Describes a JSON web service.
Наследование: IDocumentPathProvider
Пример #1
0
        /// <summary>Initializes a new instance of the <see cref="SwaggerSchemaResolver" /> class.</summary>
        /// <param name="document">The Swagger document.</param>
        /// <param name="settings">The settings.</param>
        /// <exception cref="ArgumentNullException"><paramref name="document" /> is <see langword="null" /></exception>
        public SwaggerSchemaResolver(SwaggerDocument document, JsonSchemaGeneratorSettings settings)
            : base(settings)
        {
            if (document == null)
                throw new ArgumentNullException(nameof(document));

            _document = document;
            _typeNameGenerator = settings.TypeNameGenerator;
        }
Пример #2
0
        public string Gen(SwaggerDocument service, SwaggerToolSettings setting)
        {
            var settings = new SwaggerToCSharpClientGeneratorSettings
            {
                ClassName = setting.CSharpGen.ClassName,
                 CSharpGeneratorSettings=new NJsonSchema.CodeGeneration.CSharp.CSharpGeneratorSettings() {  Namespace= setting.CSharpGen.Namespace}
            };

            var generator = new SwaggerToCSharpClientGenerator(service, settings);
            var code = generator.GenerateFile();

            return code;
        }
        public string Gen(SwaggerDocument service,string root,SwaggerToolSettings setting)
        {
            var collectionId = PostMan.GetId();
            var apis = service.Operations;
            var requests = GetPostmanRequests(apis, collectionId, root,setting);
            var collection = new PostmanCollection
            {
                id = collectionId,
                name = setting.PostmanGen.name,
                description = "",
                //在文件夹出现的order Id不能出现该order中
               // order = requests.Select(x => x.id).ToList(),
                timestamp = DateTime.Now.DateTimeToStamp(),
                requests = requests
            };

            //按照tag分组
            List<Postfolder> folders = new List<Postfolder>();
                var groups = requests.GroupBy(s => s.tagname);
                foreach (var item in groups)
                {
                    Postfolder floder = new Postfolder();
                    floder.id = PostMan.GetId();
                if (service.Tags != null)
                {
                    var desc = service.Tags.Where(p => p.Name == item.Key).FirstOrDefault();
                    if (desc!=null)
                    {
                        floder.name = desc.Description;
                    }
                    else
                    {
                        floder.name = item.Key;
                    }
                   
                }
                else
                {
                    floder.name = item.Key;
                }
                floder.order = requests.Where(p => p.tagname == item.Key).Select(s => s.id).ToList();

                foreach (var req in requests.Where(p => p.tagname == item.Key).ToList())
                {
                    req.folder = floder.id;
                }
                folders.Add(floder);
            }
            collection.folders = folders;
            return JsonConvert.SerializeObject(collection);
        }
        public string Gen(SwaggerDocument service, SwaggerToolSettings setting, TypeScriptTemplate Template)
        {
            var settings = new SwaggerToTypeScriptClientGeneratorSettings
            {
                ClassName =setting.TypeScriptGen.ClassName,
                Template = Template,
                PromiseType=PromiseType.Promise,
                TypeScriptGeneratorSettings=new NJsonSchema.CodeGeneration.TypeScript.TypeScriptGeneratorSettings() { ModuleName= setting.TypeScriptGen.ModuleName }
            };
        

        var generator = new SwaggerToTypeScriptClientGenerator(service, settings);
        var code = generator.GenerateFile();
            return code;
    }
Пример #5
0
 public string Gen(string type, SwaggerDocument service, SwaggerToolSettings setting)
 {
     switch (type)
     {
         case "CSharp":
             { return new CSharpGen().Gen(service, setting); }
         case "JQueryCallbacks":
         case "JQueryPromises":
         case "AngularJS":
         case "Angular2":
             {
                 return new TypeScriptGen().Gen(service, setting,(TypeScriptTemplate)Enum.Parse(typeof(TypeScriptTemplate),type));
             }
         default:
             return "Don't support  "+type+" Keyword";
     }
 }