openfga / sdk-generator

OpenFGA Client SDK Generator
Apache License 2.0
16 stars 43 forks source link

Adjust logic on handlebars to avoid 'if true' statement on models #211

Closed gabrielbussolo closed 1 year ago

gabrielbussolo commented 1 year ago

There was a small logic on handlebars causing to create if true statements on the golang sdk as we can see here

Description

with this new implementation the code is now like this: before

func (o ListObjectsRequest) MarshalJSON() ([]byte, error) {
    toSerialize := map[string]interface{}{}
    if o.AuthorizationModelId != nil {
        toSerialize["authorization_model_id"] = o.AuthorizationModelId
    }
    if true {
        toSerialize["type"] = o.Type
    }
    if true {
        toSerialize["relation"] = o.Relation
    }
    if true {
        toSerialize["user"] = o.User
    }
    if o.ContextualTuples != nil {
        toSerialize["contextual_tuples"] = o.ContextualTuples
    }
    return json.Marshal(toSerialize)
}

after

func (o ListObjectsRequest) MarshalJSON() ([]byte, error) {
    toSerialize := map[string]interface{}{}
    if o.AuthorizationModelId != nil {
        toSerialize["authorization_model_id"] = o.AuthorizationModelId
    }
    toSerialize["type"] = o.Type
    toSerialize["relation"] = o.Relation
    toSerialize["user"] = o.User
    if o.ContextualTuples != nil {
        toSerialize["contextual_tuples"] = o.ContextualTuples
    }
    return json.Marshal(toSerialize)
}

References

close https://github.com/openfga/go-sdk/issues/11

Review Checklist

gabrielbussolo commented 1 year ago

now that I noticed that has some problem on CI:

2023-09-24T06:24:39.4544560Z ##[group]Run ./scripts/clone_sdk.sh
2023-09-24T06:24:39.4544895Z [36;1m./scripts/clone_sdk.sh [0m
2023-09-24T06:24:39.4606088Z shell: /usr/bin/bash -e {0}
2023-09-24T06:24:39.4606328Z env:
2023-09-24T06:24:39.4606539Z   GITHUB_ORG_ID: 
2023-09-24T06:24:39.4606767Z   GITHUB_REPO_ID: 
2023-09-24T06:24:39.4606971Z   SSH_KEY: 
2023-09-24T06:24:39.4607202Z   SDK_PATH: clients/fga-js-sdk
2023-09-24T06:24:39.4607440Z   KNOWN_HOSTS: 
2023-09-24T06:24:39.4607640Z ##[endgroup]
2023-09-24T06:24:39.5003625Z Agent pid 1755
2023-09-24T06:24:39.6400279Z ./scripts/clone_sdk.sh: line 6: GIT_SSH_COMMAND:: command not found
2023-09-24T06:24:39.6429660Z Error loading key "(stdin)": error in libcrypto
2023-09-24T06:24:39.6430229Z Cloning into 'clients/fga-js-sdk'...
2023-09-24T06:24:39.6430559Z git@github.com: Permission denied (publickey).
2023-09-24T06:24:39.6430903Z fatal: Could not read from remote repository.
2023-09-24T06:24:39.6431102Z 
2023-09-24T06:24:39.6431347Z Please make sure you have the correct access rights
2023-09-24T06:24:39.6431945Z and the repository exists.
2023-09-24T06:24:39.6443073Z ##[error]Process completed with exit code 128.

sounds like it cant pull the sdk repositories

rhamzeh commented 1 year ago

@gabrielbussolo yeah, these are secrets stored in the CI and not available to external branches (they're only available for branches on the openfga/sdk-generator repo), but it's not an issue here (verified build was working locally, so will merge). Thanks for your PR!

rhamzeh commented 1 year ago

Added https://github.com/openfga/sdk-generator/issues/212 to tackle to allow tests to pass for future PRs