Skip to content

Commit

Permalink
Update openapi spec with new params
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Jetmar committed Sep 30, 2024
1 parent f49302a commit 4834a1d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 74 deletions.
24 changes: 21 additions & 3 deletions cmd/spec/parameters.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
# It is necessary to have the initial indetation!
queryParams:
Bundle:
name: bundle
description: If set, content is associated with a specific CRC bundle
ProductFamilies:
name: product-families
description: If set, content is associated with a specific CRC product families
in: query
required: false
schema:
type: string
explode: true
style: form
Content:
name: content
description: If set, content is associated with a specific CRC content
in: query
required: false
schema:
type: string
explode: true
style: form
UseCase:
name: use-case
description: If set, content is associated with a specific CRC use case
in: query
required: false
schema:
Expand Down
5 changes: 3 additions & 2 deletions cmd/spec/path.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ paths:
items:
$ref: '#/components/schemas/v1.Quickstart'
parameters:
- $ref: '#/components/schemas/queryParams/Bundle'
- $ref: '#/components/schemas/queryParams/ProductFamilies'
- $ref: '#/components/schemas/queryParams/Content'
- $ref: '#/components/schemas/queryParams/UseCase'
- $ref: '#/components/schemas/queryParams/Application'
- $ref: '#/components/schemas/queryParams/Limit'
- $ref: '#/components/schemas/queryParams/Offset'
Expand Down Expand Up @@ -65,7 +67,6 @@ paths:
items:
$ref: '#/components/schemas/v1.HelpTopic'
parameters:
- $ref: '#/components/schemas/queryParams/Bundle'
- $ref: '#/components/schemas/queryParams/Application'
- $ref: '#/components/schemas/queryParams/Name'
/helptopics/{name}:
Expand Down
11 changes: 1 addition & 10 deletions pkg/routes/help_topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ func concatAppendTags(slices [][]string) []string {
func GetAllHelpTopics(w http.ResponseWriter, r *http.Request) {
var helpTopic []models.HelpTopic
var tagTypes []models.TagType
// first try bundle query param
bundleQueries := r.URL.Query()["bundle"]
if len(bundleQueries) == 0 {
// if empty try bundle[] queries
bundleQueries = r.URL.Query()["bundle[]"]
}

applicationQueries := r.URL.Query()["application"]
if len(applicationQueries) == 0 {
Expand All @@ -73,9 +67,7 @@ func GetAllHelpTopics(w http.ResponseWriter, r *http.Request) {
}

var err error
if len(bundleQueries) > 0 {
tagTypes = append(tagTypes, models.BundleTag)
}

if len(applicationQueries) > 0 {
tagTypes = append(tagTypes, models.ApplicationTag)
}
Expand All @@ -85,7 +77,6 @@ func GetAllHelpTopics(w http.ResponseWriter, r *http.Request) {
* future proofing more than 2 tag queries
*/
tagQueries := make([][]string, 2)
tagQueries[0] = bundleQueries
tagQueries[1] = applicationQueries
helpTopic, err = findHelpTopics(tagTypes, concatAppendTags(tagQueries), nameQueries)
} else {
Expand Down
49 changes: 2 additions & 47 deletions pkg/routes/quickstarts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var rhelBudleTag models.Tag
var rhelContentTypeTag models.Tag
var rhelProductFamiliesTag models.Tag
var rhelUseCaseTag models.Tag
var settingsBundleTag models.Tag
var settingsContentTypeTag models.Tag
var settingsProductFamiliesTag models.Tag
var settingsUseCaseTag models.Tag
Expand All @@ -32,7 +31,6 @@ var rbacProductFamiliesTag models.Tag
var rbacContentTypeTag models.Tag
var rbacUseCaseTag models.Tag
var unusedTag models.Tag
var favoriteQuickstart models.FavoriteQuickstart

func mockQuickstart(name string) *models.Quickstart {
quickstart.Name = name
Expand Down Expand Up @@ -69,17 +67,13 @@ func setupRouter() *chi.Mux {
}

func setupTags() {
rhelBudleTag.Type = models.BundleTag
rhelBudleTag.Value = "rhel"
rhelProductFamiliesTag.Type = models.ProductFamilies
rhelProductFamiliesTag.Value = "rhel"
rhelContentTypeTag.Type = models.ContentType
rhelContentTypeTag.Value = "quickstart"
rhelUseCaseTag.Type = models.UseCase
rhelUseCaseTag.Value = "deploy"

settingsBundleTag.Type = models.BundleTag
settingsBundleTag.Value = "settings"
settingsProductFamiliesTag.Type = models.ProductFamilies
settingsProductFamiliesTag.Value = "settings"
settingsContentTypeTag.Type = models.ContentType
Expand All @@ -96,14 +90,10 @@ func setupTags() {
rbacUseCaseTag.Type = models.UseCase
rbacUseCaseTag.Value = "clusters"

unusedTag.Type = models.BundleTag
unusedTag.Value = "unused"

database.DB.Create(&rhelBudleTag)
database.DB.Create(&rhelContentTypeTag)
database.DB.Create(&rhelProductFamiliesTag)
database.DB.Create(&rhelUseCaseTag)
database.DB.Create(&settingsBundleTag)
database.DB.Create(&settingsProductFamiliesTag)
database.DB.Create(&settingsContentTypeTag)
database.DB.Create(&settingsUseCaseTag)
Expand All @@ -119,14 +109,14 @@ func setupTaggedQuickstarts() {
taggedQuickstart.Content = []byte(`{"tags": "all-tags"}`)

database.DB.Create(&taggedQuickstart)
database.DB.Model(&taggedQuickstart).Association("Tags").Append(&rhelBudleTag, &settingsBundleTag, &rbacApplicationTag)
database.DB.Model(&taggedQuickstart).Association("Tags").Append(&rhelBudleTag, &rbacApplicationTag)
database.DB.Save(&taggedQuickstart)

settingsQuickstart.Name = "settings-quickstart"
settingsQuickstart.Content = []byte(`{"tags": "settings"}`)

database.DB.Create(&settingsQuickstart)
database.DB.Model(&settingsQuickstart).Association("Tags").Append(&settingsBundleTag, &settingsContentTypeTag, &settingsProductFamiliesTag, &settingsUseCaseTag)
database.DB.Model(&settingsQuickstart).Association("Tags").Append(&settingsContentTypeTag, &settingsProductFamiliesTag, &settingsUseCaseTag)
database.DB.Save(&settingsQuickstart)

rhelQuickstart.Name = "rhel-quickstart"
Expand Down Expand Up @@ -157,41 +147,6 @@ func TestGetAll(t *testing.T) {
setupTaggedQuickstarts()
leafQuickstart := mockQuickstart("non-tags-quickstart")

t.Run("should get all quickstarts with 'rhel' or 'settings' bundle tags", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/?bundle[]=rhel&bundle[]=settings", nil)
response := httptest.NewRecorder()
router.ServeHTTP(response, request)

var payload *responsePayload
json.NewDecoder(response.Body).Decode(&payload)
assert.Equal(t, 200, response.Code)
assert.Equal(t, 3, len(payload.Data))
})

t.Run("should get all quickstarts with 'rhel' bundle tag", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/?bundle=rhel", nil)
response := httptest.NewRecorder()
router.ServeHTTP(response, request)

var payload *responsePayload
json.NewDecoder(response.Body).Decode(&payload)
assert.Equal(t, 200, response.Code)
assert.Equal(t, 2, len(payload.Data))
})

t.Run("should get all quickstarts with 'settings' bundle tag", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/?bundle=settings", nil)
response := httptest.NewRecorder()
router.ServeHTTP(response, request)

var payload *responsePayload
json.NewDecoder(response.Body).Decode(&payload)
assert.Equal(t, 200, response.Code)
assert.Equal(t, 2, len(payload.Data))
assert.Equal(t, "tagged-quickstart", payload.Data[0].Name)
assert.Equal(t, "settings-quickstart", payload.Data[1].Name)
})

t.Run("should get all quickstarts with 'rbac' application tag", func(t *testing.T) {
request, _ := http.NewRequest(http.MethodGet, "/?application=rbac", nil)
response := httptest.NewRecorder()
Expand Down
39 changes: 32 additions & 7 deletions spec/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
},
"style": "form"
},
"Bundle": {
"description": "If set, content is associated with a specific CRC bundle",
"Content": {
"description": "If set, content is associated with a specific CRC content",
"explode": true,
"in": "query",
"name": "bundle",
"name": "content",
"required": false,
"schema": {
"type": "string"
Expand Down Expand Up @@ -91,6 +91,17 @@
},
"style": "form"
},
"ProductFamilies": {
"description": "If set, content is associated with a specific CRC product families",
"explode": true,
"in": "query",
"name": "product-families",
"required": false,
"schema": {
"type": "string"
},
"style": "form"
},
"TopicName": {
"description": "identifier",
"in": "path",
Expand All @@ -99,6 +110,17 @@
"schema": {
"type": "string"
}
},
"UseCase": {
"description": "If set, content is associated with a specific CRC use case",
"explode": true,
"in": "query",
"name": "use-case",
"required": false,
"schema": {
"type": "string"
},
"style": "form"
}
},
"v1.FavoriteQuickstart": {
Expand Down Expand Up @@ -423,9 +445,6 @@
"/helptopics": {
"get": {
"parameters": [
{
"$ref": "#/components/schemas/queryParams/Bundle"
},
{
"$ref": "#/components/schemas/queryParams/Application"
},
Expand Down Expand Up @@ -507,7 +526,13 @@
"get": {
"parameters": [
{
"$ref": "#/components/schemas/queryParams/Bundle"
"$ref": "#/components/schemas/queryParams/ProductFamilies"
},
{
"$ref": "#/components/schemas/queryParams/Content"
},
{
"$ref": "#/components/schemas/queryParams/UseCase"
},
{
"$ref": "#/components/schemas/queryParams/Application"
Expand Down
29 changes: 24 additions & 5 deletions spec/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,27 @@ components:
type: object
# It is necessary to have the initial indetation!
queryParams:
Bundle:
name: bundle
description: If set, content is associated with a specific CRC bundle
ProductFamilies:
name: product-families
description: If set, content is associated with a specific CRC product families
in: query
required: false
schema:
type: string
explode: true
style: form
Content:
name: content
description: If set, content is associated with a specific CRC content
in: query
required: false
schema:
type: string
explode: true
style: form
UseCase:
name: use-case
description: If set, content is associated with a specific CRC use case
in: query
required: false
schema:
Expand Down Expand Up @@ -252,7 +270,9 @@ paths:
items:
$ref: '#/components/schemas/v1.Quickstart'
parameters:
- $ref: '#/components/schemas/queryParams/Bundle'
- $ref: '#/components/schemas/queryParams/ProductFamilies'
- $ref: '#/components/schemas/queryParams/Content'
- $ref: '#/components/schemas/queryParams/UseCase'
- $ref: '#/components/schemas/queryParams/Application'
- $ref: '#/components/schemas/queryParams/Limit'
- $ref: '#/components/schemas/queryParams/Offset'
Expand Down Expand Up @@ -296,7 +316,6 @@ paths:
items:
$ref: '#/components/schemas/v1.HelpTopic'
parameters:
- $ref: '#/components/schemas/queryParams/Bundle'
- $ref: '#/components/schemas/queryParams/Application'
- $ref: '#/components/schemas/queryParams/Name'
/helptopics/{name}:
Expand Down

0 comments on commit 4834a1d

Please sign in to comment.