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

!fix(missing-kind-type): convert auto generated enums to union types #137

Closed
wants to merge 3 commits into from

Conversation

alfetopito
Copy link
Contributor

Summary

Closes #134

Converting openapi enums to union types

⚠️ Attention!! ⚠️

This is a breaking change and will have cascading effects on consumers, as the enums will be removed!

Context

We auto-generate the types based on the orderbook/openapi spec.
The OrderQuoteSide is defined here
It uses kind.sell for some options and kind.buy for another.
We use openapi cli tool to generate the corresponding TS types
The resulting type can be seen here

It does NOT include the enum buy.

It's a limitation of the lib used for generating the types. See this issue.

This change applies the suggested workaround:

Use union types instead of enums (often though it's desirable to have the options available at runtime)

Here's a write up about this option.

Test

@github-actions
Copy link

github-actions bot commented Aug 3, 2023

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request

@@ -26,7 +26,7 @@
"prepare": "npm run build",
"prepublishOnly": "npm test && npm run lint",
"graphql:codegen": "graphql-codegen --config graphql-codegen.yml",
"swagger:codegen": " openapi --input https://raw.githubusercontent.com/cowprotocol/services/main/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false"
"swagger:codegen": "openapi --input https://raw.githubusercontent.com/cowprotocol/services/main/crates/orderbook/openapi.yml --output src/order-book/generated --exportServices false --exportCore false --useUnionTypes"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change. See what the option does in the docs

Everything else is adapting to the consequences of it.

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 71.565%. remained the same when pulling 1818ab7 on 134/fix-auto-generated-enums into ad0c108 on main.

@alfetopito alfetopito self-assigned this Aug 3, 2023
@alfetopito alfetopito requested a review from a team August 3, 2023 14:16
Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no! do we really need to do this?

We've been using the enums with no issues before.

@anxolin
Copy link
Contributor

anxolin commented Aug 3, 2023

Is the options 2 possible?

2. Restructure the schema and split it up into further components to avoid conflicts?

@alfetopito
Copy link
Contributor Author

Is the options 2 possible?

2. Restructure the schema and split it up into further components to avoid conflicts?

It requires changes to the openapi specs in the services repo instead.
I can also try that as an alternative solution.

alfetopito added a commit to cowprotocol/services that referenced this pull request Aug 3, 2023
Part of the fix to address cowprotocol/cow-sdk#134

This is the second approach as suggested here ferdikoomen/openapi-typescript-codegen#1424

The first approach was implemented on cowprotocol/cow-sdk#137
It's a breaking change on the SDK side and creates a lot of noise.

This change will allows us to fix the issue with minimal changes
@alfetopito
Copy link
Contributor Author

alfetopito added a commit to cowprotocol/services that referenced this pull request Aug 3, 2023
# Summary

Part of the fix to address
cowprotocol/cow-sdk#134

This is the second approach as suggested here
ferdikoomen/openapi-typescript-codegen#1424

The first approach was implemented on
cowprotocol/cow-sdk#137 It's a breaking change
on the SDK side and creates a lot of noise.

This change will allows us to fix the issue with minimal changes

Describe context of what this change does, why it is needed and how it
is accomplished

### Test Plan

There are no effective changes on the code per se, and the resulting
schema doc should be equivalent.

I did test it on the target repo (SDK) and the generated the types with
the changes here. See [this
PR](https://github.com/cowprotocol/cow-sdk/pull/138/files)
@alfetopito
Copy link
Contributor Author

Superseded by #138

@alfetopito alfetopito closed this Aug 3, 2023
@alfetopito alfetopito deleted the 134/fix-auto-generated-enums branch August 3, 2023 17:22
@github-actions github-actions bot locked and limited conversation to collaborators Aug 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing type on OrderQuoteSide.kind
3 participants