kogosoftwarellc / open-api

A Monorepo of various packages to power OpenAPI in node
MIT License
892 stars 235 forks source link

Possibly wrong type for `additionalProperty` and `allOf` in OpenAPI v2 definition #760

Open balanza opened 3 years ago

balanza commented 3 years ago

I may be wrong on this, but I think additionalProperty and allOf parameters should be both defined as OpenAPIV2.SchemaObject; instead, now they are IJsonSchema.

As for OA2 documentation:

The following properties are taken from the JSON Schema definition but their definitions were adjusted to the Swagger Specification. Their definition is the same as the one from JSON Schema, only where the original definition references the JSON Schema definition, the Schema Object definition is used instead.

  • items
  • allOf
  • properties
  • additionalProperties

While properties field is defined as OpenAPIV2.SchemaObject here, and items has its own ItemsObject definition, both additionalProperty and allOf aren't explicitly defined in OpenAPIV2.SchemaObject as they're inherited from IJsonSchema; hence, they are recursively defined as IJsonSchema as well.

This causes issues when modeling nested objects, as they are recursively defined as IJsonSchema, hence having no definition for SchemaObject-specific fields. The following is an example of a valid OA2 declaration which has no mapping in current type definitions:

  AnObject:
    type: object
    additionalProperties:
      type: array
      items:
        $ref: '#/definitions/AnotherObject'

($ref field has no definition in IJsonSchema).

In OA3, you solved the issue by just re-declaring such fields in OpenAPIV3.BaseSchemaObject.

I don't know if my point is even good, or I am missing something. In case, I can provide a PR to fix this.

Thanks