migueleliasweb / go-github-mock

A library to aid unittesting code that uses Golang's Github SDK
MIT License
98 stars 24 forks source link

Dynamically create routes without optional parameters #19

Closed migueleliasweb closed 2 years ago

migueleliasweb commented 2 years ago

Some endpoints have parameters that are optional, we should be able to dynamically create endpoints without them to cater to some other code flows.

E.g.

"/repos/{owner}/{repo}/zipball/{ref}": {
      "get": {
        "summary": "Download a repository archive (zip)",
        "description": "Gets a redirect URL to download a zip archive for a repository. If you omit `:ref`, the repository’s default branch (usually\n`master`) will be used. Please make sure your HTTP framework is configured to follow redirects or you will need to use\nthe `Location` header to make a second `GET` request.\n**Note**: For private repositories, these links are temporary and expire after five minutes.",
        "tags": [
          "repos"
        ],
        "externalDocs": {
          "description": "API method documentation",
          "url": "https://docs.github.com/rest/reference/repos#download-a-repository-archive"
        },
        "operationId": "repos/download-zipball-archive",
        "parameters": [
          {
            "$ref": "#/components/parameters/owner"
          },
          {
            "$ref": "#/components/parameters/repo"
          },
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "302": {
            "description": "Response",
            "headers": {
              "Location": {
                "example": "https://codeload.github.com/me/myprivate/legacy.zip/master?login=me&token=thistokenexpires",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        },
        "x-github": {
          "githubCloudOnly": false,
          "enabledForGitHubApps": true,
          "category": "repos",
          "subcategory": "contents"
        }
      }
    },

The above example shows that only owner and repo are required arguments.

migueleliasweb commented 2 years ago

Related to: https://github.com/migueleliasweb/go-github-mock/issues/18

migueleliasweb commented 2 years ago

Possibly use https://github.com/go-swagger/go-swagger/blob/master/docs/usage/expand.md as a pre-processing step to simplify the iteration over the json.

It should be possible to embed the Expand call to the gen.go script with https://github.com/go-swagger/go-swagger/blob/master/cmd/swagger/commands/expand.go .