Incorrect typing in @googleapis/healthcare

Open
#3,490 1 comment 4 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
nodejs, typescript
Domain
api

Research direction

Start with the generated healthcare definitions in src/apis/healthcare/v1.ts, especially the request and response types referenced in the report, and compare them with the linked FHIR example. Verify the corrected types against the shown createFhirResource call and its returned data; done means the example compiles without workarounds and matches the API response.

Written by the indexing model from the issue text.

Description

priority: p2 type: bug
Environment details
  • OS: macOS Sonoma 14.4.1
  • Node.js version: 20.5.1
  • npm version: 9.8.0
  • @googleapis/healthcare version: 16.0.0

Hi there- following the example code for creating FHIR resources, it seems the generated types do not match what the api expects.

Running the example code indicates the requestBody is mistyped and should be of type Scehma$HttpBody.

The response is also mistyped as it seems to return a BLOB. Below is the example code with comments added. This was tested using valid config variables.

const google = require('@googleapis/healthcare');
const healthcare = google.healthcare({
	version: 'v1',
	auth: new google.auth.GoogleAuth({
		scopes: ['https://www.googleapis.com/auth/cloud-platform'],
	}),
	headers: { 'Content-Type': 'application/fhir+json' },
});

async function createFhirResource() {
	// Replace the following body with the data for the resource you want to
	// create.
	const body = {
		name: [{ use: 'official', family: 'Smith', given: ['Darcy'] }],
		gender: 'female',
		birthDate: '1970-01-01',
		resourceType: 'Patient',
	};

	// TODO(developer): uncomment these lines before running the sample
	// const cloudRegion = 'us-central1';
	// const projectId = 'adjective-noun-123';
	// const datasetId = 'my-dataset';
	// const fhirStoreId = 'my-fhir-store';
	// const resourceType = 'Patient';

	// Example code request - type errors for `requestBody`, returns 200
	const request = { parent, type: resourceType, requestBody: body };
	const resource = await healthcare.projects.locations.datasets.fhirStores.fhir.create(request);

	// Modified to satisfy type errors, throws 400
	// const request = { parent, type: resourceType, requestBody: { data: JSON.stringify(body) } };
	// const resource = await healthcare.projects.locations.datasets.fhirStores.fhir.create(request);

	// Example code response - `id` is undefined, `resource.data` is a BLOB.  Type error: Property 'id' does not exist on type 'Schema$HttpBody'.
	// console.log(`Created FHIR resource with ID ${resource.data.id}`);
	// console.log(resource.data);

	// Modified to parse response correctly, throws type errors
	const textData = await resource.data.text();
	const parsedData = JSON.parse(textData);
	console.log(`Created FHIR resource with ID ${parsedData.id}`);
	console.log(parsedData);
}

createFhirResource();

It seems there have been a couple other similar issues in the other api libraries.
See: #1944 and #1168

Dominant language
TypeScript
Stars
12.3k
Forks
2k
Avg merge
3d 10h
Merged PRs (30d)
9

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/google-api-nodejs-client

All issues in googleapis/google-api-nodejs-client

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.