Skip to content

Commit

Permalink
Merge pull request #221 from opentofu/api-root-path
Browse files Browse the repository at this point in the history
  • Loading branch information
Yantrio authored Sep 11, 2024
2 parents 0db806b + 56cd189 commit 4adefb4
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 36 deletions.
12 changes: 6 additions & 6 deletions backend/internal/moduleindex/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package moduleindex

// GetModuleList returns a module list from storage.
//
// swagger:operation GET /modules/index.json Modules GetModuleList
// swagger:operation GET /registry/docs/modules/index.json Modules GetModuleList
// ---
// produces:
// - application/json
Expand All @@ -14,7 +14,7 @@ package moduleindex

// GetModule returns a list of all versions of a module.
//
// swagger:operation GET /modules/{namespace}/{name}/{target}/index.json Modules GetModule
// swagger:operation GET /registry/docs/modules/{namespace}/{name}/{target}/index.json Modules GetModule
// ---
// produces:
// - application/json
Expand Down Expand Up @@ -42,7 +42,7 @@ package moduleindex

// GetModuleVersion returns the details of one specific module version.
//
// swagger:operation GET /modules/{namespace}/{name}/{target}/{version}/index.json Modules GetModuleVersion
// swagger:operation GET /registry/docs/modules/{namespace}/{name}/{target}/{version}/index.json Modules GetModuleVersion
// ---
// produces:
// - application/json
Expand Down Expand Up @@ -75,7 +75,7 @@ package moduleindex

// GetModuleReadme returns the readme of a module.
//
// swagger:operation GET /modules/{namespace}/{name}/{target}/{version}/README.md Modules GetModuleReadme
// swagger:operation GET /registry/docs/modules/{namespace}/{name}/{target}/{version}/README.md Modules GetModuleReadme
// ---
// parameters:
// - name: namespace
Expand Down Expand Up @@ -108,7 +108,7 @@ package moduleindex

// GetSubmoduleReadme returns the readme of a submodule.
//
// swagger:operation GET /modules/{namespace}/{name}/{target}/{version}/modules/{submodule}/README.md Modules GetSubmoduleReadme
// swagger:operation GET /registry/docs/modules/{namespace}/{name}/{target}/{version}/modules/{submodule}/README.md Modules GetSubmoduleReadme
// ---
// parameters:
// - name: namespace
Expand Down Expand Up @@ -146,7 +146,7 @@ package moduleindex

// GetModuleExampleReadme returns the readme of a module example.
//
// swagger:operation GET /modules/{namespace}/{name}/{target}/{version}/examples/{example}/README.md Modules GetModuleExampleReadme
// swagger:operation GET /registry/docs/modules/{namespace}/{name}/{target}/{version}/examples/{example}/README.md Modules GetModuleExampleReadme
// ---
// parameters:
// - name: namespace
Expand Down
14 changes: 7 additions & 7 deletions backend/internal/providerindex/providerindexstorage/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type API interface {
// GetProviderList returns a provider list from storage. If there is no provider list, it will return a ready-to-use
// empty provider list alongside a *ProviderListNotFoundError.
//
// swagger:operation GET /providers/index.json Providers GetProviderList
// swagger:operation GET /registry/docs/providers/index.json Providers GetProviderList
// ---
// produces:
// - application/json
Expand All @@ -27,7 +27,7 @@ type API interface {

// GetProvider returns a list of all versions of a provider.
//
// swagger:operation GET /providers/{namespace}/{name}/index.json Providers GetProvider
// swagger:operation GET /registry/docs/providers/{namespace}/{name}/index.json Providers GetProvider
// ---
// produces:
// - application/json
Expand All @@ -53,7 +53,7 @@ type API interface {

// GetProviderVersion returns the details of one specific provider version.
//
// swagger:operation GET /providers/{namespace}/{name}/{version}/index.json Providers GetProviderVersion
// swagger:operation GET /registry/docs/providers/{namespace}/{name}/{version}/index.json Providers GetProviderVersion
// ---
// produces:
// - application/json
Expand Down Expand Up @@ -84,7 +84,7 @@ type API interface {

// GetProviderDoc returns a root provider document if it exists.
//
// swagger:operation GET /providers/{namespace}/{name}/{version}/index.md Providers GetProviderDoc
// swagger:operation GET /registry/docs/providers/{namespace}/{name}/{version}/index.md Providers GetProviderDoc
// ---
// parameters:
// - name: namespace
Expand Down Expand Up @@ -114,7 +114,7 @@ type API interface {

// GetProviderDocItem returns a provider document.
//
// swagger:operation GET /providers/{namespace}/{name}/{version}/{kind}s/{document}.md Providers GetProviderDocItem
// swagger:operation GET /registry/docs/providers/{namespace}/{name}/{version}/{kind}s/{document}.md Providers GetProviderDocItem
// ---
// parameters:
// - name: namespace
Expand Down Expand Up @@ -155,7 +155,7 @@ type API interface {

// GetProviderCDKTFDoc returns a CDKTF root document.
//
// swagger:operation GET /providers/{namespace}/{name}/{version}/cdktf/{language}/index.md Providers GetProviderCDKTFDoc
// swagger:operation GET /registry/docs/providers/{namespace}/{name}/{version}/cdktf/{language}/index.md Providers GetProviderCDKTFDoc
// ---
// parameters:
// - name: namespace
Expand Down Expand Up @@ -191,7 +191,7 @@ type API interface {

// GetProviderCDKTFDocItem returns a CDKTF document item.
//
// swagger:operation GET /providers/{namespace}/{name}/{version}/cdktf/{language}/{kind}s/{document}.md Providers GetProviderCDKTFDocItem
// swagger:operation GET /registry/docs/providers/{namespace}/{name}/{version}/cdktf/{language}/{kind}s/{document}.md Providers GetProviderCDKTFDocItem
// ---
// parameters:
// - name: namespace
Expand Down
4 changes: 2 additions & 2 deletions backend/internal/search/searchstorage/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package searchstorage
// GetSearchIndex returns a newline-delimited search index suitable for insertion into a database. The records are not
// guaranteed to be in order.
//
// swagger:operation GET /search.ndjson Search GetSearchIndex
// swagger:operation GET /registry/docs/search.ndjson Search GetSearchIndex
// ---
// produces:
// - application/x-ndjson
Expand Down Expand Up @@ -53,7 +53,7 @@ type SearchResultItem struct {

// Search returns a list of search results matching the query.
//
// swagger:operation GET /search Search Search
// swagger:operation GET /registry/docs/search Search Search
// ---
// produces:
// - application/json
Expand Down
2 changes: 1 addition & 1 deletion backend/internal/server/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// The API to fetch documentation index and documentation files from the OpenTofu registry.
//
// Version: 1.0.0-alpha1
// Version: 1.0.0-beta
// License: MPL-2.0
// Host: api.opentofu.org
// Schemes: https
Expand Down
36 changes: 18 additions & 18 deletions backend/internal/server/openapi.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
definitions:
Addr:
description: |-
Addr describes a module address combination of NAMESPACE-NAME-TARGETSYSTEM. This will translate to
github.com/NAMESPACE/terraform-TARGETSYSTEM-NAME for now.
Addr represents a full provider address (NAMESPACE/NAME). It currently translates to
github.com/NAMESPACE/terraform-provider-NAME .
type: object
BaseDetails:
properties:
Expand Down Expand Up @@ -794,9 +794,9 @@ info:
license:
name: MPL-2.0
title: OpenTofu Registry Docs API
version: 1.0.0-alpha1
version: 1.0.0-beta
paths:
/modules/{namespace}/{name}/{target}/{version}/README.md:
/registry/docs/modules/{namespace}/{name}/{target}/{version}/README.md:
get:
operationId: GetModuleReadme
parameters:
Expand Down Expand Up @@ -829,7 +829,7 @@ paths:
type: file
tags:
- Modules
/modules/{namespace}/{name}/{target}/{version}/examples/{example}/README.md:
/registry/docs/modules/{namespace}/{name}/{target}/{version}/examples/{example}/README.md:
get:
operationId: GetModuleExampleReadme
parameters:
Expand Down Expand Up @@ -867,7 +867,7 @@ paths:
type: file
tags:
- Modules
/modules/{namespace}/{name}/{target}/{version}/index.json:
/registry/docs/modules/{namespace}/{name}/{target}/{version}/index.json:
get:
operationId: GetModuleVersion
parameters:
Expand Down Expand Up @@ -900,7 +900,7 @@ paths:
$ref: '#/definitions/ModuleVersion'
tags:
- Modules
/modules/{namespace}/{name}/{target}/{version}/modules/{submodule}/README.md:
/registry/docs/modules/{namespace}/{name}/{target}/{version}/modules/{submodule}/README.md:
get:
operationId: GetSubmoduleReadme
parameters:
Expand Down Expand Up @@ -938,7 +938,7 @@ paths:
type: file
tags:
- Modules
/modules/{namespace}/{name}/{target}/index.json:
/registry/docs/modules/{namespace}/{name}/{target}/index.json:
get:
operationId: GetModule
parameters:
Expand Down Expand Up @@ -966,7 +966,7 @@ paths:
$ref: '#/definitions/Module'
tags:
- Modules
/modules/index.json:
/registry/docs/modules/index.json:
get:
operationId: GetModuleList
produces:
Expand All @@ -978,7 +978,7 @@ paths:
$ref: '#/definitions/ModuleList'
tags:
- Modules
/providers/{namespace}/{name}/{version}/{kind}s/{document}.md:
/registry/docs/providers/{namespace}/{name}/{version}/{kind}s/{document}.md:
get:
operationId: GetProviderDocItem
parameters:
Expand Down Expand Up @@ -1021,7 +1021,7 @@ paths:
type: file
tags:
- Providers
/providers/{namespace}/{name}/{version}/cdktf/{language}/{kind}s/{document}.md:
/registry/docs/providers/{namespace}/{name}/{version}/cdktf/{language}/{kind}s/{document}.md:
get:
operationId: GetProviderCDKTFDocItem
parameters:
Expand Down Expand Up @@ -1075,7 +1075,7 @@ paths:
type: file
tags:
- Providers
/providers/{namespace}/{name}/{version}/cdktf/{language}/index.md:
/registry/docs/providers/{namespace}/{name}/{version}/cdktf/{language}/index.md:
get:
operationId: GetProviderCDKTFDoc
parameters:
Expand Down Expand Up @@ -1114,7 +1114,7 @@ paths:
type: file
tags:
- Providers
/providers/{namespace}/{name}/{version}/index.json:
/registry/docs/providers/{namespace}/{name}/{version}/index.json:
get:
operationId: GetProviderVersion
parameters:
Expand Down Expand Up @@ -1142,7 +1142,7 @@ paths:
$ref: '#/definitions/ProviderVersion'
tags:
- Providers
/providers/{namespace}/{name}/{version}/index.md:
/registry/docs/providers/{namespace}/{name}/{version}/index.md:
get:
operationId: GetProviderDoc
parameters:
Expand Down Expand Up @@ -1170,7 +1170,7 @@ paths:
type: file
tags:
- Providers
/providers/{namespace}/{name}/index.json:
/registry/docs/providers/{namespace}/{name}/index.json:
get:
operationId: GetProvider
parameters:
Expand All @@ -1193,7 +1193,7 @@ paths:
$ref: '#/definitions/Provider'
tags:
- Providers
/providers/index.json:
/registry/docs/providers/index.json:
get:
operationId: GetProviderList
produces:
Expand All @@ -1205,7 +1205,7 @@ paths:
$ref: '#/definitions/ProviderList'
tags:
- Providers
/search:
/registry/docs/search:
get:
operationId: Search
parameters:
Expand All @@ -1227,7 +1227,7 @@ paths:
description: Invalid search query.
tags:
- Search
/search.ndjson:
/registry/docs/search.ndjson:
get:
operationId: GetSearchIndex
produces:
Expand Down
4 changes: 2 additions & 2 deletions search/pg-indexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func completeJob(db *sql.DB, id int) error {

func downloadSearchMetaIndex() (io.ReadCloser, error) {
// Get the data
resp, err := http.Get("https://api.opentofu.org/search.ndjson")
resp, err := http.Get("https://api.opentofu.org/registry/docs/search.ndjson")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -303,7 +303,7 @@ func insertItems(tx *sql.Tx, items []SearchIndexItem) error {
query := fmt.Sprintf(`
INSERT INTO entities (id, type, addr, version, title, description, link_variables, last_updated)
VALUES %s
ON CONFLICT (id) DO UPDATE
ON CONFLICT (id) DO UPDATE
SET type = EXCLUDED.type,
addr = EXCLUDED.addr,
version = EXCLUDED.version,
Expand Down
6 changes: 6 additions & 0 deletions search/worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,19 @@ export default {
}

switch (url.pathname) {
case '/registry/docs/search':
case '/search':
response = await handleSearchRequest(request, env, ctx);
break;
case '/':
response = await serveR2Object(request, env, 'index.html');
break;
default:
if (url.pathname.startsWith('/registry/docs/')) {
const objectKey = url.pathname.replace('/registry/docs/', '');
response = await serveR2Object(request, env, objectKey);
break;
}
const objectKey = url.pathname.slice(1);
response = await serveR2Object(request, env, objectKey);
break;
Expand Down

0 comments on commit 4adefb4

Please sign in to comment.