diff --git a/example.php b/example.php index eb1ebd40b..8ac0e5044 100644 --- a/example.php +++ b/example.php @@ -42,7 +42,7 @@ function getSSLPage($url) { $platform = 'console'; // $platform = 'server'; - $spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/1.7.x/app/config/specs/swagger2-latest-{$platform}.json"); + $spec = getSSLPage("https://raw.githubusercontent.com/appwrite/appwrite/deprecate-old-methods/app/config/specs/swagger2-1.8.x-{$platform}.json"); if(empty($spec)) { throw new Exception('Failed to fetch spec from Appwrite server'); diff --git a/src/SDK/Language/CLI.php b/src/SDK/Language/CLI.php index dc1038ce7..f331a6a31 100644 --- a/src/SDK/Language/CLI.php +++ b/src/SDK/Language/CLI.php @@ -433,7 +433,7 @@ public function getFilters(): array { return array_merge(parent::getFilters(), [ new TwigFilter('caseKebab', function ($value) { - return strtolower(preg_replace('/(?twig->addFilter(new TwigFilter('capitalizeFirst', function ($value) { + return ucfirst($value); + })); + $this->twig->addFilter(new TwigFilter('caseSnakeExceptFirstDot', function ($value) { + $parts = explode('.', $value, 2); + $toSnake = function ($str) { + preg_match_all('!([A-Za-z][A-Z0-9]*(?=$|[A-Z][a-z0-9])|[A-Za-z][a-z0-9]+)!', $str, $matches); + return implode('_', array_map(function ($m) { + return $m === strtoupper($m) ? strtolower($m) : lcfirst($m); + }, $matches[0])); + }; + if (count($parts) < 2) { + return $toSnake($value); + } + return $parts[0] . '.' . $toSnake($parts[1]); + })); } /** diff --git a/src/Spec/Swagger2.php b/src/Spec/Swagger2.php index dcefa5fbd..e1e22b07e 100644 --- a/src/Spec/Swagger2.php +++ b/src/Spec/Swagger2.php @@ -176,6 +176,7 @@ protected function parseMethod(string $methodName, string $pathName, array $meth 'consumes' => $method['consumes'] ?? [], 'cookies' => $method['x-appwrite']['cookies'] ?? false, 'type' => $method['x-appwrite']['type'] ?? false, + 'deprecated' => $method['deprecated'] ?? false, 'headers' => [], 'parameters' => [ 'all' => [], @@ -188,6 +189,11 @@ protected function parseMethod(string $methodName, string $pathName, array $meth 'responseModel' => $responseModel, ]; + if ($method['x-appwrite']['deprecated'] ?? false) { + $output['since'] = $method['x-appwrite']['deprecated']['since'] ?? ''; + $output['replaceWith'] = $method['x-appwrite']['deprecated']['replaceWith'] ?? ''; + } + if ($output['type'] == 'graphql') { $output['headers']['x-sdk-graphql'] = "true"; } diff --git a/templates/android/library/src/main/java/io/package/services/Service.kt.twig b/templates/android/library/src/main/java/io/package/services/Service.kt.twig index 10f4064e5..86ca774de 100644 --- a/templates/android/library/src/main/java/io/package/services/Service.kt.twig +++ b/templates/android/library/src/main/java/io/package/services/Service.kt.twig @@ -38,6 +38,19 @@ class {{ service.name | caseUcfirst }}(client: Client) : Service(client) { * @return [{{ method | returnType(spec, sdk.namespace | caseDot) | raw }}] {%~ endif %} */ + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + @Deprecated( + message = "This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.", + replaceWith = ReplaceWith("{{ sdk.namespace | caseDot }}.services.{{ method.replaceWith | capitalizeFirst }}"), + since = "{{ method.since }}" + ) + {%~ else %} + @Deprecated( + message = "This API has been deprecated." + ) + {%~ endif %} + {%~ endif %} {%~ if method.parameters.all | reduce((carry, param) => carry or not param.required) %} @JvmOverloads {%~ endif %} @@ -192,6 +205,19 @@ class {{ service.name | caseUcfirst }}(client: Client) : Service(client) { * @return [{{ method | returnType(spec, sdk.namespace | caseDot) | raw }}] {%~ endif %} */ + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + @Deprecated( + message = "This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.", + replaceWith = ReplaceWith("{{ sdk.namespace | caseDot }}.services.{{ method.replaceWith | capitalizeFirst }}"), + since = "{{ method.since }}" + ) + {%~ else %} + @Deprecated( + message = "This API has been deprecated." + ) + {%~ endif %} + {%~ endif %} {%~ if method.parameters.all | reduce((carry, param) => carry or not param.required) %} @JvmOverloads {%~ endif %} diff --git a/templates/apple/Sources/Services/Service.swift.twig b/templates/apple/Sources/Services/Service.swift.twig index d3226c144..66ff009af 100644 --- a/templates/apple/Sources/Services/Service.swift.twig +++ b/templates/apple/Sources/Services/Service.swift.twig @@ -23,6 +23,13 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { {%~ if method.type == "webAuth" %} @available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {%~ endif %} + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + @available(*, deprecated, message: "This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.") + {%~ else %} + @available(*, deprecated, message: "This API has been deprecated.") + {%~ endif %} + {%~ endif %} open func {{ method.name | caseCamel | overrideIdentifier }}{% if method.responseModel | hasGenericType(spec) %}{% endif %}( {%~ for parameter in method.parameters.all %} {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName(spec) | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes or method.responseModel | hasGenericType(spec) %},{% endif %} @@ -87,6 +94,13 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { {%~ if method.type == "webAuth" %} @available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {%~ endif %} + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + @available(*, deprecated, message: "This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.") + {%~ else %} + @available(*, deprecated, message: "This API has been deprecated.") + {%~ endif %} + {%~ endif %} open func {{ method.name | caseCamel }}( {%~ for parameter in method.parameters.all %} {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName(spec) | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes %},{% endif %} diff --git a/templates/cli/lib/commands/command.js.twig b/templates/cli/lib/commands/command.js.twig index 51536b24d..2b10c2f64 100644 --- a/templates/cli/lib/commands/command.js.twig +++ b/templates/cli/lib/commands/command.js.twig @@ -59,7 +59,7 @@ const {{ service.name | caseLower }} = new Command("{{ service.name | caseLower /** * @param {{ "{" }}{{ service.name | caseUcfirst }}{{ method.name | caseUcfirst }}RequestParams{{ "}" }} params */ -{%~ block decleration -%} +{% block declaration %} const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {%- for parameter in method.parameters.all -%} {{ parameter.name | caseCamel | escapeKeyword }}, @@ -72,7 +72,13 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {%- if method.type == 'location' -%}, destination{%- endif -%} {% if hasConsolePreview(method.name,service.name) %}, console{%- endif -%} }) => { -{%~ endblock %} +{% if method.deprecated %} +{% if method.since and method.replaceWith %} + console.warn('Warning: This command is deprecated since {{ method.since }}.{% if method.replaceWith %} Please use "{{ method.replaceWith | replace({'.': ' '}) | caseKebab }}" instead.{% endif %}'); +{% else %} + console.warn('Warning: This command is deprecated.'); +{% endif %} +{% endif %} let client = !sdk ? await {% if service.name == "projects" %}sdkForConsole(){% else %}sdkForProject(){% endif %} : sdk; let apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %}; @@ -82,13 +88,14 @@ const {{ service.name | caseLower }}{{ method.name | caseUcfirst }} = async ({ {{ include('cli/base/requests/api.twig') }} {% endif %} } +{% endblock declaration %} {% endfor %} {% for method in service.methods %} {{service.name | caseLower }} .command(`{{ method.name | caseKebab }}`) {% autoescape false %} - .description(`{{ method.description | replace({'`':'\''}) | replace({'\n':' '}) | replace({'\n \n':' '}) }}`) + .description(`{% if method.deprecated %}[**DEPRECATED** - This command is deprecated.{% if method.replaceWith %} Please use '{{ method.replaceWith | replace({'.': ' '}) | caseKebab }}' instead{% endif %}] {% endif %}{{ method.description | replace({'`':'\''}) | replace({'\n':' '}) | replace({'\n \n':' '}) }}`) {% for parameter in method.parameters.all %} .{% if parameter.required and not parameter.nullable %}requiredOption{% else %}option{% endif %}(`--{{ parameter.name | escapeKeyword | caseKebab }}{% if parameter | typeName == 'boolean' %} [value]{% else %} {% if parameter.array.type|length > 0 %}[{% else %}<{% endif %}{{ parameter.name | escapeKeyword | caseKebab }}{% if parameter.array.type|length > 0 %}...{% endif %}{% if parameter.array.type|length > 0 %}]{% else %}>{% endif %}{% endif %}`, `{{ parameter.description | replace({'`':'\''}) | replace({'\n':' '}) | replace({'\n \n':' '}) }}`{% if parameter | typeName == 'boolean' %}, (value) => value === undefined ? true : parseBool(value){% elseif parameter | typeName == 'number' %}, parseInteger{% endif %}) {% endfor %} diff --git a/templates/dart/lib/services/service.dart.twig b/templates/dart/lib/services/service.dart.twig index b7ea9048f..836d10b5d 100644 --- a/templates/dart/lib/services/service.dart.twig +++ b/templates/dart/lib/services/service.dart.twig @@ -17,6 +17,13 @@ class {{ service.name | caseUcfirst }} extends Service { {%~ if method.description %} {{ method.description | dartComment }} {% endif %} +{%~ if method.deprecated %} +{%~ if method.since and method.replaceWith %} + @Deprecated('This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.') +{%~ else %} + @Deprecated('This API has been deprecated.') +{%~ endif %} +{%~ endif %} {% if method.type == 'location' %}Future{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel | overrideIdentifier }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async { final String apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}{% if parameter.enumValues | length > 0 %}.value{% endif %}){% endfor %}; diff --git a/templates/deno/src/services/service.ts.twig b/templates/deno/src/services/service.ts.twig index fedf272a5..2eeca149b 100644 --- a/templates/deno/src/services/service.ts.twig +++ b/templates/deno/src/services/service.ts.twig @@ -77,6 +77,13 @@ export class {{ service.name | caseUcfirst }} extends Service { {% endfor %} * @throws {AppwriteException} * @returns {Promise} + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + * @deprecated This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead. + {%~ else %} + * @deprecated This API has been deprecated. + {%~ endif %} + {%~ endif %} */ async {{ method.name | caseCamel }}{% if generics %}<{{generics}}>{% endif %}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required or parameter.nullable %}?{% endif %}: {{ parameter | typeName }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): Promise<{% if method.type == 'webAuth' %}string{% elseif method.type == 'location' %}ArrayBuffer{% else %}{% if method.responseModel and method.responseModel != 'any' %}{% if not spec.definitions[method.responseModel].additionalProperties %}Models.{% endif %}{{method.responseModel | caseUcfirst}}{% if generics_return %}<{{generics_return}}>{% endif %}{% else %}Response{% endif %}{% endif %}> { {% for parameter in method.parameters.all %} diff --git a/templates/dotnet/Package/Services/ServiceTemplate.cs.twig b/templates/dotnet/Package/Services/ServiceTemplate.cs.twig index 1fb9321c1..99cf15653 100644 --- a/templates/dotnet/Package/Services/ServiceTemplate.cs.twig +++ b/templates/dotnet/Package/Services/ServiceTemplate.cs.twig @@ -26,6 +26,13 @@ namespace {{ spec.title | caseUcfirst }}.Services /// {%~ endif %} /// + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + [Obsolete("This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.")] + {%~ else %} + [Obsolete("This API has been deprecated.")] + {%~ endif %} + {%~ endif %} public Task{% if method.type == "webAuth" %}{% else %}<{{ utils.resultType(spec.title, method) }}>{% endif %} {{ method.name | caseUcfirst }}({{ utils.method_parameters(method.parameters, method.consumes) }}) { var apiPath = "{{ method.path }}"{% if method.parameters.path | length == 0 %};{% endif %} diff --git a/templates/flutter/lib/services/service.dart.twig b/templates/flutter/lib/services/service.dart.twig index 829c312bb..f3aa80056 100644 --- a/templates/flutter/lib/services/service.dart.twig +++ b/templates/flutter/lib/services/service.dart.twig @@ -18,6 +18,13 @@ class {{ service.name | caseUcfirst }} extends Service { {%~ if method.description %} {{ method.description|dartComment }} {% endif %} +{%~ if method.deprecated %} +{%~ if method.since and method.replaceWith %} + @Deprecated('This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.') +{%~ else %} + @Deprecated('This API has been deprecated.') +{%~ endif %} +{%~ endif %} {% if method.type == 'webAuth' %}Future{% elseif method.type == 'location' %}Future{% else %}{% if method.responseModel and method.responseModel != 'any' %}Future{% else %}Future{% endif %}{% endif %} {{ method.name | caseCamel | overrideIdentifier }}({{ _self.method_parameters(method.parameters.all, method.consumes) }}) async { {% if method.parameters.path | length > 0 %}final{% else %}const{% endif %} String apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replaceAll('{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}', {{ parameter.name | caseCamel | overrideIdentifier }}{% if parameter.enumValues | length > 0 %}.value{% endif %}){% endfor %}; diff --git a/templates/go/services/service.go.twig b/templates/go/services/service.go.twig index e5a76818a..0c065a15c 100644 --- a/templates/go/services/service.go.twig +++ b/templates/go/services/service.go.twig @@ -87,6 +87,14 @@ func (srv *{{ service.name | caseUcfirst }}) With{{ method.name | caseUcfirst }} {% else %} // {{ method.name | caseUcfirst }} {% endif %} +{% if method.deprecated %} +// +{%~ if method.since and method.replaceWith %} +// Deprecated: This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead. +{%~ else %} +// Deprecated: This API has been deprecated. +{%~ endif %} +{% endif %} func (srv *{{ service.name | caseUcfirst }}) {{ method.name | caseUcfirst }}({{ params }})(*{{ method | returnType(spec, spec.title | caseLower) }}, error) { {% if method.parameters.path|length > 0 %} r := strings.NewReplacer({% for parameter in method.parameters.path %}"{{ '{' }}{{ parameter.name | caseCamel }}{{ '}' }}", {{ parameter.name | caseUcfirst }}{% if not loop.last %}, {% endif %}{% endfor %}) diff --git a/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig b/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig index a95ca7c82..98821575b 100644 --- a/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig +++ b/templates/kotlin/src/main/kotlin/io/appwrite/services/ServiceTemplate.kt.twig @@ -30,6 +30,19 @@ class {{ service.name | caseUcfirst }}(client: Client) : Service(client) { {%~ endfor %} * @return [{{ method | returnType(spec, sdk.namespace | caseDot) | raw }}] */ + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + @Deprecated( + message = "This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.", + replaceWith = ReplaceWith("{{ sdk.namespace | caseDot }}.services.{{ method.replaceWith | capitalizeFirst }}"), + since = "{{ method.since }}" + ) + {%~ else %} + @Deprecated( + message = "This API has been deprecated." + ) + {%~ endif %} + {%~ endif %} {%~ if method.parameters.all | reduce((carry, param) => carry or not param.required) %} @JvmOverloads {%~ endif %} @@ -91,6 +104,19 @@ class {{ service.name | caseUcfirst }}(client: Client) : Service(client) { {%~ endfor %} * @return [{{ method | returnType(spec, sdk.namespace | caseDot) | raw }}] */ + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + @Deprecated( + message = "This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.", + replaceWith = ReplaceWith("{{ sdk.namespace | caseDot }}.services.{{ method.replaceWith | capitalizeFirst }}"), + since = "{{ method.since }}" + ) + {%~ else %} + @Deprecated( + message = "This API has been deprecated." + ) + {%~ endif %} + {%~ endif %} {%~ if method.parameters.all | reduce((carry, param) => carry or not param.required) %} @JvmOverloads {%~ endif %} diff --git a/templates/node/src/services/template.ts.twig b/templates/node/src/services/template.ts.twig index 52c79cb81..05759bd5e 100644 --- a/templates/node/src/services/template.ts.twig +++ b/templates/node/src/services/template.ts.twig @@ -27,7 +27,7 @@ export class {{ service.name | caseUcfirst }} { {%~ for method in service.methods %} /** {%~ if method.description %} - * {{ method.description }} + * {{ method.description | replace({'\n': '\n * '}) }} {%~ endif %} * {%~ for parameter in method.parameters.all %} @@ -35,6 +35,13 @@ export class {{ service.name | caseUcfirst }} { {%~ endfor %} * @throws {{ '{' }}{{ spec.title | caseUcfirst}}Exception} * @returns {{ '{' }}{{ method | getReturn(spec) | raw }}{{ '}' }} + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + * @deprecated This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead. + {%~ else %} + * @deprecated This API has been deprecated. + {%~ endif %} + {%~ endif %} */ {{ method.name | caseCamel }}{{ method.responseModel | getGenerics(spec) | raw }}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required or parameter.nullable %}?{% endif %}: {{ parameter | getPropertyType(method) | raw }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec) | raw }} { {%~ for parameter in method.parameters.all %} @@ -94,5 +101,8 @@ export class {{ service.name | caseUcfirst }} { ); {%~ endif %} } +{% if not loop.last %} + +{% endif %} {%~ endfor %} } diff --git a/templates/php/src/Services/Service.php.twig b/templates/php/src/Services/Service.php.twig index 0061fd2e6..32338d2d5 100644 --- a/templates/php/src/Services/Service.php.twig +++ b/templates/php/src/Services/Service.php.twig @@ -31,6 +31,7 @@ class {{ service.name | caseUcfirst }} extends Service } {% for method in service.methods %} +{% set deprecated_message = '' %} /** {% if method.description %} {{ method.description|comment1 }} @@ -41,6 +42,17 @@ class {{ service.name | caseUcfirst }} extends Service {% endfor %} * @throws {{spec.title | caseUcfirst}}Exception * @return {{ method | getReturn }} +{% if method.deprecated %} + * +{%~ if method.since and method.replaceWith %} + * @deprecated This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | split('.') | last | caseCamel }}` instead. +{%~ else %} + * @deprecated This API has been deprecated. +{%~ endif %} +{% if method.replaceWith %} + * @see {{ method.replaceWith | replace({'.': '::'}) | capitalizeFirst }} +{% endif %} +{% endif %} */ public function {{ method.name | caseCamel }}({% for parameter in method.parameters.all %}{% if not parameter.required or parameter.nullable %}?{% endif %}{{ parameter | typeName }} ${{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required %} = null{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, callable $onProgress = null{% endif %}): {{ method | getReturn }} { diff --git a/templates/python/package/services/service.py.twig b/templates/python/package/services/service.py.twig index 2eca9a794..97c96b527 100644 --- a/templates/python/package/services/service.py.twig +++ b/templates/python/package/services/service.py.twig @@ -34,6 +34,16 @@ class {{ service.name | caseUcfirst }}(Service): {% if method.parameters.all|length > 0 or 'multipart/form-data' in method.consumes %} +{% if method.deprecated %} +{%~ if method.since and method.replaceWith %} + .. deprecated::{{ method.since }} + This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | caseSnakeExceptFirstDot }}` instead. +{%~ else %} + .. deprecated:: + This API has been deprecated. +{%~ endif %} +{% endif %} + Parameters ---------- {% for parameter in method.parameters.all %}{{ parameter.name | escapeKeyword | caseSnake }} : {{ parameter | getPropertyType(method) | raw }} diff --git a/templates/react-native/src/services/template.ts.twig b/templates/react-native/src/services/template.ts.twig index 890d19d5c..7ebcaf03f 100644 --- a/templates/react-native/src/services/template.ts.twig +++ b/templates/react-native/src/services/template.ts.twig @@ -41,7 +41,14 @@ export class {{ service.name | caseUcfirst }} extends Service { * @throws {{ '{' }}{{ spec.title | caseUcfirst}}Exception} * @returns {% if method.type == 'webAuth' %}{void|string}{% elseif method.type == 'location' %}{ArrayBuffer}{% else %}{Promise}{% endif %} - */ + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + * @deprecated This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead. + {%~ else %} + * @deprecated This API has been deprecated. + {%~ endif %} + {%~ endif %} + */ {% if method.type == 'upload'%}async {% endif %}{{ method.name | caseCamel }}{{ method.responseModel | getGenerics(spec) | raw }}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required or parameter.nullable %}?{% endif %}: {{ parameter | getPropertyType(method) | raw }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec) | raw }} { {% for parameter in method.parameters.all %} {% if parameter.required %} @@ -187,6 +194,9 @@ export class {{ service.name | caseUcfirst }} extends Service { {% endfor %} * @throws {{ '{' }}{{ spec.title | caseUcfirst}}Exception} * @returns {{ '{' }}URL{{ '}' }} + {%~ if method.deprecated %} + * @deprecated This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead. + {%~ endif %} */ {{ method.name | caseCamel }}URL({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required or parameter.nullable %}?{% endif %}: {{ parameter | getPropertyType(method) | raw }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): URL { const apiPath = '{{ method.path }}'{% for parameter in method.parameters.path %}.replace('{{ '{' }}{{ parameter.name | caseCamel | escapeKeyword }}{{ '}' }}', {{ parameter.name | caseCamel | escapeKeyword }}){% endfor %}; diff --git a/templates/ruby/lib/container/services/service.rb.twig b/templates/ruby/lib/container/services/service.rb.twig index dbfc91d67..393b6fd16 100644 --- a/templates/ruby/lib/container/services/service.rb.twig +++ b/templates/ruby/lib/container/services/service.rb.twig @@ -8,6 +8,15 @@ module {{spec.title | caseUcfirst}} end {% for method in service.methods %} +{% if method.deprecated %} + # +{%~ if method.since and method.replaceWith %} + # @deprecated This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead. +{%~ else %} + # @deprecated This API has been deprecated. +{%~ endif %} + # +{% endif %} {{ method.description | rubyComment }} # {% for parameter in method.parameters.all %} diff --git a/templates/swift/Sources/Services/Service.swift.twig b/templates/swift/Sources/Services/Service.swift.twig index 6d74ee44b..597037fbd 100644 --- a/templates/swift/Sources/Services/Service.swift.twig +++ b/templates/swift/Sources/Services/Service.swift.twig @@ -20,6 +20,13 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { /// @throws Exception /// @return array /// + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + @available(*, deprecated, message: "This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.") + {%~ else %} + @available(*, deprecated, message: "This API has been deprecated.") + {%~ endif %} + {%~ endif %} open func {{ method.name | caseCamel | overrideIdentifier }}{% if method.responseModel | hasGenericType(spec) %}{% endif %}( {%~ for parameter in method.parameters.all %} {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName(spec) | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes or method.responseModel | hasGenericType(spec) %},{% endif %} @@ -81,6 +88,13 @@ open class {{ service.name | caseUcfirst | overrideIdentifier }}: Service { /// @throws Exception /// @return array /// + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + @available(*, deprecated, message: "This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead.") + {%~ else %} + @available(*, deprecated, message: "This API has been deprecated.") + {%~ endif %} + {%~ endif %} open func {{ method.name | caseCamel }}( {%~ for parameter in method.parameters.all %} {{ parameter.name | caseCamel | escapeSwiftKeyword }}: {{ parameter | typeName(spec) | raw }}{% if not parameter.required or parameter.nullable %}? = nil{% endif %}{% if not loop.last or 'multipart/form-data' in method.consumes %},{% endif %} diff --git a/templates/web/src/services/template.ts.twig b/templates/web/src/services/template.ts.twig index 397b3175e..259d6b1e3 100644 --- a/templates/web/src/services/template.ts.twig +++ b/templates/web/src/services/template.ts.twig @@ -28,7 +28,7 @@ export class {{ service.name | caseUcfirst }} { {%~ for method in service.methods %} /** {%~ if method.description %} - * {{ method.description }} + * {{ method.description | replace({'\n': '\n * '}) }} {%~ endif %} * {%~ for parameter in method.parameters.all %} @@ -36,6 +36,13 @@ export class {{ service.name | caseUcfirst }} { {%~ endfor %} * @throws {{ '{' }}{{ spec.title | caseUcfirst}}Exception} * @returns {{ '{' }}{{ method | getReturn(spec) | raw }}{{ '}' }} + {%~ if method.deprecated %} + {%~ if method.since and method.replaceWith %} + * @deprecated This API has been deprecated since {{ method.since }}. Please use `{{ method.replaceWith | capitalizeFirst }}` instead. + {%~ else %} + * @deprecated This API has been deprecated. + {%~ endif %} + {%~ endif %} */ {{ method.name | caseCamel }}{{ method.responseModel | getGenerics(spec) | raw }}({% for parameter in method.parameters.all %}{{ parameter.name | caseCamel | escapeKeyword }}{% if not parameter.required or parameter.nullable %}?{% endif %}: {{ parameter | getPropertyType(method) | raw }}{% if not loop.last %}, {% endif %}{% endfor %}{% if 'multipart/form-data' in method.consumes %}, onProgress = (progress: UploadProgress) => {}{% endif %}): {{ method | getReturn(spec) | raw }} { {%~ for parameter in method.parameters.all %} @@ -108,5 +115,8 @@ export class {{ service.name | caseUcfirst }} { ); {%~ endif %} } +{% if not loop.last %} + +{% endif %} {%~ endfor %} }