Skip to content

Commit ca888c4

Browse files
committed
fix!: use arrays for collections instead of sets
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
1 parent 152c535 commit ca888c4

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const client = new RemotePinningServiceClient(config)
2929
// Get 10 failed Pins
3030
const pinsGetOptions: PinsGetRequest = {
3131
limit: 10,
32-
status: new Set([Status.Failed]) // requires a set, and not an array
32+
status: [Status.Failed]
3333
}
3434
const {count, results}: PinResults = await client.pinsGet(pinsGetOptions)
3535

@@ -53,6 +53,8 @@ npm run build
5353

5454
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.
5555

56+
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.
57+
5658
If you need to modify the generated code's import paths, you will have to run `npm run postgen` manually.
5759

5860
### Contributing

generated/fetch/src/apis/PinsApi.ts

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/fetch/src/models/Pin.ts

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/fetch/src/models/PinResults.ts

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generated/fetch/src/models/PinStatus.ts

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/client.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ describe('Client', () => {
3838

3939
it('GET: Can get failed Pins', async () => {
4040
const Client = new RemotePinningServiceClient(Config)
41-
const response = await Client.pinsGet({ limit: 1, status: new Set([Status.Failed]) })
42-
expect(response).to.deep.eq({ count: 0, results: new Set() })
41+
const response = await Client.pinsGet({ limit: 1, status: [Status.Failed] })
42+
expect(response).to.deep.eq({ count: 0, results: [] })
4343
})
4444

4545
it('GET: Can add a Pin successfully', async () => {

0 commit comments

Comments
 (0)