How to use @tsed/swagger - 10 common examples

To help you get started, we’ve selected a few @tsed/swagger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TypedProject / ts-express-decorators / test / integration / app / models / Event.ts View on Github external
import {Any, IgnoreProperty, JsonProperty, Property, PropertyType, Required} from "@tsed/common";
import {Description, Example, Title} from "@tsed/swagger";

export class Task {
  @JsonProperty() public name: string = "";

  @JsonProperty() public percent: number;
}

@Title("EventModel Title")
export class EventModel {
  @Title("iD")
  @Description("Description of event model id")
  @Example("1FDCHZKH")
  @JsonProperty()
  public id: string;

  @Required()
  @Example("example1", "2017-10-15T17:05:58.106Z")
  public startDate: Date;

  @JsonProperty()
  @Required()
  // @Format("date")
  public endDate: Date;

  @JsonProperty("Name")
  @Required()
  public name: string;
github TypedProject / ts-express-decorators / test / integration / app / models / Event.ts View on Github external
export class Task {
  @JsonProperty() public name: string = "";

  @JsonProperty() public percent: number;
}

@Title("EventModel Title")
export class EventModel {
  @Title("iD")
  @Description("Description of event model id")
  @Example("1FDCHZKH")
  @JsonProperty()
  public id: string;

  @Required()
  @Example("example1", "2017-10-15T17:05:58.106Z")
  public startDate: Date;

  @JsonProperty()
  @Required()
  // @Format("date")
  public endDate: Date;

  @JsonProperty("Name")
  @Required()
  public name: string;

  @JsonProperty({use: Task})
  public tasks: Task[];

  @IgnoreProperty() public _id: string;
github TypedProject / ts-express-decorators / test / integration / app / models / Event.ts View on Github external
import {Any, IgnoreProperty, JsonProperty, Property, PropertyType, Required} from "@tsed/common";
import {Description, Example, Title} from "@tsed/swagger";

export class Task {
  @JsonProperty() public name: string = "";

  @JsonProperty() public percent: number;
}

@Title("EventModel Title")
export class EventModel {
  @Title("iD")
  @Description("Description of event model id")
  @Example("1FDCHZKH")
  @JsonProperty()
  public id: string;

  @Required()
  @Example("example1", "2017-10-15T17:05:58.106Z")
  public startDate: Date;

  @JsonProperty()
  @Required()
  // @Format("date")
  public endDate: Date;

  @JsonProperty("Name")
  @Required()
  public name: string;
github TypedProject / ts-express-decorators / test / integration / app / models / Event.ts View on Github external
import {Any, IgnoreProperty, JsonProperty, Property, PropertyType, Required} from "@tsed/common";
import {Description, Example, Title} from "@tsed/swagger";

export class Task {
  @JsonProperty() public name: string = "";

  @JsonProperty() public percent: number;
}

@Title("EventModel Title")
export class EventModel {
  @Title("iD")
  @Description("Description of event model id")
  @Example("1FDCHZKH")
  @JsonProperty()
  public id: string;

  @Required()
  @Example("example1", "2017-10-15T17:05:58.106Z")
  public startDate: Date;

  @JsonProperty()
  @Required()
  // @Format("date")
  public endDate: Date;
github TypedProject / ts-express-decorators / test / integration / app / models / Event.ts View on Github external
import {Any, IgnoreProperty, JsonProperty, Property, PropertyType, Required} from "@tsed/common";
import {Description, Example, Title} from "@tsed/swagger";

export class Task {
  @JsonProperty() public name: string = "";

  @JsonProperty() public percent: number;
}

@Title("EventModel Title")
export class EventModel {
  @Title("iD")
  @Description("Description of event model id")
  @Example("1FDCHZKH")
  @JsonProperty()
  public id: string;

  @Required()
  @Example("example1", "2017-10-15T17:05:58.106Z")
  public startDate: Date;

  @JsonProperty()
  @Required()
  // @Format("date")
  public endDate: Date;

  @JsonProperty("Name")
  @Required()
github TypedProject / ts-express-decorators / integration / typeorm / src / entity / User.ts View on Github external
import {Minimum, Required, Property} from "@tsed/common";
import {Example, Description} from "@tsed/swagger";
import {Column, Entity, PrimaryGeneratedColumn} from "typeorm";

@Entity()
export class User {
  @Description('Database assigned id')
  @PrimaryGeneratedColumn()
  id: number;

  @Description('User firstname')
  @Column()
  @Required()
  firstName: string;

  @Description('User lastname')
  @Column()
  @Required()
  lastName: string;

  @Description('User Age')
  @Column()
  @Minimum(18)
  @Example(18)
  age: number;

  additional: string; // won't be serialized/deserialized by Ts.ED because @PropertyType or other Ts.ED decorator are missing

  @Property()
  additional2: string;
}
github TypedProject / ts-express-decorators / examples / passport-azure-ad / packages / server / src / decorators / OAuthBearer.ts View on Github external
UseAuth(Passport.authenticate("oauth-bearer", {session: false, ...options}) as any),

    // Metadata for swagger
    Security("oauth", ...(options.scopes || [])),
    Operation({
      "parameters": [
        {
          "in": "header",
          "name": "Authorization",
          "type": "string",
          "required": true
        }
      ]
    }),
    Responses(401, {description: "Unauthorized"}),
    Responses(403, {description: "Forbidden"}),
    OAuthHead()
  );
}
github TypedProject / ts-express-decorators / examples / passport-azure-ad / packages / server / src / decorators / OAuthBearer.ts View on Github external
AuthOptions(OAuthBearerOptions as any, options), // Add this to store all options and retrieve it in verify function
    UseAuth(Passport.authenticate("oauth-bearer", {session: false, ...options}) as any),

    // Metadata for swagger
    Security("oauth", ...(options.scopes || [])),
    Operation({
      "parameters": [
        {
          "in": "header",
          "name": "Authorization",
          "type": "string",
          "required": true
        }
      ]
    }),
    Responses(401, {description: "Unauthorized"}),
    Responses(403, {description: "Forbidden"}),
    OAuthHead()
  );
}
github TypedProject / ts-express-decorators / integration / typeorm / src / entity / User.ts View on Github external
id: number;

  @Description('User firstname')
  @Column()
  @Required()
  firstName: string;

  @Description('User lastname')
  @Column()
  @Required()
  lastName: string;

  @Description('User Age')
  @Column()
  @Minimum(18)
  @Example(18)
  age: number;

  additional: string; // won't be serialized/deserialized by Ts.ED because @PropertyType or other Ts.ED decorator are missing

  @Property()
  additional2: string;
}
github TypedProject / ts-express-decorators / examples / passport-azure-ad / packages / server / src / decorators / OAuthBearer.ts View on Github external
export function OAuthBearer(options: any = {}): Function {
  return applyDecorators(
    AuthOptions(OAuthBearerOptions as any, options), // Add this to store all options and retrieve it in verify function
    UseAuth(Passport.authenticate("oauth-bearer", {session: false, ...options}) as any),

    // Metadata for swagger
    Security("oauth", ...(options.scopes || [])),
    Operation({
      "parameters": [
        {
          "in": "header",
          "name": "Authorization",
          "type": "string",
          "required": true
        }
      ]
    }),
    Responses(401, {description: "Unauthorized"}),
    Responses(403, {description: "Forbidden"}),
    OAuthHead()
  );
}