New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ama-sdk/generator-sdk

Package Overview
Dependencies
Maintainers
4
Versions
777
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ama-sdk/generator-sdk

Swagger specification SDK Generator

  • 8.0.0-alpha.13
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
345
increased by21.48%
Maintainers
4
Weekly downloads
 
Created
Source

<%=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:
// src/models/base/<model name>/index.ts
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
  • Create your core models
// src/models/core/<model name>/index.ts
export * from "./<model name>.ts";
export * from "./<model name>.reviver.ts";
// src/models/core/<model name>/<model name>.ts
import { <model name> as Base<model name> } from "../../base/<model name>/<model name>";

export interface <model name> extends BaseB<model name> {
  // Additional fields
}
// src/models/core/<model name>/<model name>.reviver.ts
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'

Keywords

FAQs

Package last updated on 31 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc