mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-06 12:37:49 +00:00
example
This commit is contained in:
@@ -690,29 +690,36 @@ func TestCreateDocument_YamlAnchor(t *testing.T) {
|
|||||||
panic("cannot build document")
|
panic("cannot build document")
|
||||||
}
|
}
|
||||||
|
|
||||||
examplePath := document.Paths.Value.FindPath("/system/examples/{id}")
|
examplePath := document.Paths.GetValue().FindPath("/system/examples/{id}")
|
||||||
assert.NotNil(t, examplePath)
|
assert.NotNil(t, examplePath)
|
||||||
|
|
||||||
// Check tag reference
|
// Check tag reference
|
||||||
getOp := examplePath.Value.Get.Value
|
getOp := examplePath.GetValue().Get.GetValue()
|
||||||
assert.NotNil(t, getOp)
|
assert.NotNil(t, getOp)
|
||||||
postOp := examplePath.Value.Get.Value
|
postOp := examplePath.GetValue().Get.GetValue()
|
||||||
assert.NotNil(t, postOp)
|
assert.NotNil(t, postOp)
|
||||||
assert.Equal(t, 1, len(getOp.GetTags().Value))
|
assert.Equal(t, 1, len(getOp.GetTags().GetValue()))
|
||||||
assert.Equal(t, 1, len(postOp.GetTags().Value))
|
assert.Equal(t, 1, len(postOp.GetTags().GetValue()))
|
||||||
assert.Equal(t, getOp.GetTags().Value, postOp.GetTags().Value)
|
assert.Equal(t, getOp.GetTags().GetValue(), postOp.GetTags().GetValue())
|
||||||
|
|
||||||
// Check paramter reference
|
|
||||||
|
|
||||||
|
// Check parameter reference
|
||||||
getParams := examplePath.Value.Get.Value.Parameters.Value
|
getParams := examplePath.Value.Get.Value.Parameters.Value
|
||||||
assert.NotNil(t, getParams)
|
assert.NotNil(t, getParams)
|
||||||
postParams := examplePath.Value.Post.Value.Parameters.Value
|
postParams := examplePath.Value.Post.Value.Parameters.Value
|
||||||
assert.NotNil(t, postParams)
|
assert.NotNil(t, postParams)
|
||||||
|
|
||||||
assert.Equal(t, 1, len(getParams))
|
assert.Equal(t, 1, len(getParams))
|
||||||
assert.Equal(t, 1, len(postParams))
|
assert.Equal(t, 1, len(postParams))
|
||||||
assert.Equal(t, getParams, 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() {
|
func ExampleCreateDocument() {
|
||||||
|
|||||||
@@ -3,18 +3,7 @@ info:
|
|||||||
title: Example
|
title: Example
|
||||||
version: 0.0.1
|
version: 0.0.1
|
||||||
components:
|
components:
|
||||||
securitySchemes:
|
|
||||||
bearerAuth:
|
|
||||||
type: http
|
|
||||||
scheme: bearer
|
|
||||||
bearerFormat: JWT
|
|
||||||
schemas:
|
schemas:
|
||||||
Error:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
message:
|
|
||||||
type: string
|
|
||||||
description: Error message
|
|
||||||
Example:
|
Example:
|
||||||
type: object
|
type: object
|
||||||
required:
|
required:
|
||||||
@@ -29,15 +18,12 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
title: Description
|
title: Description
|
||||||
description: Brief description of this Example. Optional.
|
description: Brief description of this Example. Optional.
|
||||||
security:
|
|
||||||
- bearerAuth: []
|
|
||||||
paths:
|
paths:
|
||||||
/system/examples/{id}:
|
/system/examples/{id}:
|
||||||
get:
|
get:
|
||||||
tags:
|
tags:
|
||||||
&a1
|
&a1
|
||||||
- Examples
|
- Examples
|
||||||
summary: Get a list of Example objects
|
|
||||||
parameters:
|
parameters:
|
||||||
&id
|
&id
|
||||||
- name: id
|
- name: id
|
||||||
@@ -45,41 +31,18 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
type: string
|
type: string
|
||||||
description: Unique ID
|
|
||||||
description: Get a list of Example objects
|
|
||||||
responses:
|
responses:
|
||||||
&a2
|
&a2
|
||||||
"200":
|
"200":
|
||||||
description: a list of Example objects
|
description: a list of Example objects
|
||||||
content:
|
content:
|
||||||
|
&example
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
$ref: '#/components/schemas/Example'
|
||||||
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"
|
|
||||||
post:
|
post:
|
||||||
tags: *a1
|
tags: *a1
|
||||||
parameters: *id
|
parameters: *id
|
||||||
summary: Create Example
|
responses: *a2
|
||||||
description: Create Example
|
|
||||||
requestBody:
|
requestBody:
|
||||||
description: New Example object
|
content: *example
|
||||||
content:
|
|
||||||
application/json:
|
|
||||||
schema:
|
|
||||||
$ref: "#/components/schemas/Example"
|
|
||||||
responses: *a2
|
|
||||||
|
|||||||
Reference in New Issue
Block a user