Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): add JSON export for schema #1299

Merged
merged 44 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
09c254e
wip
nourbalaha Nov 5, 2024
3a9a7fb
wip
nourbalaha Nov 6, 2024
4ea11be
wip
nourbalaha Nov 6, 2024
a69a084
wip
nourbalaha Nov 6, 2024
0a426aa
wip: implement schema for public api
nourbalaha Nov 6, 2024
08c0302
revert
nourbalaha Nov 6, 2024
5c01ae6
fix
nourbalaha Nov 6, 2024
d22dbc4
Merge branch 'main' into feat-server/schema-json-export
nourbalaha Nov 6, 2024
29c7f49
refactor
nourbalaha Nov 7, 2024
8b58bc3
wip: update integration end points
nourbalaha Nov 8, 2024
c3edb1a
wip: add 4 more integration api endpoints
nourbalaha Nov 11, 2024
ff95373
refactor PublicApiItemOrAsset
nourbalaha Nov 11, 2024
9ebe325
implement toJSONSchemaProperties
nourbalaha Nov 11, 2024
7cced87
implement schema json export for public api
nourbalaha Nov 11, 2024
25784d7
refactor integration schema
nourbalaha Nov 11, 2024
23fc23a
refactor schema export integration api
nourbalaha Nov 11, 2024
fe53058
add integration api e2e tests
nourbalaha Nov 12, 2024
ca39bb8
refactor integration schema
nourbalaha Nov 12, 2024
8255a34
add more e2e cases
nourbalaha Nov 12, 2024
a308f1b
wip: public api properties
nourbalaha Nov 13, 2024
6ddca80
implement find schema by group
nourbalaha Nov 13, 2024
e8626bc
refactor integration api
nourbalaha Nov 13, 2024
2e750dc
lint
nourbalaha Nov 13, 2024
91e5247
Merge branch 'main' into feat-server/schema-json-export
nourbalaha Nov 13, 2024
8edf568
update determineTypeAndFormat
nourbalaha Nov 13, 2024
f16d996
Merge branch 'feat-server/schema-json-export' of ssh://github.com/ree…
nourbalaha Nov 13, 2024
ef87bd6
add const defaultJSONSchemaVersion
nourbalaha Nov 13, 2024
b861094
refactor
nourbalaha Nov 13, 2024
132d722
add unit test for determineTypeAndFormat
nourbalaha Nov 14, 2024
e370e3d
add TestBuildProperties
nourbalaha Nov 14, 2024
1577665
refactor
nourbalaha Nov 19, 2024
53520c5
Revert "refactor"
nourbalaha Nov 25, 2024
9048c1e
Merge branch 'main' into feat-server/schema-json-export
nourbalaha Nov 25, 2024
4fee3eb
requested changes
nourbalaha Nov 26, 2024
24bb268
fix ci
nourbalaha Nov 26, 2024
57550de
unify the logic for integration and publicapi
nourbalaha Nov 26, 2024
3a6e589
requested changes 2
nourbalaha Nov 26, 2024
b2002f9
add type to properties
nourbalaha Nov 27, 2024
17e8a12
fix types
nourbalaha Nov 27, 2024
f743f06
fix empty values
nourbalaha Nov 27, 2024
c262c24
remove useless function
nourbalaha Nov 27, 2024
6945f77
refactor
nourbalaha Nov 27, 2024
f6c191a
refactor
nourbalaha Nov 27, 2024
dd2b302
Merge branch 'main' into feat-server/schema-json-export
nourbalaha Nov 29, 2024
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
219 changes: 219 additions & 0 deletions server/e2e/integration_schema_export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package e2e

import (
"net/http"
"testing"

"github.com/reearth/reearth-cms/server/internal/app"
"github.com/reearth/reearth-cms/server/pkg/id"
)

func TestIntegrationSchemaJSONExportAPI(t *testing.T) {
e := StartServer(t, &app.Config{}, true, baseSeeder)

// /api/schemata/{schemaId}/schema.json
e.GET("/api/schemata/{schemaId}/schema.json", sid1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/schemata/{schemaId}/schema.json", id.NewSchemaID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/schemata/{schemaId}/schema.json", sid1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": sid1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
"asset": map[string]any{
"description": "",
"title": "",
"type": "string",
"format": "binary",
},
sfKey1.String(): map[string]any{
"description": "",
"title": "",
"type": "string",
},
},
"type": "object",
})

