-
Notifications
You must be signed in to change notification settings - Fork 193
Closed
Description
This issue will cover on how to add response models for Deno.
The twig templates for Deno can be found here => https://github.com/appwrite/sdk-generator/tree/master/templates/deno
For reference - you can use this PR which has implemented this for Web => #261
Following things are important:
- We can have all Models in a single file - which can be imported everywhere. (for example
src/models.ts) - Add generics to Models that have
additionalPropertiesin their spec (likeDocument) - Pass a generic to Models that are nested and have
additionalProperties(likeDocumentListthat hasDocumentnested) - Make sure arrays are handled properly (The
documentsattribute onDocumentListusesDocument[])
This is how we generate the typings on Web SDK:
{% macro sub_schema(property) %}{% if property.sub_schema %}{% if property.type == 'array' %}{{property.sub_schema | caseUcfirst}}[]{% else %}{{property.sub_schema | caseUcfirst}}{% endif %}{% else %}{{property.type | typeName}}{% endif %}{% endmacro %}
namespace Models {
{% for definition in spec.definitions %}
/**
* {{ definition.description }}
*/
export type {{ definition.name | caseUcfirst }}<{% for property in definition.properties %}{% if spec.definitions[property.sub_schema].additionalProperties %}{{property.sub_schema | caseUcfirst}} extends Models.{{property.sub_schema | caseUcfirst}}{% endif %}{% endfor %}> = {
{% for property in definition.properties %}
/**
* {{ property.description }}
*/
{{ property.name | escapeKeyword }}{% if not property.required %}?{% endif %}: {{_self.sub_schema(property)}};
{% endfor %}
}
{% endfor %}
}What we want to achieve
This is an example of how the before and after should look like.
Before
async getCurrencies<T extends unknown>(): Promise<T> {
// ...
}After
namespace Models {
/**
* Currencies List
*/
export type CurrencyList<> = {
/**
* Total sum of items in the list.
*/
sum: number;
/**
* List of currencies.
*/
currencies: Currency[];
}
/**
* Currency
*/
export type Currency<> = {
/**
* Currency symbol.
*/
symbol: string;
/**
* Currency name.
*/
name: string;
/**
* Currency native symbol.
*/
symbolNative: string;
/**
* Number of decimal digits.
*/
decimalDigits: number;
/**
* Currency digit rounding.
*/
rounding: number;
/**
* Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format.
*/
code: string;
/**
* Currency plural name
*/
namePlural: string;
}
}
async getCurrencies(collectionId: string, documentId: string): Promise<Models.CurrencyList> {
// ...
}Metadata
Metadata
Assignees
Labels
No labels