Ejemplo n.º 1
0
 public Task<JSchema> GetSchemaFromTemplateAsync(TemplateInfo template)
 {
     // TODO: use async
     var type = _modelTypeRepository.GetModelTypeFromTemplate(template);
     var schemaGenerator = new JSchemaGenerator();
     return Task.FromResult(schemaGenerator.Generate(type));
 }
        private static JSchema GetSchema(Type type)
        {
            JSchemaGenerator generator = new JSchemaGenerator();

            JSchema schema =  generator.Generate(type);

            // I didn't find the way how to disallow JSchemaGenerator to use nullable types, swagger doesn't work with them

            string tmp = schema.ToString();
            string s = @"\""type\"":[\s\n\r]*\[[\s\n\r]*\""(\w+)\"",[\s\n\r]*\""null\""[\s\n\r]*\]";
            tmp = Regex.Replace(tmp, s, "\"type\": \"$1\"");

            return JSchema.Parse(tmp);
        }