gospecpaths

command module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Go Spec Paths

CI Go Report Card version

Go Spec Paths retrieves the paths of an OpenAPI spec file and generates a struct with the paths defined in the spec.

[!WARNING]

This library is under development. The API may change.

🚀 Features

Go Spec Paths creates a struct with the paths defined in the openapi spec file.

e.g.

paths:
  /pet/findByStatus:
    get:
      operationId: findPetsByStatus
      ...
  /pet/{petId}:
    get:
      operationId: getPetById
      ...

It will generate:

package gospecpaths

import "strings"

type FindPetsByTagsEndpoint struct {}

type FindPetsByTagsEndpointQueryParams struct {
  Tags []string
}

func (p FindPetsByTagsParam) Path(queryParams FindPetsByTagsEndpointQueryParams) string {
  message := "/pet/findByTags"
  if queryString := queryParams.ToQueryString(); queryString != "" {
    message = message + "?" + queryString
  }
  return message
}

type GetPetByIdParam struct{}

func (p GetPetByIdParam) Path(petId string) string {
 message := "/pet/{petId}"
 message = strings.Replace(message, "{petId}", petId, -1)
 return message
}

...

type Paths struct {
 GetPetByIdParam       GetPetByIdParam
 FindPetsByTagsParam   FindPetsByTagsParam
 ...
}

So then it can be used as:

p := Paths{}.GetPetByIdParam.Path("1")
fmt.Printf("%s\n", p)
// /pet/1

This is useful for building a router or to create HATEOAS links.

⬇️ Getting started

As cli
gospecpaths [--package {package}] [--output {output}] [FILE]

Parameters:

  • FILE: Path to the OpenAPI spec file.
  • package: (Required) Package name for the generated file.
  • output: Path and name to the save the generated code (e.g. 'gospecpaths.gen.go'). If not present, it will output to stdout.
As Go tool

Go tool support is available from Go 1.24+ for managing the dependency of gospecpaths alongside your core application.

To do this, you run go get -tool:

$ go get -tool github.com/manuelarte/gospecpaths@latest
# this will then modify your `go.mod`

From there, each invocation of gospecpaths would be used like so:

//go:generate go tool gospecpaths --package api --output api/paths.gen.go ../../api.yaml

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL