Skip to content

Commit 97e175c

Browse files
committed
2 parents 37e5bea + 07d4564 commit 97e175c

File tree

6 files changed

+61
-28
lines changed

6 files changed

+61
-28
lines changed

src/c-sharp/JakubKozera.OpenApiUi/JakubKozera.OpenApiUi.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
1+
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup>
32
<TargetFrameworks>net6.0;net8.0;net9.0</TargetFrameworks>
43
<PackageId>JakubKozera.OpenApiUi</PackageId>
5-
<Version>1.0.16</Version>
4+
<Version>1.0.18</Version>
65
<Authors>Jakub Kozera</Authors>
76
<Description>A .NET library serving OpenAPI UI with HTML/CSS</Description>
87
<PackageTags>openapi;ui;html;css;dotnet</PackageTags>

src/core/demo-dist/bundle.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4591,13 +4591,19 @@ function generateValidExampleFromSchema(
45914591
if (resolvedSchema.example !== undefined) {
45924592
return resolvedSchema.example;
45934593
}
4594-
45954594
// Use default value if available
45964595
if (resolvedSchema.default !== undefined) {
45974596
return resolvedSchema.default;
45984597
}
45994598

4600-
if (resolvedSchema.type === "object" && resolvedSchema.properties) {
4599+
// Handle type as array (OpenAPI 3.1 JSON Schema compatibility)
4600+
let schemaType = resolvedSchema.type;
4601+
if (Array.isArray(resolvedSchema.type) && resolvedSchema.type.length > 0) {
4602+
// Use first non-null type
4603+
schemaType = resolvedSchema.type.find(type => type !== "null") || resolvedSchema.type[0];
4604+
}
4605+
4606+
if (schemaType === "object" && resolvedSchema.properties) {
46014607
const example = {};
46024608
const required = resolvedSchema.required || [];
46034609

@@ -4631,10 +4637,8 @@ function generateValidExampleFromSchema(
46314637
example[propName] = value;
46324638
}
46334639
}
4634-
}
4635-
4636-
return example;
4637-
} else if (resolvedSchema.type === "array" && resolvedSchema.items) {
4640+
} return example;
4641+
} else if (schemaType === "array" && resolvedSchema.items) {
46384642
if (indent < 5) {
46394643
const itemExample = generateValidExampleFromSchema(
46404644
resolvedSchema.items,
@@ -4662,13 +4666,19 @@ function generateValidPrimitiveExample(schema) {
46624666

46634667
// Use default value if available
46644668
if (schema.default !== undefined) return schema.default;
4665-
46664669
// Handle enums first
46674670
if (schema.enum && schema.enum.length > 0) {
46684671
return schema.enum[0];
46694672
}
46704673

4671-
switch (schema.type) {
4674+
// Handle type as array (OpenAPI 3.1 JSON Schema compatibility)
4675+
let schemaType = schema.type;
4676+
if (Array.isArray(schema.type) && schema.type.length > 0) {
4677+
// Use first non-null type
4678+
schemaType = schema.type.find(type => type !== "null") || schema.type[0];
4679+
}
4680+
4681+
switch (schemaType) {
46724682
case "string":
46734683
return generateValidStringExample(schema);
46744684
case "integer":

src/core/demo-dist/demo-info.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@
2222
"description": "A comprehensive test API demonstrating all supported OpenAPI security schemes"
2323
}
2424
],
25+
<<<<<<< HEAD
2526
"buildDate": "2025-07-30T17:21:51.894Z"
27+
=======
28+
"buildDate": "2025-06-24T16:37:09.045Z"
29+
>>>>>>> 07d45644b435fc4296c20372b982b2ec86229c8a
2630
}

src/core/dist/bundle.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4591,13 +4591,19 @@ function generateValidExampleFromSchema(
45914591
if (resolvedSchema.example !== undefined) {
45924592
return resolvedSchema.example;
45934593
}
4594-
45954594
// Use default value if available
45964595
if (resolvedSchema.default !== undefined) {
45974596
return resolvedSchema.default;
45984597
}
45994598

4600-
if (resolvedSchema.type === "object" && resolvedSchema.properties) {
4599+
// Handle type as array (OpenAPI 3.1 JSON Schema compatibility)
4600+
let schemaType = resolvedSchema.type;
4601+
if (Array.isArray(resolvedSchema.type) && resolvedSchema.type.length > 0) {
4602+
// Use first non-null type
4603+
schemaType = resolvedSchema.type.find(type => type !== "null") || resolvedSchema.type[0];
4604+
}
4605+
4606+
if (schemaType === "object" && resolvedSchema.properties) {
46014607
const example = {};
46024608
const required = resolvedSchema.required || [];
46034609

@@ -4631,10 +4637,8 @@ function generateValidExampleFromSchema(
46314637
example[propName] = value;
46324638
}
46334639
}
4634-
}
4635-
4636-
return example;
4637-
} else if (resolvedSchema.type === "array" && resolvedSchema.items) {
4640+
} return example;
4641+
} else if (schemaType === "array" && resolvedSchema.items) {
46384642
if (indent < 5) {
46394643
const itemExample = generateValidExampleFromSchema(
46404644
resolvedSchema.items,
@@ -4662,13 +4666,19 @@ function generateValidPrimitiveExample(schema) {
46624666

46634667
// Use default value if available
46644668
if (schema.default !== undefined) return schema.default;
4665-
46664669
// Handle enums first
46674670
if (schema.enum && schema.enum.length > 0) {
46684671
return schema.enum[0];
46694672
}
46704673

4671-
switch (schema.type) {
4674+
// Handle type as array (OpenAPI 3.1 JSON Schema compatibility)
4675+
let schemaType = schema.type;
4676+
if (Array.isArray(schema.type) && schema.type.length > 0) {
4677+
// Use first non-null type
4678+
schemaType = schema.type.find(type => type !== "null") || schema.type[0];
4679+
}
4680+
4681+
switch (schemaType) {
46724682
case "string":
46734683
return generateValidStringExample(schema);
46744684
case "integer":

src/core/js/exampleGenerator.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ function generateValidExampleFromSchema(
3131
if (resolvedSchema.example !== undefined) {
3232
return resolvedSchema.example;
3333
}
34-
3534
// Use default value if available
3635
if (resolvedSchema.default !== undefined) {
3736
return resolvedSchema.default;
3837
}
3938

40-
if (resolvedSchema.type === "object" && resolvedSchema.properties) {
39+
// Handle type as array (OpenAPI 3.1 JSON Schema compatibility)
40+
let schemaType = resolvedSchema.type;
41+
if (Array.isArray(resolvedSchema.type) && resolvedSchema.type.length > 0) {
42+
// Use first non-null type
43+
schemaType = resolvedSchema.type.find(type => type !== "null") || resolvedSchema.type[0];
44+
}
45+
46+
if (schemaType === "object" && resolvedSchema.properties) {
4147
const example = {};
4248
const required = resolvedSchema.required || [];
4349

@@ -71,10 +77,8 @@ function generateValidExampleFromSchema(
7177
example[propName] = value;
7278
}
7379
}
74-
}
75-
76-
return example;
77-
} else if (resolvedSchema.type === "array" && resolvedSchema.items) {
80+
} return example;
81+
} else if (schemaType === "array" && resolvedSchema.items) {
7882
if (indent < 5) {
7983
const itemExample = generateValidExampleFromSchema(
8084
resolvedSchema.items,
@@ -102,13 +106,19 @@ function generateValidPrimitiveExample(schema) {
102106

103107
// Use default value if available
104108
if (schema.default !== undefined) return schema.default;
105-
106109
// Handle enums first
107110
if (schema.enum && schema.enum.length > 0) {
108111
return schema.enum[0];
109112
}
110113

111-
switch (schema.type) {
114+
// Handle type as array (OpenAPI 3.1 JSON Schema compatibility)
115+
let schemaType = schema.type;
116+
if (Array.isArray(schema.type) && schema.type.length > 0) {
117+
// Use first non-null type
118+
schemaType = schema.type.find(type => type !== "null") || schema.type[0];
119+
}
120+
121+
switch (schemaType) {
112122
case "string":
113123
return generateValidStringExample(schema);
114124
case "integer":

src/vsc-extension/openapi-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "openapi-ui",
33
"displayName": "OpenAPI UI",
44
"description": "OpenAPI UI viewer for VS Code",
5-
"version": "1.0.14",
5+
"version": "1.0.15",
66
"publisher": "JakubKozera",
77
"icon": "openapi-ui.png",
88
"repository": {

0 commit comments

Comments
 (0)