Skip to content

Commit 50cded6

Browse files
committed
snapshot
1 parent ad612fa commit 50cded6

16 files changed

Lines changed: 70 additions & 53 deletions

samples/client/petstore/nim/petstore/apis/api_pet.nim

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ const basepath = "http://petstore.swagger.io/v2"
2828
template constructResult[T](response: Response): untyped =
2929
if response.code in {Http200, Http201, Http202, Http204, Http206}:
3030
try:
31-
when name(stripGenericParams(T.typedesc).typedesc) == name(Table):
32-
(some(json.to(parseJson(response.body), T.typedesc)), response)
33-
else:
34-
(some(marshal.to[T](response.body)), response)
31+
(some(to(parseJson(response.body), T)), response)
3532
except JsonParsingError:
3633
# The server returned a malformed response though the response code is 2XX
3734
# TODO: need better error handling
@@ -58,19 +55,19 @@ proc deletePet*(httpClient: HttpClient, petId: int64, apiKey: string): Response
5855

5956
proc findPetsByStatus*(httpClient: HttpClient, status: seq[Status]): (Option[seq[Pet]], Response) =
6057
## Finds Pets by status
61-
let url_encoded_query_params = encodeQuery([
62-
("status", $status.join(",")), # Status values that need to be considered for filter
63-
])
58+
var query_params_list: seq[(string, string)] = @[]
59+
query_params_list.add(("status", $status.join(",")))
60+
let url_encoded_query_params = encodeQuery(query_params_list)
6461

6562
let response = httpClient.get(basepath & "/pet/findByStatus" & "?" & url_encoded_query_params)
6663
constructResult[seq[Pet]](response)
6764

6865

6966
proc findPetsByTags*(httpClient: HttpClient, tags: seq[string]): (Option[seq[Pet]], Response) {.deprecated.} =
7067
## Finds Pets by tags
71-
let url_encoded_query_params = encodeQuery([
72-
("tags", $tags.join(",")), # Tags to filter by
73-
])
68+
var query_params_list: seq[(string, string)] = @[]
69+
query_params_list.add(("tags", $tags.join(",")))
70+
let url_encoded_query_params = encodeQuery(query_params_list)
7471

7572
let response = httpClient.get(basepath & "/pet/findByTags" & "?" & url_encoded_query_params)
7673
constructResult[seq[Pet]](response)

samples/client/petstore/nim/petstore/apis/api_store.nim

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ const basepath = "http://petstore.swagger.io/v2"
2525
template constructResult[T](response: Response): untyped =
2626
if response.code in {Http200, Http201, Http202, Http204, Http206}:
2727
try:
28-
when name(stripGenericParams(T.typedesc).typedesc) == name(Table):
29-
(some(json.to(parseJson(response.body), T.typedesc)), response)
30-
else:
31-
(some(marshal.to[T](response.body)), response)
28+
(some(to(parseJson(response.body), T)), response)
3229
except JsonParsingError:
3330
# The server returned a malformed response though the response code is 2XX
3431
# TODO: need better error handling

samples/client/petstore/nim/petstore/apis/api_user.nim

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ const basepath = "http://petstore.swagger.io/v2"
2525
template constructResult[T](response: Response): untyped =
2626
if response.code in {Http200, Http201, Http202, Http204, Http206}:
2727
try:
28-
when name(stripGenericParams(T.typedesc).typedesc) == name(Table):
29-
(some(json.to(parseJson(response.body), T.typedesc)), response)
30-
else:
31-
(some(marshal.to[T](response.body)), response)
28+
(some(to(parseJson(response.body), T)), response)
3229
except JsonParsingError:
3330
# The server returned a malformed response though the response code is 2XX
3431
# TODO: need better error handling
@@ -74,10 +71,10 @@ proc getUserByName*(httpClient: HttpClient, username: string): (Option[User], Re
7471

7572
proc loginUser*(httpClient: HttpClient, username: string, password: string): (Option[string], Response) =
7673
## Logs user into the system
77-
let url_encoded_query_params = encodeQuery([
78-
("username", $username), # The user name for login
79-
("password", $password), # The password for login in clear text
80-
])
74+
var query_params_list: seq[(string, string)] = @[]
75+
query_params_list.add(("username", $username))
76+
query_params_list.add(("password", $password))
77+
let url_encoded_query_params = encodeQuery(query_params_list)
8178

8279
let response = httpClient.get(basepath & "/user/login" & "?" & url_encoded_query_params)
8380
constructResult[string](response)

samples/client/petstore/nim/petstore/models/model_api_response.nim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
import json
1111
import tables
12+
import marshal
13+
import options
1214

1315

1416
type ApiResponse* = object
1517
## Describes the result of uploading an image resource
16-
code*: int
17-
`type`*: string
18-
message*: string
18+
code*: Option[int]
19+
`type`*: Option[string]
20+
message*: Option[string]
1921

samples/client/petstore/nim/petstore/models/model_category.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
import json
1111
import tables
12+
import marshal
13+
import options
1214

1315

1416
type Category* = object
1517
## A category for a pet
16-
id*: int64
17-
name*: string
18+
id*: Option[int64]
19+
name*: Option[string]
1820

samples/client/petstore/nim/petstore/models/model_get_pet_stats200response.nim

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@
99

1010
import json
1111
import tables
12+
import marshal
13+
import options
1214

1315

1416
type GetPetStats200response* = object
1517
##
16-
totalPets*: int
17-
status*: string
18+
totalPets*: Option[int]
19+
status*: Option[string]
1820

samples/client/petstore/nim/petstore/models/model_order.nim

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import json
1111
import tables
12+
import marshal
13+
import options
1214

1315

1416
type Status* {.pure.} = enum
@@ -18,12 +20,12 @@ type Status* {.pure.} = enum
1820

1921
type Order* = object
2022
## An order for a pets from the pet store
21-
id*: int64
22-
petId*: int64
23-
quantity*: int
24-
shipDate*: string
23+
id*: Option[int64]
24+
petId*: Option[int64]
25+
quantity*: Option[int]
26+
shipDate*: Option[string]
2527
status*: Status ## Order Status
26-
complete*: bool
28+
complete*: Option[bool]
2729

2830
func `%`*(v: Status): JsonNode =
2931
result = case v:

samples/client/petstore/nim/petstore/models/model_pet.nim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
import json
1111
import tables
12+
import marshal
13+
import options
1214

1315
import model_category
1416
import model_tag
@@ -20,11 +22,11 @@ type Status* {.pure.} = enum
2022

2123
type Pet* = object
2224
## A pet for sale in the pet store
23-
id*: int64
24-
category*: Category
25+
id*: Option[int64]
26+
category*: Option[Category]
2527
name*: string
2628
photoUrls*: seq[string]
27-
tags*: seq[Tag]
29+
tags*: Option[seq[Tag]]
2830
status*: Status ## pet status in the store
2931

3032
func `%`*(v: Status): JsonNode =

samples/client/petstore/nim/petstore/models/model_pet_config_any_of1.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
import json
1111
import tables
12+
import marshal
13+
import options
1214

1315

1416
type PetConfigAnyOf1* = object
1517
##
16-
version*: int
18+
version*: Option[int]
1719

samples/client/petstore/nim/petstore/models/model_pet_metadata.nim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
import json
1111
import tables
12+
import marshal
13+
import options
1214

1315

1416
type PetMetadata* = object
1517
##
16-
metadata*: string
18+
metadata*: Option[string]
1719

0 commit comments

Comments
 (0)