.net core WebAPI: get rid of "/swagger/v1/swagger.json" for $ref properties in SwaggerExample in case of returning JSON-Schema value

Viewed 18

Swagger somehow adds some stuff I like to be removed. All examples shown are simplified.

I have a WebAPI with a controller operation which returns JSON-Schemas. It looks like this:

    [SwaggerResponseExample((int)HttpStatusCode.OK, typeof(ServiceDemandContractExamplesProvider))]

    public IActionResult GetContract(string serviceName)
    {
        return Content(jsonSchemaAsString, "application/json")
    }

Then I have a Swagger Example for that Operation looking like this:

    public class ServiceDemandContractExamplesProvider : IMultipleExamplesProvider<JsonDocument>
    {
        public IEnumerable<SwaggerExample<JsonDocument>> GetExamples()
        {
            JsonDocument jsonDocument;
            // Build a JsonDocument which represents a JSON schema.
            // ....
            // check the JSON-String outcome with debugger: 
            // The $ref properties inside the schema points to the correct position in the schema itself, 
            // no '/swagger/v1/swagger.json' content so far
        
            yield return SwaggerExample.Create("Example1", jsonDocument);
        }
    }

When I now create an example like this (simplified): enter image description here

The SwaggerUI shows me the example like that: enter image description here

How can I get rid of that /swagger/v1/swagger.json in the $ref properties?

0 Answers
Related