Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Absolute paths are generated? #85

Closed
AnderssonPeter opened this issue Apr 22, 2024 · 6 comments · Fixed by #84
Closed

Absolute paths are generated? #85

AnderssonPeter opened this issue Apr 22, 2024 · 6 comments · Fixed by #84
Assignees
Labels
bug Something isn't working

Comments

@AnderssonPeter
Copy link

AnderssonPeter commented Apr 22, 2024

Describe the bug
When i generate my client code, absolute paths are used instead of relative.

Example of output

export const useLocalizationServiceGetTranslationTexts = <TData = Common.LocalizationServiceGetTranslationTextsDefaultResponse, TError = unknown, TQueryKey extends Array<unknown> = unknown[]>({ language, module }: {
    language: import("C:/Projekt/test/test_3.0/Frontend/src/openapi/requests/models").Language;
    module: import("C:/Projekt/test/test_3.0/Frontend/src/openapi/requests/models").Module;
}
  • OS: Windows 11 22H2
  • Version v1.1.0
@AnderssonPeter AnderssonPeter changed the title Static paths are generated? Absolute paths are generated? Apr 22, 2024
@AnderssonPeter
Copy link
Author

AnderssonPeter commented Apr 22, 2024

The wierd thing here is that both Language and Module are imported using a normal import further up in the file.
import { ...., Language, Module, .... } from "../requests/models";

All invalid imports have one thing in common, they are enums, generated using --enums typescript

@seriouslag
Copy link
Collaborator

seriouslag commented Apr 22, 2024

@AnderssonPeter, this is fixed in #84

@AnderssonPeter
Copy link
Author

It's for both queries and suspense, I don't have access to the spec right now but will try to get you an example tomorrow.

@seriouslag seriouslag added the bug Something isn't working label Apr 22, 2024
@seriouslag seriouslag self-assigned this Apr 22, 2024
seriouslag added a commit that referenced this issue Apr 23, 2024
- Update to the latest `@hey-api/openapi-ts` version `0.42.1`
  - fixes: #83,
  - Enables work towards #81
- Fixed a bug where types in mutation hooks were imported from a (non-relative) direct file import.
    - This is the same fix implemented in #61, which was done for query hooks.
    - Expand the match regex to take account of non-alphabetical file paths
      - fixes: #85
- Fixed a bug where JSDocs were not being added to generated hooks.
- Add more unit testing
@AnderssonPeter
Copy link
Author

@seriouslag the following specification causes the issue:

{
  "openapi": "3.0.1",
  "info": {
    "title": "API",
    "version": "1.0"
  },
  "paths": {
    "/api/localization/module/{module}/{language}": {
      "get": {
        "tags": [
          "localization"
        ],
        "operationId": "GetTranslationTexts",
        "parameters": [
          {
            "name": "module",
            "in": "path",
            "required": true,
            "style": "simple",
            "schema": {
              "$ref": "#/components/schemas/Module"
            }
          },
          {
            "name": "language",
            "in": "path",
            "required": true,
            "style": "simple",
            "schema": {
              "$ref": "#/components/schemas/Language"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/LocalizationText"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ValidationProblemDetails"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "403": {
            "description": "Forbidden",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProblemDetails"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Language": {
        "enum": [
          "Swedish",
          "English"
        ],
        "type": "string"
      },
      "LocalizationText": {
        "required": [
          "key",
          "text"
        ],
        "type": "object",
        "properties": {
          "key": {
            "$ref": "#/components/schemas/TranslationTextKey"
          },
          "text": {
            "type": "string"
          }
        },
        "additionalProperties": false
      },
      "Module": {
        "enum": [
          "Global",
          "ResearchProjects"
        ],
        "type": "string"
      },
      "ProblemDetails": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "instance": {
            "type": "string",
            "nullable": true
          }
        },
        "additionalProperties": { }
      },
      "TranslationTextKey": {
        "enum": [
          "Close",
          "Menu"
        ],
        "type": "string"
      },
      "ValidationProblemDetails": {
        "required": [
          "errors"
        ],
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "nullable": true
          },
          "title": {
            "type": "string",
            "nullable": true
          },
          "status": {
            "type": "integer",
            "format": "int32",
            "nullable": true
          },
          "detail": {
            "type": "string",
            "nullable": true
          },
          "instance": {
            "type": "string",
            "nullable": true
          },
          "errors": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "additionalProperties": { }
      }
    }
  }
}

@7nohe 7nohe closed this as completed in #84 Apr 23, 2024
@seriouslag
Copy link
Collaborator

This was fixed in 1.2.0

@AnderssonPeter
Copy link
Author

@seriouslag I just tested it and it works as expected, thanks for the quick fix!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants