Skip to content

Commit

Permalink
fix!: use arrays for collections instead of sets
Browse files Browse the repository at this point in the history
Because we have `uniqueItems: true` in our service definition yaml, fields with `type: array` are generated as `Set`s by the typescript generator.

Serialization/deserialization of these types is [broken](OpenAPITools/openapi-generator#11746) so where we use these APIs [we pass arrays with `@ts-expect-error` anyway](https://github.com/ipfs/helia-remote-pinning/blob/main/src/heliaRemotePinner.ts#L155).

It doesn't look possible to override the use of Set by the generator in a way that works (`type-mappings=set=array` produces uncompilable code) so manually change the generated code.

Also adds a note to the readme reminding people to do it.

BREAKING CHANGE: fields that were Sets such as `PinResults.results` and `PinsGetRequest.cid` are now Arrays
  • Loading branch information
achingbrain committed Oct 5, 2024
1 parent 152c535 commit 7a25aa1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 14 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ npm run build

To update the client, you need to `npm run gen` npm script. This will fetch the latest version of the OpenAPI spec and generate the client. However, openapi-generator-cli does not currently generate the client code with proper import syntax. So you must modify the imports in `generated/fetch/**` directly, or just `git checkout -p` to remove the invalid import path changes.

It also uses `Set`s for all collection types though it cannot serialize or deserialize these types to/from JSON. They must be manually changed to be `Array`s.

If you need to modify the generated code's import paths, you will have to run `npm run postgen` manually.

### Contributing
Expand Down
12 changes: 6 additions & 6 deletions generated/fetch/src/apis/PinsApi.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated/fetch/src/models/Pin.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions generated/fetch/src/models/PinResults.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions generated/fetch/src/models/PinStatus.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7a25aa1

Please sign in to comment.