public JSchema?Create(ASTAlias astAlias, ASTGenerator generator)
        {
            var schema = new JSchema();

            if (schema != null)
            {
                schema.SchemaVersion = new Uri("http://json-schema.org/draft-07/schema#");
                schema.Title         = astAlias.Name;
                schema.Description   = JsonMapper.Annotate(astAlias.Annotations);

                var _mod  = astAlias.Types.First().Value;
                var _type = astAlias.Types.Last().Value;

                if (_mod == "List")
                {
                    schema.Type = JSchemaType.Array;
                    if (Parser.BaseTypes.Contains(_mod))
                    {
                        schema.Items.Add(JsonMapper.MapBasicType(_type, astAlias, this.CarConfig));
                        return(schema);
                    }
                    else
                    {
                        var typeDef = generator.Find <ASTType>(_type);
                        if (typeDef != null)
                        {
                            var typeSchema = new ASTTypeToJSchema(this.CarConfig).Create(typeDef, generator.AST);
                            schema.Items.Add(typeSchema);
                        }
                    }
                }
                else if (Parser.BaseTypes.Contains(_type))
                {
                    var mappedType = JsonMapper.MapBasicType(_type, astAlias, this.CarConfig);
                    schema.Properties.Clear();
                    schema.Type = mappedType.Type;
                }
                else
                {
                    schema.Type = JSchemaType.Object;
                    var typeDef = generator.Find <ASTType>(_type);
                    if (typeDef != null)
                    {
                        var typeSchema = new ASTTypeToJSchema(this.CarConfig).Create(typeDef, generator.AST);
                        schema.Items.Add(typeSchema);
                    }
                }
            }
            return(schema);
        }
Example #2
0
 public void Start()
 {
     foreach (var node in this.Generator.AST)
     {
         if (node is ASTType _type && _type != null && _type.Directives.Any())
         {
             var apiDirective = _type.Directives.FirstOrDefault(d => d.Key == "api");
             if (!(apiDirective is null) && _type != null)
             {
                 var schema = new ASTTypeToJSchema(this.CarConfig).Create(_type, this.Generator.AST);
                 if (schema != null)
                 {
                     this.Schemas.Add($"{_type.Name}.schema.json", schema);
                 }
             }
         }
Example #3
0
 public void Start()
 {
     foreach (var node in this.Nodes)
     {
         if (node is ASTType && ((ASTType)node).Directives.Any())
         {
             var astType      = (ASTType)node;
             var apiDirective = astType.Directives.FirstOrDefault(d => d.Key == "api");
             if (!(apiDirective is null))
             {
                 this.Schemas.Add($"{astType.Name}.schema.json",
                                  ASTTypeToJSchema.Create(astType, this.Nodes));
             }
         }
     }
 }