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

Axios Client responsetype text instead of json #1624

Open
yvesInnofactory opened this issue Jan 24, 2025 · 2 comments
Open

Axios Client responsetype text instead of json #1624

yvesInnofactory opened this issue Jan 24, 2025 · 2 comments
Labels
bug 🔥 Something isn't working

Comments

@yvesInnofactory
Copy link

yvesInnofactory commented Jan 24, 2025

Description

Using
"@hey-api/openapi-ts": "^0.62.3",
"@hey-api/client-axios": "^0.5.1",

Client config:

export default defineConfig({
  client: '@hey-api/client-axios',
  input: 'c:/tmp/swagger.json',
  output: 'src/app/_lib/_generated-client',
  plugins: [
    ...defaultPlugins,
    {
      name: '@hey-api/schemas',
      type: 'json', 
    },
  ],
});

This is part of the swagger:

"/api/meeting-protocols": {
      "get": {
        "tags": [
          "MeetingProtocol"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MeetingProtocol"
                  }
                }
              },
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MeetingProtocol"
                  }
                }
              },
              "text/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MeetingProtocol"
                  }
                }
              }
            }
          }
        }
      },

Generates this sdk:

export const getApiMeetingProtocols = <ThrowOnError extends boolean = false>(options?: Options<GetApiMeetingProtocolsData, ThrowOnError>) => {
    return (options?.client ?? client).get<GetApiMeetingProtocolsResponse, unknown, ThrowOnError>({
        responseType: 'text',
        url: '/api/meeting-protocols',
        ...options
    });
};

The problem is, it's not return an array but the plain string.
When I change it manually to "reponseType: 'json', then it works fine.

I can't find a way to tell openapi-ts to generate 'json' instead of 'text'.
Any help would be appreciated!

@yvesInnofactory yvesInnofactory added the bug 🔥 Something isn't working label Jan 24, 2025
Copy link

stackblitz bot commented Jan 24, 2025

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@Sanideth
Copy link

Have the same exact issue, using the same versions of api and axios client.

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

No branches or pull requests

2 participants