bitnami / readme-generator-for-helm

Auto generate READMEs for Helm Charts
https://bitnami.com
Apache License 2.0
212 stars 48 forks source link

Removed empty type for unknown arrays #48

Closed castelblanque closed 1 year ago

castelblanque commented 2 years ago

Description of the change

This change removes the empty type for unknown array items in JSON schemas. Generated schemas were being output with:

"someProperty": {
    "type": "array",
    ...
    "items": {
        "type": ""
    }
}

Given that the item's type is meant as a restriction to the schema, not having any type defined does not add any value. This change does not affect arrays that contain at least one value, only the ones empty that are generated now in this way:

"someProperty": {
    "type": "array",
    ...
    "items": {
        "type": ""
    }
}

Benefits

Cleaner JSON schemas generated, without verbosity.

Possible drawbacks

Empty items type might be there for some practical reason that is unknown to me, and this change might break some logic somewhere?

Applicable issues

Mentioned comment in the original PR that introduced this.

Checklist

fmulero commented 2 years ago

Sorry @castelblanque for my very late response.

According to the schema object defined in OpenAPI v3.0.3:

items - Value MUST be an object and not an array. Inline or referenced schema MUST be of a Schema Object and not a standard JSON Schema. items MUST be present if the type is array.

So we shouldn't remove the items definition for array objects

castelblanque commented 2 years ago

No worries @fmulero , this is not a blocker for us at all.

With this PR we are not removing the items type for types that could be inferred, only for those that could not be found and end up generating "type": "".

Letting structures like

"items": {
  "type": ""
}

only adds verbosity and no meaning whatsoever.

Some schema parsers fail, please try this OpenAPI validator with the following:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Test
paths:
  /thepath:
    get:
      responses:
        200:
          description: OK
components:
  schemas:
    anArray:
      type: array
      items:
        type: 

or this JSON schema validator the following code:

{
  "type": "object",
   "properties": {
      "someProperty": {
        "type": "array",
          "items": {
            "type": ""
          }
      }
    }
}

If we need to keep items according to spec, it is suggested here to output an "any-type" like:

"items": {}

I can do the change, WDYT?