Avanade/Beef

OpenAPI (Swagger) contains unnecessary models

karamem0 opened this issue · 1 comments

Hi team,

I want to provide OpenAPI (Swagger) json file to other system (e.g. Power Platform). As I checked, the json file seems to contains unnecessary model definitions (System.Reflection.Assembly and its descendant types).

  "definitions": {
    "Assembly": {
      "type": "object",
      "properties": {
        "definedTypes": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/TypeInfo"
          },
          "readOnly": true
        },
    (...)

Assembly type is not refered from API definition, so I want to remove it from json file. Is it possible?

Hi @karamem0,

I have had a look into this and found the culprit. You need to tweak the following code adding the [ApiExplorerSettings(IgnoreApi = true)] line to exclude. TBH, not 100% sure why that operation results in all the reflection types etc.; I think it might be related to the IReferenceData within 🤷‍♂️. This is a specialist operation that I believe is OK to exclude from the OpenAPI output.

        [HttpGet()]
        [Route("ref")]
        [ProducesResponseType(typeof(IEnumerable<CoreEx.RefData.ReferenceDataMultiItem>), (int)HttpStatusCode.OK)]
        [ApiExplorerSettings(IgnoreApi = true)]
        public Task<IActionResult> GetNamed() => _webApi.GetAsync(Request, p => _orchestrator.GetNamedAsync(p.RequestOptions));

I will include this update to the code-gen template (v5 only) as part of the current changes and publish.