Skip to content
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

refactor(spec): add uint8 for int encoding and templatize #711

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-walls-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@azure-tools/cadl-ranch-specs": patch
---

refactor(spec): add uint8 for int encoding and templatize
21 changes: 21 additions & 0 deletions packages/cadl-ranch-specs/cadl-ranch-summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,27 @@ Expected response body:
}
```

### Encode_Numeric_Property_uint8AsString

- Endpoint: `post /encode/numeric/property/uint8`

Test operation with request and response model contains property of uint8 type with string encode.
Expected request body:

```json
{
"value": "255"
archerzz marked this conversation as resolved.
Show resolved Hide resolved
}
```

Expected response body:

```json
{
"value": "255"
}
```

### Parameters_Basic_ExplicitBody_simple

- Endpoint: `put /parameters/basic/explicit-body/simple`
Expand Down
79 changes: 43 additions & 36 deletions packages/cadl-ranch-specs/http/encode/numeric/main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,60 @@ namespace Encode.Numeric;
@operationGroup
@route("/property")
namespace Property {
alias SendSafeIntAsString = SendIntAsString<safeint, "10000000000", SafeintAsStringProperty>;

@route("/safeint")
@scenario
@scenarioDoc("""
Test operation with request and response model contains property of safeint type with string encode.
Expected request body:
```json
{
"value": "10000000000"
}
```
Expected response body:
```json
{
"value": "10000000000"
}
```
""")
@post
op safeintAsString(@body body: SafeintAsStringProperty): SafeintAsStringProperty;
op safeintAsString is SendSafeIntAsString.sendIntAsString;

model SafeintAsStringProperty {
@encode(string)
value: safeint;
}

alias SendUint32AsString = SendIntAsString<uint32, "1", Uint32AsStringProperty>;

@route("/uint32")
@scenario
@scenarioDoc("""
Test operation with request and response model contains property of uint32 type with string encode.
Expected request body:
```json
{
"value": "1"
}
```
Expected response body:
```json
{
"value": "1"
}
```
""")
@post
op uint32AsStringOptional(@body body: Uint32AsStringProperty): Uint32AsStringProperty;
op uint32AsStringOptional is SendUint32AsString.sendIntAsString;
archerzz marked this conversation as resolved.
Show resolved Hide resolved

model Uint32AsStringProperty {
@encode(string)
value?: uint32;
}

alias SendUint8AsString = SendIntAsString<uint8, "255", Uint8AsStringProperty>;

@route("/uint8")
op uint8AsString is SendUint8AsString.sendIntAsString;

model Uint8AsStringProperty {
@encode(string)
value: uint8;
}

interface SendIntAsString<IntType extends integer, StringValue extends string, Payload> {
@scenario
@scenarioDoc(
"""
Test operation with request and response model contains property of {type} type with string encode.
Expected request body:
```json
{
"value": "{value}"
}
```
Expected response body:
```json
{
"value": "{value}"
}
```
""",
{
type: IntType,
value: StringValue,
}
)
@post
sendIntAsString(@body value: Payload): Payload;
}
}
2 changes: 2 additions & 0 deletions packages/cadl-ranch-specs/http/encode/numeric/mockapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ function createPropertyMockApis(route: string, value: string): MockApi {
Scenarios.Encode_Numeric_Property_safeintAsString = passOnSuccess(createPropertyMockApis("safeint", "10000000000"));

Scenarios.Encode_Numeric_Property_uint32AsStringOptional = passOnSuccess(createPropertyMockApis("uint32", "1"));

Scenarios.Encode_Numeric_Property_uint8AsString = passOnSuccess(createPropertyMockApis("uint8", "255"));
Loading