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

typescript-fetch-client2 - Type 'application/json' is not assignable to type 'application/xml' #33

Open
taras opened this issue Mar 9, 2022 · 2 comments

Comments

@taras
Copy link

taras commented Mar 9, 2022

Related #32

Using the same the petstore swagger.json, the generated TypeScript includes the following code:

		loginUser(__params: UserApi.LoginUserRequest, options?: RequestInit): (fetch?: FetchAPI, basePath?: string) => Promise<UserApi.LoginUserResponse> {
			const localVarFetchArgs = UserApiFetchParamCreator(configuration).loginUser(__params, options);
			return async (fetch: FetchAPI = defaultFetch, basePath: string = BASE_PATH) => {
				const response = await fetch(basePath + localVarFetchArgs.url, localVarFetchArgs.options)
				const contentType = response.headers.get('Content-Type');
				const mimeType = contentType ? contentType.replace(/;.*/, '') : undefined;
				
				if (response.status === 200) {
					if (mimeType === 'application/json') {
						return {
							status: 200,
							contentType: 'application/json',
							body: await response.json() as string,
							headers: {
								xExpiresAfter: response.headers.get('X-Expires-After'),
								xRateLimit: response.headers.get('X-Rate-Limit'),
							},
						}
					}
					if (mimeType === 'application/xml') {
						return {
							status: 200,
							contentType: 'application/xml',
							body: await response.text(),
							headers: {
								xExpiresAfter: response.headers.get('X-Expires-After'),
								xRateLimit: response.headers.get('X-Rate-Limit'),
							},
						}
					}
					throw response;
				}
				if (response.status === 400) {
					return {
						status: 400,
						/* No content */
					}
				}
				throw response;
			};
		},

It doesn't compile because of the following error,

image

@karlvr
Copy link
Owner

karlvr commented Apr 25, 2022

@taras thank you for reporting this... could you please post what was generated for UserApi.LoginUserResponse?

@taras
Copy link
Author

taras commented Apr 26, 2022

@karlvr thank you for looking into it. I pushed the generated code to a repo. You can find it here https://github.com/taras/backstage-openapi-client-scaffolding/blob/main/plugins/petstore-client-common/src/__generated__/api.ts#L1691

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants