Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Emojis for the following are chosen based on [gitmoji](https://gitmoji.dev/).
- The `updated_at` date for language data is now the most recent last modified date of the data, matching `/data-version`, rather than the date of the request.
- Data contracts exported from Scribe-Data are now copied to the server and deployed to Toolforge with the data so that `/contracts` returns them, and a clear error is returned if they're not available ([#113](https://github.com/scribe-org/Scribe-Server/issues/113)).
- `/contracts?lang={lang}` returns only that language's contract exactly as exported by Scribe-Data as JSON (e.g. `en.json`), keeping the order of the contract's keys.
- `/contracts` returns a `data_contracts.zip` archive with a `data_contracts` directory of JSON contracts for all languages.
- `/contracts` returns a `scribe_data_contracts.zip` archive with a `scribe_data_contracts` directory of JSON contracts for all languages.
- The `update_data.sh` download command was fixed to specify the correct dump snapshot location ([#65](https://github.com/scribe-org/Scribe-Server/pull/65)).
- Trusted proxies are now explicitly configured for security.
- `/packs` requests with `..` in the path are rejected so they can't show whether directories outside of the packs directory exist, `/packs/sqlite/list` returns `[]` instead of `null` when there are no SQLite files, and SQLite download file names are quoted ([#91](https://github.com/scribe-org/Scribe-Server/issues/91)).
Expand Down
4 changes: 2 additions & 2 deletions api/handlers/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

// contractsArchiveDir is the directory in the zip archive of all contracts.
const contractsArchiveDir = "data_contracts"
const contractsArchiveDir = "scribe_data_contracts"

// contractExtensions are the file extensions of contracts in order of preference.
var contractExtensions = []string{".yaml", ".yml"}
Expand Down Expand Up @@ -218,7 +218,7 @@ func loadAllContracts(contractsDir string) ([]contractFile, error) {

// MARK: Contracts Archive

// writeContractsZip writes a zip archive with a data_contracts directory of JSON contracts.
// writeContractsZip writes a zip archive with a scribe_data_contracts directory of JSON contracts.
// It's a package-level variable to allow mocking in unit tests.
var writeContractsZip = func(w io.Writer, contracts []contractFile) error {
archive := zip.NewWriter(w)
Expand Down
8 changes: 4 additions & 4 deletions api/handlers/contracts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ type failingWriter struct{}
func (failingWriter) Write(_ []byte) (int, error) { return 0, errors.New("write failed") }

func TestWriteContractsZip(t *testing.T) {
t.Run("writes a data_contracts directory of JSON contracts", func(t *testing.T) {
t.Run("writes a scribe_data_contracts directory of JSON contracts", func(t *testing.T) {
modified := time.Date(2026, 10, 1, 12, 0, 0, 0, time.UTC)
contracts := []contractFile{
{lang: "de", json: []byte(`{"prepositions": {}}`), modified: modified},
Expand All @@ -313,7 +313,7 @@ func TestWriteContractsZip(t *testing.T) {
require.Len(t, reader.File, 2)

for i, file := range reader.File {
assert.Equal(t, "data_contracts/"+contracts[i].lang+".json", file.Name)
assert.Equal(t, "scribe_data_contracts/"+contracts[i].lang+".json", file.Name)
assert.True(t, file.Modified.Equal(modified))

content, err := file.Open()
Expand Down Expand Up @@ -368,7 +368,7 @@ func TestGetContracts(t *testing.T) {

require.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "application/zip", rec.Header().Get("Content-Type"))
assert.Equal(t, `attachment; filename="data_contracts.zip"`, rec.Header().Get("Content-Disposition"))
assert.Equal(t, `attachment; filename="scribe_data_contracts.zip"`, rec.Header().Get("Content-Disposition"))

reader, err := zip.NewReader(bytes.NewReader(rec.Body.Bytes()), int64(rec.Body.Len()))
require.NoError(t, err)
Expand All @@ -386,7 +386,7 @@ func TestGetContracts(t *testing.T) {
lang := strings.TrimSuffix(filepath.Base(file.Name), ".json")
assert.Equal(t, getContracts(router, "?lang="+lang).Body.Bytes(), data)
}
assert.Equal(t, []string{"data_contracts/de.json", "data_contracts/en.json"}, names)
assert.Equal(t, []string{"scribe_data_contracts/de.json", "scribe_data_contracts/en.json"}, names)
})

t.Run("400 for an invalid language code", func(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions api/handlers/language.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,13 @@ func GetLanguageVersion(c *gin.Context) {
// GetContracts returns the data contract for a language as JSON, or a zip archive of all contracts.
//
// @Summary Retrieve data contracts
// @Description Returns a language's contract as JSON ({lang}.json), or a zip of all contracts (data_contracts.zip) without 'lang'.
// @Description Returns a language's contract as JSON ({lang}.json), or a zip of all contracts (scribe_data_contracts.zip) without 'lang'.
// @Tags Contracts
// @Accept json
// @Produce json,application/zip
// @Param lang query string false "Language code (ISO 639-1)" example(es)
// @Success 200 {file} file "The language's contract as JSON, or a zip archive of all contracts"
// @Header 200 {string} Content-Disposition "inline; filename={lang}.json, or attachment; filename=data_contracts.zip for all languages"
// @Header 200 {string} Content-Disposition "inline; filename={lang}.json, or attachment; filename=scribe_data_contracts.zip for all languages"
// @Failure 400 {object} models.ErrorResponse "Invalid language code provided"
// @Failure 404 {object} models.ErrorResponse "Language not supported"
// @Failure 500 {object} models.ErrorResponse "Failed to load contract files"
Expand Down
4 changes: 2 additions & 2 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const docTemplate = `{
"paths": {
"/api/v1/contracts": {
"get": {
"description": "Returns a language's contract as JSON ({lang}.json), or a zip of all contracts (data_contracts.zip) without 'lang'.",
"description": "Returns a language's contract as JSON ({lang}.json), or a zip of all contracts (scribe_data_contracts.zip) without 'lang'.",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -56,7 +56,7 @@ const docTemplate = `{
"headers": {
"Content-Disposition": {
"type": "string",
"description": "inline; filename={lang}.json, or attachment; filename=data_contracts.zip for all languages"
"description": "inline; filename={lang}.json, or attachment; filename=scribe_data_contracts.zip for all languages"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"paths": {
"/api/v1/contracts": {
"get": {
"description": "Returns a language's contract as JSON ({lang}.json), or a zip of all contracts (data_contracts.zip) without 'lang'.",
"description": "Returns a language's contract as JSON ({lang}.json), or a zip of all contracts (scribe_data_contracts.zip) without 'lang'.",
"consumes": [
"application/json"
],
Expand Down Expand Up @@ -50,7 +50,7 @@
"headers": {
"Content-Disposition": {
"type": "string",
"description": "inline; filename={lang}.json, or attachment; filename=data_contracts.zip for all languages"
"description": "inline; filename={lang}.json, or attachment; filename=scribe_data_contracts.zip for all languages"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ paths:
consumes:
- application/json
description: Returns a language's contract as JSON ({lang}.json), or a zip of
all contracts (data_contracts.zip) without 'lang'.
all contracts (scribe_data_contracts.zip) without 'lang'.
parameters:
- description: Language code (ISO 639-1)
example: es
Expand All @@ -152,7 +152,7 @@ paths:
description: The language's contract as JSON, or a zip archive of all contracts
headers:
Content-Disposition:
description: inline; filename={lang}.json, or attachment; filename=data_contracts.zip
description: inline; filename={lang}.json, or attachment; filename=scribe_data_contracts.zip
for all languages
type: string
schema:
Expand Down
Loading