openapi-to-postman icon indicating copy to clipboard operation
openapi-to-postman copied to clipboard

Parameter example is undefined for $ref schema parameters

Open homemdasneves opened this issue 2 years ago • 0 comments

If a spec has a reference schema parameter with an example like sortDirection here:

"/api/v1/application/Area/list": {
      "post": {
        "tags": [
          "Area"
        ],
        "summary": "Retrieve a list of records of entity type",
        "operationId": "Area_GetMany",
        "parameters": [
          {
            "name": "sortDirection",
            "in": "query",
            "description": "Direction to sort by",
            "schema": {
              "$ref": "#/components/schemas/SortDirection"
            },
            "example": "asc"
          },
...

we won't get "asc" in the value, we'll get <string> instead:

{
    "id": "c9dbad06-eeb4-4771-8d8e-5b471483b9e5",
    "name": "Retrieve a list of records of entity type",
    "request": {
        "name": "Retrieve a list of records of entity type",
        "description": {},
        "url": {
            "path": [
                "api",
                "v1",
                "application",
                "Area",
                "list"
            ],
            "host": [
                "{{baseUrl}}"
            ],
            "query": [
                {
                    "disabled": false,
                    "key": "sortDirection",
                    "value": "<string>",
                    "description": "Direction to sort by"
                },
...

But, if the schema is inline, like below:

"/api/v1/application/UnitType/list": {
      "post": {
        "tags": [
          "UnitType"
        ],
        "summary": "Retrieve a list of records of entity type",
        "operationId": "UnitType_GetMany",
        "parameters": [
          {
            "name": "sortDirection",
            "in": "query",
            "description": "Direction to sort by",
            "schema": {
              "enum": [
                "asc",
                "desc"
              ],
              "type": "string"
            },
            "example": "asc"
          },

the value is correctly filled as asc in the generated postman collection:

{
    "id": "b4a0b4df-ed78-4245-ac62-17dc4f5c2775",
    "name": "Retrieve a list of records of entity type",
    "request": {
        "name": "Retrieve a list of records of entity type",
        "description": {},
        "url": {
            "path": [
                "api",
                "v1",
                "application",
                "UnitType",
                "list"
            ],
            "host": [
                "{{baseUrl}}"
            ],
            "query": [
                {
                    "disabled": false,
                    "key": "sortDirection",
                    "value": "asc",
                    "description": "Direction to sort by"
                },
...

As a workaround, in order to have a valid value upon generation, we can set a default value in the $ref schema parameter.

This could be related with #401 and #559

homemdasneves avatar Oct 01 '22 11:10 homemdasneves