openapi icon indicating copy to clipboard operation
openapi copied to clipboard

Type error thrown when schema uses oneOf

Open maxmurmann opened this issue 4 years ago • 1 comments

schema:

    oneOf:  

         - type: array  

         - type: string 

Will throw

Exception occurred: File "/Users/maxmurmann/opt/anaconda3/envs/bullhorn-apis/lib/python3.8/site-packages/sphinxcontrib/openapi/openapi30.py", line 282, in _httpresource type=param['schema']['type'], KeyError: 'type'

whereas I believe this should be a fine formatting for OpenAPI?

maxmurmann avatar Jul 29 '21 09:07 maxmurmann

This is certainly valid OpenAPI.

freddrake avatar Jul 29 '21 22:07 freddrake

This same issue occurs with anyOf, e.g.:

"schema": {
    "anyOf": [
        {
            "type": "string",
            "format": "date"
        },
        {
            "type": "null"
        }
    ],
}

which should also be valid OpenAPI.

Sphinx : 6.2.1 sphinxcontrib-openapi: 0.8.1

khorn avatar Aug 09 '23 22:08 khorn

Can someone provide a minimal example of a full schema with this used that can be tested against?

stephenfin avatar Aug 10 '23 11:08 stephenfin

This might be related to https://github.com/sphinx-contrib/openapi/issues/96

That issue has a possible workaround (the "experimental renderer") which I might try.

@stephenfin I'll see if I can get a minimal example together.

khorn avatar Aug 14 '23 16:08 khorn

This issue seems to be related as well to #53, #54, and #113. The two latter also proposed fixing changes, though that was years ago, so I don't know if they can be copy-pasted. I'll definitely try the workaround mentioned in #96, but feel free to check out our current build failure on the PR linked to above where I mentioned this issue and let me know how I could help with a fix. The issue does seem to lie with entries like {"name": "table", "in": "query", "required": false, "schema": {"anyOf": [{"type": "boolean"}, {"type": "null"}], "default": false, "title": "Table"}} in our openapi-v1.json. They are created automatically, in this case from line 28 of ixmp4/server/rest/iamc/datapoint.py, which type-hints table as bool | None.

glatterf42 avatar Oct 12 '23 15:10 glatterf42

If the contents of the log file are of any interest: sphinx-err-dzck2sih.log

glatterf42 avatar Oct 12 '23 15:10 glatterf42

With the workaround in #96, the docs "build successfully", but I still see

WARNING: unknown directive or role name: openapi:httpdomain
/home/fridolin/ixmp4/doc/source/devs/ixmp4.server/endpoints.rst:4: ERROR: Error in "openapi:httpdomain" directive:
unknown option: "examples".

.. openapi:httpdomain:: /openapi-v1.json
    :examples:
    :group:

The error can be fixed by removing :examples: and :groups: and using the supported options detailed in issue/96, but this doesn't solve the warning that the directive openapi:httpdomain seems to be unknown.

glatterf42 avatar Oct 13 '23 08:10 glatterf42

Resolved via https://github.com/sphinx-contrib/openapi/pull/143

stephenfin avatar Oct 26 '23 11:10 stephenfin