Ejemplo n.º 1
0
        private void ShemeModelToParameters(DefinitionModel model)
        {
            if (model == null || model.properties == null)
            {
                return;
            }

            foreach (KeyValuePair <string, PropertyModel> property in model.properties)
            {
                ParameterModel parameter = new ParameterModel
                {
                    In   = ParameterPosition.body,
                    name = property.Key
                };
                if (!string.IsNullOrEmpty(property.Value.type))
                {
                    parameter.type = property.Value.type;
                }
                if (model.required.IndexOf(property.Key) != -1)
                {
                    parameter.required = true;
                }
                else
                {
                    parameter.required = false;
                }

                parameter = ReplaceType(parameter);

                BodyParams.Add(parameter);
                Params.Add(parameter);
            }
        }
Ejemplo n.º 2
0
        public DefinitionModel GetShemeModel(string definitionsName)
        {
            DefinitionModel model = new DefinitionModel();

            definitionsName = definitionsName.Replace("#/definitions/", string.Empty);
            if (structure.definitions.ContainsKey(definitionsName))
            {
                structure.definitions.TryGetValue(definitionsName, out model);
                //TODO: add recursive getModel
            }

            return(model);
        }
Ejemplo n.º 3
0
        private List <ParameterModel> ResponceShemeToParameters(DefinitionModel model)
        {
            List <ParameterModel> responces = new List <ParameterModel>();

            if (model == null || model.properties == null)
            {
                return(responces);
            }

            foreach (KeyValuePair <string, PropertyModel> property in model.properties)
            {
                ParameterModel parameter = new ParameterModel
                {
                    In   = ParameterPosition.responce,
                    name = property.Key
                };
                if (!string.IsNullOrEmpty(property.Value.type))
                {
                    parameter.type = property.Value.type;
                }
                if (model.required.IndexOf(property.Key) != -1)
                {
                    parameter.required = true;
                }
                else
                {
                    parameter.required = false;
                }
                if (property.Value.items != null && !string.IsNullOrEmpty(property.Value.items.refName))
                {
                    DefinitionModel itemsModel = GetShemeModelFunc.Invoke(property.Value.items.refName);
                    parameter.items = ResponceShemeToParameters(itemsModel);
                }
                else if (!string.IsNullOrEmpty(property.Value.refName) && property.Value.refName == "#/definitions/representation.Money")
                {
                    parameter.type = "Price";
                }

                parameter = ReplaceType(parameter);

                responces.Add(parameter);
            }

            return(responces);
        }