[bugfix] Fix Swagger spec and add test script (#2698)

* Add Swagger spec test script

* Fix Swagger spec errors not related to statuses with polls

* Add API tests that post a status with a poll

* Fix creating a status with a poll from form params

* Fix Swagger spec errors related to statuses with polls (this is the last error)

* Fix Swagger spec warnings not related to unused definitions

* Suppress a duplicate list update params definition that was somehow causing wrong param names

* Add Swagger test to CI

- updates Drone config
- vendorizes go-swagger
- fixes a file extension issue that caused the test script to generate JSON instead of YAML with the vendorized version

* Put `Sample: ` on its own line everywhere

* Remove unused id param from emojiCategoriesGet

* Add 5 more pairs of profile fields to account update API Swagger

* Remove Swagger prefix from dummy fields

It makes the generated code look weird

* Manually annotate params for statusCreate operation

* Fix all remaining Swagger spec warnings

- Change some models into operation parameters
- Ignore models that already correspond to manually documented operation parameters but can't be trivially changed (those with file fields)

* Documented that creating a status with scheduled_at isn't implemented yet

* sign drone.yml

* Fix filter API Swagger errors

* fixup! Fix filter API Swagger errors

---------

Co-authored-by: tobi <tobi.smethurst@protonmail.com>
This commit is contained in:
Vyr Cossont
2024-03-06 09:05:45 -08:00
committed by GitHub
parent 68c8fe67cc
commit fc3741365c
672 changed files with 135624 additions and 713 deletions

View File

@@ -120,12 +120,67 @@ import (
// description: Enable RSS feed for this account's Public posts at `/[username]/feed.rss`
// type: boolean
// -
// name: fields_attributes
// name: fields_attributes[0][name]
// in: formData
// description: Profile fields to be added to this account's profile
// type: array
// items:
// type: object
// description: Name of 1st profile field to be added to this account's profile.
// (The index may be any string; add more indexes to send more fields.)
// type: string
// -
// name: fields_attributes[0][value]
// in: formData
// description: Value of 1st profile field to be added to this account's profile.
// (The index may be any string; add more indexes to send more fields.)
// type: string
// -
// name: fields_attributes[1][name]
// in: formData
// description: Name of 2nd profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[1][value]
// in: formData
// description: Value of 2nd profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[2][name]
// in: formData
// description: Name of 3rd profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[2][value]
// in: formData
// description: Value of 3rd profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[3][name]
// in: formData
// description: Name of 4th profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[3][value]
// in: formData
// description: Value of 4th profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[4][name]
// in: formData
// description: Name of 5th profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[4][value]
// in: formData
// description: Value of 5th profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[5][name]
// in: formData
// description: Name of 6th profile field to be added to this account's profile.
// type: string
// -
// name: fields_attributes[5][value]
// in: formData
// description: Value of 6th profile field to be added to this account's profile.
// type: string
//
// security:
// - OAuth2 Bearer:

View File

@@ -61,8 +61,9 @@ import (
// -
// name: domain
// in: formData
// description: Domain to expire keys for.
// example: example.org
// description: |-
// Domain to expire keys for.
// Sample: example.org
// type: string
//
// security:

View File

@@ -38,21 +38,13 @@ import (
// produces:
// - application/json
//
// parameters:
// -
// name: id
// type: string
// description: The id of the emoji.
// in: path
// required: true
//
// responses:
// '200':
// description: Array of existing emoji categories.
// schema:
// type: array
// items:
// "$ref": "#/definitions/adminEmojiCategory"
// "$ref": "#/definitions/emojiCategory"
// '400':
// description: bad request
// '401':

View File

@@ -67,10 +67,11 @@ import (
// name: category
// in: formData
// description: >-
// Category in which to place the new emoji. 64 characters or less.
// Category in which to place the new emoji.
// If left blank, emoji will be uncategorized. If a category with the
// given name doesn't exist yet, it will be created.
// type: string
// maximumLength: 64
// required: false
//
// security:

View File

@@ -73,6 +73,10 @@ import (
// For REMOTE emojis, `copy` or `disable` are supported.
// For LOCAL emojis, only `modify` is supported.
// type: string
// enum:
// - copy
// - disable
// - modify
// required: true
// -
// name: shortcode
@@ -94,9 +98,10 @@ import (
// name: category
// in: formData
// description: >-
// Category in which to place the emoji. 64 characters or less.
// Category in which to place the emoji.
// If a category with the given name doesn't exist yet, it will be created.
// type: string
// maximumLength: 64
//
// security:
// - OAuth2 Bearer:

View File

@@ -60,8 +60,9 @@ import (
// Useful for providing an explanation about what action was taken (if any)
// before the report was marked as resolved. This will be visible to the user
// that created the report!
//
// Sample: The reported account was suspended.
// type: string
// example: The reported account was suspended.
//
// security:
// - OAuth2 Bearer:

View File

@@ -43,15 +43,6 @@ import (
// produces:
// - application/json
//
// parameters:
// -
// name: text
// in: formData
// description: >-
// Text body for the instance rule, plaintext.
// type: string
// required: true
//
// security:
// - OAuth2 Bearer:
// - admin

View File

@@ -28,7 +28,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
// RuleDELETEHandler swagger:operation DELETE /api/v1/admin/instance/rules{id} ruleDelete
// RuleDELETEHandler swagger:operation DELETE /api/v1/admin/instance/rules/{id} ruleDelete
//
// Delete an existing instance rule.
//
@@ -45,10 +45,10 @@ import (
// parameters:
// -
// name: id
// in: formData
// in: path
// description: >-
// The id of the rule to delete.
// type: path
// type: string
// required: true
//
// security:

View File

@@ -27,7 +27,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
// rulesGETHandler swagger:operation GET /api/v1/admin/rules rules
// RulesGETHandler swagger:operation GET /api/v1/admin/rules adminsRuleGet
//
// View instance rules, with IDs.
//

View File

@@ -29,7 +29,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
// RulePATCHHandler swagger:operation PATCH /api/v1/admin/instance/rules{id} ruleUpdate
// RulePATCHHandler swagger:operation PATCH /api/v1/admin/instance/rules/{id} ruleUpdate
//
// Update an existing instance rule.
//
@@ -43,22 +43,6 @@ import (
// produces:
// - application/json
//
// parameters:
// -
// name: id
// in: formData
// description: >-
// The id of the rule to update.
// type: path
// required: true
// -
// name: text
// in: formData
// description: >-
// Text body for the updated instance rule, plaintext.
// type: string
// required: true
//
// security:
// - OAuth2 Bearer:
// - admin

View File

@@ -48,49 +48,58 @@ import (
// name: phrase
// in: formData
// required: true
// description: The text to be filtered.
// description: |-
// The text to be filtered.
//
// Sample: fnord
// maxLength: 40
// type: string
// example: "fnord"
// -
// name: context
// in: formData
// required: true
// description: The contexts in which the filter should be applied.
// description: |-
// The contexts in which the filter should be applied.
//
// Sample: home, public
// enum:
// - home
// - notifications
// - public
// - thread
// - account
// example:
// - home
// - public
// items:
// $ref: '#/definitions/filterContext'
// minLength: 1
// type: array
// items:
// type:
// string
// minItems: 1
// uniqueItems: true
// -
// name: expires_in
// in: formData
// description: Number of seconds from now that the filter should expire. If omitted, filter never expires.
// description: |-
// Number of seconds from now that the filter should expire. If omitted, filter never expires.
//
// Sample: 86400
// type: number
// example: 86400
// -
// name: irreversible
// in: formData
// description: Should matching entities be removed from the user's timelines/views, instead of hidden? Not supported yet.
// description: |-
// Should matching entities be removed from the user's timelines/views, instead of hidden? Not supported yet.
//
// Sample: false
// type: boolean
// default: false
// example: false
// -
// name: whole_word
// in: formData
// description: Should the filter consider word boundaries?
// description: |-
// Should the filter consider word boundaries?
//
// Sample: true
// type: boolean
// default: false
// example: true
//
// security:
// - OAuth2 Bearer:

View File

@@ -54,49 +54,58 @@ import (
// name: phrase
// in: formData
// required: true
// description: The text to be filtered.
// description: |-
// The text to be filtered.
//
// Sample: fnord
// maxLength: 40
// type: string
// example: "fnord"
// -
// name: context
// in: formData
// required: true
// description: The contexts in which the filter should be applied.
// description: |-
// The contexts in which the filter should be applied.
//
// Sample: home, public
// enum:
// - home
// - notifications
// - public
// - thread
// - account
// example:
// - home
// - public
// items:
// $ref: '#/definitions/filterContext'
// minLength: 1
// type: array
// items:
// type:
// string
// minItems: 1
// uniqueItems: true
// -
// name: expires_in
// in: formData
// description: Number of seconds from now that the filter should expire. If omitted, filter never expires.
// description: |-
// Number of seconds from now that the filter should expire. If omitted, filter never expires.
//
// Sample: 86400
// type: number
// example: 86400
// -
// name: irreversible
// in: formData
// description: Should matching entities be removed from the user's timelines/views, instead of hidden? Not supported yet.
// description: |-
// Should matching entities be removed from the user's timelines/views, instead of hidden? Not supported yet.
//
// Sample: false
// type: boolean
// default: false
// example: false
// -
// name: whole_word
// in: formData
// description: Should the filter consider word boundaries?
// description: |-
// Should the filter consider word boundaries?
//
// Sample: true
// type: boolean
// default: false
// example: true
//
// security:
// - OAuth2 Bearer:

View File

@@ -52,7 +52,7 @@ import (
// in: formData
// description: Title to use for the instance.
// type: string
// maximum: 40
// maxLength: 40
// allowEmptyValue: true
// -
// name: contact_username
@@ -73,21 +73,21 @@ import (
// in: formData
// description: Short description of the instance.
// type: string
// maximum: 500
// maxLength: 500
// allowEmptyValue: true
// -
// name: description
// in: formData
// description: Longer description of the instance.
// type: string
// maximum: 5000
// maxLength: 5000
// allowEmptyValue: true
// -
// name: terms
// in: formData
// description: Terms and conditions of the instance.
// type: string
// maximum: 5000
// maxLength: 5000
// allowEmptyValue: true
// -
// name: thumbnail
@@ -113,7 +113,7 @@ import (
// '200':
// description: "The newly updated instance."
// schema:
// "$ref": "#/definitions/instance"
// "$ref": "#/definitions/instanceV1"
// '400':
// description: bad request
// '401':

View File

@@ -57,9 +57,10 @@ import (
// -
// name: title
// type: string
// description: Title of this list.
// description: |-
// Title of this list.
// Sample: Cool People
// in: formData
// example: Cool People
// -
// name: replies_policy
// type: string
@@ -68,8 +69,12 @@ import (
// followed = Show replies to any followed user
// list = Show replies to members of the list
// none = Show replies to no one
// Sample: list
// enum:
// - followed
// - list
// - none
// in: formData
// example: list
//
// security:
// - OAuth2 Bearer:

View File

@@ -38,6 +38,14 @@ import (
// produces:
// - application/json
//
// parameters:
// -
// name: id
// type: string
// description: The ID of the notification.
// in: path
// required: true
//
// security:
// - OAuth2 Bearer:
// - read:notifications

View File

@@ -48,6 +48,145 @@ import (
// - application/xml
// - application/x-www-form-urlencoded
//
// parameters:
// -
// name: status
// x-go-name: Status
// description: |-
// Text content of the status.
// If media_ids is provided, this becomes optional.
// Attaching a poll is optional while status is provided.
// type: string
// in: formData
// -
// name: media_ids
// x-go-name: MediaIDs
// description: |-
// Array of Attachment ids to be attached as media.
// If provided, status becomes optional, and poll cannot be used.
//
// If the status is being submitted as a form, the key is 'media_ids[]',
// but if it's json or xml, the key is 'media_ids'.
// type: array
// items:
// type: string
// in: formData
// -
// name: poll[options][]
// x-go-name: PollOptions
// description: |-
// Array of possible poll answers.
// If provided, media_ids cannot be used, and poll[expires_in] must be provided.
// type: array
// items:
// type: string
// in: formData
// -
// name: poll[expires_in]
// x-go-name: PollExpiresIn
// description: |-
// Duration the poll should be open, in seconds.
// If provided, media_ids cannot be used, and poll[options] must be provided.
// type: integer
// format: int64
// in: formData
// -
// name: poll[multiple]
// x-go-name: PollMultiple
// description: Allow multiple choices on this poll.
// type: boolean
// default: false
// in: formData
// -
// name: poll[hide_totals]
// x-go-name: PollHideTotals
// description: Hide vote counts until the poll ends.
// type: boolean
// default: true
// in: formData
// -
// name: in_reply_to_id
// x-go-name: InReplyToID
// description: ID of the status being replied to, if status is a reply.
// type: string
// in: formData
// -
// name: sensitive
// x-go-name: Sensitive
// description: Status and attached media should be marked as sensitive.
// type: boolean
// in: formData
// -
// name: spoiler_text
// x-go-name: SpoilerText
// description: |-
// Text to be shown as a warning or subject before the actual content.
// Statuses are generally collapsed behind this field.
// type: string
// in: formData
// -
// name: visibility
// x-go-name: Visibility
// description: Visibility of the posted status.
// type: string
// enum:
// - public
// - unlisted
// - private
// - mutuals_only
// - direct
// in: formData
// -
// name: scheduled_at
// x-go-name: ScheduledAt
// description: |-
// ISO 8601 Datetime at which to schedule a status.
// Providing this parameter will cause ScheduledStatus to be returned instead of Status.
// Must be at least 5 minutes in the future.
//
// This feature isn't implemented yet.
// type: string
// in: formData
// -
// name: language
// x-go-name: Language
// description: ISO 639 language code for this status.
// type: string
// in: formData
// -
// name: content_type
// x-go-name: ContentType
// description: Content type to use when parsing this status.
// type: string
// enum:
// - text/plain
// - text/markdown
// in: formData
// -
// name: federated
// x-go-name: Federated
// description: This status will be federated beyond the local timeline(s).
// in: formData
// type: boolean
// -
// name: boostable
// x-go-name: Boostable
// description: This status can be boosted/reblogged.
// in: formData
// type: boolean
// -
// name: replyable
// x-go-name: Replyable
// description: This status can be replied to.
// in: formData
// type: boolean
// -
// name: likeable
// x-go-name: Likeable
// description: This status can be liked/faved.
// in: formData
// type: boolean
//
// produces:
// - application/json
//

View File

@@ -21,10 +21,12 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"github.com/stretchr/testify/suite"
@@ -427,6 +429,74 @@ func (suite *StatusCreateTestSuite) TestPostNewStatusWithNoncanonicalLanguageTag
suite.Equal("en-US", *statusReply.Language)
}
// Post a new status with an attached poll.
func (suite *StatusCreateTestSuite) testPostNewStatusWithPoll(configure func(request *http.Request)) {
t := suite.testTokens["local_account_1"]
oauthToken := oauth.DBTokenToToken(t)
// setup
recorder := httptest.NewRecorder()
ctx, _ := testrig.CreateGinTestContext(recorder, nil)
ctx.Set(oauth.SessionAuthorizedApplication, suite.testApplications["application_1"])
ctx.Set(oauth.SessionAuthorizedToken, oauthToken)
ctx.Set(oauth.SessionAuthorizedUser, suite.testUsers["local_account_1"])
ctx.Set(oauth.SessionAuthorizedAccount, suite.testAccounts["local_account_1"])
ctx.Request = httptest.NewRequest(http.MethodPost, fmt.Sprintf("http://localhost:8080/%s", statuses.BasePath), nil) // the endpoint we're hitting
ctx.Request.Header.Set("accept", "application/json")
configure(ctx.Request)
suite.statusModule.StatusCreatePOSTHandler(ctx)
suite.EqualValues(http.StatusOK, recorder.Code)
result := recorder.Result()
defer result.Body.Close()
b, err := ioutil.ReadAll(result.Body)
suite.NoError(err)
statusReply := &apimodel.Status{}
err = json.Unmarshal(b, statusReply)
suite.NoError(err)
suite.Equal("<p>this is a status with a poll!</p>", statusReply.Content)
suite.Equal(apimodel.VisibilityPublic, statusReply.Visibility)
if suite.NotNil(statusReply.Poll) {
if suite.Len(statusReply.Poll.Options, 2) {
suite.Equal("first option", statusReply.Poll.Options[0].Title)
suite.Equal("second option", statusReply.Poll.Options[1].Title)
}
suite.NotZero(statusReply.Poll.ExpiresAt)
suite.False(statusReply.Poll.Expired)
suite.True(statusReply.Poll.Multiple)
}
}
func (suite *StatusCreateTestSuite) TestPostNewStatusWithPollForm() {
suite.testPostNewStatusWithPoll(func(request *http.Request) {
request.Form = url.Values{
"status": {"this is a status with a poll!"},
"visibility": {"public"},
"poll[options][]": {"first option", "second option"},
"poll[expires_in]": {"3600"},
"poll[multiple]": {"true"},
}
})
}
func (suite *StatusCreateTestSuite) TestPostNewStatusWithPollJSON() {
suite.testPostNewStatusWithPoll(func(request *http.Request) {
request.Header.Set("content-type", "application/json")
request.Body = io.NopCloser(strings.NewReader(`{
"status": "this is a status with a poll!",
"visibility": "public",
"poll": {
"options": ["first option", "second option"],
"expires_in": 3600,
"multiple": true
}
}`))
})
}
func TestStatusCreateTestSuite(t *testing.T) {
suite.Run(t, new(StatusCreateTestSuite))
}

View File

@@ -26,7 +26,7 @@ import (
"github.com/superseriousbusiness/gotosocial/internal/oauth"
)
// HomeTimelineGETHandler swagger:operation GET /api/v1/timelines/tag/{tag_name} tagTimeline
// TagTimelineGETHandler swagger:operation GET /api/v1/timelines/tag/{tag_name} tagTimeline
//
// See public statuses that use the given hashtag (case insensitive).
//
@@ -49,6 +49,12 @@ import (
//
// parameters:
// -
// name: tag_name
// type: string
// description: Name of the tag
// in: path
// required: true
// -
// name: max_id
// type: string
// description: >-