Are there some JSON Schema files for Node-RED HTTP APIs?

I was looking to creating some API Integration Tests and generally a good idea would be to use JSON Schema for the Requests/Requests responses? One can use these schema files to check conformity.

Did you search flows library?

https://flows.nodered.org/search?term=schema

Also, in case you were not aware - the built in JSON node accepts a schema...

RTM...

Not for flows, but I meant the HTTP Admin APIs Authentication : Node-RED I was trying to work out some simple HTTP API integration tests when creating a custom Node-RED docker container. The Schema for the response of the HTTP Admin APIs was what I can use to validate if the container is running accordingly.

Would be nice if you include that info up front!

Then just import a JSON validation library and do what is necessary.

a duck type test is more "simple"

Apologies for the unclear description, As you mentioned a validator was the way to go.

I have been able to create some JSON Schemas created for the API as reference for the community

/auth/login Response Schema

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
        "type": {
            "type": "string"
        },
        "prompts": {
            "type": "array",
            "items": {
                "$ref": "#/$defs/prompt"
            }
        }
    },
    "$defs": {
        "prompt": {
            "type": "object",
            "required": ["id", "type", "label"],
            "properties": {
                "id": {
                    "type": "string"
                },
                "type": {
                    "type": "string"
                },
                "label": {
                    "type": "string"
                }
            }
        }
    }
}

/nodes Response Schema

{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "array",
    "items": {
        "$ref": "#/$defs/node"
    },
    "$defs": {
        "node": {
            "type": "object",
            "required": ["id", "name", "types", "enabled", "module", "version"],
            "properties": {
                "id": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "types": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                },
                "enabled": {
                    "type": "boolean"
                },
                "module": {
                    "type": "string"
                },
                "version": {
                    "type": "string"
                }
            }
        }
    }
}

I am still working on /flows API and I am not sure which fields should be marked required but I will update the schema here.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.