Browse Source

Add spectral linter for Swagger (#20321)

[spectral](https://github.com/stoplightio/spectral) lints
openapi/swagger files for mistakes of which it has identified a few and
which I've fixed.

I had to put it into `lint-frontend` because it depends on node_modules
so can not run on Drone during the backend target. I plan to refactor
these targets later to `lint-js` and `lint-go` so that they are
categorized based on the tool dependencies.
tags/v1.18.0-rc0
silverwind 1 year ago
parent
commit
c8e0fd0bcc
No account linked to committer's email address
7 changed files with 10347 additions and 7544 deletions
  1. 12
    0
      .spectral.yaml
  2. 1
    0
      Makefile
  3. 10331
    7443
      package-lock.json
  4. 1
    0
      package.json
  5. 1
    1
      routers/api/v1/org/hook.go
  6. 0
    3
      routers/api/v1/swagger/options.go
  7. 1
    97
      templates/swagger/v1_json.tmpl

+ 12
- 0
.spectral.yaml View File

extends: [[spectral:oas, all]]

rules:
info-contact: off
oas2-api-host: off
oas2-parameter-description: off
oas2-schema: off
oas2-valid-schema-example: off
openapi-tags: off
operation-description: off
operation-singular-tag: off
operation-tag-defined: off

+ 1
- 0
Makefile View File

lint-frontend: node_modules lint-frontend: node_modules
npx eslint --color --max-warnings=0 web_src/js build templates *.config.js docs/assets/js npx eslint --color --max-warnings=0 web_src/js build templates *.config.js docs/assets/js
npx stylelint --color --max-warnings=0 web_src/less npx stylelint --color --max-warnings=0 web_src/less
npx spectral lint -q -F hint $(SWAGGER_SPEC)


.PHONY: lint-backend .PHONY: lint-backend
lint-backend: golangci-lint vet editorconfig-checker lint-backend: golangci-lint vet editorconfig-checker

+ 10331
- 7443
package-lock.json
File diff suppressed because it is too large
View File


+ 1
- 0
package.json View File

}, },
"devDependencies": { "devDependencies": {
"@happy-dom/jest-environment": "4.0.1", "@happy-dom/jest-environment": "4.0.1",
"@stoplight/spectral-cli": "6.4.1",
"eslint": "8.15.0", "eslint": "8.15.0",
"eslint-plugin-html": "6.2.0", "eslint-plugin-html": "6.2.0",
"eslint-plugin-import": "2.26.0", "eslint-plugin-import": "2.26.0",

+ 1
- 1
routers/api/v1/org/hook.go View File



// CreateHook create a hook for an organization // CreateHook create a hook for an organization
func CreateHook(ctx *context.APIContext) { func CreateHook(ctx *context.APIContext) {
// swagger:operation POST /orgs/{org}/hooks/ organization orgCreateHook
// swagger:operation POST /orgs/{org}/hooks organization orgCreateHook
// --- // ---
// summary: Create a hook // summary: Create a hook
// consumes: // consumes:

+ 0
- 3
routers/api/v1/swagger/options.go View File

// in:body // in:body
EditUserOption api.EditUserOption EditUserOption api.EditUserOption


// in:body
MigrateRepoForm forms.MigrateRepoForm

// in:body // in:body
EditAttachmentOptions api.EditAttachmentOptions EditAttachmentOptions api.EditAttachmentOptions



+ 1
- 97
templates/swagger/v1_json.tmpl View File

"$ref": "#/responses/HookList" "$ref": "#/responses/HookList"
} }
} }
}
},
"/orgs/{org}/hooks/": {
},
"post": { "post": {
"consumes": [ "consumes": [
"application/json" "application/json"
}, },
"x-go-package": "code.gitea.io/gitea/modules/structs" "x-go-package": "code.gitea.io/gitea/modules/structs"
}, },
"GitServiceType": {
"description": "GitServiceType represents a git service",
"type": "integer",
"format": "int64",
"x-go-package": "code.gitea.io/gitea/modules/structs"
},
"GitTreeResponse": { "GitTreeResponse": {
"description": "GitTreeResponse returns a git tree", "description": "GitTreeResponse returns a git tree",
"type": "object", "type": "object",
"x-go-name": "MergePullRequestForm", "x-go-name": "MergePullRequestForm",
"x-go-package": "code.gitea.io/gitea/services/forms" "x-go-package": "code.gitea.io/gitea/services/forms"
}, },
"MigrateRepoForm": {
"description": "MigrateRepoForm form for migrating repository\nthis is used to interact with web ui",
"type": "object",
"required": [
"clone_addr",
"uid",
"repo_name"
],
"properties": {
"auth_password": {
"type": "string",
"x-go-name": "AuthPassword"
},
"auth_token": {
"type": "string",
"x-go-name": "AuthToken"
},
"auth_username": {
"type": "string",
"x-go-name": "AuthUsername"
},
"clone_addr": {
"type": "string",
"x-go-name": "CloneAddr"
},
"description": {
"type": "string",
"x-go-name": "Description"
},
"issues": {
"type": "boolean",
"x-go-name": "Issues"
},
"labels": {
"type": "boolean",
"x-go-name": "Labels"
},
"lfs": {
"type": "boolean",
"x-go-name": "LFS"
},
"lfs_endpoint": {
"type": "string",
"x-go-name": "LFSEndpoint"
},
"milestones": {
"type": "boolean",
"x-go-name": "Milestones"
},
"mirror": {
"type": "boolean",
"x-go-name": "Mirror"
},
"mirror_interval": {
"type": "string",
"x-go-name": "MirrorInterval"
},
"private": {
"type": "boolean",
"x-go-name": "Private"
},
"pull_requests": {
"type": "boolean",
"x-go-name": "PullRequests"
},
"releases": {
"type": "boolean",
"x-go-name": "Releases"
},
"repo_name": {
"type": "string",
"x-go-name": "RepoName"
},
"service": {
"$ref": "#/definitions/GitServiceType"
},
"uid": {
"type": "integer",
"format": "int64",
"x-go-name": "UID"
},
"wiki": {
"type": "boolean",
"x-go-name": "Wiki"
}
},
"x-go-package": "code.gitea.io/gitea/services/forms"
},
"MigrateRepoOptions": { "MigrateRepoOptions": {
"description": "MigrateRepoOptions options for migrating repository's\nthis is used to interact with api v1", "description": "MigrateRepoOptions options for migrating repository's\nthis is used to interact with api v1",
"type": "object", "type": "object",

Loading…
Cancel
Save