discovery

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Contact

type Contact struct {
	Name  string `json:"name,omitempty"  yaml:"name,omitempty"`
	URL   string `json:"url,omitempty"   yaml:"url,omitempty"`
	Email string `json:"email,omitempty" yaml:"email,omitempty"`
}

type Info

type Info struct {
	Title          string   `json:"title"                    yaml:"title"`
	Version        string   `json:"version"                  yaml:"version"`
	Description    string   `json:"description,omitempty"    yaml:"description,omitempty"`
	TermsOfService string   `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty"`
	Contact        *Contact `json:"contact,omitempty"        yaml:"contact,omitempty"`
	License        *License `json:"license,omitempty"        yaml:"license,omitempty"`
}

type License

type License struct {
	Name string `json:"name"          yaml:"name"`
	URL  string `json:"url,omitempty" yaml:"url,omitempty"`
}

type OpenAPI3Doc

type OpenAPI3Doc struct {
	OpenAPI      string          `json:"openapi"                     yaml:"openapi"` // e.g., "3.0.3" / "3.1.0"
	Info         Info            `json:"info"                        yaml:"info"`
	Servers      json.RawMessage `json:"servers,omitempty"           yaml:"servers,omitempty"`
	Paths        json.RawMessage `json:"paths,omitempty"             yaml:"paths,omitempty"`
	Components   json.RawMessage `json:"components,omitempty"        yaml:"components,omitempty"`
	Security     json.RawMessage `json:"security,omitempty"          yaml:"security,omitempty"`
	Tags         json.RawMessage `json:"tags,omitempty"              yaml:"tags,omitempty"`
	ExternalDocs json.RawMessage `json:"externalDocs,omitempty"      yaml:"externalDocs,omitempty"`
	// OAS 3.1 additions:
	JSONSchemaDialect string          `json:"jsonSchemaDialect,omitempty" yaml:"jsonSchemaDialect,omitempty"`
	Webhooks          json.RawMessage `json:"webhooks,omitempty"          yaml:"webhooks,omitempty"`
}

OpenAPI3Doc captures top-level OpenAPI 3.x/3.1 fields.

type Swagger2Doc

type Swagger2Doc struct {
	Swagger             string          `json:"swagger"                       yaml:"swagger"` // e.g., "2.0"
	Info                Info            `json:"info"                          yaml:"info"`
	Host                string          `json:"host,omitempty"                yaml:"host,omitempty"`
	BasePath            string          `json:"basePath,omitempty"            yaml:"basePath,omitempty"`
	Schemes             []string        `json:"schemes,omitempty"             yaml:"schemes,omitempty"`
	Consumes            []string        `json:"consumes,omitempty"            yaml:"consumes,omitempty"`
	Produces            []string        `json:"produces,omitempty"            yaml:"produces,omitempty"`
	Paths               json.RawMessage `json:"paths,omitempty"               yaml:"paths,omitempty"`
	Definitions         json.RawMessage `json:"definitions,omitempty"         yaml:"definitions,omitempty"`
	Parameters          json.RawMessage `json:"parameters,omitempty"          yaml:"parameters,omitempty"`
	Responses           json.RawMessage `json:"responses,omitempty"           yaml:"responses,omitempty"`
	SecurityDefinitions json.RawMessage `json:"securityDefinitions,omitempty" yaml:"securityDefinitions,omitempty"`
	Security            json.RawMessage `json:"security,omitempty"            yaml:"security,omitempty"`
	Tags                json.RawMessage `json:"tags,omitempty"                yaml:"tags,omitempty"`
	ExternalDocs        json.RawMessage `json:"externalDocs,omitempty"        yaml:"externalDocs,omitempty"`
}

Swagger2Doc captures top-level Swagger 2.0 fields. Large/variable subtrees stay as json.RawMessage to remain schema-agnostic here.

type SwaggerSpec

type SwaggerSpec struct {
	// --- Version-specific top-level fields (one of these will be set) ---
	*Swagger2Doc `json:",omitempty" yaml:",omitempty,inline"`
	*OpenAPI3Doc `json:",omitempty" yaml:",omitempty,inline"`

	// --- Metadata (yours; keep/extend as needed) ---
	Name        string `json:"name"        yaml:"name"`
	Title       string `json:"title"       yaml:"title"`
	Version     string `json:"version"     yaml:"version"`
	Description string `json:"description" yaml:"description"`
	Path        string `json:"path"        yaml:"path"`
	Service     string `json:"service"     yaml:"service"`
	Format      string `json:"format"      yaml:"format"` // "yaml" or "json"
	FileName    string `json:"fileName"    yaml:"fileName"`

	// --- Version markers (redundant but handy for quick checks) ---
	OpenAPIVersion string `json:"openapiVersion,omitempty" yaml:"openapiVersion,omitempty"` // e.g., "3.1.0"
	SwaggerVersion string `json:"swaggerVersion,omitempty" yaml:"swaggerVersion,omitempty"` // e.g., "2.0"

	// --- Canonical, full documents (for complete fidelity & downstream logic) ---
	DocV3 *oas3.T       `json:"-" yaml:"-"` // full OpenAPI 3.x/3.1 document
	DocV2 *oas2.Swagger `json:"-" yaml:"-"` // full Swagger 2.0 document

	// (Optional) Keep raw bytes if you need to re-serve the original file as-is.
	Raw []byte `json:"-" yaml:"-"`
}

SwaggerSpec is a complete, version-agnostic container for API specs. Exactly one of V2 or V3 should be non-nil. Both are embedded so the present one inlines on marshal. The canonical documents (DocV2/DocV3) preserve the full, typed content.

func DiscoverSwaggerSpecs

func DiscoverSwaggerSpecs(projectRoot string) ([]SwaggerSpec, error)

DiscoverSwaggerSpecs scans within the given project root recursively and returns a list of SwaggerSpec objects for all discovered OpenAPI/Swagger files. It looks for files with .yaml, .yml, or .json extensions anywhere under the root path.

The function attempts to parse each YAML/JSON file as an OpenAPI/Swagger spec. Files that cannot be parsed or are not valid OpenAPI specs are skipped with a warning.

Example path structures supported:

  • connector/{service}/spec/{swagger_file}.yaml
  • apis/{service}/{swagger_file}.json
  • docs/openapi.yaml
  • any/nested/path/to/spec.yml

Parameters:

  • projectRoot: the root directory of the project.

Returns:

  • A sorted slice of SwaggerSpec objects by service name.
  • An error if the directory walk fails.

Jump to

Keyboard shortcuts

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