Ejemplo n.º 1
0
        public virtual bool VisitCompoundExpression(CompoundExpression expression)
        {
            VisitNodes(expression.Statements);
            VisitExpression(expression);

            return(true);
        }
        public TypeExpression[] compoundExpressionToArray(CompoundExpression args)
        {
            TypeExpression[] aux = new TypeExpression[args.ExpressionCount];
            TypeExpression   te;

            for (int i = 0; i < args.ExpressionCount; i++)
            {
                if ((te = args.GetExpressionElement(i).ILTypeExpression) != null)
                {
                    if (te is FieldType)
                    {
                        te = ((FieldType)te).FieldTypeExpression;
                    }
                    else if (te is UnionType)
                    {
                        te = ((UnionType)te).Simplify(false);
                    }
                    aux[i] = te;
                }
                else
                {
                    return(null);
                }
            }
            return(aux);
        }
Ejemplo n.º 3
0
        public static Predicate ReadFunctionExpression(CompoundExpression exp, Dictionary <string, string> dParameterNameToType, Domain d)
        {
            Constant c     = null;
            string   sName = exp.SubExpressions[0].ToString();

            if (exp.Type == "=")
            {
                GroundedPredicate gp = new GroundedPredicate("=");
                gp.AddConstant(new Constant("cost", "(total-cost)"));
                gp.AddConstant(new Constant("", "0"));
                return(gp);



                /*
                 * string sParam1 = exp.SubExpressions[0].ToString();
                 * string sParam2 = exp.SubExpressions[1].ToString();
                 * if (!dParameterNameToType.ContainsKey(sParam1))
                 *  throw new ArgumentException("First argument of = must be a parameter");
                 * ParameterizedPredicate pp = new ParameterizedPredicate("=");
                 * pp.AddParameter(new Parameter(dParameterNameToType[sParam1], sParam1));
                 * if (dParameterNameToType.ContainsKey(sParam2))
                 *  pp.AddParameter(new Parameter(dParameterNameToType[sParam2], sParam2));
                 * else
                 *  pp.AddParameter(new Constant(d.ConstantNameToType[sParam2], sParam2));
                 * return pp;*/

                /*
                 * Sag: I dont know what was the meaning of this code, but it was meant not to work. If = is given,
                 * dParameterNameToType will be null and then if (!dParameterNameToType.ContainsKey(sParam1)) will throw null exception.
                 * */
            }


            GroundedPredicate p      = new GroundedPredicate(exp.Type);
            double            dValue = 0.0;

            if (d.Functions.Contains(sName))
            {
                c = new Constant("Function", sName);
            }
            else
            {
                throw new ArgumentException("First argument of increase or decrease must be a function");
            }
            p.AddConstant(c);

            sName = exp.SubExpressions[1].ToString();
            if (double.TryParse(sName, out dValue))
            {
                c = new Constant("Number", sName);
            }
            else
            {
                throw new ArgumentException("Second argument of increase or decrease must be a number");
            }
            p.AddConstant(c);
            return(p);
        }
Ejemplo n.º 4
0
 private static void ReadPredicates(CompoundExpression exp, Domain d)
 {
     foreach (Expression e in exp.SubExpressions)
     {
         Predicate p = ReadPredicate((CompoundExpression)e, d);
         d.AddPredicate(p);
     }
 }
Ejemplo n.º 5
0
        public static Problem ParseProblem(string sProblemFile, Domain d)
        {
            StreamReader       sr  = new StreamReader(sProblemFile);
            CompoundExpression exp = (CompoundExpression)ToExpression(sr);

            sr.Close();
            return(ParseProblem(exp, d, sProblemFile));
        }
Ejemplo n.º 6
0
        public override Object Visit(CompoundExpression node, Object obj)
        {
            for (int i = 0; i < node.ExpressionCount; i++)
            {
                node.GetExpressionElement(i).Accept(this, obj);
            }

            return(null);
        }
 public override object Visit(CompoundExpression node, object obj)
 {
     if (node.Location == ((AstNode)obj).Location || found)
     {
         found = true;
         return(this.table);
     }
     return(base.Visit(node, obj));
 }
Ejemplo n.º 8
0
        public override Object Visit(CompoundExpression node, Object obj)
        {
            CompoundExpression clonedCompoundExpression = new CompoundExpression(node.Location);

            for (int i = 0; i < node.ExpressionCount; i++)
            {
                clonedCompoundExpression.AddExpression((Expression)node.GetExpressionElement(i).Accept(this, obj));
            }
            return(clonedCompoundExpression);
        }
Ejemplo n.º 9
0
        public static CompoundFormula ParseFormula(string sFile, Domain d)
        {
            string             sPath = sFile.Substring(0, sFile.LastIndexOf(@"\") + 1);
            StreamReader       sr    = new StreamReader(sFile);
            CompoundExpression exp   = (CompoundExpression)ToExpression(sr);

            sr.Close();
            Formula cf = ReadFormula(exp, null, false, d);

            return((CompoundFormula)cf);
        }
Ejemplo n.º 10
0
        private Func <List <T>, string> GetLambda <T>(params string[] strings)
        {
            var param  = Expression.Parameter(typeof(List <T>), "p");
            var result = CompoundExpression.Enumerator(
                itemCallback: (e) => Expression.Call(e, typeof(T).GetMethod("ToString", new Type[0])),
                enumerable: param);

            Console.WriteLine(result.ToString());

            return(Expression.Lambda <Func <List <T>, string> >(result, param).Compile());
        }
Ejemplo n.º 11
0
 private static void ReadFunctions(CompoundExpression eFunctions, Domain d)
 {
     foreach (Expression eSub in eFunctions.SubExpressions)
     {
         if (eSub.ToString() != ":functions")
         {
             CompoundExpression eFunction = (CompoundExpression)eSub;
             //BUGBUG - only reading non parametrized functions for now
             d.AddFunction("(" + eFunction.Type + ")");
         }
     }
 }
Ejemplo n.º 12
0
        public static void ParseDomainAndProblem(string sFileName, out Domain d, out Problem p)
        {
            string       sPath = sFileName.Substring(0, sFileName.LastIndexOf(@"\") + 1);
            StreamReader sr    = new StreamReader(sFileName);

            Stack <string>     s        = ToStack(sr);
            CompoundExpression eDomain  = (CompoundExpression)ToExpression(s);
            CompoundExpression eProblem = (CompoundExpression)ToExpression(s);

            sr.Close();
            d = ParseDomain(eDomain, sPath, "");
            p = ParseProblem(eProblem, d, "");
        }
Ejemplo n.º 13
0
        public static Domain ParseDomain(string sDomainFile, string sAgentCallsign)
        {
            string             sPath = sDomainFile.Substring(0, sDomainFile.LastIndexOf(@"\") + 1);
            StreamReader       sr    = new StreamReader(sDomainFile);
            CompoundExpression exp   = (CompoundExpression)ToExpression(sr);

            sr.Close();

            Domain d = ParseDomain(exp, sPath, sDomainFile);

            d.AgentCallsign = sAgentCallsign;
            return(d);
        }
Ejemplo n.º 14
0
        public static void CallbackBuilder_Build()
        {
            var cbb = new CallbackBuilder()
            {
                [CompoundExpression.Parse("http://test/{$statusCode}")]   = new Referable <Path>("#/test"),
                [CompoundExpression.Parse("http://test/1/{$statusCode}")] = new Referable <Path>("#/test/1"),
            };
            var cb  = cbb.Build();
            var rcb = new CallbackBuilder(cb);

            Assert.Equal(cbb, cb);
            Assert.Equal(cbb, rcb);
        }
Ejemplo n.º 15
0
        public override Object Visit(CompoundExpression node, Object obj)
        {
            Object aux = null;

            for (int i = 0; i < node.ExpressionCount; i++)
            {
                node.GetExpressionElement(i).LeftExpression = node.LeftExpression;
                if ((aux = node.GetExpressionElement(i).Accept(this, false)) is SingleIdentifierExpression)
                {
                    node.SetExpressionElement(i, (SingleIdentifierExpression)aux);
                }
            }
            return(null);
        }
Ejemplo n.º 16
0
        private static void ReadObserve(CompoundExpression exp, Action pa, Domain d, bool bParametrized)
        {
            string  sOperator = exp.Type;
            Formula f         = null;

            if (pa is ParametrizedAction)
            {
                f = ReadFormula(exp, ((ParametrizedAction)pa).ParameterNameToType, bParametrized, d);
            }
            else
            {
                f = ReadFormula(exp, d.ConstantNameToType, bParametrized, d);
            }
            pa.Observe = f;
        }
Ejemplo n.º 17
0
        private static GroundedPredicate ReadGroundedPredicate(CompoundExpression exp, Domain d)
        {
            GroundedPredicate gp = new GroundedPredicate(exp.Type);
            int      iExpression = 0;
            Constant c           = null;
            string   sName       = "";

            for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
            {
                sName = exp.SubExpressions[iExpression].ToString();
                c     = d.GetConstant(sName);
                gp.AddConstant(c);
            }
            return(gp);
        }
Ejemplo n.º 18
0
        private static Action ReadAction(CompoundExpression exp, Domain d)
        {
            string sName       = exp.SubExpressions[0].ToString();
            Action pa          = null;
            int    iExpression = 0;

            for (iExpression = 1; iExpression < exp.SubExpressions.Count; iExpression++)
            {
                if (exp.SubExpressions[iExpression].ToString() == ":parameters")
                {
                    CompoundExpression ceParams = (CompoundExpression)exp.SubExpressions[iExpression + 1];
                    if (ceParams.Type != "N/A")
                    {
                        pa = new ParametrizedAction(sName);
                        ReadParameters((CompoundExpression)exp.SubExpressions[iExpression + 1], (ParametrizedAction)pa);
                    }
                    iExpression++;
                }
                else if (exp.SubExpressions[iExpression].ToString() == ":effect")
                {
                    if (pa == null)
                    {
                        pa = new Action(sName);
                    }
                    ReadEffect((CompoundExpression)exp.SubExpressions[iExpression + 1], pa, d, pa is ParametrizedAction);
                    iExpression++;
                }
                else if (exp.SubExpressions[iExpression].ToString() == ":precondition")
                {
                    if (pa == null)
                    {
                        pa = new Action(sName);
                    }
                    ReadPrecondition((CompoundExpression)exp.SubExpressions[iExpression + 1], pa, d, pa is ParametrizedAction);
                    iExpression++;
                }
                else if (exp.SubExpressions[iExpression].ToString() == ":observe")
                {
                    if (pa == null)
                    {
                        pa = new Action(sName);
                    }
                    ReadObserve((CompoundExpression)exp.SubExpressions[iExpression + 1], pa, d, pa is ParametrizedAction);
                    iExpression++;
                }
            }
            return(pa);
        }
Ejemplo n.º 19
0
        private static Formula ReadGroundedFormula(CompoundExpression exp, Domain d)
        {
            bool bPredicate = true;

            if (IsUniversalQuantifier(exp))
            {
                CompoundExpression          eParameter           = (CompoundExpression)exp.SubExpressions[0];
                CompoundExpression          eBody                = (CompoundExpression)exp.SubExpressions[1];
                string                      sParameter           = eParameter.Type;
                string                      sType                = eParameter.SubExpressions[1].ToString();
                Dictionary <string, string> dParameterNameToType = new Dictionary <string, string>();
                dParameterNameToType[sParameter] = sType;
                ParametrizedFormula cfQuantified = new ParametrizedFormula(exp.Type);
                cfQuantified.Parameters[sParameter] = sType;
                Formula fBody = ReadFormula(eBody, dParameterNameToType, true, d);
                cfQuantified.AddOperand(fBody);
                return(cfQuantified);
            }
            foreach (Expression eSub in exp.SubExpressions)
            {
                if (eSub is CompoundExpression)
                {
                    bPredicate = false;
                    break;
                }
            }
            if (bPredicate)
            {
                return(new PredicateFormula(ReadGroundedPredicate(exp, d)));
            }
            else
            {
                CompoundFormula cf          = new CompoundFormula(exp.Type);
                int             iExpression = 0;
                for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
                {
                    Formula f = ReadGroundedFormula((CompoundExpression)exp.SubExpressions[iExpression], d);
                    cf.AddOperand(f);
                }
                if (cf.Operator == "not" && cf.Operands[0] is PredicateFormula)
                {
                    return(new PredicateFormula(((PredicateFormula)cf.Operands[0]).Predicate.Negate()));
                }
                return(cf);
            }
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets the type expression of the arguments.
        /// </summary>
        /// <param name="args">Arguments information.</param>
        /// <returns>Returns the argument type expressions </returns>
        private TypeExpression[] compoundExpressionToArray(CompoundExpression args)
        {
            TypeExpression[] aux = new TypeExpression[args.ExpressionCount];
            TypeExpression   te;

            for (int i = 0; i < args.ExpressionCount; i++)
            {
                if ((te = args.GetExpressionElement(i).ExpressionType) != null)
                {
                    aux[i] = te;
                }
                else
                {
                    return(null);
                }
            }
            return(aux);
        }
Ejemplo n.º 21
0
        private static Domain ParseDomain(CompoundExpression exp, string sPath, string sDomainPath)
        {
            Domain d = null;

            foreach (Expression e in exp.SubExpressions)
            {
                if (e is CompoundExpression)
                {
                    CompoundExpression eSub = (CompoundExpression)e;
                    if (eSub.Type == "domain")
                    {
                        d = new Domain(eSub.SubExpressions.First().ToString(), sPath);
                    }
                    else if (eSub.Type == ":requirements")
                    {
                    }
                    else if (eSub.Type == ":types")
                    {
                        foreach (Expression eType in ((CompoundExpression)eSub).SubExpressions)
                        {
                            d.Types.Add(eType.ToString());
                        }
                    }
                    else if (eSub.Type == ":constants")
                    {
                        ReadConstants(eSub, d);
                    }
                    else if (eSub.Type == ":functions")
                    {
                        ReadFunctions(eSub, d);
                    }
                    else if (eSub.Type == ":predicates")
                    {
                        ReadPredicates(eSub, d);
                    }
                    else if (eSub.Type == ":action")
                    {
                        d.AddAction(ReadAction(eSub, d));
                    }
                }
            }
            d.FilePath = sDomainPath;
            return(d);
        }
Ejemplo n.º 22
0
        private static void ReadInitState(Problem p, Domain d, CompoundExpression eInitState)
        {
            foreach (Expression e in eInitState.SubExpressions)
            {
                CompoundExpression eSub = (CompoundExpression)e;
                if (d.IsFunctionExpression(eSub.Type))
                {
                    p.AddKnown(ReadFunctionExpression(eSub, null, d));
                }
                else if (d.ContainsPredicate(eSub.Type))
                {
                    p.AddKnown(ReadGroundedPredicate(eSub, d));
                }
                else
                {
                    if (eSub.Type != "unknown")
                    {
                        Formula f = ReadGroundedFormula(eSub, d);
                        if (f is CompoundFormula)
                        {
                            p.AddHidden((CompoundFormula)f);
                        }
                        if (f is PredicateFormula)//this happens in (not (p)) statments
                        {
                            p.AddKnown(((PredicateFormula)f).Predicate);
                        }
                    }
                    else
                    {
                        //causing a problem - add operand does some basic reasoning - adding p and ~p results in true for or statements.
                        //skipping unknown for now...

                        Predicate       pUnknown = ReadGroundedPredicate((CompoundExpression)eSub.SubExpressions[0], d);
                        CompoundFormula cfOr     = new CompoundFormula("or");
                        cfOr.SimpleAddOperand(pUnknown);
                        cfOr.SimpleAddOperand(pUnknown.Negate());
                        p.AddHidden(cfOr);
                    }
                }
            }
            p.ComputeRelevanceClosure();
        }
Ejemplo n.º 23
0
        private static Expression ToExpression(Stack <string> sStack)
        {
            string sToken = sStack.Pop();

            if (sToken == "(")
            {
                bool bDone             = false;
                CompoundExpression exp = new CompoundExpression();
                sToken = sStack.Pop();
                if (sToken == ")")
                {
                    exp.Type = "N/A";
                    bDone    = true;
                }
                else
                {
                    exp.Type = sToken;
                }
                while (!bDone)
                {
                    if (sStack.Count == 0)
                    {
                        throw new InvalidDataException("Exp " + exp.Type + " was not closed");
                    }
                    sToken = sStack.Pop();
                    if (sToken == ")")
                    {
                        bDone = true;
                    }
                    else
                    {
                        sStack.Push(sToken);
                        exp.SubExpressions.Add(ToExpression(sStack));
                    }
                }
                return(exp);
            }
            else
            {
                return(new StringExpression(sToken));
            }
        }
Ejemplo n.º 24
0
        public static void CompoundExpression_Parse()
        {
            var sut = CompoundExpression.Parse("http://example.com/api/foo?bar={$request.body#/bar}&baz={$url}&foo={$method}{$statusCode}");

            Assert.Equal(7, sut.Count);
            Assert.Equal(ExpressionComponentType.Literal, sut[0].ComponentType);
            Assert.Equal(ExpressionComponentType.Field, sut[1].ComponentType);
            Assert.Equal(ExpressionComponentType.Literal, sut[2].ComponentType);
            Assert.Equal(ExpressionComponentType.Field, sut[3].ComponentType);
            Assert.Equal(ExpressionComponentType.Literal, sut[4].ComponentType);
            Assert.Equal(ExpressionComponentType.Field, sut[5].ComponentType);
            Assert.Equal(ExpressionComponentType.Field, sut[6].ComponentType);

            Assert.Equal("http://example.com/api/foo?bar=", sut[0].ToString());
            Assert.Equal("$request.body#/bar", sut[1].ToString());
            Assert.Equal("&baz=", sut[2].ToString());
            Assert.Equal("$url", sut[3].ToString());
            Assert.Equal("&foo=", sut[4].ToString());
            Assert.Equal("$method", sut[5].ToString());
            Assert.Equal("$statusCode", sut[6].ToString());
        }
Ejemplo n.º 25
0
        public override Object Visit(InvocationExpression node, Object obj)
        {
            CompoundExpression clonedArguments  = (CompoundExpression)node.Arguments.Accept(this, obj);
            Expression         clonedIdentifier = (Expression)node.Identifier.Accept(this, obj);


            InvocationExpression clonedInvocationExpression = new InvocationExpression(clonedIdentifier, clonedArguments, node.Location);

            if (node.ExpressionType != null)
            {
                clonedInvocationExpression.ExpressionType = node.ExpressionType.CloneType(this.typeVariableMappings, this.typeExpresionVariableMapping);
            }
            clonedInvocationExpression.ActualMethodCalled = node.ActualMethodCalled.CloneType(this.typeVariableMappings, this.typeExpresionVariableMapping);

            //var previousShowMessages = ErrorManager.Instance.ShowMessages;
            //ErrorManager.Instance.ShowMessages = false;
            //clonedInvocationExpression.Accept(visitorSpecializer.visitorTypeInference, obj);
            //ErrorManager.Instance.ShowMessages = previousShowMessages;

            clonedInvocationExpression.Accept(visitorSpecializer, obj);
            return(clonedInvocationExpression);
        }
Ejemplo n.º 26
0
        private static void ReadConstants(CompoundExpression exp, Domain d)
        {
            string        sType = "?", sExp = "";
            List <string> lUndefined = new List <string>();

            for (int iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
            {
                sExp = exp.SubExpressions[iExpression].ToString().Trim();
                if (sExp == "-")
                {
                    sType = exp.SubExpressions[iExpression + 1].ToString();
                    iExpression++;
                    foreach (string sName in lUndefined)
                    {
                        Constant newC = new Constant(sType, sName);
                        if (!d.Constants.Contains(newC))
                        {
                            d.AddConstant(newC);
                        }
                    }
                    lUndefined.Clear();
                }
                else if (!sExp.StartsWith(":"))
                {
                    lUndefined.Add(sExp);
                }
            }
            if (lUndefined.Count > 0)
            {
                //supporting objects with undefined types as type "OBJ"
                foreach (string sName in lUndefined)
                {
                    d.AddConstant(new Constant("OBJ", sName));
                }
                //throw new NotImplementedException();
            }
        }
Ejemplo n.º 27
0
        private static Predicate ReadPredicate(CompoundExpression exp, Domain d)
        {
            ParameterizedPredicate pp           = new ParameterizedPredicate(exp.Type);
            int              iExpression        = 0;
            Parameter        p                  = null;
            string           sName              = "";
            List <Parameter> lUntypedParameters = new List <Parameter>();

            for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
            {
                sName = exp.SubExpressions[iExpression].ToString();
                if (sName == "-")
                {
                    string sType = exp.SubExpressions[iExpression + 1].ToString();
                    foreach (Parameter pUntyped in lUntypedParameters)
                    {
                        pUntyped.Type = sType;
                    }
                    lUntypedParameters.Clear();
                    iExpression++;//skip the "-" and the type
                }
                else
                {
                    p = new Parameter("", sName);
                    lUntypedParameters.Add(p);
                    pp.AddParameter(p);
                }
            }
            if (d.Types.Count == 1)
            {
                foreach (Parameter pUntyped in lUntypedParameters)
                {
                    pUntyped.Type = d.Types[0];
                }
            }
            return(pp);
        }
Ejemplo n.º 28
0
        private static void ReadParameters(CompoundExpression exp, ParametrizedAction pa)
        {
            // unfortunately, expressions have a weird non standard structure with no type -(? i - pos ? j - pos )
            //  so we must have a special case
            List <string> lTokens  = exp.ToTokenList();
            List <string> lNames   = new List <string>();
            string        sType    = "";
            int           iCurrent = 0;

            while (iCurrent < lTokens.Count)
            {
                if (lTokens[iCurrent] == "-")
                {
                    sType = lTokens[iCurrent + 1];
                    foreach (string sName in lNames)
                    {
                        pa.AddParameter(new Parameter(sType, sName));
                    }
                    lNames    = new List <string>();
                    sType     = "";
                    iCurrent += 2;
                }
                else
                {
                    lNames.Add(lTokens[iCurrent]);
                    iCurrent++;
                }
            }
            if (lNames.Count != 0) //allowing no types specified
            {
                foreach (string sName in lNames)
                {
                    pa.AddParameter(new Parameter("OBJ", sName));
                }
            }
        }
Ejemplo n.º 29
0
 /// <summary>Gets the element that has the specified key in the read-only dictionary.</summary>
 /// <param name="key">The key to locate.</param>
 /// <returns>The element that has the specified key in the read-only dictionary.</returns>
 /// <exception cref="T:System.ArgumentNullException">
 ///   <paramref name="key">key</paramref> is null.</exception>
 /// <exception cref="T:System.Collections.Generic.KeyNotFoundException">The property is retrieved and <paramref name="key">key</paramref> is not found.</exception>
 public Referable <Path> this[CompoundExpression key]
 {
     get => _dictionary[key];
Ejemplo n.º 30
0
		/////////////////////////////////////////////////////////////////////////////

		public virtual object EvalCompoundExpression( object objIn, CompoundExpression exp )
		{
			// ******
			var obj = objIn;
			foreach( Expression expression in exp.Cast<CompoundExpression>().Items ) {
				object newObj = Process( obj, expression );

				if( null == newObj ) {
					ReturnNull();
				}

				obj = newObj;
			}

			// ******
			return obj;
		}
Ejemplo n.º 31
0
		// ******
		public abstract string DumpCompoundExpression( CompoundExpression exp );
Ejemplo n.º 32
0
        public static void OpenApiSerializer_Serialize()
        {
            var sut = new OpenApiSerializer();

            #region Graph

            var actualGraphBuilder = new DocumentBuilder()
            {
                Components = new ComponentsBuilder()
                {
                    Callbacks =
                    {
                        ["callback1"] = new CallbackBuilder()
                                    {
                                    [CompoundExpression.Parse("http://foo{$statusCode}")] = new PathBuilder()
                                    {
                                    Description = "path1",
                                    Delete      = new OperationBuilder()
                                    {
                                    Callbacks =
                                    {
                                    ["callback1"] = "#/components/callbacks/callback1"
                                    },
                                    Description           = "Delete operation",
                                    ExternalDocumentation = new ExternalDocumentationBuilder()
                                    {
                                    Description = "External docs 1",
                                    Url         = new Uri("http://example.org")
                                    },
                                    OperationIdentifier = "Operation 1",
                                    Options             = OperationOptions.Deprecated,
                                    Parameters          =
                                    {
                                    [new ParameterKey("p1")] = "#/components/parameters/parameter1"
                                    },
                                    RequestBody = "#/components/requestBodies/requestBody1",
                                    Responses   =
                                    {
                                    [ResponseKey.Default] = "#/components/responses/response1"
                                    },
                                    Summary = "Delete operation summary"
                                    },
                                    Get = new OperationBuilder()
                                    {
                                    Description = "Get"
                                    },
                                    Head = new OperationBuilder()
                                    {
                                    Description = "Head"
                                    },
                                    Options = new OperationBuilder()
                                    {
                                    Description = "Options"
                                    },
                                    Parameters =
                                    {
                                    [new ParameterKey("p1")] = "#/components/parameters/parameter1"
                                    },
                                    Patch = new OperationBuilder()
                                    {
                                    Description = "Patch"
                                    },
                                    Post = new OperationBuilder()
                                    {
                                    Description = "Post"
                                    },
                                    Put = new OperationBuilder()
                                    {
                                    Description = "Put"
                                    },
                                    Summary = "Summary",
                                    Trace   = new OperationBuilder()
                                    {
                                    Description = "Trace"
                                    }
                                    }
                                    }
                    },
                    Examples =
                    {
                        ["example1"] = new ExampleBuilder()
                        {
                        Description   = "Description",
                        ExternalValue = new Uri("http://example.org/example"),
                        Summary       = "Summary"
                        }
                    },
                    Headers =
                    {
                        ["header1"] = new ParameterBodyBuilder()
                                            {
                                            Content =
                                            {
                                            [new ContentType("application/json")] = new MediaTypeBuilder()
                                            {
                                            Encoding =
                                            {
                                            ["header1"] = new PropertyEncodingBuilder()
                                            {
                                            ContentType = new ContentType("application/json"),
                                            Headers     =
                                            {
                                            ["header1"] = "#/components/headers/header1"
                                            },
                                            Options = PropertyEncodingOptions.AllowReserved | PropertyEncodingOptions.Explode,
                                            Style   = ParameterStyle.DeepObject
                                            }
                                            },
                                            Examples =
                                            {
                                            ["Main Example"] = "#/components/examples/example1"
                                            },
                                            Schema = "#/components/schemas/schema1"
                                            }
                                            }
                                            }
                    },
                    Links =
                    {
                        ["link1"] = new LinkBuilder()
                                        {
                                        Description         = "Description",
                                        OperationIdentifier = "operation1",
                                        OperationReference  = "http://example.org/#/operation1",
                                        Server = new ServerBuilder()
                                        {
                                        Description = "Description",
                                        Url         = new Uri("http://example.org"),
                                        Variables   =
                                        {
                                        ["variable1"] = new ServerVariableBuilder()
                                        {
                                        Default     = "Value",
                                        Description = "Description",
                                        Enum        =
                                        {
                                        "Value", "Value1"
                                        }
                                        }
                                        }
                                        }
                                        }
                    },
                    Parameters =
                    {
                        ["parameter1"] = new ParameterBuilder()
                                {
                                Content =
                                {
                                [new ContentType("application/json")] = new MediaTypeBuilder()
                                {
                                Schema = "#/components/schemas/schema1"
                                }
                                },
                                Description = "Description",
                                Examples    =
                                {
                                [new ContentType("application/json")] = "#/components/examples/example1"
                                },
                                Location = ParameterLocation.Header,
                                Name     = "parameter1",
                                Options  = ParameterOptions.AllowEmptyValue | ParameterOptions.AllowReserved | ParameterOptions.Deprecated | ParameterOptions.Explode | ParameterOptions.Required,
                                Schema   = "#/components/schemas/schema1",
                                Style    = ParameterStyle.Matrix
                                }
                    },
                    RequestBodies =
                    {
                        ["requestbody1"] = new RequestBodyBuilder()
                                {
                                Content =
                                {
                                [new ContentType("application/json")] = new MediaTypeBuilder()
                                {
                                Schema = "#/components/schemas/schema1"
                                }
                                },
                                Description = "Description",
                                Options     = RequestBodyOptions.Required
                                }
                    },
                    Responses =
                    {
                        ["response1"] = new ResponseBuilder()
                                {
                                Content =
                                {
                                [new ContentType("application/json")] = new MediaTypeBuilder()
                                {
                                Schema = "#/components/schemas/schema1"
                                }
                                },
                                Description = "Description",
                                Headers     =
                                {
                                ["header1"] = "#/components/headers/header1"
                                },
                                Links =
                                {
                                ["link1"] = "#/components/links/link1"
                                }
                                }
                    },
                    Schemas =
                    {
                        ["schema1"] = new SchemaBuilder()
                            {
                            AdditionalProperties =
                            {
                            ["prop1"] = "#/components/schemas/schema1"
                            },
                            Description           = "Description",
                            ExternalDocumentation = new ExternalDocumentationBuilder()
                            {
                            Description = "Description",
                            Url         = new Uri("http://example.org/docs")
                            },
                            Format      = "Format",
                            Items       = "#/components/schemas/schema1",
                            ItemsRange  = new CountRange(100, 200, RangeOptions.Inclusive),
                            LengthRange = new CountRange(200, 300, RangeOptions.Exclusive),
                            NumberRange = new NumberRange(300, 400, RangeOptions.Exclusive),
                            Options     = SchemaOptions.Deprecated | SchemaOptions.Nullable | SchemaOptions.Required | SchemaOptions.UniqueItems,
                            Pattern     = "[a-z]",
                            Properties  =
                            {
                            ["prop1"] = "#/components/schemas/schema1"
                            },
                            PropertiesRange = new CountRange(100, 200),
                            Title           = "Schema1",
                            JsonType        = SchemaType.Object
                            }
                    },
                    SecuritySchemes =
                    {
                        ["sec1"] = new HttpSecuritySchemeBuilder()
                                {
                                BearerFormat = "Bearer",
                                Description  = "Description",
                                Scheme       = "Schema"
                                },
                        ["sec2"] = new ApiKeySecuritySchemeBuilder()
                                {
                                Description = "Description",
                                Location    = ParameterLocation.Cookie,
                                Name        = "Name"
                                },
                        ["sec3"] = new OpenIdConnectSecuritySchemeBuilder()
                                {
                                Description = "Description",
                                Url         = new Uri("http://example.org/openid")
                                },
                        ["sec4"] = new OAuth2SecuritySchemeBuilder()
                                {
                                AuthorizationCodeFlow = new OAuthFlowBuilder()
                                {
                                AuthorizationUrl = new Uri("http://example.org/auth/auth"),
                                RefreshUrl       = new Uri("http://example.org/auth/refresh"),
                                TokenUrl         = new Uri("http://example.org/auth/token"),
                                Scopes           =
                                {
                                ["user:details"] = "Get the user details"
                                }
                                },
                                ClientCredentialsFlow = new OAuthFlowBuilder()
                                {
                                AuthorizationUrl = new Uri("http://example.org/cli/auth")
                                },
                                Description  = "Description",
                                ImplicitFlow = new OAuthFlowBuilder()
                                {
                                AuthorizationUrl = new Uri("http://example.org/imp/auth")
                                },
                                PasswordFlow = new OAuthFlowBuilder()
                                {
                                AuthorizationUrl = new Uri("http://example.org/pwd/auth")
                                }
                                }
                    }
                },
                ExternalDocumentation = new ExternalDocumentationBuilder()
                {
                    Description = "Description",
                    Url         = new Uri("http://example.org/docs")
                },
                Info = new InformationBuilder()
                {
                    Contact = new ContactBuilder()
                    {
                        Email = new MailAddress("*****@*****.**"),
                        Name  = "Jonathan",
                        Url   = new Uri("http://example.org/jonathan")
                    },
                    Description = "Description",
                    License     = new LicenseBuilder()
                    {
                        Name = "MIT",
                        Url  = new Uri("https://opensource.org/licenses/MIT")
                    },
                    TermsOfService = new Uri("http://example.org/tos"),
                    Title          = "Title",
                    Version        = new SemanticVersion(1, 2, 3, "pre1", "build1")
                },
                Version = new SemanticVersion(3, 0, 1),
                Paths   =
                {
                    ["path1"] = new PathBuilder()
                    {
                    Description = "Description"
                    }
                },
                Security =
                {
                    "#/components/security/sec1"
                }
            };

            var actualJson = sut.Serialize(actualGraphBuilder.Build());

            #endregion

            #region JSON

            var expectedJson = new JsonObject()
            {
                ["components"] = new JsonObject()
                {
                    ["callbacks"] = new JsonObject()
                    {
                        ["callback1"] = new JsonObject()
                        {
                            ["http://foo{$statusCode}"] = new JsonObject()
                            {
                                ["delete"] = new JsonObject()
                                {
                                    ["callbacks"] = new JsonObject()
                                    {
                                        ["callback1"] = new JsonObject()
                                        {
                                            ["$ref"] = "#/components/callbacks/callback1"
                                        }
                                    },
                                    ["deprecated"]   = true,
                                    ["description"]  = "Delete operation",
                                    ["externalDocs"] = new JsonObject()
                                    {
                                        ["description"] = "External docs 1",
                                        ["url"]         = "http://example.org/"
                                    },
                                    ["operationId"] = "Operation 1",
                                    ["parameters"]  = new JsonArray()
                                    {
                                        "#/components/parameters/parameter1"
                                    },
                                    ["requestBody"] = "#/components/requestBodies/requestBody1",
                                    ["responses"]   = new JsonObject()
                                    {
                                        ["default"] = new JsonObject()
                                        {
                                            ["$ref"] = "#/components/responses/response1"
                                        }
                                    },
                                    ["summary"] = "Delete operation summary"
                                },
                                ["description"] = "path1",
                                ["get"]         = new JsonObject()
                                {
                                    ["description"] = "Get"
                                },
                                ["head"] = new JsonObject()
                                {
                                    ["description"] = "Head"
                                },
                                ["options"] = new JsonObject()
                                {
                                    ["description"] = "Options"
                                },
                                ["parameters"] = new JsonArray()
                                {
                                    "#/components/parameters/parameter1"
                                },
                                ["patch"] = new JsonObject()
                                {
                                    ["description"] = "Patch"
                                },
                                ["post"] = new JsonObject()
                                {
                                    ["description"] = "Post"
                                },
                                ["put"] = new JsonObject()
                                {
                                    ["description"] = "Put"
                                },
                                ["summary"] = "Summary",
                                ["trace"]   = new JsonObject()
                                {
                                    ["description"] = "Trace"
                                }
                            }
                        }
                    },
                    ["examples"] = new JsonObject()
                    {
                        ["example1"] = new JsonObject()
                        {
                            ["description"]   = "Description",
                            ["externalValue"] = "http://example.org/example",
                            ["summary"]       = "Summary"
                        }
                    },
                    ["headers"] = new JsonObject()
                    {
                        ["header1"] = new JsonObject()
                        {
                            ["content"] = new JsonObject()
                            {
                                ["application/json"] = new JsonObject()
                                {
                                    ["encoding"] = new JsonObject()
                                    {
                                        ["header1"] = new JsonObject()
                                        {
                                            ["allowReserved"] = true,
                                            ["contentType"]   = "application/json",
                                            ["explode"]       = true,
                                            ["headers"]       = new JsonObject()
                                            {
                                                ["header1"] = new JsonObject()
                                                {
                                                    ["$ref"] = "#/components/headers/header1"
                                                }
                                            },
                                            ["style"] = "deepObject"
                                        }
                                    },
                                    ["examples"] = new JsonObject()
                                    {
                                        ["Main Example"] = new JsonObject()
                                        {
                                            ["$ref"] = "#/components/examples/example1"
                                        }
                                    },
                                    ["schema"] = "#/components/schemas/schema1"
                                }
                            }
                        }
                    },
                    ["links"] = new JsonObject()
                    {
                        ["link1"] = new JsonObject()
                        {
                            ["description"]  = "Description",
                            ["operationId"]  = "operation1",
                            ["operationRef"] = "http://example.org/#/operation1",
                            ["server"]       = new JsonObject()
                            {
                                ["description"] = "Description",
                                ["url"]         = "http://example.org/",
                                ["variables"]   = new JsonObject()
                                {
                                    ["variable1"] = new JsonObject()
                                    {
                                        ["default"]     = "Value",
                                        ["description"] = "Description",
                                        ["enum"]        = new JsonArray()
                                        {
                                            "Value",
                                            "Value1"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    ["parameters"] = new JsonObject()
                    {
                        ["parameter1"] = new JsonObject()
                        {
                            ["allowEmptyValue"] = true,
                            ["allowReserved"]   = true,
                            ["content"]         = new JsonObject()
                            {
                                ["application/json"] = new JsonObject()
                                {
                                    ["schema"] = "#/components/schemas/schema1"
                                }
                            },
                            ["deprecated"]  = true,
                            ["description"] = "Description",
                            ["examples"]    = new JsonObject()
                            {
                                ["application/json"] = new JsonObject()
                                {
                                    ["$ref"] = "#/components/examples/example1"
                                }
                            },
                            ["explode"]  = true,
                            ["in"]       = "header",
                            ["name"]     = "parameter1",
                            ["required"] = true,
                            ["schema"]   = "#/components/schemas/schema1",
                            ["style"]    = "matrix"
                        }
                    },
                    ["requestBodies"] = new JsonObject()
                    {
                        ["requestbody1"] = new JsonObject()
                        {
                            ["content"] = new JsonObject()
                            {
                                ["application/json"] = new JsonObject()
                                {
                                    ["schema"] = "#/components/schemas/schema1"
                                }
                            },
                            ["description"]   = "Description",
                            ["requestBodies"] = true
                        }
                    },
                    ["responses"] = new JsonObject()
                    {
                        ["response1"] = new JsonObject()
                        {
                            ["content"] = new JsonObject()
                            {
                                ["application/json"] = new JsonObject()
                                {
                                    ["schema"] = "#/components/schemas/schema1"
                                }
                            },
                            ["description"] = "Description",
                            ["headers"]     = new JsonObject()
                            {
                                ["header1"] = new JsonObject()
                                {
                                    ["$ref"] = "#/components/headers/header1"
                                }
                            },
                            ["links"] = new JsonObject()
                            {
                                ["link1"] = new JsonObject()
                                {
                                    ["$ref"] = "#/components/links/link1"
                                }
                            }
                        }
                    },
                    ["schemas"] = new JsonObject()
                    {
                        ["schema1"] = new JsonObject()
                        {
                            ["additionalProperties"] = new JsonObject()
                            {
                                ["prop1"] = new JsonObject()
                                {
                                    ["$ref"] = "#/components/schemas/schema1"
                                }
                            },
                            ["deprecated"]       = true,
                            ["description"]      = "Description",
                            ["exclusiveMaximum"] = true,
                            ["exclusiveMinimum"] = true,
                            ["externalDocs"]     = new JsonObject()
                            {
                                ["description"] = "Description",
                                ["url"]         = "http://example.org/docs"
                            },
                            ["format"]        = "Format",
                            ["items"]         = "#/components/schemas/schema1",
                            ["maxLength"]     = 300,
                            ["maxProperties"] = 200,
                            ["maximum"]       = 400,
                            ["minLength"]     = 200,
                            ["minProperties"] = 100,
                            ["minimum"]       = 300,
                            ["nullable"]      = true,
                            ["pattern"]       = "[a-z]",
                            ["properties"]    = new JsonObject()
                            {
                                ["prop1"] = new JsonObject()
                                {
                                    ["$ref"] = "#/components/schemas/schema1"
                                }
                            },
                            ["required"]    = true,
                            ["title"]       = "Schema1",
                            ["type"]        = "object",
                            ["uniqueItems"] = true
                        }
                    },
                    ["securitySchemes"] = new JsonObject()
                    {
                        ["sec1"] = new JsonObject()
                        {
                            ["bearerFormat"] = "Bearer",
                            ["description"]  = "Description",
                            ["scheme"]       = "Schema",
                            ["type"]         = "http"
                        },
                        ["sec2"] = new JsonObject()
                        {
                            ["description"] = "Description",
                            ["in"]          = "cookie",
                            ["name"]        = "Name",
                            ["type"]        = "apiKey"
                        },
                        ["sec3"] = new JsonObject()
                        {
                            ["description"]      = "Description",
                            ["openIdConnectUrl"] = "http://example.org/openid",
                            ["type"]             = "openIdConnect"
                        },
                        ["sec4"] = new JsonObject()
                        {
                            ["description"] = "Description",
                            ["flows"]       = new JsonObject()
                            {
                                ["authorizationCode"] = new JsonObject()
                                {
                                    ["authorizationUrl"] = "http://example.org/auth/auth",
                                    ["refreshUrl"]       = "http://example.org/auth/refresh",
                                    ["scopes"]           = new JsonObject()
                                    {
                                        ["user:details"] = "Get the user details"
                                    },
                                    ["tokenUrl"] = "http://example.org/auth/token"
                                },
                                ["clientCredentials"] = new JsonObject()
                                {
                                    ["authorizationUrl"] = "http://example.org/cli/auth",
                                    ["tokenUrl"]         = null
                                },
                                ["implicit"] = new JsonObject()
                                {
                                    ["authorizationUrl"] = "http://example.org/imp/auth",
                                    ["tokenUrl"]         = null
                                },
                                ["password"] = new JsonObject()
                                {
                                    ["authorizationUrl"] = "http://example.org/pwd/auth",
                                    ["tokenUrl"]         = null
                                }
                            },
                            ["type"] = "oauth2"
                        }
                    }
                },
                ["externalDocs"] = new JsonObject()
                {
                    ["description"] = "Description",
                    ["url"]         = "http://example.org/docs"
                },
                ["info"] = new JsonObject()
                {
                    ["contact"] = new JsonObject()
                    {
                        ["email"] = "*****@*****.**",
                        ["name"]  = "Jonathan",
                        ["url"]   = "http://example.org/jonathan"
                    },
                    ["description"] = "Description",
                    ["license"]     = new JsonObject()
                    {
                        ["name"] = "MIT",
                        ["url"]  = "https://opensource.org/licenses/MIT"
                    },
                    ["termsOfService"] = "http://example.org/tos",
                    ["title"]          = "Title",
                    ["version"]        = "1.2.3-pre1+build1"
                },
                ["openapi"] = "3.0.1",
                ["paths"]   = new JsonObject()
                {
                    ["path1"] = new JsonObject()
                    {
                        ["description"] = "Description"
                    }
                },
                ["security"] = new JsonArray()
                {
                    new JsonObject()
                    {
                        ["$ref"] = "#/components/security/sec1"
                    }
                }
            };

            #endregion

            Assert.Equal(expectedJson.ToString(), actualJson.ToString());
        }
Ejemplo n.º 33
0
		/////////////////////////////////////////////////////////////////////////////

		public override string DumpCompoundExpression( CompoundExpression exp )
		{
			// ******
			string typeName = "ExpressionList";

			// ******
			DisplayExpression de = new DisplayExpression();
			string value = de.Dump( exp );

			// ******
			return string.Format( " ({0}) {1}", typeName, value );
		}