Skip to content

Commit 513c19a

Browse files
fix: JSON.stringify object defaults + examples (openapi-ts#910)
1 parent 08d42a6 commit 513c19a

File tree

10 files changed

+2231
-356
lines changed

10 files changed

+2231
-356
lines changed

src/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export function prepareComment(v: CommentObject): string | void {
4949
if (v[field] === "" && !allowEmptyString) {
5050
continue;
5151
}
52-
commentsArray.push(`@${field} ${v[field]} `);
52+
const serialized = typeof v[field] === "object" ? JSON.stringify(v[field], null, 2) : v[field];
53+
commentsArray.push(`@${field} ${serialized} `);
5354
}
5455

5556
// * JSDOC 'Constant' without value

test/bin/expected/specs/manifold.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ export interface definitions {
639639
sso_url?: string;
640640
/** @enum {string} */
641641
version?: "v1";
642-
/** @default [object Object] */
642+
/** @default {} */
643643
features?: {
644644
access_code?: boolean;
645645
sso?: boolean;
@@ -762,7 +762,13 @@ export interface definitions {
762762
/**
763763
* @description Price describes how the feature cost should be calculated.
764764
*
765-
* @example [object Object]
765+
* @example {
766+
* "feature_multiplies_base_cost": "(* plan#base_cost feature-a#multiply_factor)",
767+
* "feature_multiplies_feature_cost": "(* feature-b#cost feature-a#multiply_factor)",
768+
* "feature_multiplies_numeric_value": "(* feature-c#number feature-a#multiply_factor)",
769+
* "feature_multiplies_total_cost": "(* plan#total_cost feature-a#multiply_factor)",
770+
* "feature_nested_formulas": "(+ (- (* feature-a#cost feature-b#multiply_factor) 500) plan#partial_cost)"
771+
* }
766772
*/
767773
formula?: definitions["PriceFormula"];
768774
/** @description Description explains how a feature is calculated to the user. */
@@ -834,7 +840,7 @@ export interface definitions {
834840
ProductTags: definitions["Label"][];
835841
/** @enum {string} */
836842
ProductState: "available" | "hidden" | "grandfathered" | "new" | "upcoming";
837-
/** @default [object Object] */
843+
/** @default {} */
838844
ProductListing: {
839845
/**
840846
* @description When true, everyone can see the product when requested. When false it will
@@ -859,7 +865,7 @@ export interface definitions {
859865
* we find ourselves in a position where we think they should, we should
860866
* consider refactoring our listing definition.
861867
*
862-
* @default [object Object]
868+
* @default {}
863869
*/
864870
marketing?: {
865871
/**
@@ -898,7 +904,7 @@ export interface definitions {
898904
* @enum {string}
899905
*/
900906
ProductProvisioning: "provider-only" | "pre-order" | "public";
901-
/** @default [object Object] */
907+
/** @default {} */
902908
ProductIntegrationFeatures: {
903909
/**
904910
* @description Indicates whether or not this product supports resource transitions to

test/v2/expected/http.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ export interface definitions {
639639
sso_url?: string;
640640
/** @enum {string} */
641641
version?: "v1";
642-
/** @default [object Object] */
642+
/** @default {} */
643643
features?: {
644644
access_code?: boolean;
645645
sso?: boolean;
@@ -762,7 +762,13 @@ export interface definitions {
762762
/**
763763
* @description Price describes how the feature cost should be calculated.
764764
*
765-
* @example [object Object]
765+
* @example {
766+
* "feature_multiplies_base_cost": "(* plan#base_cost feature-a#multiply_factor)",
767+
* "feature_multiplies_feature_cost": "(* feature-b#cost feature-a#multiply_factor)",
768+
* "feature_multiplies_numeric_value": "(* feature-c#number feature-a#multiply_factor)",
769+
* "feature_multiplies_total_cost": "(* plan#total_cost feature-a#multiply_factor)",
770+
* "feature_nested_formulas": "(+ (- (* feature-a#cost feature-b#multiply_factor) 500) plan#partial_cost)"
771+
* }
766772
*/
767773
formula?: definitions["PriceFormula"];
768774
/** @description Description explains how a feature is calculated to the user. */
@@ -834,7 +840,7 @@ export interface definitions {
834840
ProductTags: definitions["Label"][];
835841
/** @enum {string} */
836842
ProductState: "available" | "hidden" | "grandfathered" | "new" | "upcoming";
837-
/** @default [object Object] */
843+
/** @default {} */
838844
ProductListing: {
839845
/**
840846
* @description When true, everyone can see the product when requested. When false it will
@@ -859,7 +865,7 @@ export interface definitions {
859865
* we find ourselves in a position where we think they should, we should
860866
* consider refactoring our listing definition.
861867
*
862-
* @default [object Object]
868+
* @default {}
863869
*/
864870
marketing?: {
865871
/**
@@ -898,7 +904,7 @@ export interface definitions {
898904
* @enum {string}
899905
*/
900906
ProductProvisioning: "provider-only" | "pre-order" | "public";
901-
/** @default [object Object] */
907+
/** @default {} */
902908
ProductIntegrationFeatures: {
903909
/**
904910
* @description Indicates whether or not this product supports resource transitions to

test/v2/expected/manifold.immutable.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ export interface definitions {
639639
readonly sso_url?: string
640640
/** @enum {string} */
641641
readonly version?: 'v1'
642-
/** @default [object Object] */
642+
/** @default {} */
643643
readonly features?: {
644644
readonly access_code?: boolean
645645
readonly sso?: boolean
@@ -762,7 +762,13 @@ export interface definitions {
762762
/**
763763
* @description Price describes how the feature cost should be calculated.
764764
*
765-
* @example [object Object]
765+
* @example {
766+
* "feature_multiplies_base_cost": "(* plan#base_cost feature-a#multiply_factor)",
767+
* "feature_multiplies_feature_cost": "(* feature-b#cost feature-a#multiply_factor)",
768+
* "feature_multiplies_numeric_value": "(* feature-c#number feature-a#multiply_factor)",
769+
* "feature_multiplies_total_cost": "(* plan#total_cost feature-a#multiply_factor)",
770+
* "feature_nested_formulas": "(+ (- (* feature-a#cost feature-b#multiply_factor) 500) plan#partial_cost)"
771+
* }
766772
*/
767773
readonly formula?: definitions['PriceFormula']
768774
/** @description Description explains how a feature is calculated to the user. */
@@ -834,7 +840,7 @@ export interface definitions {
834840
readonly ProductTags: readonly definitions['Label'][]
835841
/** @enum {string} */
836842
readonly ProductState: 'available' | 'hidden' | 'grandfathered' | 'new' | 'upcoming'
837-
/** @default [object Object] */
843+
/** @default {} */
838844
readonly ProductListing: {
839845
/**
840846
* @description When true, everyone can see the product when requested. When false it will
@@ -859,7 +865,7 @@ export interface definitions {
859865
* we find ourselves in a position where we think they should, we should
860866
* consider refactoring our listing definition.
861867
*
862-
* @default [object Object]
868+
* @default {}
863869
*/
864870
readonly marketing?: {
865871
/**
@@ -898,7 +904,7 @@ export interface definitions {
898904
* @enum {string}
899905
*/
900906
readonly ProductProvisioning: 'provider-only' | 'pre-order' | 'public'
901-
/** @default [object Object] */
907+
/** @default {} */
902908
readonly ProductIntegrationFeatures: {
903909
/**
904910
* @description Indicates whether or not this product supports resource transitions to

test/v2/expected/manifold.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ export interface definitions {
639639
sso_url?: string
640640
/** @enum {string} */
641641
version?: 'v1'
642-
/** @default [object Object] */
642+
/** @default {} */
643643
features?: {
644644
access_code?: boolean
645645
sso?: boolean
@@ -762,7 +762,13 @@ export interface definitions {
762762
/**
763763
* @description Price describes how the feature cost should be calculated.
764764
*
765-
* @example [object Object]
765+
* @example {
766+
* "feature_multiplies_base_cost": "(* plan#base_cost feature-a#multiply_factor)",
767+
* "feature_multiplies_feature_cost": "(* feature-b#cost feature-a#multiply_factor)",
768+
* "feature_multiplies_numeric_value": "(* feature-c#number feature-a#multiply_factor)",
769+
* "feature_multiplies_total_cost": "(* plan#total_cost feature-a#multiply_factor)",
770+
* "feature_nested_formulas": "(+ (- (* feature-a#cost feature-b#multiply_factor) 500) plan#partial_cost)"
771+
* }
766772
*/
767773
formula?: definitions['PriceFormula']
768774
/** @description Description explains how a feature is calculated to the user. */
@@ -834,7 +840,7 @@ export interface definitions {
834840
ProductTags: definitions['Label'][]
835841
/** @enum {string} */
836842
ProductState: 'available' | 'hidden' | 'grandfathered' | 'new' | 'upcoming'
837-
/** @default [object Object] */
843+
/** @default {} */
838844
ProductListing: {
839845
/**
840846
* @description When true, everyone can see the product when requested. When false it will
@@ -859,7 +865,7 @@ export interface definitions {
859865
* we find ourselves in a position where we think they should, we should
860866
* consider refactoring our listing definition.
861867
*
862-
* @default [object Object]
868+
* @default {}
863869
*/
864870
marketing?: {
865871
/**
@@ -898,7 +904,7 @@ export interface definitions {
898904
* @enum {string}
899905
*/
900906
ProductProvisioning: 'provider-only' | 'pre-order' | 'public'
901-
/** @default [object Object] */
907+
/** @default {} */
902908
ProductIntegrationFeatures: {
903909
/**
904910
* @description Indicates whether or not this product supports resource transitions to

0 commit comments

Comments
 (0)