Skip to content

Commit

Permalink
3.1.7: fixup for nim-1.0 nosinks
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed May 25, 2020
1 parent 17decc6 commit 953bb02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion openapi.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "3.1.6"
version = "3.1.7"
author = "disruptek"
description = "OpenAPI Code Generator"
license = "MIT"
Expand Down
21 changes: 13 additions & 8 deletions src/openapi/codegen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,11 @@ proc makeCallWithLocationInputs(generator: var Generator;
ident"validator").newCall(validatorParams))

var
urlProc = newDotExpr(callName, ident"url")
urlProc = newDotExpr(callName, ident"makeUrl")
urlHost = newDotExpr(callName, ident"host")
urlBase = newDotExpr(callName, ident"base")
urlRoute = newDotExpr(callName, ident"route")
letUrl = ident"uri"
scheme = ident"scheme"
protocol = newDotExpr(scheme, ident"get")
path = newCall(newDotExpr(ident"valid", ident"getOrDefault"),
Expand All @@ -658,7 +659,7 @@ proc makeCallWithLocationInputs(generator: var Generator;
body.add quote do:
if `scheme`.isNone:
raise newException(IOError, "unable to find a supported scheme")
body.add newLetStmt(ident"url", newCall(urlProc, protocol, urlHost,
body.add newLetStmt(letUrl, newCall(urlProc, protocol, urlHost,
urlBase, urlRoute, path, query))
if generator.recallable == nil:
# pull the headers out of the validated input JsonNode
Expand All @@ -669,12 +670,12 @@ proc makeCallWithLocationInputs(generator: var Generator;
# by default, we just run newRecallable() with the url, headers, and body
body.add newAssignment(ident"result",
newCall(ident"newRecallable", callName,
ident"url", heads, ident"_"))
letUrl, heads, ident"_"))
else:
# if the user supplies a hook, we'll supply the validated inputs node
body.add newAssignment(ident"result",
newCall(generator.recallable, callName,
ident"url", ident"valid", ident"_"))
letUrl, ident"valid", ident"_"))

var params = @[ident"Recallable"]
params.add newIdentDefs(callName, op.typename)
Expand Down Expand Up @@ -752,7 +753,10 @@ proc makeValidator(op: Operation; name: NimNode; root: JsonNode): Option[NimNode
params.add newIdentDefs(ident"_", ident"string", newStrLitNode"")
let
maybe = maybeDeprecate(name, params, body, deprecate=op.deprecated)
result = addNoSink(maybe).some
when NimMajor == 1 and NimMinor < 1:
result = maybe.some
else:
result = addNoSink(maybe).some

proc usesJsonWhenNative(param: Parameter): bool =
## simple test to see if a parameter should use a json type
Expand Down Expand Up @@ -911,7 +915,7 @@ proc makeCallVar(generator: Generator; path: PathItem; op: Operation): NimNode =
result = quote do:
var `saneCall` = `saneType`(name: `sane`, meth: `methId`, host: `host`,
route: `route`, validator: `validId`,
base: `base`, url: `urlId`, schemes: `schemes`)
base: `base`, makeUrl: `urlId`, schemes: `schemes`)

proc newOperation(path: PathItem; meth: HttpOpName; root: JsonNode; input: JsonNode): Operation =
## create a new operation for a given http method on a given path
Expand Down Expand Up @@ -1152,8 +1156,9 @@ proc preamble(oac: NimNode): NimNode =
base*: string
host*: string
schemes*: set[Scheme]
url*: proc (`protoP`: Scheme; `hostP`: string; `baseP`: string;
`routeP`: string; `pathP`: JsonNode; `queryP`: JsonNode): Uri
makeUrl*: proc (`protoP`: Scheme; `hostP`: string;
`baseP`: string; `routeP`: string;
`pathP`: JsonNode; `queryP`: JsonNode): Uri

# this gives the user a type to hook into for code in their macro
`oac` = ref object of `oarcP`
Expand Down

0 comments on commit 953bb02

Please sign in to comment.