private string GetSchemaValueBasedOnContentType(RESTReturnedSchemaTemplateProperties schemaTemplateProperties)
        {
            if (!(schemaTemplateProperties.document is JToken))
            {
                return(JsonConvert.SerializeObject(schemaTemplateProperties.document));
            }

            var schemaJson = schemaTemplateProperties.document as JToken;

            switch (schemaTemplateProperties.contentType.ToLowerInvariant())
            {
            case "application/vnd.ms-azure-apim.swagger.definitions+json":
                if (schemaJson["definitions"] != null && schemaJson.Count() == 1)
                {
                    schemaJson = schemaJson["definitions"];
                }
                break;

            case "application/vnd.ms-azure-apim.xsd+xml":
                if (schemaJson["value"] != null && schemaJson.Count() == 1)
                {
                    return(schemaJson["value"].ToString());
                }
                break;
            }

            return(JsonConvert.SerializeObject(schemaJson));
        }
예제 #2
0
        private string GetSchemaValueBasedOnContentType(RESTReturnedSchemaTemplateProperties schemaTemplateProperties)
        {
            var contentType = schemaTemplateProperties.contentType.ToLowerInvariant();

            if (contentType.Equals("application/vnd.oai.openapi.components+json"))
            {
                // for OpenAPI "value" is not used, but "components" which is resolved during json deserialization
                return(null);
            }

            if (!(schemaTemplateProperties.document is JToken))
            {
                return(JsonConvert.SerializeObject(schemaTemplateProperties.document));
            }

            var schemaJson = schemaTemplateProperties.document as JToken;

            switch (contentType)
            {
            case "application/vnd.ms-azure-apim.swagger.definitions+json":
                if (schemaJson["definitions"] != null && schemaJson.Count() == 1)
                {
                    schemaJson = schemaJson["definitions"];
                }
                break;

            case "application/vnd.ms-azure-apim.xsd+xml":
                if (schemaJson["value"] != null && schemaJson.Count() == 1)
                {
                    return(schemaJson["value"].ToString());
                }
                break;
            }

            return(JsonConvert.SerializeObject(schemaJson));
        }