docusaurus-plugin-openapi-docs 4.3.4 → 4.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -224,10 +224,8 @@ custom_edit_url: null
224
224
  schema: schemaPageGenerator,
225
225
  };
226
226
  loadedApi.map(async (item) => {
227
- if (item.type === "info") {
228
- if (downloadUrl) {
229
- item.downloadUrl = downloadUrl;
230
- }
227
+ if (downloadUrl) {
228
+ item.downloadUrl = downloadUrl;
231
229
  }
232
230
  const markdown = pageGeneratorByType[item.type](item);
233
231
  item.markdown = markdown;
@@ -93,8 +93,8 @@ function getQualifierMessage(schema) {
93
93
  }
94
94
  qualifierGroups.push(lengthQualifier);
95
95
  }
96
- if (schema.minimum ||
97
- schema.maximum ||
96
+ if (schema.minimum != null ||
97
+ schema.maximum != null ||
98
98
  typeof schema.exclusiveMinimum === "number" ||
99
99
  typeof schema.exclusiveMaximum === "number") {
100
100
  let minmaxQualifier = "";
@@ -103,19 +103,19 @@ function getQualifierMessage(schema) {
103
103
  if (typeof schema.exclusiveMinimum === "number") {
104
104
  minimum = `\`> ${schema.exclusiveMinimum}\``;
105
105
  }
106
- else if (schema.minimum && !schema.exclusiveMinimum) {
106
+ else if (schema.minimum != null && !schema.exclusiveMinimum) {
107
107
  minimum = `\`>= ${schema.minimum}\``;
108
108
  }
109
- else if (schema.minimum && schema.exclusiveMinimum === true) {
109
+ else if (schema.minimum != null && schema.exclusiveMinimum === true) {
110
110
  minimum = `\`> ${schema.minimum}\``;
111
111
  }
112
112
  if (typeof schema.exclusiveMaximum === "number") {
113
113
  maximum = `\`< ${schema.exclusiveMaximum}\``;
114
114
  }
115
- else if (schema.maximum && !schema.exclusiveMaximum) {
115
+ else if (schema.maximum != null && !schema.exclusiveMaximum) {
116
116
  maximum = `\`<= ${schema.maximum}\``;
117
117
  }
118
- else if (schema.maximum && schema.exclusiveMaximum === true) {
118
+ else if (schema.maximum != null && schema.exclusiveMaximum === true) {
119
119
  maximum = `\`< ${schema.maximum}\``;
120
120
  }
121
121
  if (minimum && !maximum) {
@@ -106,6 +106,16 @@ describe("getQualifierMessage", () => {
106
106
  const actual = (0, schema_1.getQualifierMessage)({ minimum: 1, maximum: 40 });
107
107
  expect(actual).toBe(expected);
108
108
  });
109
+ it("should render 0 minimum and maximum", () => {
110
+ const expected = "**Possible values:** `>= 0` and `<= 40`";
111
+ const actual = (0, schema_1.getQualifierMessage)({ minimum: 0, maximum: 40 });
112
+ expect(actual).toBe(expected);
113
+ });
114
+ it("should render minimum and 0 maximum", () => {
115
+ const expected = "**Possible values:** `>= -10` and `<= 0`";
116
+ const actual = (0, schema_1.getQualifierMessage)({ minimum: -10, maximum: 0 });
117
+ expect(actual).toBe(expected);
118
+ });
109
119
  it("should render boolean exclusiveMinimum and maximum", () => {
110
120
  const expected = "**Possible values:** `> 1` and `<= 40`";
111
121
  const actual = (0, schema_1.getQualifierMessage)({
@@ -150,7 +150,7 @@ function createItems(openapiData, options, sidebarOptions) {
150
150
  }
151
151
  // Handle vendor JSON media types
152
152
  const bodyContent = (_o = operationObject.requestBody) === null || _o === void 0 ? void 0 : _o.content;
153
- if (bodyContent) {
153
+ if (bodyContent && Object.keys(bodyContent).length > 0) {
154
154
  const firstBodyContentKey = Object.keys(bodyContent)[0];
155
155
  if (firstBodyContentKey.endsWith("+json")) {
156
156
  const firstBody = bodyContent[firstBodyContentKey];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-openapi-docs",
3
3
  "description": "OpenAPI plugin for Docusaurus.",
4
- "version": "4.3.4",
4
+ "version": "4.3.6",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "openapi",
@@ -65,5 +65,5 @@
65
65
  "engines": {
66
66
  "node": ">=14"
67
67
  },
68
- "gitHead": "2c732880a5508e292c49b83cbc01f6030aef4dfe"
68
+ "gitHead": "852aca183dfbda7e28ba961d74fb639736be76a3"
69
69
  }
package/src/index.ts CHANGED
@@ -315,10 +315,8 @@ custom_edit_url: null
315
315
  };
316
316
 
317
317
  loadedApi.map(async (item) => {
318
- if (item.type === "info") {
319
- if (downloadUrl) {
320
- item.downloadUrl = downloadUrl;
321
- }
318
+ if (downloadUrl) {
319
+ item.downloadUrl = downloadUrl;
322
320
  }
323
321
  const markdown = pageGeneratorByType[item.type](item as any);
324
322
  item.markdown = markdown;
@@ -124,6 +124,18 @@ describe("getQualifierMessage", () => {
124
124
  expect(actual).toBe(expected);
125
125
  });
126
126
 
127
+ it("should render 0 minimum and maximum", () => {
128
+ const expected = "**Possible values:** `>= 0` and `<= 40`";
129
+ const actual = getQualifierMessage({ minimum: 0, maximum: 40 });
130
+ expect(actual).toBe(expected);
131
+ });
132
+
133
+ it("should render minimum and 0 maximum", () => {
134
+ const expected = "**Possible values:** `>= -10` and `<= 0`";
135
+ const actual = getQualifierMessage({ minimum: -10, maximum: 0 });
136
+ expect(actual).toBe(expected);
137
+ });
138
+
127
139
  it("should render boolean exclusiveMinimum and maximum", () => {
128
140
  const expected = "**Possible values:** `> 1` and `<= 40`";
129
141
  const actual = getQualifierMessage({
@@ -116,8 +116,8 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
116
116
  }
117
117
 
118
118
  if (
119
- schema.minimum ||
120
- schema.maximum ||
119
+ schema.minimum != null ||
120
+ schema.maximum != null ||
121
121
  typeof schema.exclusiveMinimum === "number" ||
122
122
  typeof schema.exclusiveMaximum === "number"
123
123
  ) {
@@ -126,16 +126,16 @@ export function getQualifierMessage(schema?: SchemaObject): string | undefined {
126
126
  let maximum;
127
127
  if (typeof schema.exclusiveMinimum === "number") {
128
128
  minimum = `\`> ${schema.exclusiveMinimum}\``;
129
- } else if (schema.minimum && !schema.exclusiveMinimum) {
129
+ } else if (schema.minimum != null && !schema.exclusiveMinimum) {
130
130
  minimum = `\`>= ${schema.minimum}\``;
131
- } else if (schema.minimum && schema.exclusiveMinimum === true) {
131
+ } else if (schema.minimum != null && schema.exclusiveMinimum === true) {
132
132
  minimum = `\`> ${schema.minimum}\``;
133
133
  }
134
134
  if (typeof schema.exclusiveMaximum === "number") {
135
135
  maximum = `\`< ${schema.exclusiveMaximum}\``;
136
- } else if (schema.maximum && !schema.exclusiveMaximum) {
136
+ } else if (schema.maximum != null && !schema.exclusiveMaximum) {
137
137
  maximum = `\`<= ${schema.maximum}\``;
138
- } else if (schema.maximum && schema.exclusiveMaximum === true) {
138
+ } else if (schema.maximum != null && schema.exclusiveMaximum === true) {
139
139
  maximum = `\`< ${schema.maximum}\``;
140
140
  }
141
141
 
@@ -191,7 +191,8 @@ function createItems(
191
191
 
192
192
  // Handle vendor JSON media types
193
193
  const bodyContent = operationObject.requestBody?.content;
194
- if (bodyContent) {
194
+
195
+ if (bodyContent && Object.keys(bodyContent).length > 0) {
195
196
  const firstBodyContentKey = Object.keys(bodyContent)[0];
196
197
  if (firstBodyContentKey.endsWith("+json")) {
197
198
  const firstBody = bodyContent[firstBodyContentKey];