Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

feat (package/nhost-js): update openapi specs and properly generate formData when uploading/updating files#47

Merged
dbarrosop merged 7 commits into
mainfrom
storage-api
Aug 13, 2025
Merged

feat (package/nhost-js): update openapi specs and properly generate formData when uploading/updating files#47
dbarrosop merged 7 commits into
mainfrom
storage-api

Conversation

@dbarrosop

@dbarrosop dbarrosop commented Aug 11, 2025

Copy link
Copy Markdown
Member

PR Type

Enhancement


Description

  • Update OpenAPI specs to version 0.8.0-beta3

  • Fix FormData generation for file uploads

  • Update test expectations for API changes

  • Add new authentication method descriptions


Diagram Walkthrough

flowchart LR
  A["OpenAPI Specs"] --> B["Code Generation"]
  B --> C["FormData Fix"]
  C --> D["Test Updates"]
  A --> E["API Documentation"]
Loading

File Walkthrough

Relevant files
Tests
6 files
storage.test.ts
Update test expectations for API changes                                 
+9/-10   
docstrings.test.ts
Update error response structure in tests                                 
+2/-0     
content.yaml.ts
Add new test data for code generation                                       
+149/-0 
methods_ref.yaml.ts
Update FormData generation in test reference                         
+10/-2   
intermediate_test.go
Add new test case for content processing                                 
+3/-0     
content.yaml
Add OAuth provider test specification                                       
+144/-0 
Enhancement
5 files
client.ts
Update auth client with new API specs                                       
+34/-66 
client.ts
Regenerate storage client from updated specs                         
+309/-265
methods.go
Improve parameter handling for content types                         
+25/-5   
auth.yaml
Update auth OpenAPI specification                                               
+246/-203
storage.yaml
Update storage OpenAPI specification                                         
+446/-311
Configuration changes
2 files
flake.nix
Update nixops reference to main branch                                     
+1/-1     
nhost.toml
Update service versions to 0.8.0-beta1                                     
+3/-3     
Documentation
2 files
auth.mdx
Update auth documentation with new descriptions                   
+33/-58 
storage.mdx
Update storage documentation with new API                               
+193/-131
Dependencies
2 files
pnpm-lock.yaml
Update dependency versions and security overrides               
+32/-27 
pnpm-workspace.yaml
Add security overrides for dependencies                                   
+4/-0     
Bug fix
2 files
client.tmpl
Fix FormData generation for JSON objects                                 
+10/-2   
types.tmpl
Fix parameter attribute help rendering                                     
+1/-1     

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

FormData Generation

The FormData generation for file uploads has been significantly changed to use Blob objects for JSON metadata. This needs careful validation to ensure proper multipart/form-data encoding and server compatibility.

  formData.append(
    "metadata[]",
    new Blob([JSON.stringify(value)], { type: "application/json" }),
    "",
  ),
);
Test Expectations

Multiple test expectations have been updated to match new API responses. The changes in error message formats and cache control headers should be verified against actual API behavior.

expect(err.body.error).toBe(
  'error in openapi3filter.RequestError: request body has an error: doesn\'t match schema: Error at "/file[]": property "file[]" is missing',
);
Parameter Handling

New parameter handling logic has been added to support both schema and content-based parameters. The fallback logic and error handling should be thoroughly tested.

switch {
case param.Schema != nil:
	t2, tt, err := GetType(param.Schema, method+format.Title(param.Name), p, false)
	if err != nil {
		return nil, nil, fmt.Errorf("failed to get type for parameter %s: %w", param.Name, err)
	}
	types = append(types, tt...)
	t = t2
case param.Content != nil:
	jsonMediaType, ok := param.Content.Get("application/json")
	if !ok {
		return nil, nil, fmt.Errorf( //nolint:err113
			"parameter %s in operation %s has no application/json content defined",
			param.Name,
			operation.OperationId,
		)
	}
	t2, tt, err := GetType(jsonMediaType.Schema, method+format.Title(param.Name), p, false)
	if err != nil {
		return nil, nil, fmt.Errorf("failed to get type for parameter %s: %w", param.Name, err)
	}
	types = append(types, tt...)
	t = t2
default:
	return nil, nil, fmt.Errorf("parameter %s in operation %s has no schema or content defined", param.Name, operation.OperationId) //nolint:goerr113,lll
}

@github-actions

Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Remove unnecessary empty filename parameter

The empty string as the third parameter to formData.append() creates a Blob without
a filename. This may cause issues with some servers that expect a filename for file
uploads. Consider providing a meaningful filename or removing the parameter
entirely.

tools/codegen/processor/typescript/templates/client.tmpl [137-141]

 formData.append(
   "{{ .Name }}",
   new Blob([JSON.stringify(value)], { type: "application/json" }),
-  "",
 ),
Suggestion importance[1-10]: 5

__

Why: The suggestion correctly identifies that the empty string filename parameter is unnecessary when appending a Blob to FormData. Removing it simplifies the code without affecting functionality, as the filename parameter is optional for Blobs.

Low
Remove unnecessary empty filename parameter

The empty string as the third parameter to formData.append() creates a blob with no
filename. This could cause issues with server-side parsing that expects proper form
field names. Consider omitting the third parameter or providing a meaningful
filename.

packages/nhost-js/src/storage/client.ts [631-635]

 formData.append(
   "metadata[]",
-  new Blob([JSON.stringify(value)], { type: "application/json" }),
-  "",
+  new Blob([JSON.stringify(value)], { type: "application/json" })
 )
Suggestion importance[1-10]: 4

__

Why: The suggestion correctly identifies that the empty string filename parameter is unnecessary when appending a Blob to FormData. However, this is a minor code style improvement that doesn't affect functionality, as both approaches work correctly.

Low

@dbarrosop dbarrosop merged commit 22d6765 into main Aug 13, 2025
13 checks passed
@dbarrosop dbarrosop deleted the storage-api branch August 13, 2025 12:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants