Skip to content

A prefix is added when there is path collision #3442

@kossel

Description

@kossel

Description

Hi, this is a follow-up on #3428. when there is a path collision on both path and method, a {prefix} will still be added . the prefix would be the name of the file, the uri of a url etc. however this could be an issue for specs that uses header on version.

A use case example below, both are POST /pet/{petId}, one with accept-version: 1, one with accept-version: 2, the version 2 can optionally support breed:

swagerv1.json

{
  "swagger": "2.0",
  "info": {
    "version": "1.0.7",
    "title": "Swagger Petstore v1",
    "description": "Filtered spec containing only POST /pet/{petId}"
  },
  "host": "petstore.swagger.io",
  "schemes": ["https", "http"],
  "paths": {
    "/pet/{petId}": {
      "post": {
        "tags": ["pet"],
        "summary": "Updates a pet in the store with form data",
        "description": "",
        "operationId": "updatePetWithForm",
        "consumes": ["application/x-www-form-urlencoded"],
        "produces": ["application/json", "application/xml"],
        "parameters": [
          {
            "name": "Accept-version",
            "in": "header",
            "description": "API version header",
            "required": true,
            "type": "string",
            "default": "1"
          },
          {
            "name": "petId",
            "in": "path",
            "description": "ID of pet that needs to be updated",
            "required": true,
            "type": "integer",
            "format": "int64"
          },
          {
            "name": "name",
            "in": "formData",
            "description": "Updated name of the pet",
            "required": false,
            "type": "string"
          },
          {
            "name": "status",
            "in": "formData",
            "description": "Updated status of the pet",
            "required": false,
            "type": "string"
          }
        ],
        "responses": {
          "405": {
            "description": "Invalid input"
          }
        },
        "security": [
          {
            "petstore_auth": ["write:pets", "read:pets"]
          }
        ]
      }
    }
  },
  "securityDefinitions": {
    "petstore_auth": {
      "type": "oauth2",
      "authorizationUrl": "https://petstore.swagger.io/oauth/authorize",
      "flow": "implicit",
      "scopes": {
        "read:pets": "read your pets",
        "write:pets": "modify pets in your account"
      }
    }
  }
}

swagger2.json

{
  "swagger": "2.0",
  "info": {
    "version": "2.1.0",
    "title": "Swagger Petstore vs",
    "description": "Filtered spec containing only POST /pet/{petId}"
  },
  "host": "petstore.swagger.io",
  "schemes": ["https", "http"],
  "paths": {
    "/pet/{petId}": {
      "post": {
        "tags": ["pet"],
        "summary": "Updates a pet in the store with form data",
        "description": "",
        "operationId": "updatePetWithForm",
        "consumes": ["application/x-www-form-urlencoded"],
        "produces": ["application/json", "application/xml"],
        "parameters": [
          {
            "name": "Accept-version",
            "in": "header",
            "description": "API version header",
            "required": true,
            "type": "string",
            "default": "2"
          },
          {
            "name": "petId",
            "in": "path",
            "description": "ID of pet that needs to be updated",
            "required": true,
            "type": "integer",
            "format": "int64"
          },
          {
            "name": "name",
            "in": "formData",
            "description": "Updated name of the pet",
            "required": false,
            "type": "string"
          },
          {
            "name": "status",
            "in": "formData",
            "description": "Updated status of the pet",
            "required": false,
            "type": "string"
          },
          {
            "name": "breed",
            "in": "formData",
            "description": "Updated breed of the pet",
            "required": false,
            "type": "string"
          }
        ],
        "responses": {
          "405": {
            "description": "Invalid input"
          }
        },
        "security": [
          {
            "petstore_auth": ["write:pets", "read:pets"]
          }
        ]
      }
    }
  },
  "securityDefinitions": {
    "petstore_auth": {
      "type": "oauth2",
      "authorizationUrl": "https://petstore.swagger.io/oauth/authorize",
      "flow": "implicit",
      "scopes": {
        "read:pets": "read your pets",
        "write:pets": "modify pets in your account"
      }
    }
  }
}

I'm using @next the generated sdk is below:

export const swagger1UpdatePetWithForm = <ThrowOnError extends boolean = false>(
  options: Options<Swagger1UpdatePetWithFormData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    unknown,
    Swagger1UpdatePetWithFormErrors,
    ThrowOnError
  >({
    ...urlSearchParamsBodySerializer,
    url: '/pet/{petId}',
    ...options,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      ...options.headers,
    },
  });

/**
 * Updates a pet in the store with form data
 */
export const swagger2UpdatePetWithForm = <ThrowOnError extends boolean = false>(
  options: Options<Swagger2UpdatePetWithFormData, ThrowOnError>,
) =>
  (options.client ?? client).post<
    unknown,
    Swagger2UpdatePetWithFormErrors,
    ThrowOnError
  >({
    ...urlSearchParamsBodySerializer,
    url: '/swagger2/pet/{petId}',
    ...options,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      ...options.headers,
    },
  });

Noticed /swagger2 is being added automatically, however it's a invalid path, /swagger2/pet/{petId} will be 404 for the client. I feel the code gen shouldn't assume that a prefix is needed, if we want it to be /swagger2/pet/{petId} we would've defined that as a path. the generated type is correct though, one has breed, the other doesn't

Reproducible example or configuration

https://stackblitz.com/edit/hey-api-client-fetch-example-3m8dggm5?file=src%2Fclient%2Fsdk.gen.ts

OpenAPI specification (optional)

No response

System information (optional)

No response

Metadata

Metadata

Labels

bug 🔥Broken or incorrect behavior.needs info ⏳More information needed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions