PhilanthropyDataCommons / service

A project for collecting and serving public information associated with grant applications
GNU Affero General Public License v3.0
8 stars 2 forks source link

Some types allow for `any` in @pdc-sdk #1004

Closed hminsky2002 closed 2 months ago

hminsky2002 commented 2 months ago

While working on pdc front-end issue 705 I discovered that, currently, our @pdc-sdk allows for type 'any' in multiple different schemas.

Image Image Image

Per my understanding of the sdk and a discussion with @slifty in front-end PR 719, it seems like these are erroneous and should be fixed to be only of a specific type!

slifty commented 2 months ago

The root cause here is that these fields use allOf in order to mark certain items as readonly.

For instance: https://github.com/PhilanthropyDataCommons/service/blob/c1f7e8717beb727d622bfd4273aaae450ed68dce/src/openapi.json#L199-L206

The code gen is treating both of those as separate entities, and using & to combine them. One might think "oh, well, BaseField is narrower than any so it should collapse to just BaseField" but apparently not.

This is partly related to #854, which would prevent the need to use that pattern.

Unfortunately the components of the swagger ecosystem that add that & any are not necessarily directly in our control. That said, I'll look into whether we can use a different pattern in our specification or if it's possible to update the code generation script.

slifty commented 2 months ago

OK! It looks like switching to this format does the trick (hat tip https://stackoverflow.com/questions/51402156/how-to-declare-a-ref-property-as-readonly-in-openapi-swagger)

                    "applicationFormField": {
                        "readOnly": true,
                        "allOf": [
                            {
                                "$ref": "#/components/schemas/ApplicationFormField"
                            }
                        ]
                    },