Skip to content

Schemas that references other schemas don't work for some scenarios #19

Description

@williamrjribeiro

Consider the following contrived OpenAPI Spec Doc openapi.json:

{
  "openapi": "3.0.1",
  "info": {
    "title": "Minimal API",
    "version": "1.0.0",
    "description": "A minimal OpenAPI 3.0.1 specification with a single /documents endpoint"
  },
  "paths": {
    "/test": {
      "post": {
        "summary": "Create document",
        "description": "Create a new document",
        "operationId": "createDocument",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Document"
              }
            }
          }
        },
        "responses": {
          "200": {
            "$ref": "#/components/responses/DocumentResponse"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "_documentalias": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Document identifier"
          },
          "title": {
            "type": "string",
            "description": "Document title"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time",
            "description": "Document creation timestamp"
          }
        },
        "required": ["id", "title", "createdAt"]
      },
      "Document": {
        "$ref": "#/components/schemas/_documentalias"
      }
    },
    "responses": {
      "DocumentResponse": {
        "description": "Successful response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Document"
            }
          }
        }
      }
    }
  }
}

When I use massimo-cli to generate the client with the command pnpx massimo-cli ./openapi.json I get the following error:

ERROR: Error parsing OpenAPI definition: "Type undefined not supported". Trying with GraphQL
    err: {
      "type": "FastifyError",
      "message": "Type undefined not supported",
      "stack":
          FastifyError: Type undefined not supported
              at writeObjectProperties (file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/massimo-cli@1.0.1/node_modules/massimo-cli/lib/openapi-common.js:279:11)
              at file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/massimo-cli@1.0.1/node_modules/massimo-cli/lib/openapi-common.js:243:26
              at CodeBlockWriter._indentBlockInternal (file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/code-block-writer@13.0.3/node_modules/code-block-writer/esm/mod.js:261:13)
              at CodeBlockWriter.inlineBlock (file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/code-block-writer@13.0.3/node_modules/code-block-writer/esm/mod.js:236:14)
              at CodeBlockWriter.block (file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/code-block-writer@13.0.3/node_modules/code-block-writer/esm/mod.js:225:14)
              at writeContent (file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/massimo-cli@1.0.1/node_modules/massimo-cli/lib/openapi-common.js:243:14)
              at writeOperations (file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/massimo-cli@1.0.1/node_modules/massimo-cli/lib/openapi-common.js:91:34)
              at file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/massimo-cli@1.0.1/node_modules/massimo-cli/lib/openapi-generator.js:152:5
              at CodeBlockWriter._indentBlockInternal (file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/code-block-writer@13.0.3/node_modules/code-block-writer/esm/mod.js:261:13)
              at CodeBlockWriter.inlineBlock (file:///Users/wrjr/Library/Caches/pnpm/dlx/4abd75c70f72620c22256fb9c164164c50034f33f7a09eaf6387d51e0d40f24d/1994dd27e35-aa30/node_modules/.pnpm/code-block-writer@13.0.3/node_modules/code-block-writer/esm/mod.js:236:14)
      "code": "PLT_MASSIMO_CLI_TYPE_NOT_SUPPORTED",
      "name": "FastifyError",
      "statusCode": 500
    }

I was expecting it to work just fine. Also, the error PLT_MASSIMO_CLI_TYPE_NOT_SUPPORTED is not documented.

Version used: "massimo": "^1.0.1"

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions