docusaurus-openapi-docs icon indicating copy to clipboard operation
docusaurus-openapi-docs copied to clipboard

Error when generating API docs - "Error: No resolver found for key if"

Open hadar-co opened this issue 1 year ago • 0 comments

Describe the bug

When running npx docusaurus gen-api-docs all against my JSON schema, I get the following error:

Error: No resolver found for key if. You can provide a resolver for this keyword in the options, or provide a default resolver.
    at /Users/hadar/Desktop/Source/docs/fourth/port-docs/node_modules/json-schema-merge-allof/src/index.js:314:30
    at Array.forEach (<anonymous>)
    at mergeSchemas (/Users/hadar/Desktop/Source/docs/fourth/port-docs/node_modules/json-schema-merge-allof/src/index.js:301:13)
    at merger (/Users/hadar/Desktop/Source/docs/fourth/port-docs/node_modules/json-schema-merge-allof/src/index.js:334:18)
    at mergeAllOf (/Users/hadar/Desktop/Source/docs/fourth/port-docs/node_modules/docusaurus-plugin-openapi-docs/lib/markdown/createSchema.js:26:27)
    at createNodes (/Users/hadar/Desktop/Source/docs/fourth/port-docs/node_modules/docusaurus-plugin-openapi-docs/lib/markdown/createSchema.js:575:35)
    at /Users/hadar/Desktop/Source/docs/fourth/port-docs/node_modules/docusaurus-plugin-openapi-docs/lib/markdown/createSchema.js:75:45
    at Array.map (<anonymous>)
    at createAnyOneOf (/Users/hadar/Desktop/Source/docs/fourth/port-docs/node_modules/docusaurus-plugin-openapi-docs/lib/markdown/createSchema.js:65:40)
    at createItems (/Users/hadar/Desktop/Source/docs/fourth/port-docs/node_modules/docusaurus-plugin-openapi-docs/lib/markdown/createSchema.js:221:13)

The schema passes OpenAPI validation.

Expected behavior

Docs should be generated successfully.

Current behavior

Docs generation fails with an error.

Steps to reproduce

  1. Use a schema that contains the following properties:
"allOf": [
                {
                    "if": {
                        "properties": {
                            "urlType": {
                                "enum": [
                                    "protected"
                                ]
                            }
                        }
                    },
                    "then": {
                        "properties": {
                            "tokenUrl": {
                                "type": "string",
                                "format": "url"
                            },
                            "authorizationUrl": {
                                "type": "string",
                                "format": "url"
                            },
                            "clientId": {
                                "type": "string"
                            },
                            "scopes": {
                                "type": "array",
                                "items": {
                                    "type": "string"
                                }
                            }
                        },
                        "required": [
                            "tokenUrl",
                            "authorizationUrl",
                            "clientId",
                            "scopes"
                        ]
                    }
                }
            ]
  1. Run npx docusaurus gen-api-docs all against the schema

Your Environment

  • OpenAPI Version used: 3.0.1
  • Environment name and version (e.g. Chrome 59, node.js 5.4, python 3.7.3):
  • Operating System and version: MacOS 14.1.1

hadar-co avatar Jan 22 '24 09:01 hadar-co