Skip to content

Default value missing from OpenAPI output #5369

@lcawl

Description

@lcawl

There seem to be cases where a default value specified in the typescript file is missing from the OpenAPI output. For example, in https://github.com/elastic/elasticsearch-specification/blob/main/specification/inference/text_embedding/TextEmbeddingRequest.ts

... there is a query parameter with a default value as follows:

  query_parameters: {
    /**
     * Specifies the amount of time to wait for the inference request to complete.
     * @server_default 30s
     */
    timeout?: Duration

However, that default is missing from both the docs-specific and generic output elasticsearch-openapi.json file:

          {
            "in": "query",
            "name": "timeout",
            "description": "Specifies the amount of time to wait for the inference request to complete.",
            "deprecated": false,
            "schema": {
              "$ref": "#/components/schemas/_types.Duration"
            },
            "style": "form"
          }

...
      "_types.Duration": {
        "description": "A duration. Units can be `nanos`, `micros`, `ms` (milliseconds), `s` (seconds), `m` (minutes), `h` (hours) and\n`d` (days). Also accepts \"0\" without a unit and \"-1\" to indicate an unspecified value.",
        "oneOf": [
          {
            "type": "string"
          },
          {
            "type": "string",
            "enum": [
              "-1"
            ]
          },
          {
            "type": "string",
            "enum": [
              "0"
            ]
          }
        ]
      },

This makes me wonder if the generator ought to consolidate that info rather than using a $ref. Specifically for cases where we're trying to add more info (such as default values) to the re-used type. For example, create this output instead:

  {
            "in": "query",
            "name": "timeout",
            "description": "Specifies the amount of time to wait for the inference request to complete. ",
            "deprecated": false,
            "schema": {
                "default": "30s"
                "oneOf": [
                  {
                    "type": "string"
                  },
                 {
                    "type": "string",
                    "enum": [
                      "-1"
                    ]
                  },
                 {
                    "type": "string",
                    "enum": [
                      "0"
                    ]
                  }
                ]
              },

[Edited Oct 1]
Per #5369 (comment) rather than inlining the full schema, it seems like using an allOf might be another option.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions