public static JArray Parameter(this JArray parameters, string name, string kind, string description,
                                       Microsoft.OData.Edm.IEdmType type, bool?required)
        {
            var parameter = new JObject()
            {
                { "name", name },
                { "in", kind },
                { "description", description },
            };

            if (kind != "body")
            {
                OData4.SetSwaggerType(parameter, type);
            }
            else
            {
                var schema = new JObject();
                OData4.SetSwaggerType(schema, type);
                parameter.Add("schema", schema);
            }
            if (required != null)
            {
                parameter.Add("required", required);
            }
            parameters.Add(parameter);
            return(parameters);
        }
        public static JObject Response(this JObject responses, string name, string description, Microsoft.OData.Edm.IEdmType type)
        {
            var schema = new JObject();

            OData4.SetSwaggerType(schema, type);
            responses.Add(name, new JObject()
            {
                { "description", description },
                { "schema", schema }
            });
            return(responses);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)

        {
            //  log4net.Config.BasicConfigurator.Configure();
            log.Debug("Converting odatav3 document");
            string samlDisabled = "saml2=disabled";
            bool   disableSAML  = false;
            string username     = null;
            string password     = null;

            if (args.Length < 2)
            {
                Console.WriteLine("Invalid command line arguments");
                Console.WriteLine("Example OData 4: OdataSwaggerConverter.exe http://services.odata.org/V4/TripPinServiceRW trip.json");
                Console.WriteLine("Example OData 3: OdataSwaggerConverter.exe http://services.odata.org/V3/Northwind/Northwind.svc/$metadata northwind.json");
                return;
            }

            string outputFile  = args[1];
            string metadataURI = args[0];

            if (args.Length == 4)
            {
                username = args[2];
                password = args[3];
            }
            else if (args.Length == 5 || args.Length == 3)
            {
                username = args[2];
                password = args[3];
                string samlFlag = args[4].Trim();
                if (samlFlag.Equals(samlDisabled))
                {
                    disableSAML = true;
                    metadataURI = metadataURI + "?" + samlDisabled;
                }
            }

            try
            {
                var url = new Uri(metadataURI);
                HttpResponseValue httpResponseValue = Util.Get(metadataURI, username, password);
                int    statusCode   = httpResponseValue.getStatusCode();
                string responseBody = httpResponseValue.getResponseBody();
                string contentType  = httpResponseValue.getContentType();

                log.Debug("Response Http Status code : " + statusCode);
                log.Debug("Response from metadata URI : " + responseBody);
                log.Debug("Response Content-Type : " + contentType);

                if (statusCode == 200)
                {
                    if (contentType.Contains("application/json"))
                    {
                        log.Info("Processing odata 4 meta data");
                        OData4.process(url, username, password, httpResponseValue.getResponseBody(), outputFile);
                    }
                    else if (contentType.Contains("application/xml"))
                    {
                        StringReader stringReader = new StringReader(responseBody);
                        IEdmModel    model        = EdmxReader.Parse(System.Xml.XmlTextReader.Create(stringReader));
                        process(url, model, outputFile, disableSAML);
                    }
                }
            }catch (Exception e)
            {
                log.Error("Problem in reading meta data file", e);
                return;
            }
        }