Repository navigation
add api defaults and scalar #128
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,28 @@ | ||
| namespace MobileConfiguration.DataTransferObjects; | ||
| using System.ComponentModel; | ||
|
|
||
| namespace MobileConfiguration.DataTransferObjects; | ||
|
|
||
| [Description("Configuration settings associated with a Transaction Mobile device.")] | ||
| public class Configuration | ||
| { | ||
| [Description("Client identifier used by the mobile device.")] | ||
| public string ClientId { get; set; } | ||
|
|
||
| [Description("Client secret used by the mobile device. Treat this value as sensitive.")] | ||
| public string ClientSecret { get; set; } | ||
|
|
||
| [Description("Identifier of the mobile device.")] | ||
| public string DeviceIdentifier { get; set; } | ||
|
|
||
| [Description("Whether the mobile device should install updates automatically.")] | ||
| public bool EnableAutoUpdates { get; set; } | ||
|
|
||
| [Description("Service URI values available to the mobile device.")] | ||
| public List<HostAddress> HostAddresses { get; set; } | ||
|
|
||
| [Description("Unique identifier for this configuration.")] | ||
| public string Id { get; set; } | ||
|
|
||
| [Description("Minimum severity level written by the mobile client. Enum values are numeric in JSON.")] | ||
| public LoggingLevel LogLevel { get; set; } | ||
| } |
12 changes: 11 additions & 1 deletion
12
MobileConfiguration/DataTransferObjects/ConfigurationResponse.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,27 @@ | ||
| namespace MobileConfiguration.DataTransferObjects; | ||
| using System.ComponentModel; | ||
|
|
||
| namespace MobileConfiguration.DataTransferObjects; | ||
|
|
||
| [Description("Configuration returned for a Transaction Mobile device. Includes the client secret.")] | ||
| public class ConfigurationResponse | ||
| { | ||
| [Description("Client identifier used by the mobile device.")] | ||
| public string ClientId { get; set; } | ||
| [Description("Client secret used by the mobile device. Treat this value as sensitive.")] | ||
| public string ClientSecret { get; set; } | ||
|
|
||
| [Description("Identifier of the mobile device.")] | ||
| public string DeviceIdentifier { get; set; } | ||
|
|
||
| [Description("Whether the mobile device should install updates automatically.")] | ||
| public bool EnableAutoUpdates { get; set; } | ||
|
|
||
| [Description("Service URI values available to the mobile device.")] | ||
| public List<HostAddress> HostAddresses { get; set; } | ||
|
|
||
| [Description("Unique identifier for this configuration.")] | ||
| public string Id { get; set; } | ||
|
|
||
| [Description("Minimum severity level written by the mobile client. Enum values are numeric in JSON.")] | ||
| public LoggingLevel LogLevel { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,13 @@ | ||
| namespace MobileConfiguration.DataTransferObjects; | ||
| using System.ComponentModel; | ||
|
|
||
| namespace MobileConfiguration.DataTransferObjects; | ||
|
|
||
| [Description("A service type and the URI where the mobile client can reach it.")] | ||
| public class HostAddress | ||
| { | ||
| [Description("Service represented by this address. Enum values are numeric in JSON.")] | ||
| public ServiceType ServiceType { get; set; } | ||
|
|
||
| [Description("URI for the service endpoint.")] | ||
| public string Uri { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,14 @@ | ||
| namespace MobileConfiguration.DataTransferObjects; | ||
| using System.ComponentModel; | ||
|
|
||
| namespace MobileConfiguration.DataTransferObjects; | ||
|
|
||
| [Description("A log event submitted by a mobile client.")] | ||
| public class LogMessage | ||
| { | ||
| [Description("Timestamp associated with the log event.")] | ||
| public DateTime EntryDateTime { get; set; } | ||
| [Description("Log severity label supplied by the client.")] | ||
| public String LogLevel { get; set; } | ||
| [Description("Text of the log event.")] | ||
| public String Message { get; set; } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
MobileConfiguration/OpenApi/MobileConfigurationExamplesOperationTransformer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| using System.Text.Json.Nodes; | ||
| using Microsoft.AspNetCore.OpenApi; | ||
| using Microsoft.OpenApi; | ||
|
|
||
| namespace MobileConfiguration.OpenApi; | ||
|
|
||
| /// <summary> | ||
| /// Adds representative request and response payloads to the generated OpenAPI document. | ||
| /// </summary> | ||
| internal sealed class MobileConfigurationExamplesOperationTransformer : IOpenApiOperationTransformer | ||
| { | ||
| private const string ConfigurationExample = """ | ||
| { | ||
| "clientId": "mobile-client", | ||
| "clientSecret": "example-secret", | ||
| "deviceIdentifier": "device-123", | ||
| "enableAutoUpdates": true, | ||
| "hostAddresses": [ | ||
| { "serviceType": 2, "uri": "https://transactions.example.test" } | ||
| ], | ||
| "id": "device-123", | ||
| "logLevel": 3 | ||
| } | ||
| """; | ||
|
|
||
| private const string ConfigurationResponseExample = """ | ||
| { | ||
| "clientId": "mobile-client", | ||
| "clientSecret": "example-secret", | ||
| "deviceIdentifier": "device-123", | ||
| "enableAutoUpdates": true, | ||
| "hostAddresses": [ | ||
| { "serviceType": 2, "uri": "https://transactions.example.test" } | ||
| ], | ||
| "id": "device-123", | ||
| "logLevel": 3 | ||
| } | ||
| """; | ||
|
|
||
| private const string CreateSuccessExample = """ | ||
| { | ||
| "status": 0, | ||
| "isSuccess": true, | ||
| "isFailed": false, | ||
| "message": "Configuration created successfully.", | ||
| "errors": [] | ||
| } | ||
| """; | ||
|
|
||
| private const string CreateFailureExample = """ | ||
| { | ||
| "status": 6, | ||
| "isSuccess": false, | ||
| "isFailed": true, | ||
| "message": "Failed to create configuration: persistence failed.", | ||
| "errors": [] | ||
| } | ||
| """; | ||
|
|
||
| private const string LogMessagesExample = """ | ||
| [ | ||
| { | ||
| "entryDateTime": "2026-10-21 09:30:00", | ||
| "logLevel": "Information", | ||
| "message": "Mobile client started" | ||
| } | ||
| ] | ||
| """; | ||
|
|
||
| public Task TransformAsync(OpenApiOperation operation, | ||
| OpenApiOperationTransformerContext context, | ||
| CancellationToken cancellationToken) | ||
| { | ||
| string path = context.Description.RelativePath?.Trim('/') ?? string.Empty; | ||
| string? requestExample = (context.Description.HttpMethod, path) switch | ||
| { | ||
| ("POST", "api/transactionmobile/configuration") => ConfigurationExample, | ||
| ("PUT", "api/transactionmobile/configuration/{id}") => ConfigurationExample, | ||
| ("POST", "api/transactionmobile/logging") => LogMessagesExample, | ||
| _ => null | ||
| }; | ||
|
|
||
| if (requestExample is not null | ||
| && operation.RequestBody is OpenApiRequestBody requestBody | ||
| && requestBody.Content is not null | ||
| && requestBody.Content.TryGetValue("application/json", out OpenApiMediaType? requestMediaType)) | ||
| { | ||
| requestMediaType.Example = JsonNode.Parse(requestExample); | ||
| } | ||
|
|
||
| string? successResponseExample = (context.Description.HttpMethod, path) switch | ||
| { | ||
| ("POST", "api/transactionmobile/configuration") => CreateSuccessExample, | ||
| ("GET", "api/transactionmobile/configuration/{id}") => ConfigurationResponseExample, | ||
| _ => null | ||
| }; | ||
|
|
||
| SetResponseExample(operation, "200", successResponseExample); | ||
|
|
||
| if (context.Description.HttpMethod == "POST" && path == "api/transactionmobile/configuration") | ||
| { | ||
| SetResponseExample(operation, "400", CreateFailureExample); | ||
| } | ||
|
|
||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private static void SetResponseExample(OpenApiOperation operation, string statusCode, string? example) | ||
| { | ||
| if (example is not null | ||
| && operation.Responses is not null | ||
| && operation.Responses.TryGetValue(statusCode, out IOpenApiResponse? response) | ||
| && response.Content is not null | ||
| && response.Content.TryGetValue("application/json", out OpenApiMediaType? mediaType)) | ||
| { | ||
| mediaType.Example = JsonNode.Parse(example); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,3 @@ | ||
| # MobileConfiguration | ||
| # MobileConfiguration | ||
|
|
||
| Open Scalar at `/scalar` for the interactive, generated API reference. See [the API and DTO reference](docs/api.md) for endpoint routes, request and response shapes, enum values, and examples. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.