Added support for 3.1 docs and variations, as well as removed duplicated descriptions from sample spec.

This commit is contained in:
Dave Shanley
2022-09-26 15:58:32 -04:00
parent ee4aec4cdb
commit e80b640627
4 changed files with 11 additions and 11 deletions

View File

@@ -217,7 +217,7 @@ func TestNewDocument_Components_Headers(t *testing.T) {
initTest() initTest()
h := NewDocument(lowDoc) h := NewDocument(lowDoc)
assert.Len(t, h.Components.Headers, 1) assert.Len(t, h.Components.Headers, 1)
assert.Equal(t, "this is a header", h.Components.Headers["UseOil"].Description) assert.Equal(t, "this is a header example for UseOil", h.Components.Headers["UseOil"].Description)
assert.Equal(t, 318, h.Components.Headers["UseOil"].GoLow().Description.ValueNode.Line) assert.Equal(t, 318, h.Components.Headers["UseOil"].GoLow().Description.ValueNode.Line)
assert.Equal(t, 20, h.Components.Headers["UseOil"].GoLow().Description.ValueNode.Column) assert.Equal(t, 20, h.Components.Headers["UseOil"].GoLow().Description.ValueNode.Column)
} }

View File

@@ -212,7 +212,7 @@ func TestCreateDocument_Paths(t *testing.T) {
param := burgerId.Value.Get.Value.Parameters.Value[1] param := burgerId.Value.Get.Value.Parameters.Value[1]
assert.Equal(t, "burgerHeader", param.Value.Name.Value) assert.Equal(t, "burgerHeader", param.Value.Name.Value)
prop := param.Value.Schema.Value.Schema().FindProperty("burgerTheme").Value prop := param.Value.Schema.Value.Schema().FindProperty("burgerTheme").Value
assert.Equal(t, "something about a theme?", prop.Schema().Description.Value) assert.Equal(t, "something about a theme goes in here?", prop.Schema().Description.Value)
assert.Equal(t, "big-mac", param.Value.Example.Value) assert.Equal(t, "big-mac", param.Value.Example.Value)
// check content // check content
@@ -284,7 +284,7 @@ func TestCreateDocument_Paths(t *testing.T) {
assert.Len(t, okCode.Value.Headers.Value, 1) assert.Len(t, okCode.Value.Headers.Value, 1)
okheader := okCode.Value.FindHeader("UseOil") okheader := okCode.Value.FindHeader("UseOil")
assert.NotNil(t, okheader.Value) assert.NotNil(t, okheader.Value)
assert.Equal(t, "this is a header", okheader.Value.Description.Value) assert.Equal(t, "this is a header example for UseOil", okheader.Value.Description.Value)
respContent := okCode.Value.FindContent("application/json").Value respContent := okCode.Value.FindContent("application/json").Value
assert.NotNil(t, respContent) assert.NotNil(t, respContent)
@@ -432,7 +432,7 @@ func TestCreateDocument_Components_Headers(t *testing.T) {
useOil := components.FindHeader("UseOil") useOil := components.FindHeader("UseOil")
assert.NotNil(t, useOil.Value) assert.NotNil(t, useOil.Value)
assert.Equal(t, "this is a header", useOil.Value.Description.Value) assert.Equal(t, "this is a header example for UseOil", useOil.Value.Description.Value)
assert.Equal(t, "string", useOil.Value.Schema.Value.Schema().Type.Value.A) assert.Equal(t, "string", useOil.Value.Schema.Value.Schema().Type.Value.A)
} }
@@ -602,4 +602,4 @@ func ExampleCreateDocument() {
// print out email address from the info > contact object. // print out email address from the info > contact object.
fmt.Print(document.Info.Value.Contact.Value.Email.Value) fmt.Print(document.Info.Value.Contact.Value.Email.Value)
// Output: apiteam@swagger.io // Output: apiteam@swagger.io
} }

View File

@@ -89,7 +89,7 @@ func ExtractSpecInfo(spec []byte) (*SpecInfo, error) {
if spec.SpecType == utils.OpenApi3 { if spec.SpecType == utils.OpenApi3 {
switch spec.Version { switch spec.Version {
case "3.0.0", "3.0.1": case "3.0.0", "3.0.1", "3.0", "3":
spec.APISchema = OpenAPI3SchemaData spec.APISchema = OpenAPI3SchemaData
case "3.1.0": case "3.1.0":
spec.APISchema = OpenAPI31SchemaData spec.APISchema = OpenAPI31SchemaData

View File

@@ -315,7 +315,7 @@ components:
url: https://pb33f.io url: https://pb33f.io
headers: headers:
UseOil: UseOil:
description: this is a header description: this is a header example for UseOil
schema: schema:
type: string type: string
requestBodies: requestBodies:
@@ -389,10 +389,10 @@ components:
properties: properties:
burgerTheme: burgerTheme:
type: string type: string
description: something about a theme? description: something about a theme goes in here?
burgerTime: burgerTime:
type: number type: number
description: number of burgers ordered this year. description: number of burgers ordered so far this year.
example: big-mac example: big-mac
description: the name of the burger. use this to order your food description: the name of the burger. use this to order your food
required: true required: true
@@ -423,7 +423,7 @@ components:
schema: schema:
type: string type: string
example: big-mac example: big-mac
description: the name of the burger. use this to order your food description: the name of the burger. use this to order your tasty burger
required: true required: true
schemas: schemas:
Error: Error:
@@ -531,7 +531,7 @@ components:
x-screaming-baby: loud x-screaming-baby: loud
x-something-something: darkside x-something-something: darkside
externalDocs: externalDocs:
description: "Find out more information about our products)" description: "Find out more information about our products and services"
url: "https://pb33f.io" url: "https://pb33f.io"
jsonSchemaDialect: https://pb33f.io/schema jsonSchemaDialect: https://pb33f.io/schema
webhooks: webhooks: