Specifying allowed media types to generate RAML tools for .NET


#1

I am trying to restrict the amount of media types I generate when using RAML tools for .NET

When generating metadata output I get all available media types in my RAML:

#%RAML 1.0
title: Api
baseUri: /
/api/Scan/Send:
  post:
    description: " (Scan.Send)"
    headers:
    body:
      application/json:
      text/json:
      application/xml:
      text/xml:
      application/x-www-form-urlencoded:

This won’t work in a HTTP Endpoint in Anypoint Studio. I get:

There are multiple input types: [application/xml, application/json, text/json, text/xml, application/x-www-form-urlencoded] . Datasense will not work for this config.

Does anyone have any experience of restricting these types?

I need application/x-www-form-urlencoded only.
Thanks

J


#2
private static string GetRamlContents(string version)
        {
            HttpConfiguration config = GlobalConfiguration.Configuration;
            config.Formatters.Clear();
            config.Formatters.Add(new FormUrlEncodedMediaTypeFormatter());
            var apiExplorer = config.Services.GetApiExplorer();
            var ramlVersion = (version == "0.8" ? RamlVersion.Version08 : RamlVersion.Version1);
            ApiExplorerService apiExplorerService;
            if (ramlVersion == RamlVersion.Version1)
                apiExplorerService = new ApiExplorerServiceVersion1(apiExplorer, config.VirtualPathRoot);
            else
                apiExplorerService = new ApiExplorerServiceVersion08(apiExplorer, config.VirtualPathRoot);

            var ramlDocument = apiExplorerService.GetRaml(ramlVersion);
            var ramlContents = new RamlSerializer().Serialize(ramlDocument);
            return ramlContents;
        }

Just clear the formatters and add a new one:

config.Formatters.Clear();
config.Formatters.Add(new FormUrlEncodedMediaTypeFormatter());