-
Notifications
You must be signed in to change notification settings - Fork 68
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
[BUG] @shopware/api-gen not behaving as expected when applying multiple patches. #1746
Comments
hey @max-zinn looking at the overrides we currently can override:
Here's more info on that: https://github.com/shopware/frontends/tree/main/packages/api-gen#partial-overrides What is the problem in your case:
Working override for you would be (although I would suggest to change {
"components": {
"Product": [
{
"properties": {
"customFields": {
"$ref": "#/components/schemas/CustomFields"
}
}
}
],
"CustomFields": {
"properties": {
"my_custom_field": {
"type": "string",
"required": true
}
}
}
}
} so result is: |
Hey @patzick, thanks for the clarification. I understood the documentation as "you can choose The documentation didn't state that every patch file needs to have the same format of applying patches.
I just tested this out and both patch files get only applied if they follow the same structure. Example: given this {
"$schema": "https://raw.githubusercontent.com/shopware/frontends/main/packages/api-gen/api-gen.schema.json",
"patches": ["api-types/storeApiTypes2.overrides.json", "api-types/storeApiTypes3.overrides.json"]
} Following are four variants where there are issues I got confused with: // api-types/storeApiTypes2.overrides.json
{
"components": {
"Product": {
"required": ["weight"]
}
}
}
// api-types/storeApiTypes3.overrides.json
{
"components": {
"Product": {
"required": ["versionId"]
}
}
} This works because both files use object syntax for patching the product // api-types/storeApiTypes2.overrides.json
{
"components": {
"Product": [
{
"required": ["weight"]
}
]
}
}
// api-types/storeApiTypes3.overrides.json
{
"components": {
"Product": [
{
"required": ["versionId"]
}
]
}
} This also works because both files use array syntax // api-types/storeApiTypes2.overrides.json
{
"components": {
"Product": {
"required": ["weight"]
}
}
}
// api-types/storeApiTypes3.overrides.json
{
"components": {
"Product": [
{
"required": ["versionId"]
}
]
}
} This doesn't work, only the first patch is applied // api-types/storeApiTypes2.overrides.json
{
"components": {
"Product": [
{
"required": ["weight"]
}
]
}
}
// api-types/storeApiTypes3.overrides.json
{
"components": {
"Product": {
"required": ["versionId"]
}
}
} This doesn't work, only the first patch is applied If this is intended behaviour, I'd highly suggest updating the README to clearly state this. I can create a PR with a suggestion for the |
Regarding
I didn't want to extendd the existing It had no reference to the Product schema as well so I figured I create |
that's also fine, it just looked like a typo ;) So it that working for you in current shape? |
sorry missed you typed two comments :) yes, you're right about not clear info. You're use case is totally valid. |
Sounds good, thanks! In any way, I already made some changes to the README.md and posted a PR. It's up to you if you want to accept it and/or make the changes :) Happy weekend! |
Current Behavior
The @shopware/api-gen package doesn't work when two patches affect the same schema.
Expected Behavior
I found the patch linked by the npm package here:
https://raw.githubusercontent.com/shopware/frontends/main/packages/api-client/api-types/storeApiSchema.overrides.json
But I also want to customize the
customFields
property to our needs. You can see a minimal example in this repository(
storeApiTypes.overrides.json
). Since both apply changes to theProduct
schema, only the first one (in this case theshopware default patch) is applied.
Simply checkout this repository and run
The result is the applied patch including the one for
calculatedCheapestPrice
, but not the patch forcustomFields
.Swap the order of both patches in
api-gen.config.json
and the result will change. Now the patch forcustomFields
isapplied but not the patch for
calculatedCheapestPrice
.I really don't understand the underlying mechanic as I expected it to apply patches by simply deepmerging all patches
after each other into the
storeApiSchema.json
and then generating thestoreApiTypes.d.ts
based on the openAPI specs.The documentation of
@shopware/api-gen
states the following:Why do I have to use a different schema than the
storeApiSchema.json
?The structure there is:
whereas the
storeApiTypes.overrides.json
requires the following structure:If I use the same structure as originally defined, it doesn't work at all.
Steps To Reproduce
Anything else?
No response
The text was updated successfully, but these errors were encountered: