xojo-client.api_mock.mustache Maven / Gradle / Ivy
#tag Class
Public Class Mock
{{#apiInfo}}{{#apis}}{{^supportsAsync}} #tag Method, Flags = &h0
Sub test{{classname}}(basePath As String)
Dim error As New {{> nameException}}(0, "No Error")
Dim tmpDownloadFile As FolderItem = GetTemporaryFolderItem
Dim api As New {{projectName}}.{{apiPackage}}.{{classname}}
api.BasePath = basePath
api.BasicAuthUser = "user"
api.BasicAuthPassword = "password"
api.UseHTTPS = false
{{#operations}}{{#operation}}
// Operation {{{operationIdOriginal}}}{{#summary}}
// {{{.}}}{{/summary}}{{^supportsAsync}}
// - parameter localOutStatus: Information on whether the operation succeeded.{{/supportsAsync}}{{#returnProperty}}
// - {{#isBinary}}parameter downloadToFile: The writable, non-existing path in the filesystem where the response body should be stored.{{/isBinary}}{{^isBinary}}{{^supportsAsync}}parameter localOutData: On success, contains the data returned by the API.{{/supportsAsync}}{{/isBinary}}{{/returnProperty}}{{#allParams}}
// - parameter {{paramName}}: ({{#isFormParam}}form{{/isFormParam}}{{#isQueryParam}}query{{/isQueryParam}}{{#isPathParam}}path{{/isPathParam}}{{#isHeaderParam}}header{{/isHeaderParam}}{{#isBodyParam}}body{{/isBodyParam}}) {{description}} {{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}{{/allParams}}
//
// - {{httpMethod}} {{{path}}}{{#notes}}
// - {{{.}}}{{/notes}}{{#subresourceOperation}}
// - subresourceOperation: {{.}}{{/subresourceOperation}}{{#defaultResponse}}
// - defaultResponse: {{.}}{{/defaultResponse}}
//{{#authMethods}}
// - {{#isBasicBasic}}BASIC{{/isBasicBasic}}{{#isBasicBearer}}Bearer Token{{/isBasicBearer}}{{#isOAuth}}OAuth{{/isOAuth}}{{#isApiKey}}API Key{{/isApiKey}}:
// - type: {{type}}{{#keyParamName}} {{keyParamName}} {{#isKeyInQuery}}(QUERY){{/isKeyInQuery}}{{#isKeyInHeader}}(HEADER){{/isKeyInHeader}}{{/keyParamName}}
// - name: {{name}}{{/authMethods}}
//{{#hasResponseHeaders}}
// - responseHeaders: [{{#responseHeaders}}{{{baseName}}}({{{dataType}}}){{^-last}}, {{/-last}}{{/responseHeaders}}]{{/hasResponseHeaders}}{{#allParams}}{{#isArray}}
Dim {{operationId}}{{paramName}}Array() As {{#items}}{{#isModel}}{{> prefixModel}}{{/isModel}}{{{dataType}}}{{/items}}{{/isArray}}{{#isModel}}
Dim {{operationId}}{{paramName}}Model As New {{> prefixModel}}{{{dataType}}}
{{#requiredVars}}{{^isArray}}{{^isEnum}}{{^isEnumOrRef}}{{operationId}}{{paramName}}Model.{{{name}}} = {{#isString}}"{{{example}}}"{{/isString}}{{#isDate}}FromRFC3339("{{{example}}}"){{/isDate}}{{#isDateTime}}FromRFC3339("{{{example}}}"){{/isDateTime}}{{^isString}}{{^isDate}}{{^isDateTime}}{{{example}}}{{/isDateTime}}{{/isDate}}{{/isString}}
{{/isEnumOrRef}}{{/isEnum}}{{/isArray}}{{#isEnum}}// TODO: generating in-model enums is not supported. Issue something like: {{> prefixModel}}MODEL_NAME.{{enumName}}ToString({{> prefixModel}}MODEL_NAME.{{enumName}}.SOMETHING){{/isEnum}}{{/requiredVars}}{{/isModel}}{{/allParams}}{{#returnProperty}}{{^isBinary}}
Dim {{operationId}}Data{{#isArray}}(){{/isArray}} As {{#isModel}}{{> prefixModel}}{{/isModel}}{{#isArray}}{{#items}}{{#isModel}}{{> prefixModel}}{{/isModel}}{{{dataType}}}{{/items}}{{/isArray}}{{^isArray}}{{{dataType}}}{{/isArray}}{{/isBinary}}{{/returnProperty}}
If api.{{operationId}}(error{{#returnProperty}}, {{^isBinary}}{{operationId}}Data{{/isBinary}}{{#isBinary}}tmpDownloadFile{{/isBinary}}{{/returnProperty}}{{#hasParams}}, {{/hasParams}}{{#allParams}}{{#isModel}}{{operationId}}{{paramName}}Model{{/isModel}}{{^isModel}}{{#isEnum}}{{projectName}}.{{apiPackage}}.{{classname}}.{{enumName}}_{{operationId}}.{{#allowableValues}}{{#enumVars}}{{#-first}}{{{name}}}{{/-first}}{{/enumVars}}{{/allowableValues}}{{/isEnum}}{{^isEnum}}{{#isArray}}{{operationId}}{{paramName}}Array{{/isArray}}{{^isArray}}{{#isString}}"{{/isString}}{{{example}}}{{#isString}}"{{/isString}}{{/isArray}}{{#schema}}{{#isEnumRef}}{{projectName}}.{{apiPackage}}.{{classname}}.{{dataType}}.{{#allowableValues}}{{#enumVars}}{{#-first}}{{{name}}}{{/-first}}{{/enumVars}}{{/allowableValues}}{{/isEnumRef}}{{/schema}}{{/isEnum}}{{/isModel}}{{^-last}}, {{/-last}}{{/allParams}}) Then
Print("[+] {{classname}}.{{operationId}} successful.")
Else
Print("[-] {{classname}}.{{operationId}} unsuccessful.")
Print(" " + " | ErrorNumber: " + Str(error.ErrorNumber) + " | HTTP Status: " + Str(error.HTTPCode) + " | SocketCode: " + Str(error.SocketCode) + " | Message: " + error.Message)
End If
{{/operation}}{{/operations}}
End Sub
#tag EndMethod
{{/supportsAsync}}{{/apis}}{{/apiInfo}}
#tag Method, Flags = &h21
Private Function FromRFC3339(stringRepresentation As String) As Date
Dim d As New Xoson.DateIntermediate(stringRepresentation)
return New Date(d.year, d.month, d.day, d.hour, d.minute, d.second, 0.0)
End Function
#tag EndMethod
#tag ViewBehavior
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
InitialValue=""
Type="String"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="useHTTPS"
Visible=false
Group="Behavior"
InitialValue="true"
Type="Boolean"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="port"
Visible=false
Group="Behavior"
InitialValue=""
Type="Integer"
EditorType=""
#tag EndViewProperty
#tag ViewProperty
Name="host"
Visible=false
Group="Behavior"
InitialValue=""
Type="String"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag ViewProperty
Name="BasePath"
Visible=false
Group="Behavior"
InitialValue=""
Type="String"
EditorType="MultiLineEditor"
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass