Skip to content

Commit

Permalink
fix: dont escape HTML characters in conditions (#73)
Browse files Browse the repository at this point in the history
The behaviour of json.Marshal is to escape any HTML characters in a string, by using json.Encoder
we are able to disable the escaping of these characters
  • Loading branch information
ewanharris authored Jan 26, 2024
1 parent f50d59c commit 014b8d1
Show file tree
Hide file tree
Showing 60 changed files with 600 additions and 60 deletions.
11 changes: 10 additions & 1 deletion model_aborted_message_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -111,7 +113,14 @@ func (o AbortedMessageResponse) MarshalJSON() ([]byte, error) {
if o.Message != nil {
toSerialize["message"] = o.Message
}
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableAbortedMessageResponse struct {
Expand Down
11 changes: 10 additions & 1 deletion model_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -75,7 +77,14 @@ func (o Any) MarshalJSON() ([]byte, error) {
if o.Type != nil {
toSerialize["@type"] = o.Type
}
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableAny struct {
Expand Down
11 changes: 10 additions & 1 deletion model_assertion.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -93,7 +95,14 @@ func (o Assertion) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
toSerialize["tuple_key"] = o.TupleKey
toSerialize["expectation"] = o.Expectation
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableAssertion struct {
Expand Down
11 changes: 10 additions & 1 deletion model_assertion_tuple_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -120,7 +122,14 @@ func (o AssertionTupleKey) MarshalJSON() ([]byte, error) {
toSerialize["object"] = o.Object
toSerialize["relation"] = o.Relation
toSerialize["user"] = o.User
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableAssertionTupleKey struct {
Expand Down
11 changes: 10 additions & 1 deletion model_authorization_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -156,7 +158,14 @@ func (o AuthorizationModel) MarshalJSON() ([]byte, error) {
if o.Conditions != nil {
toSerialize["conditions"] = o.Conditions
}
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableAuthorizationModel struct {
Expand Down
11 changes: 10 additions & 1 deletion model_check_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -212,7 +214,14 @@ func (o CheckRequest) MarshalJSON() ([]byte, error) {
if o.Context != nil {
toSerialize["context"] = o.Context
}
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableCheckRequest struct {
Expand Down
11 changes: 10 additions & 1 deletion model_check_request_tuple_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -120,7 +122,14 @@ func (o CheckRequestTupleKey) MarshalJSON() ([]byte, error) {
toSerialize["user"] = o.User
toSerialize["relation"] = o.Relation
toSerialize["object"] = o.Object
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableCheckRequestTupleKey struct {
Expand Down
11 changes: 10 additions & 1 deletion model_check_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -112,7 +114,14 @@ func (o CheckResponse) MarshalJSON() ([]byte, error) {
if o.Resolution != nil {
toSerialize["resolution"] = o.Resolution
}
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableCheckResponse struct {
Expand Down
11 changes: 10 additions & 1 deletion model_computed.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -66,7 +68,14 @@ func (o *Computed) SetUserset(v string) {
func (o Computed) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
toSerialize["userset"] = o.Userset
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableComputed struct {
Expand Down
11 changes: 10 additions & 1 deletion model_condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -131,7 +133,14 @@ func (o Condition) MarshalJSON() ([]byte, error) {
if o.Parameters != nil {
toSerialize["parameters"] = o.Parameters
}
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableCondition struct {
Expand Down
11 changes: 10 additions & 1 deletion model_condition_param_type_ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -104,7 +106,14 @@ func (o ConditionParamTypeRef) MarshalJSON() ([]byte, error) {
if o.GenericTypes != nil {
toSerialize["generic_types"] = o.GenericTypes
}
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableConditionParamTypeRef struct {
Expand Down
11 changes: 10 additions & 1 deletion model_contextual_tuple_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -66,7 +68,14 @@ func (o *ContextualTupleKeys) SetTupleKeys(v []TupleKey) {
func (o ContextualTupleKeys) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
toSerialize["tuple_keys"] = o.TupleKeys
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableContextualTupleKeys struct {
Expand Down
11 changes: 10 additions & 1 deletion model_create_store_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -66,7 +68,14 @@ func (o *CreateStoreRequest) SetName(v string) {
func (o CreateStoreRequest) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
toSerialize["name"] = o.Name
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableCreateStoreRequest struct {
Expand Down
11 changes: 10 additions & 1 deletion model_create_store_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
"time"
)
Expand Down Expand Up @@ -148,7 +150,14 @@ func (o CreateStoreResponse) MarshalJSON() ([]byte, error) {
toSerialize["name"] = o.Name
toSerialize["created_at"] = o.CreatedAt
toSerialize["updated_at"] = o.UpdatedAt
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableCreateStoreResponse struct {
Expand Down
11 changes: 10 additions & 1 deletion model_difference.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -93,7 +95,14 @@ func (o Difference) MarshalJSON() ([]byte, error) {
toSerialize := map[string]interface{}{}
toSerialize["base"] = o.Base
toSerialize["subtract"] = o.Subtract
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableDifference struct {
Expand Down
11 changes: 10 additions & 1 deletion model_expand_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
package openfga

import (
"bytes"

"encoding/json"
)

Expand Down Expand Up @@ -102,7 +104,14 @@ func (o ExpandRequest) MarshalJSON() ([]byte, error) {
if o.AuthorizationModelId != nil {
toSerialize["authorization_model_id"] = o.AuthorizationModelId
}
return json.Marshal(toSerialize)
var b bytes.Buffer
enc := json.NewEncoder(&b)
enc.SetEscapeHTML(false)
err := enc.Encode(toSerialize)
if err != nil {
return nil, err
}
return b.Bytes(), nil
}

type NullableExpandRequest struct {
Expand Down
Loading

0 comments on commit 014b8d1

Please sign in to comment.