Skip to content

Conversation

IvanFarkas
Copy link

Allow property type metadata to be extracted from property comment.

Javascript input

export class Test {
	constructor() {
		// Types: [`TS Type` #TS Default# @TS IsNullable@ ^OA Type^ ~OA Format~] - https://regex101.com
		// TypeScript Data Types - https://www.typescriptlang.org/docs/handbook/basic-types.html
		// OpenAPI Data Types - https://swagger.io/docs/specification/data-models/data-types
		// TS Type pattern: `` - (?<=`).*(?=`)
		// TS Default pattern: ## - (?<=#).*(?=#)
		// TS IsNullable pattern: @@ - (?<=@).*(?=@)
		// OA Type pattern: ^^ - (?<=\^).*(?=\^)
		// OA Format pattern: ~~ - (?<=~).*(?=~)
		this.strProp = null; // Types: [`string` #'New Value'# @true@ ^string^ ~~] - 
		this.boolProp = null; // Types: [`boolean` #true# @true@ ^boolean^ ~~] - 

		// OpenAPI String - https://swagger.io/docs/specification/data-models/data-types/#string
		this.dateProp = null; // Types: [`Date` ## @@ ^string^ ~date~] - 
		this.dateTimeProp = null; // Types: [`Date` ## @@ ^string^ ~date-time~] - 
		this.byteProp = null; // Types: [`string` ## @@ ^string^ ~byte~] - 
		this.binaryProp = null; // Types: [`string` ## @@ ^string^ ~binary~] - 
		this.emailProp = null; // Types: [`string` ## @@ ^string^ ~email~] - 

		// OpenAPI Numbers - https://swagger.io/docs/specification/data-models/data-types/#numbers
		this.intProp = null; // Types: [`number` ## @@ ^integer^] - 
		this.int32Prop = null; // Types: [`number` ## @@ ^integer^ ~int32~] - 
		this.int64Prop = null; // Types: [`number` ## @@ ^integer^ ~int64~] - 
		this.floatProp = null; // Types: [`number` ## @@ ^number^ ~float~] - 
		this.doubleProp = null; // Types: [`number` ## @@ ^number^ ~double~] - 

		this.classProp = new TestRef(); // Types: [`TestRef` ## @@ ^object^ ~REF:TestRef~] - TestRef class
		this.arrayofClassProp = [new TestRef()]; // Types: [`TestRef[]` ## @@ ^array^ ~REF:TestRef[]~] - Arrray of TestRef class
	}
}

Typescript output:

export class Test {
	public strProp: string | null = 'New Value';
	public boolProp: boolean | null = true;
	public dateProp: Date;
	public dateTimeProp: Date;
	public byteProp: string;
	public binaryProp: string;
	public emailProp: string;
	public intProp: number;
	public int32Prop: number;
	public int64Prop: number;
	public floatProp: number;
	public doubleProp: number;
	public classProp: TestRef;
	public arrayofClassProp: TestRef[];

	constructor() {
		// Types: [`TS Type` #TS Default# @TS IsNullable@ ^OA Type^ ~OA Format~] - https://regex101.com
		// TypeScript Data Types - https://www.typescriptlang.org/docs/handbook/basic-types.html
		// OpenAPI Data Types - https://swagger.io/docs/specification/data-models/data-types
		// TS Type pattern: `` - (?<=`).*(?=`)
		// TS Default pattern: ## - (?<=#).*(?=#)
		// TS IsNullable pattern: @@ - (?<=@).*(?=@)
		// OA Type pattern: ^^ - (?<=\^).*(?=\^)
		// OA Format pattern: ~~ - (?<=~).*(?=~)
		this.strProp = null; // Types: [`string` #'New Value'# @true@ ^string^ ~~] - 
		this.boolProp = null; // Types: [`boolean` #true# @true@ ^boolean^ ~~] - 

		// OpenAPI String - https://swagger.io/docs/specification/data-models/data-types/#string
		this.dateProp = null; // Types: [`Date` ## @@ ^string^ ~date~] - 
		this.dateTimeProp = null; // Types: [`Date` ## @@ ^string^ ~date-time~] - 
		this.byteProp = null; // Types: [`string` ## @@ ^string^ ~byte~] - 
		this.binaryProp = null; // Types: [`string` ## @@ ^string^ ~binary~] - 
		this.emailProp = null; // Types: [`string` ## @@ ^string^ ~email~] - 

		// OpenAPI Numbers - https://swagger.io/docs/specification/data-models/data-types/#numbers
		this.intProp = null; // Types: [`number` ## @@ ^integer^] - 
		this.int32Prop = null; // Types: [`number` ## @@ ^integer^ ~int32~] - 
		this.int64Prop = null; // Types: [`number` ## @@ ^integer^ ~int64~] - 
		this.floatProp = null; // Types: [`number` ## @@ ^number^ ~float~] - 
		this.doubleProp = null; // Types: [`number` ## @@ ^number^ ~double~] - 

		this.classProp = new TestRef(); // Types: [`TestRef` ## @@ ^object^ ~REF:TestRef~] - TestRef class
		this.arrayofClassProp = [new TestRef()]; // Types: [`TestRef[]` ## @@ ^array^ ~REF:TestRef[]~] - Arrray of TestRef class
	}

@gregjacobs
Copy link
Owner

Wow well this is interesting! Are those comments left by swagger generating files?

@gregjacobs
Copy link
Owner

Btw, sorry for the delay in seeing this - just saw the email notification now!

@IvanFarkas
Copy link
Author

Wow well this is interesting! Are those comments left by swagger generating files?

No. Hand generated ;-)

@IvanFarkas
Copy link
Author

Updated PR with requested items.

@IvanFarkas
Copy link
Author

Get constructor, getter, setter, methods, functions parameter and return types from JSDoc.

@IvanFarkas IvanFarkas requested a review from gregjacobs December 1, 2021 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants