<%=projectDescription%>
Based on Swagger spec 0.0.0
The SDK contains 2 different parts:
- Auto generated code (based on Swagger Spec)
- Specific code dedicated to this SDK
Structure
Auto Generated code
A main part of the SDK is automatically generated from a Swagger Spec.
The following folders contain the generated code:
- src/api: Containing the API calls files
- src/models/base: Models based of swagger definitions
The Code can be regenerated by running the following command:
yo @ama-sdk/sdk:core
Where to put my custom code?
There are 2 places where we can add custom code:
- src/helpers: should contain the helper functions to transform the data.
- src/models/custom: should contain the models specific to this SDK (mainly the helper functions return type).
How to extend a Model?
You can extend a base model in 3 steps:
- Redirect the default model to your override:
export * from "../../core/<model name>";
- Indicate to Swagger CodeGen that you have override the base model:
# in .swagger-codegen-ignore
src/models/base/<model name>/index.ts
export * from "./<model name>.ts";
export * from "./<model name>.reviver.ts";
import { <model name> as Base<model name> } from "../../base/<model name>/<model name>";
export interface <model name> extends BaseB<model name> {
// Additional fields
}
import { yourFunction } from "../../../helpers/<model name>";
import { revive<model name> as Base<model name> } from "../../base/<model name>/<model name>.reviver";
import { <model name> } from "./<model name>";
import {Reviver, utils} from "@ama-sdk/core";
export function revive<model name><T extends <model name> = <model name>>(data: any, dictionary?: any) {
// TODO: use BaseRevive<T> when ready
const revivedData: T | undefined = Base<model name>(data, dictionary) as T | undefined;
if (!revivedData) { return ; }
if (!revivedData.yourField) {
revivedData.yourField = yourFunction(revivedData);
}
return revivedData;
}
Commands
Some commands are provided to keep your SDK up-to-date.
Generate SDK from a Swagger specification
yarn swagger:regen
Run Unit Tests
You can build and run UT with:
yarn test
Vendor extensions
These are some of the available configurations using vendor extensions in the swagger spec
Manage timezone in date
In order to add the timezone to your timestamp property you can add the x-date-timezone extension in your yaml, for example:
properties:
timestamp:
title: timestamp
description: >-
Timestamp when event is triggered. UTC time (server time), with a
format similar to yyyy-MM-ddThh:mm:ss.sTZD. Refer to the pattern
type: string
format: date-time
x-date-timezone:
description: If this vendor extension is present send dates with the timezone
pattern: >-
^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{1,3}([Z]|([+][0-9]{2}:?[0-9]{2}$))
example: '2013-12-31T19:20:30.45+01:00'