reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.57k stars 1.14k forks source link

[open-api gen] Error: path paremeter not defined if schema is vague #1870

Open hannojg opened 2 years ago

hannojg commented 2 years ago

Issue

I just tried to convert an openapi schema to RTK query, and stumbled upon the following error:

Error: path parameter id does not seem to be defined?

The schema is a bit weird, but unfortunately, its generation is outside of my control. Look at how the parameter name for delete and get is in a different case:

{
   "paths":{
      "/playlists/{id}":{
         "get":{
            "tags":[
               "Playlists"
            ],
            "summary":"Get a Playlist",
            "operationId":"getPlaylist",
            "parameters":[
               {
                  "name":"id",
                  "in":"path",
                  "description":"ID of the playlist",
                  "example":1
               }
            ]
         },
         "delete":{
            "tags":[
               "Playlists"
            ],
            "summary":"Delete a playlist",
            "operationId":"deletePlaylist",
            "parameters":[
               {
                  "in":"path",
                  "name":"ID",
                  "required":true,
                  "description":"ID of playlist to delete",
                  "schema":{
                     "type":"integer",
                     "example":1
                  }
               }
            ]
         }
      }
   }
}

The solution

The error happens as this comparison fails https://github.com/reduxjs/redux-toolkit/blob/2fbf0b5e8403e31209eee9801af0256bdfc78dfb/packages/rtk-query-codegen-openapi/src/generate.ts#L414

In the example of the spec above it compares 'ID' === 'id', which fails. However, when comparing using name instead of originalName everything works, as name has the parameter in the correct case.

I am not sure whether using name for originalName is legitim though.

MinaroShikuchi commented 2 years ago

In my case pathParameters is empty [] because it does not contains param or path because it's a Dto const pathParameters = Object.values(queryArg).filter((def) => def.origin === 'param' && def.param.in === 'path');

{
  createShareDto: {
    origin: 'body',
    name: 'createShareDto',
    originalName: 'createShareDto',
    type: NodeObject {
      pos: -1,
      end: -1,
      flags: 8,
      modifierFlagsCache: 0,
      transformFlags: 1,
      parent: undefined,
      kind: 177,
      typeName: [IdentifierObject],
      typeArguments: undefined
    },
    required: true,
    body: { required: true, content: [Object] }
  }
}
MinaroShikuchi commented 2 years ago

It seems to has been fixed. I advise to pass you json/yml file in the swagger editor in order to strongly validate your structure.

ivan-halo commented 3 months ago

Error: path parameter organization_id does not seem to be defined in '/api/brands/{organization_id}/locations'!

{"/api/brands/{organization_id}/locations": {
      "get": {
        "operationId": "creator_check_in_ninja_api_brand_locations_list_locations",
        "summary": "List Locations",
        "parameters": [
          {
            "in": "query",
            "name": "organization_id",
            "schema": {
              "format": "uuid4",
              "title": "Organization Id",
              "type": "string"
            },
            "required": true
          }
        ],
        "responses": {},
        "description": "List locations of the brand.",
        "tags": [
          "Brand Locations"
        ],
        "security": [
          {
            "JWTAuth": []
          }
        ]
      },
      "post": {
        "operationId": "creator_check_in_ninja_api_brand_locations_create_location",
        "summary": "Create Location",
        "parameters": [
          {
            "in": "query",
            "name": "organization_id",
            "schema": {
              "format": "uuid4",
              "title": "Organization Id",
              "type": "string"
            },
            "required": true
          }
        ],
        "responses": {},
        "description": "Create a new location for the brand. Brand manager permission level required.",
        "tags": [
          "Brand Locations"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BrandLocationSchemaIn"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "JWTAuth": []
          }
        ]
      }
    }}
ershisan99 commented 3 months ago

Error: path parameter organization_id does not seem to be defined in '/api/brands/{organization_id}/locations'!

{"/api/brands/{organization_id}/locations": {
      "get": {
        "operationId": "creator_check_in_ninja_api_brand_locations_list_locations",
        "summary": "List Locations",
        "parameters": [
          {
            "in": "query",
            "name": "organization_id",
            "schema": {
              "format": "uuid4",
              "title": "Organization Id",
              "type": "string"
            },
            "required": true
          }
        ],
        "responses": {},
        "description": "List locations of the brand.",
        "tags": [
          "Brand Locations"
        ],
        "security": [
          {
            "JWTAuth": []
          }
        ]
      },
      "post": {
        "operationId": "creator_check_in_ninja_api_brand_locations_create_location",
        "summary": "Create Location",
        "parameters": [
          {
            "in": "query",
            "name": "organization_id",
            "schema": {
              "format": "uuid4",
              "title": "Organization Id",
              "type": "string"
            },
            "required": true
          }
        ],
        "responses": {},
        "description": "Create a new location for the brand. Brand manager permission level required.",
        "tags": [
          "Brand Locations"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BrandLocationSchemaIn"
              }
            }
          },
          "required": true
        },
        "security": [
          {
            "JWTAuth": []
          }
        ]
      }
    }}

same error for me, have you managed to get around it?