Skip to content

Client generation for Content-Type: application/x-www-form-urlencoded #146

Closed
@Larox

Description

@Larox

Hey,

I've encountered an issue when trying to create the API Client and data models from my swagger file. This is happening when the Content-Type of my API is application/x-www-form-urlencoded. Currently, it is being created as Json or form data when a query string is needed as the body and for this reason, when using the client it is failing.

Here is the definition of that specific endpoint in my swagger.json file:

"/auth/login": {
    "post": {
        "responses": {
            "500": {
                "description": "Internal server error."
            },
            "400": {
                "description": "Validation error."
            },
            "401": {
                "description": "Email or password does not match"
            },
            "200": {
                "description": "Login succeeded."
            }
        },
        "summary": "Authenticate an existing user and return an access token",
        "operationId": "post_auth_api",
        "parameters": [
            {
                "name": "email",
                "in": "formData",
                "type": "string",
                "format": "email",
                "required": true
            },
            {
                "name": "password",
                "in": "formData",
                "type": "string",
                "required": true
            }
        ],
        "security": [],
        "consumes": [
            "application/x-www-form-urlencoded",
            "multipart/form-data"
        ],
        "tags": [
            "auth"
        ]
    }
}

And the code generated:

export class Auth extends HttpClient {
  postAuthApi = (data: { email: string; password: string }, params?: RequestParams) =>
    this.request<any, any>(`/auth/login`, "POST", params, data, BodyType.FormData, true);
    ...
    }

I'm using this command for generating the models and Is there a configuration I am missing for this case?

npx swagger-typescript-api -p https://myapi.com/v1/swagger.json -o ./src/apiClient --modular

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions