Skip to content

Commit

Permalink
feat: add support for modular models metadata (#53)
Browse files Browse the repository at this point in the history
<!-- Thanks for opening a PR! Here are some quick tips:
If this is your first time contributing, [read our Contributing
Guidelines](https://github.com/openfga/.github/blob/main/CONTRIBUTING.md)
to learn how to create an acceptable PR for this repo.
By submitting a PR to this repository, you agree to the terms within the
[OpenFGA Code of
Conduct](https://github.com/openfga/.github/blob/main/CODE_OF_CONDUCT.md)

If your PR is under active development, please submit it as a "draft".
Once it's ready, open it up for review.
-->

<!-- Provide a brief summary of the changes -->

## Description
<!-- Provide a detailed description of the changes -->

This PR merges the latest upstream changes from the `sdk-generator`,
introducing support for modular models metadata, as contributed in
openfga/api@66b9e5c

## References
<!-- Provide a list of any applicable references here (GitHub Issue,
[OpenFGA RFC](https://github.com/openfga/rfcs), other PRs, etc..) -->

## Review Checklist
- [x] I have clicked on ["allow edits by
maintainers"](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork).
- [x] I have added documentation for new/changed functionality in this
PR or in a PR to [openfga.dev](https://github.com/openfga/openfga.dev)
[Provide a link to any relevant PRs in the references section above]
- [x] The correct base branch is being used, if not `main`
- [ ] I have added tests to validate that the change in functionality is
working as expected
  • Loading branch information
evansims authored Apr 4, 2024
2 parents 794d9ad + 450b688 commit 5509927
Show file tree
Hide file tree
Showing 12 changed files with 401 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ docs/CheckRequestTupleKey.md
docs/CheckResponse.md
docs/Computed.md
docs/Condition.md
docs/ConditionMetadata.md
docs/ConditionParamTypeRef.md
docs/ContextualTupleKeys.md
docs/CreateStoreRequest.md
Expand Down Expand Up @@ -60,6 +61,7 @@ docs/ReadResponse.md
docs/RelationMetadata.md
docs/RelationReference.md
docs/RelationshipCondition.md
docs/SourceInfo.md
docs/Status.md
docs/Store.md
docs/Tuple.md
Expand Down Expand Up @@ -160,6 +162,7 @@ src/OpenFga.Sdk/Model/CheckRequestTupleKey.cs
src/OpenFga.Sdk/Model/CheckResponse.cs
src/OpenFga.Sdk/Model/Computed.cs
src/OpenFga.Sdk/Model/Condition.cs
src/OpenFga.Sdk/Model/ConditionMetadata.cs
src/OpenFga.Sdk/Model/ConditionParamTypeRef.cs
src/OpenFga.Sdk/Model/ContextualTupleKeys.cs
src/OpenFga.Sdk/Model/CreateStoreRequest.cs
Expand Down Expand Up @@ -194,6 +197,7 @@ src/OpenFga.Sdk/Model/ReadResponse.cs
src/OpenFga.Sdk/Model/RelationMetadata.cs
src/OpenFga.Sdk/Model/RelationReference.cs
src/OpenFga.Sdk/Model/RelationshipCondition.cs
src/OpenFga.Sdk/Model/SourceInfo.cs
src/OpenFga.Sdk/Model/Status.cs
src/OpenFga.Sdk/Model/Store.cs
src/OpenFga.Sdk/Model/Tuple.cs
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,7 @@ namespace Example {
- [Model.CheckResponse](docs/CheckResponse.md)
- [Model.Computed](docs/Computed.md)
- [Model.Condition](docs/Condition.md)
- [Model.ConditionMetadata](docs/ConditionMetadata.md)
- [Model.ConditionParamTypeRef](docs/ConditionParamTypeRef.md)
- [Model.ContextualTupleKeys](docs/ContextualTupleKeys.md)
- [Model.CreateStoreRequest](docs/CreateStoreRequest.md)
Expand Down Expand Up @@ -845,6 +846,7 @@ namespace Example {
- [Model.RelationMetadata](docs/RelationMetadata.md)
- [Model.RelationReference](docs/RelationReference.md)
- [Model.RelationshipCondition](docs/RelationshipCondition.md)
- [Model.SourceInfo](docs/SourceInfo.md)
- [Model.Status](docs/Status.md)
- [Model.Store](docs/Store.md)
- [Model.Tuple](docs/Tuple.md)
Expand Down
1 change: 1 addition & 0 deletions docs/Condition.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Name | Type | Description | Notes
**Name** | **string** | |
**Expression** | **string** | A Google CEL expression, expressed as a string. |
**Parameters** | [**Dictionary&lt;string, ConditionParamTypeRef&gt;**](ConditionParamTypeRef.md) | A map of parameter names to the parameter&#39;s defined type reference. | [optional]
**Metadata** | [**ConditionMetadata**](ConditionMetadata.md) | | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

11 changes: 11 additions & 0 deletions docs/ConditionMetadata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OpenFga.Sdk.Model.ConditionMetadata

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Module** | **string** | | [optional]
**SourceInfo** | [**SourceInfo**](SourceInfo.md) | | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

2 changes: 2 additions & 0 deletions docs/Metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**Relations** | [**Dictionary&lt;string, RelationMetadata&gt;**](RelationMetadata.md) | | [optional]
**Module** | **string** | | [optional]
**SourceInfo** | [**SourceInfo**](SourceInfo.md) | | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

2 changes: 2 additions & 0 deletions docs/RelationMetadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**DirectlyRelatedUserTypes** | [**List&lt;RelationReference&gt;**](RelationReference.md) | | [optional]
**Module** | **string** | | [optional]
**SourceInfo** | [**SourceInfo**](SourceInfo.md) | | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

10 changes: 10 additions & 0 deletions docs/SourceInfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# OpenFga.Sdk.Model.SourceInfo

## Properties

Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**File** | **string** | | [optional]

[[Back to Model list]](../README.md#models) [[Back to API list]](../README.md#api-endpoints) [[Back to README]](../README.md)

20 changes: 19 additions & 1 deletion src/OpenFga.Sdk/Model/Condition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public Condition() {
/// <param name="name">name (required).</param>
/// <param name="expression">A Google CEL expression, expressed as a string. (required).</param>
/// <param name="parameters">A map of parameter names to the parameter&#39;s defined type reference..</param>
public Condition(string name = default(string), string expression = default(string), Dictionary<string, ConditionParamTypeRef> parameters = default(Dictionary<string, ConditionParamTypeRef>)) {
/// <param name="metadata">metadata.</param>
public Condition(string name = default(string), string expression = default(string), Dictionary<string, ConditionParamTypeRef> parameters = default(Dictionary<string, ConditionParamTypeRef>), ConditionMetadata metadata = default(ConditionMetadata)) {
// to ensure "name" is required (not null)
if (name == null) {
throw new ArgumentNullException("name is a required property for Condition and cannot be null");
Expand All @@ -48,6 +49,7 @@ public Condition() {
}
this.Expression = expression;
this.Parameters = parameters;
this.Metadata = metadata;
this.AdditionalProperties = new Dictionary<string, object>();
}

Expand Down Expand Up @@ -77,6 +79,14 @@ public Condition() {
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Dictionary<string, ConditionParamTypeRef>? Parameters { get; set; }

/// <summary>
/// Gets or Sets Metadata
/// </summary>
[DataMember(Name = "metadata", EmitDefaultValue = false)]
[JsonPropertyName("metadata")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public ConditionMetadata? Metadata { get; set; }

/// <summary>
/// Gets or Sets additional properties
/// </summary>
Expand Down Expand Up @@ -134,6 +144,11 @@ public bool Equals(Condition input) {
this.Parameters != null &&
input.Parameters != null &&
this.Parameters.SequenceEqual(input.Parameters)
) &&
(
this.Metadata == input.Metadata ||
(this.Metadata != null &&
this.Metadata.Equals(input.Metadata))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
}
Expand All @@ -155,6 +170,9 @@ public override int GetHashCode() {
if (this.Parameters != null) {
hashCode = (hashCode * 9923) + this.Parameters.GetHashCode();
}
if (this.Metadata != null) {
hashCode = (hashCode * 9923) + this.Metadata.GetHashCode();
}
if (this.AdditionalProperties != null) {
hashCode = (hashCode * 9923) + this.AdditionalProperties.GetHashCode();
}
Expand Down
147 changes: 147 additions & 0 deletions src/OpenFga.Sdk/Model/ConditionMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
//
// OpenFGA/.NET SDK for OpenFGA
//
// API version: 0.1
// Website: https://openfga.dev
// Documentation: https://openfga.dev/docs
// Support: https://openfga.dev/community
// License: [Apache-2.0](https://github.com/openfga/dotnet-sdk/blob/main/LICENSE)
//
// NOTE: This file was auto generated. DO NOT EDIT.
//


using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace OpenFga.Sdk.Model {
/// <summary>
/// ConditionMetadata
/// </summary>
[DataContract(Name = "ConditionMetadata")]
public partial class ConditionMetadata : IEquatable<ConditionMetadata>, IValidatableObject {
/// <summary>
/// Initializes a new instance of the <see cref="ConditionMetadata" /> class.
/// </summary>
[JsonConstructor]
public ConditionMetadata() {
this.AdditionalProperties = new Dictionary<string, object>();
}

/// <summary>
/// Initializes a new instance of the <see cref="ConditionMetadata" /> class.
/// </summary>
/// <param name="module">module.</param>
/// <param name="sourceInfo">sourceInfo.</param>
public ConditionMetadata(string module = default(string), SourceInfo sourceInfo = default(SourceInfo)) {
this.Module = module;
this.SourceInfo = sourceInfo;
this.AdditionalProperties = new Dictionary<string, object>();
}

/// <summary>
/// Gets or Sets Module
/// </summary>
[DataMember(Name = "module", EmitDefaultValue = false)]
[JsonPropertyName("module")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string? Module { get; set; }

/// <summary>
/// Gets or Sets SourceInfo
/// </summary>
[DataMember(Name = "source_info", EmitDefaultValue = false)]
[JsonPropertyName("source_info")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public SourceInfo? SourceInfo { get; set; }

/// <summary>
/// Gets or Sets additional properties
/// </summary>
[JsonExtensionData]
public IDictionary<string, object> AdditionalProperties { get; set; }


/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public virtual string ToJson() {
return JsonSerializer.Serialize(this);
}

/// <summary>
/// Builds a ConditionMetadata from the JSON string presentation of the object
/// </summary>
/// <returns>ConditionMetadata</returns>
public static ConditionMetadata FromJson(string jsonString) {
return JsonSerializer.Deserialize<ConditionMetadata>(jsonString) ?? throw new InvalidOperationException();
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="input">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object input) {
return this.Equals(input as ConditionMetadata);
}

/// <summary>
/// Returns true if ConditionMetadata instances are equal
/// </summary>
/// <param name="input">Instance of ConditionMetadata to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(ConditionMetadata input) {
if (input == null) {
return false;
}
return
(
this.Module == input.Module ||
(this.Module != null &&
this.Module.Equals(input.Module))
) &&
(
this.SourceInfo == input.SourceInfo ||
(this.SourceInfo != null &&
this.SourceInfo.Equals(input.SourceInfo))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode() {
unchecked // Overflow is fine, just wrap
{
int hashCode = 9661;
if (this.Module != null) {
hashCode = (hashCode * 9923) + this.Module.GetHashCode();
}
if (this.SourceInfo != null) {
hashCode = (hashCode * 9923) + this.SourceInfo.GetHashCode();
}
if (this.AdditionalProperties != null) {
hashCode = (hashCode * 9923) + this.AdditionalProperties.GetHashCode();
}
return hashCode;
}
}

/// <summary>
/// To validate all properties of the instance
/// </summary>
/// <param name="validationContext">Validation context</param>
/// <returns>Validation Result</returns>
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext) {
yield break;
}

}

}
38 changes: 37 additions & 1 deletion src/OpenFga.Sdk/Model/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ public Metadata() {
/// Initializes a new instance of the <see cref="Metadata" /> class.
/// </summary>
/// <param name="relations">relations.</param>
public Metadata(Dictionary<string, RelationMetadata> relations = default(Dictionary<string, RelationMetadata>)) {
/// <param name="module">module.</param>
/// <param name="sourceInfo">sourceInfo.</param>
public Metadata(Dictionary<string, RelationMetadata> relations = default(Dictionary<string, RelationMetadata>), string module = default(string), SourceInfo sourceInfo = default(SourceInfo)) {
this.Relations = relations;
this.Module = module;
this.SourceInfo = sourceInfo;
this.AdditionalProperties = new Dictionary<string, object>();
}

Expand All @@ -47,6 +51,22 @@ public Metadata() {
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public Dictionary<string, RelationMetadata>? Relations { get; set; }

/// <summary>
/// Gets or Sets Module
/// </summary>
[DataMember(Name = "module", EmitDefaultValue = false)]
[JsonPropertyName("module")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public string? Module { get; set; }

/// <summary>
/// Gets or Sets SourceInfo
/// </summary>
[DataMember(Name = "source_info", EmitDefaultValue = false)]
[JsonPropertyName("source_info")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
public SourceInfo? SourceInfo { get; set; }

/// <summary>
/// Gets or Sets additional properties
/// </summary>
Expand Down Expand Up @@ -94,6 +114,16 @@ public bool Equals(Metadata input) {
this.Relations != null &&
input.Relations != null &&
this.Relations.SequenceEqual(input.Relations)
) &&
(
this.Module == input.Module ||
(this.Module != null &&
this.Module.Equals(input.Module))
) &&
(
this.SourceInfo == input.SourceInfo ||
(this.SourceInfo != null &&
this.SourceInfo.Equals(input.SourceInfo))
)
&& (this.AdditionalProperties.Count == input.AdditionalProperties.Count && !this.AdditionalProperties.Except(input.AdditionalProperties).Any());
}
Expand All @@ -109,6 +139,12 @@ public override int GetHashCode() {
if (this.Relations != null) {
hashCode = (hashCode * 9923) + this.Relations.GetHashCode();
}
if (this.Module != null) {
hashCode = (hashCode * 9923) + this.Module.GetHashCode();
}
if (this.SourceInfo != null) {
hashCode = (hashCode * 9923) + this.SourceInfo.GetHashCode();
}
if (this.AdditionalProperties != null) {
hashCode = (hashCode * 9923) + this.AdditionalProperties.GetHashCode();
}
Expand Down
Loading

0 comments on commit 5509927

Please sign in to comment.