From 2c692ad8a4ee299ebe7e86a8bde1445c1675cba3 Mon Sep 17 00:00:00 2001 From: Thodin3 <30184721+Thodin3@users.noreply.github.com> Date: Tue, 11 May 2021 10:43:27 +0200 Subject: [PATCH] airtasker#1417 Add new unit tests --- .../openapi2/__snapshots__/openapi2.spec.ts.snap | 8 ++++++++ .../__spec-examples__/contract-with-schemaprops.ts | 6 ++++++ lib/src/generators/openapi2/openapi2.spec.ts | 6 ++++++ .../openapi3/__snapshots__/openapi3.spec.ts.snap | 3 +++ .../__spec-examples__/contract-with-schemaprops.ts | 2 ++ lib/src/generators/openapi3/openapi3.spec.ts | 1 + lib/src/parsers/__spec-examples__/schemaprops.ts | 2 +- 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap b/lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap index 6cf2e88f5..f08cb25c1 100644 --- a/lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap +++ b/lib/src/generators/openapi2/__snapshots__/openapi2.spec.ts.snap @@ -934,6 +934,9 @@ exports[`OpenAPI 2 generator schemaprops contract with schemaprops parses correc ], \\"minProperties\\": 1, \\"maxProperties\\": 100, + \\"example\\": { + \\"price\\": 3.14 + }, \\"description\\": \\"property-schemaprop description for object\\" }, \\"currencies\\": { @@ -955,6 +958,7 @@ exports[`OpenAPI 2 generator schemaprops contract with schemaprops parses correc \\"APPROVED\\" ], \\"title\\": \\"process-code\\", + \\"example\\": \\"WAITING\\", \\"description\\": \\"property-schemaprop description for union\\" }, \\"inheritance\\": { @@ -992,6 +996,10 @@ exports[`OpenAPI 2 generator schemaprops contract with schemaprops parses correc } ], \\"title\\": \\"process-code\\", + \\"example\\": { + \\"inheritId\\": 3.14, + \\"inheritName\\": 42 + }, \\"description\\": \\"property-schemaprop description for intersection\\" } }, diff --git a/lib/src/generators/openapi2/__spec-examples__/contract-with-schemaprops.ts b/lib/src/generators/openapi2/__spec-examples__/contract-with-schemaprops.ts index aba4a805f..7669816cc 100644 --- a/lib/src/generators/openapi2/__spec-examples__/contract-with-schemaprops.ts +++ b/lib/src/generators/openapi2/__spec-examples__/contract-with-schemaprops.ts @@ -59,6 +59,8 @@ class EndpointWithSchemaPropsOnHeaders { * 1 * @oaSchemaProp maxProperties * 100 + * @oaSchemaProp example + * {"price":3.14} * */ element: { /** property-schemaprop description for float inner object @@ -83,11 +85,15 @@ class EndpointWithSchemaPropsOnHeaders { /** property-schemaprop description for union * @oaSchemaProp title * "process-code" + * @oaSchemaProp example + * "WAITING" * */ code?: "VALID" | "NOT_VALID" | "WAITING" | "APPROVED"; /** property-schemaprop description for intersection * @oaSchemaProp title * "process-code" + * @oaSchemaProp example + * {"inheritId":3.14, "inheritName":42} * */ inheritance?: { /** property-schemaprop description for double inner intersection diff --git a/lib/src/generators/openapi2/openapi2.spec.ts b/lib/src/generators/openapi2/openapi2.spec.ts index a61a943fd..3dfa6a01f 100644 --- a/lib/src/generators/openapi2/openapi2.spec.ts +++ b/lib/src/generators/openapi2/openapi2.spec.ts @@ -332,6 +332,7 @@ describe("OpenAPI 2 generator", () => { description: "property-schemaprop description for object", maxProperties: 100, minProperties: 1, + example: { price: 3.14 }, properties: { price: { description: @@ -366,6 +367,7 @@ describe("OpenAPI 2 generator", () => { description: "property-schemaprop description for union", enum: ["VALID", "NOT_VALID", "WAITING", "APPROVED"], title: "process-code", + example: "WAITING", type: "string" }, inheritance: { @@ -400,6 +402,10 @@ describe("OpenAPI 2 generator", () => { type: "object" } ], + example: { + inheritId: 3.14, + inheritName: 42 + }, description: "property-schemaprop description for intersection", title: "process-code" diff --git a/lib/src/generators/openapi3/__snapshots__/openapi3.spec.ts.snap b/lib/src/generators/openapi3/__snapshots__/openapi3.spec.ts.snap index f6cad473e..f58426ec6 100644 --- a/lib/src/generators/openapi3/__snapshots__/openapi3.spec.ts.snap +++ b/lib/src/generators/openapi3/__snapshots__/openapi3.spec.ts.snap @@ -1147,6 +1147,9 @@ exports[`OpenAPI 3 generator schemaprops contract with schemaprops parses correc \\"minProperties\\": 1, \\"maxProperties\\": 100, \\"additionalProperties\\": true, + \\"example\\": { + \\"price\\": 3.14 + }, \\"description\\": \\"property-schemaprop description for object\\" }, \\"currencies\\": { diff --git a/lib/src/generators/openapi3/__spec-examples__/contract-with-schemaprops.ts b/lib/src/generators/openapi3/__spec-examples__/contract-with-schemaprops.ts index 5cb126580..4fb5e3e42 100644 --- a/lib/src/generators/openapi3/__spec-examples__/contract-with-schemaprops.ts +++ b/lib/src/generators/openapi3/__spec-examples__/contract-with-schemaprops.ts @@ -69,6 +69,8 @@ class EndpointWithSchemaPropsOnHeaders { * 100 * @oaSchemaProp additionalProperties * true + * @oaSchemaProp example + * {"price":3.14} * */ element: { /** property-schemaprop description for float inner object diff --git a/lib/src/generators/openapi3/openapi3.spec.ts b/lib/src/generators/openapi3/openapi3.spec.ts index fd0ceeacc..c833fc639 100644 --- a/lib/src/generators/openapi3/openapi3.spec.ts +++ b/lib/src/generators/openapi3/openapi3.spec.ts @@ -427,6 +427,7 @@ describe("OpenAPI 3 generator", () => { maxProperties: 100, minProperties: 1, additionalProperties: true, + example: { price: 3.14 }, properties: { price: { description: diff --git a/lib/src/parsers/__spec-examples__/schemaprops.ts b/lib/src/parsers/__spec-examples__/schemaprops.ts index 41e5731dd..f935ede61 100644 --- a/lib/src/parsers/__spec-examples__/schemaprops.ts +++ b/lib/src/parsers/__spec-examples__/schemaprops.ts @@ -6,7 +6,7 @@ type SchemaPropTests = { * "property-schemaprop-value" * */ "property-with-schemaprop": string; - /** + /** * @oaSchemaProp example * "123.3" */