cloudflare / chanfana

OpenAPI 3 and 3.1 schema generator and validator for Hono, itty-router and more!
https://chanfana.pages.dev
MIT License
275 stars 38 forks source link

Arr description missing from generated schema #78

Closed kristeaac closed 11 months ago

kristeaac commented 1 year ago

The description I'm defining for an Arr is missing from the generated schema.

I'm defining my request body like this:

  static schema = {
    operationId: `make-${ShutTheBoxGame.id}-move`,
    tags: TAGS,
    summary: 'Make a move in a game of Shut The Box.',
    parameters: IdParams,
    requestBody: {
      gameId: new Uuid({
        description: 'The ID of the game.',
        required: true,
      }),
      numbersToFlip: new Arr(
        new Num(),
        {
          description: 'An array of numbers the player wants to put down. Not required for a new game. If specified, gameId must be specified as well.',
          required: true,
        }),
    },
    responses: Responses,
  }

Note the description defined for numbersToFlip above in the params. This does not appear in the resulting schema:

 {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "gameId": {
                    "type": "string",
                    "description": "The ID of the game.",
                    "format": "uuid",
                    "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$"
                  },
                  "numbersToFlip": {
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  }
                },
                "required": [
                  "gameId",
                  "numbersToFlip"
                ]
              }
            }
          }
        }

Is this expected behavior? Am I defining the description correctly? If I'm reading the source right, perhaps getValue in the Arr class needs to merge in the value from its parent BaseParameters? https://github.com/cloudflare/itty-router-openapi/blob/main/src/parameters.ts#L72

gimenete commented 11 months ago

Probably fixed here I think https://github.com/cloudflare/itty-router-openapi/pull/79