Skip to content

Commit

Permalink
bug: fixes format validation #199 (#200)
Browse files Browse the repository at this point in the history
* bug: fixes format validation #199

* bug: set circular reference counter #199

* bug: set circular reference counter #199
  • Loading branch information
srinandan committed May 10, 2023
1 parent ce31aa0 commit 6892382
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/bundlegen/generateapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func LoadDocumentFromFile(filePath string, validate bool, formatValidation bool)
var err error
var jsonContent []byte

// see ./test/circular-reference.json and https://github.com/apigee/apigeecli/issues/199
openapi3.CircularReferenceCounter = 20

doc, err = openapi3.NewLoader().LoadFromFile(filePath)
if err != nil {
clilog.Error.Println(err)
Expand All @@ -123,8 +126,10 @@ func LoadDocumentFromFile(filePath string, validate bool, formatValidation bool)
// add custom string definitions
openapi3.DefineStringFormat("uuid", openapi3.FormatOfStringForUUIDOfRFC4122)

if !formatValidation {
if formatValidation {
openapi3.EnableSchemaFormatValidation()
} else {
openapi3.DisableSchemaFormatValidation()
}

if validate {
Expand Down Expand Up @@ -157,6 +162,9 @@ func LoadDocumentFromURI(uri string, validate bool, formatValidation bool) (stri
return "", nil, err
}

// see ./test/circular-reference.json and https://github.com/apigee/apigeecli/issues/199
openapi3.CircularReferenceCounter = 20

doc, err = openapi3.NewLoader().LoadFromURI(u)
if err != nil {
return "", nil, err
Expand Down
151 changes: 151 additions & 0 deletions test/circular-reference.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"openapi": "3.0.1",
"info": {
"title": "CLMBasicApi",
"description": "An endpoint to access a group of apis",
"contact": {
"name": "Developer Team",
"url": "https://smartbygep.atlassian.net/",
"email": "dm.teamabc@gep.com"
},
"version": "v1"
},
"servers": [
{
"url": "http://api-leoaksdev.gep.com/leo-clm-basic"
}
],
"tags":[
{"name": "BasicDetails"}
],
"paths": {
"/api/v1/BasicDetails/BasicDetails": {
"post": {
"tags": [
"BasicDetails"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Assembly"
}
}
}
},
"responses": {
"200": {
"description": "Success"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
}
},
"security": [
{
"oauth2": [ ]
}
]
}
}
},
"components": {
"schemas": {
"Assembly": {
"type": "object",
"properties": {
"definedTypes": {
"type": "array",
"items": {
"$ref": "#/components/schemas/TypeInfo"
},
"nullable": true,
"readOnly": true
},
"fullName": {
"type": "string",
"nullable": true,
"readOnly": true
}
},
"additionalProperties": false
},
"TypeInfo": {
"type": "object",
"properties": {
"genericTypeParameters": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Type"
},
"nullable": true,
"readOnly": true
},
"fullName": {
"type": "string",
"nullable": true,
"readOnly": true
}
},
"additionalProperties": false
},
"Type": {
"type": "object",
"properties": {
"fullName": {
"type": "string",
"nullable": true,
"readOnly": true
},
"assembly": {
"allOf": [
{
"$ref": "#/components/schemas/Assembly"
}
],
"nullable": true,
"readOnly": true
},
"declaringType": {
"allOf": [
{
"$ref": "#/components/schemas/Type"
}
],
"nullable": true,
"readOnly": true
},
"genericTypeArguments": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Type"
},
"nullable": true,
"readOnly": true
},
"baseType": {
"allOf": [
{
"$ref": "#/components/schemas/Type"
}
],
"nullable": true,
"readOnly": true
}
},
"additionalProperties": false
}
},
"securitySchemes": {
"oauth2": {
"type": "apiKey",
"description": "Standard Authorization header using the Bearer scheme. Example: \"Bearer {token}\"",
"name": "Authorization",
"in": "header"
}
}
}
}

0 comments on commit 6892382

Please sign in to comment.