Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
abnegate committed Oct 30, 2023
1 parent 4c28b96 commit c6b5686
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 36 deletions.
2 changes: 1 addition & 1 deletion templates/dart/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ void main() { // Init SDK

{% endif %}
{% if parameter.required %}
{{ parameter.name | caseCamel | overrideIdentifier }}:{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseCamel | replace({'-': ''}) }}{% else %}{{ parameter | paramExample | replace({'<field-name>': (parameter.name | caseCamel) }) | raw }} {% endif %},
{{ parameter.name | caseCamel | overrideIdentifier }}:{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseCamel | replace({'-': ''}) }}{% else %}{{ parameter | paramExample | replace({'<field-name>': (parameter.name | caseCamel) }) | raw }} {% endif %},
{% endif %}
{% endfor %}{% if method.parameters.all | length > 0 %} {% endif %});

Expand Down
2 changes: 1 addition & 1 deletion templates/deno/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ client

{% endif %}

let promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %});
let promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %});

promise.then(function (response) {
console.log(response);
Expand Down
2 changes: 1 addition & 1 deletion templates/dotnet/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ var {{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}(client
{% if method.method != 'delete' %}{% if method.type == 'location' %}byte[]{% else %}{{ method.responseModel | caseUcfirst | overrideIdentifier }}{% endif %} result = {% endif %}await {{ service.name | caseCamel }}.{{ method.name | caseUcfirst }}({% if method.parameters.all | length == 0 %});{% endif %}
{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %},{% endif %}

{{ parameter.name }}: {% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}{% if method.parameters.all | length > 0 %});{% endif %}
{{ parameter.name }}: {% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %}{% if method.parameters.all | length > 0 %});{% endif %}
6 changes: 3 additions & 3 deletions templates/flutter/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() { // Init SDK

{% endif %}
{% if parameter.required %}
{{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %},
{{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %},
{% endif %}
{% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}).then((bytes) {
final file = File('path_to_file/filename.ext');
Expand All @@ -40,7 +40,7 @@ FutureBuilder(

{% endif %}
{% if parameter.required %}
{{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %},
{{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %},
{% endif %}
{% endfor %}{% if method.parameters.all | length > 0 %} {% endif %}
), //works for both public file and private file, for private files you need to be logged in
Expand All @@ -58,7 +58,7 @@ FutureBuilder(

{% endif %}
{% if parameter.required %}
{{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ parameter.enumValues[0] | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %},
{{ parameter.name | caseCamel | overrideIdentifier}}:{% if parameter.enumValues | length > 0%} {{parameter.enumName}}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}.value{% else %}{{ parameter | paramExample}} {% endif %},
{% endif %}
{% endfor %}{% if method.parameters.all | length > 0 %} {% endif %});

Expand Down
22 changes: 17 additions & 5 deletions templates/kotlin/docs/java/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback;
import {{ sdk.namespace | caseDot }}.models.InputFile;
{% endif %}
import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }};
{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %}
{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}};{% endif %}

{% endif %}{% endfor %}
{% set added = [] %}
{% for parameter in method.parameters.all %}
{% if method == parameter.required %}
{% if parameter.enumValues is not empty %}
{% if parameter.enumName is not empty %}
{% set name = parameter.enumName %}
{% else %}
{% set name = parameter.name %}
{% endif %}
{% if name not in added %}
import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }};
{% set added = added|merge([name]) %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}

Client client = new Client()
{% if method.auth|length > 0 %}
Expand All @@ -30,7 +42,7 @@ Client client = new Client()

{% for parameter in method.parameters.all %}
{% if parameter.required %}
{% if parameter.enumValues | length > 0%} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %}
{% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %}

{% endif %}
{% if loop.last %}
Expand Down
25 changes: 19 additions & 6 deletions templates/kotlin/docs/kotlin/example.md.twig
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
import {{ sdk.namespace | caseDot }}.Client
import {{ sdk.namespace | caseDot }}.coroutines.CoroutineCallback
{% if method.parameters.all | filter((param) => param.type == 'file') | length > 0 %}
import {{ sdk.namespace | caseDot }}.models.InputFile
{% endif %}
import {{ sdk.namespace | caseDot }}.services.{{ service.name | caseUcfirst }}
{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %}
{% if parameter.enumValues | length > 0%}import {{ sdk.namespace | caseDot }}.enums.{{parameter.enumName | caseUcfirst}}{% endif %}

{% endif %}{% endfor %}
{% set added = [] %}
{% for parameter in method.parameters.all %}
{% if method == parameter.required %}
{% if parameter.enumValues is not empty %}
{% if parameter.enumName is not empty %}
{% set name = parameter.enumName %}
{% else %}
{% set name = parameter.name %}
{% endif %}
{% if name not in added %}
import {{ sdk.namespace | caseDot }}.enums.{{ name | caseUcfirst }}
{% set added = added|merge([name]) %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}

val client = Client(context)
val client = Client()
{% if method.auth|length > 0 %}
.setEndpoint("https://cloud.appwrite.io/v1") // Your API Endpoint
{% for node in method.auth %}
Expand All @@ -22,7 +35,7 @@ val {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client)

{% for parameter in method.parameters.all %}
{% if parameter.required %}
{{parameter.name}} = {% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %}
{{parameter.name}} = {% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% if not loop.last %},{% endif %}

{% endif %}
{% if loop.last %}
Expand Down
4 changes: 2 additions & 2 deletions templates/node/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require('fs');
// Init SDK
const client = new sdk.Client();

const {{ service.name | caseCamel }} = new sdk.{{service.name | caseUcfirst}}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %});
const {{ service.name | caseCamel }} = new sdk.{{service.name | caseUcfirst}}(client);

