From 1d6048dd428f27a7c181d36f8f5ab8d76d30222c Mon Sep 17 00:00:00 2001 From: Thomas Rooney Date: Mon, 17 Jul 2023 14:58:44 +0100 Subject: [PATCH] example --- datamodel/low/v3/create_document_test.go | 25 ++++++++----- test_specs/yaml-anchor.yaml | 45 +++--------------------- 2 files changed, 20 insertions(+), 50 deletions(-) diff --git a/datamodel/low/v3/create_document_test.go b/datamodel/low/v3/create_document_test.go index b6439c94..563ab536 100644 --- a/datamodel/low/v3/create_document_test.go +++ b/datamodel/low/v3/create_document_test.go @@ -690,29 +690,36 @@ func TestCreateDocument_YamlAnchor(t *testing.T) { panic("cannot build document") } - examplePath := document.Paths.Value.FindPath("/system/examples/{id}") + examplePath := document.Paths.GetValue().FindPath("/system/examples/{id}") assert.NotNil(t, examplePath) // Check tag reference - getOp := examplePath.Value.Get.Value + getOp := examplePath.GetValue().Get.GetValue() assert.NotNil(t, getOp) - postOp := examplePath.Value.Get.Value + postOp := examplePath.GetValue().Get.GetValue() assert.NotNil(t, postOp) - assert.Equal(t, 1, len(getOp.GetTags().Value)) - assert.Equal(t, 1, len(postOp.GetTags().Value)) - assert.Equal(t, getOp.GetTags().Value, postOp.GetTags().Value) - - // Check paramter reference + assert.Equal(t, 1, len(getOp.GetTags().GetValue())) + assert.Equal(t, 1, len(postOp.GetTags().GetValue())) + assert.Equal(t, getOp.GetTags().GetValue(), postOp.GetTags().GetValue()) + // Check parameter reference getParams := examplePath.Value.Get.Value.Parameters.Value assert.NotNil(t, getParams) postParams := examplePath.Value.Post.Value.Parameters.Value assert.NotNil(t, postParams) - assert.Equal(t, 1, len(getParams)) assert.Equal(t, 1, len(postParams)) assert.Equal(t, getParams, postParams) + // check post request body + responses := examplePath.GetValue().Get.GetValue().GetResponses().Value.(*Responses) + assert.NotNil(t, responses) + jsonGet := responses.FindResponseByCode("200").GetValue().FindContent("application/json") + assert.NotNil(t, jsonGet) + + // Should this work? It doesn't + //postJsonType := examplePath.GetValue().Post.GetValue().RequestBody.GetValue().FindContent("application/json") + //assert.NotNil(t, postJsonType) } func ExampleCreateDocument() { diff --git a/test_specs/yaml-anchor.yaml b/test_specs/yaml-anchor.yaml index 88e89bae..c13a77cb 100644 --- a/test_specs/yaml-anchor.yaml +++ b/test_specs/yaml-anchor.yaml @@ -3,18 +3,7 @@ info: title: Example version: 0.0.1 components: - securitySchemes: - bearerAuth: - type: http - scheme: bearer - bearerFormat: JWT schemas: - Error: - type: object - properties: - message: - type: string - description: Error message Example: type: object required: @@ -29,15 +18,12 @@ components: type: string title: Description description: Brief description of this Example. Optional. -security: - - bearerAuth: [] paths: /system/examples/{id}: get: tags: &a1 - Examples - summary: Get a list of Example objects parameters: &id - name: id @@ -45,41 +31,18 @@ paths: required: true schema: type: string - description: Unique ID - description: Get a list of Example objects responses: &a2 "200": description: a list of Example objects content: + &example application/json: schema: - type: object - properties: - count: - type: integer - description: number of items present in the items array - items: - type: array - items: - $ref: "#/components/schemas/Example" - "401": - description: Unauthorized - "500": - description: Unexpected error - content: - application/json: - schema: - $ref: "#/components/schemas/Error" + $ref: '#/components/schemas/Example' post: tags: *a1 parameters: *id - summary: Create Example - description: Create Example + responses: *a2 requestBody: - description: New Example object - content: - application/json: - schema: - $ref: "#/components/schemas/Example" - responses: *a2 \ No newline at end of file + content: *example