// /api/projects/{projectIdOrKey}/schemata/{schemaId}/schema.json
e.GET("/api/projects/{projectIdOrKey}/schemata/{schemaId}/schema.json", pid, sid1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/projects/{projectIdOrKey}/schemata/{schemaId}/schema.json", pid, id.NewSchemaID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/projects/{projectIdOrKey}/schemata/{schemaId}/schema.json", pid, sid1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": sid1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
"asset": map[string]any{
"description": "",
"title": "",
"type": "string",
"format": "binary",
},
sfKey1.String(): map[string]any{
"description": "",
"title": "",
"type": "string",
},
},
"type": "object",
})
nourbalaha marked this conversation as resolved.
Show resolved Hide resolved

// /api/projects/{projectIdOrKey}/models/{modelId}/schema.json
e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/schema.json", pid, mId1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/schema.json", pid, id.NewModelID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/schema.json", pid, mId1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": mId1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
"asset": map[string]any{
"description": "",
"title": "",
"type": "string",
"format": "binary",
},
sfKey1.String(): map[string]any{
"description": "",
"title": "",
"type": "string",
},
},
"type": "object",
"description": "m1 desc",
"title": "m1",
})

// /api/projects/{projectIdOrKey}/models/{modelId}/metadata_schema.json
e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/metadata_schema.json", pid, mId1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/metadata_schema.json", pid, id.NewModelID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/projects/{projectIdOrKey}/models/{modelId}/metadata_schema.json", pid, mId1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": mId1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
sfKey4.String(): map[string]any{
"description": "",
"title": "",
"type": "boolean",
},
},
"type": "object",
"description": "m1 desc",
"title": "m1",
})

// /api/models/{modelId}/schema.json
e.GET("/api/models/{modelId}/schema.json", mId1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/models/{modelId}/schema.json", id.NewModelID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/models/{modelId}/schema.json", mId1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": mId1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
"asset": map[string]any{
"description": "",
"title": "",
"type": "string",
"format": "binary",
},
sfKey1.String(): map[string]any{
"description": "",
"title": "",
"type": "string",
},
},
"type": "object",
"description": "m1 desc",
"title": "m1",
})

// /api/models/{modelId}/metadata_schema.json
e.GET("/api/models/{modelId}/metadata_schema.json", mId1).
WithHeader("authorization", "Bearer abcd").
Expect().
Status(http.StatusUnauthorized)

e.GET("/api/models/{modelId}/metadata_schema.json", id.NewModelID()).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusNotFound)

e.GET("/api/models/{modelId}/metadata_schema.json", mId1).
WithHeader("authorization", "Bearer "+secret).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"$id": mId1,
"$schema": "https://json-schema.org/draft/2020-12/schema",
"properties": map[string]any{
sfKey4.String(): map[string]any{
"description": "",
"title": "",
"type": "boolean",
},
},
"type": "object",
"description": "m1 desc",
"title": "m1",
})
}
51 changes: 51 additions & 0 deletions server/e2e/publicapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,57 @@ func TestPublicAPI(t *testing.T) {
// publicAPIField2Key should be removed
})

// schema export json
e.GET("/api/p/{project}/{model}/schema.json", publicAPIProjectAlias, id.RandomKey()).
Expect().
Status(http.StatusNotFound)

e.GET("/api/p/{project}/{model}/schema.json", publicAPIProjectAlias, publicAPIModelKey).
Expect().
Status(http.StatusOK).
JSON().
IsEqual(map[string]any{
"description": "",
"id": publicAPIModelID,
"properties": map[string]any{
"asset": map[string]any{
"description": "",
"title": "asset",
"type": "string",
"format": "binary",
},
"asset2": map[string]any{
"description": "",
"title": "asset2",
"type": "string",
"format": "binary",
},
"geometry-editor": map[string]any{
"description": "",
"title": "geometry-editor",
"type": "object",
},
"geometry-object": map[string]any{
"description": "",
"title": "geometry-object",
"type": "object",
},
"test-field-1": map[string]any{
"description": "",
"title": "test-field-1",
"type": "string",
},
"test-field-2": map[string]any{
"description": "",
"title": "test-field-2",
"type": "string",
},
},
"schema": "https://json-schema.org/draft/2020-12/schema",
"title": "",
"type": "object",
})

nourbalaha marked this conversation as resolved.
Show resolved Hide resolved
// make the project private
prj.Publication().SetScope(project.PublicationScopePrivate)
lo.Must0(repos.Project.Save(ctx, prj))
Expand Down
Loading