{% if method.auth|length > 0 %}
client
Expand All @@ -18,7 +18,7 @@ client
{% endfor %};

{% endif %}
const promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{parameter.enumName}}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | replace({'-': '',' ': ''}) }}{% else%}{{ parameter | paramExample}}{% endif %}{% endif %}{% endfor %});
const promise = {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}sdk.{{ parameter.enumName }}.{{(parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample}}{% endif %}{% endif %}{% endfor %});

promise.then(function (response) {
console.log(response);
Expand Down
24 changes: 18 additions & 6 deletions templates/php/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@ use {{ spec.title | caseUcfirst }}\Client;
use {{ spec.title | caseUcfirst }}\InputFile;
{% endif %}
use {{ spec.title | caseUcfirst }}\Services\{{ service.name | caseUcfirst }};
{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %}
{% if parameter.enumValues | length > 0%}use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}};{% endif %}
{% endif %}{% endfor %}
{% set added = [] %}
{% for parameter in method.parameters.all %}
{% if method == parameter.required %}
{% if parameter.enumValues is not empty %}
{% if parameter.enumName is not empty %}
{% set name = parameter.enumName %}
{% else %}
{% set name = parameter.name %}
{% endif %}
{% if name not in added %}
use {{ spec.title | caseUcfirst }}\Enums\{{parameter.enumName | caseUcfirst}};
{% set added = added|merge([name]) %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
$client = new Client();
Expand All @@ -22,6 +34,6 @@ $client
{% endfor %};
{% endif %}
${{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %});
${{ service.name | caseCamel }} = new {{ service.name | caseUcfirst }}($client);
$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %});
$result = ${{ service.name | caseCamel }}->{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0%}{{ parameter.enumName }}::{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}(){% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %});
24 changes: 18 additions & 6 deletions templates/python/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ from {{ spec.title | caseSnake }}.client import Client
{% if method.parameters.all | filter((param) => param.type == 'file') | length > 0 %}
from {{ spec.title | caseSnake }}.input_file import InputFile
{% endif %}
from {{ spec.title | caseSnake }}.services.{{ service.name | caseSnake }} import {{ service.name | caseUcfirst }}
{% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}{% endif %}
{% if parameter.enumValues | length > 0%}from {{ spec.title | caseUcfirst }}.enums import {{parameter.enumName | caseUcfirst}},{% endif %}
{% endif %}{% endfor %}
{% set added = [] %}
{% for parameter in method.parameters.all %}
{% if method == parameter.required %}
{% if parameter.enumValues is not empty %}
{% if parameter.enumName is not empty %}
{% set name = parameter.enumName %}
{% else %}
{% set name = parameter.name %}
{% endif %}
{% if name not in added %}
from {{ spec.title | caseUcfirst }}.enums import {{parameter.enumName | caseUcfirst}}
{% set added = added|merge([name]) %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}

