itaustralia
itaustralia

Reputation: 197

How to create swagger document for unknown type using OpenAPI 3.0

I am trying to build swagger document from asp.net core api application. Issue I am facing is my response object ProductResponse (see below for detail) which has IEnumerable of string as property.

String is JSON object

which could be anything (unknown type) (different key/value).

How can I build swagger document for unknown type using OpenAPI 3.0. Any advice?

Response Object like below

{
  "items": [
    "string"
  ]
}

WebApi .Net core Code as below

 /// <summary>
    /// Get product
    /// </summary>
    /// <remarks>product</remarks>
    /// <param name="RequestDto"></param>
    /// <returns></returns>
    /// <response code="200">Successful Response</response>
    /// <response code="400">Bad Request</response>
    /// <response code="401">Unauthorized</response>
    /// <response code="424">Failed Dependency</response>
    /// <response code="500">Internal Server Error</response>
    [ProducesResponseType(typeof(ProductResponse), StatusCodes.Status200OK)]
    [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status400BadRequest)]
    [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status401Unauthorized)]
    [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status424FailedDependency)]
    [ProducesResponseType(typeof(ErrorResponse), StatusCodes.Status500InternalServerError)]
    [HttpGet(Name = "getProduct")]
    public async Task<IActionResult> Get([FromQuery]Request RequestDto)
    {
       ....some code here.
    }

public class ProductResponse
{
 [JsonPropertyName("data")]
 public IEnumerable<string> data { get; set; } = Enumerable.Empty<string>();
}

Upvotes: 2

Views: 3096

Answers (1)

Md Farid Uddin Kiron
Md Farid Uddin Kiron

Reputation: 22549

How can I build swagger document for unknown type using OpenAPI 3.0. Any advice?

As we know swagger has following data type up to now.

string (this includes dates and files)
number
integer
boolean
array
object

Thorefore, A schema which doesn't matches within the above mentioned data-type are called Any Type

enter image description here

Note: If you need any further information please refer to this offical document here

Upvotes: 1

Related Questions