Skip to content

Commit 0a0f623

Browse files
authored
fix: paths to openapi specifications (#307)
- update paths to data files - add skipped tests for openapi 3.1 validation - make validator generator test that a valid spec is valid
1 parent e1ec732 commit 0a0f623

9 files changed

Lines changed: 3171 additions & 2035 deletions

packages/openapi-code-generator/src/core/openapi-validator.spec.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,72 @@ describe("core/openapi-validator", () => {
3434
"invalid-spec.yaml",
3535
{
3636
openapi: "3.0.0",
37+
info: {
38+
title: "Invalid Specification",
39+
version: "1.0.0",
40+
},
41+
paths: {
42+
"/something": {
43+
get: {
44+
responses: {},
45+
},
46+
},
47+
},
48+
},
49+
true,
50+
),
51+
).rejects.toThrow(
52+
"Validation failed: -> must NOT have fewer than 1 properties at path '/paths/~1something/get/responses'",
53+
)
54+
})
55+
})
56+
57+
describe.skip("openapi 3.1", () => {
58+
it("should accept a valid specification", async () => {
59+
const validator = await OpenapiValidator.create()
60+
await expect(
61+
validator.validate(
62+
"valid-spec.yaml",
63+
{
64+
openapi: "3.1.0",
3765
info: {
3866
title: "Valid Specification",
3967
version: "1.0.0",
4068
},
69+
paths: {
70+
"/something": {
71+
get: {
72+
responses: {default: {description: "whatever"}},
73+
},
74+
},
75+
},
76+
components: {
77+
schemas: {
78+
Something: {
79+
type: ["object", "null"],
80+
properties: {
81+
name: {type: "string"},
82+
},
83+
},
84+
},
85+
},
86+
},
87+
true,
88+
),
89+
).resolves.toBeUndefined()
90+
})
91+
92+
it("should reject an invalid specification", async () => {
93+
const validator = await OpenapiValidator.create()
94+
await expect(
95+
validator.validate(
96+
"invalid-spec.yaml",
97+
{
98+
openapi: "3.1.0",
99+
info: {
100+
title: "Invalid Specification",
101+
version: "1.0.0",
102+
},
41103
paths: {
42104
"/something": {
43105
get: {

packages/openapi-code-generator/src/core/schemas/openapi-3.0-specification-validator.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
module.exports = validate10
77
module.exports.default = validate10
88
const schema11 = {
9-
id: "https://spec.openapis.org/oas/3.0/schema/WORK-IN-PROGRESS",
9+
id: "https://spec.openapis.org/oas/3.0/schema/2024-10-18",
1010
$schema: "http://json-schema.org/draft-04/schema#",
1111
description: "The description of OpenAPI v3.0.x Documents",
1212
type: "object",
@@ -18215,7 +18215,7 @@ function validate10(
1821518215
data,
1821618216
{instancePath = "", parentData, parentDataProperty, rootData = data} = {},
1821718217
) {
18218-
/*# sourceURL="https://spec.openapis.org/oas/3.0/schema/WORK-IN-PROGRESS" */
18218+
/*# sourceURL="https://spec.openapis.org/oas/3.0/schema/2024-10-18" */
1821918219
let vErrors = null
1822018220
let errors = 0
1822118221
if (errors === 0) {

0 commit comments

Comments
 (0)