client = Client()

Expand All @@ -19,6 +31,6 @@ client = Client()
{% endfor %})

{% endif %}
{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %})
{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}(client)

result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %} {{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %})
result = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %})
15 changes: 13 additions & 2 deletions templates/ruby/docs/example.md.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
require '{{ spec.title }}'

include {{ spec.title | caseUcfirst }}
{% set break = false %}
{% for parameter in method.parameters.all %}
{% if not break %}
{% if method == parameter.required %}
{% if parameter.enumValues is not empty %}
include {{ spec.title | caseUcfirst }}::Enums
{% set break = true %}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}

client = Client.new
.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
Expand All @@ -10,8 +21,8 @@ client = Client.new
{% endfor %}
{% endfor %}

{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}.new(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{parameter.name | caseSnake}}:{{ parameter | paramExample }}{% endfor %}{% endif %})
{{ service.name | caseSnake }} = {{ service.name | caseUcfirst }}.new(client)

response = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{parameter.name|caseSnake}}: {% if parameter.type == 'file' %}{{ parameter | paramExample }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %})
response = {{ service.name | caseSnake }}.{{ method.name | caseSnake }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{{parameter.name|caseSnake}}: {% if parameter.type == 'file' %}{{ parameter | paramExample }}{% else %}{% if parameter.enumValues | length > 0%}{{ parameter.enumName }}::{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample }}{% endif %}{% endif %}{% endif %}{% endfor %})

puts response.inspect
4 changes: 2 additions & 2 deletions templates/swift/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ let client = Client()

let {{ service.name | caseCamel }} = {{ service.name | caseUcfirst }}(client{% if service.globalParams | length %}{% for parameter in service.globalParams %}, {{ parameter | paramExample }}{% endfor %}{% endif %})

let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}byteBuffer{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeSwiftKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %}
let {% if method.type == 'webAuth' %}success{% elseif method.type == 'location' %}bytes{% elseif method.responseModel | length == 0 %}result{% else %}{{ method.responseModel | caseCamel | escapeSwiftKeyword }}{% endif %} = try await {{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% if method.parameters.all | filter((param) => param.required) | length == 0 %}){{ '\n' }}{% endif %}

{% for parameter in method.parameters.all | filter((parameter) => parameter.required) %}
{{ parameter.name }}: {% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else %}{{ parameter | paramExample | escapeSwiftKeyword }}{% endif %}{% if not loop.last %},{% endif %}
{{ parameter.name }}: {% if parameter.enumValues | length > 0 %}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else %}{{ parameter | paramExample | escapeSwiftKeyword }}{% endif %}{% if not loop.last %},{% endif %}
{% if loop.last %}

)
Expand Down
2 changes: 1 addition & 1 deletion templates/web/docs/example.md.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ client
{% endif %}
{% if method.type == 'webAuth' %}// Go to OAuth provider login page
{% endif %}
{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}const result = {% else %}const promise = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ parameter.enumValues[0] | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %});
{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}const result = {% else %}const promise = {% endif %}{{ service.name | caseCamel }}.{{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if parameter.required %}{% if not loop.first %}, {% endif %}{% if parameter.enumValues | length > 0 %}{{ parameter.enumName }}.{{ (parameter.enumKeys[0] ?? parameter.enumValues[0]) | caseEnumKey }}{% else%}{{ parameter | paramExample }}{% endif %}{% endif %}{% endfor %});

{% if method.type == 'webAuth' %}{% elseif method.type == 'location' %}console.log(result); // Resource URL{% else %}promise.then(function (response) {
console.log(response); // Success
Expand Down

0 comments on commit c6b5686

Please sign in to comment.