Skip to content

Commit c596c9b

Browse files
committed
load schema dynamically
1 parent 0c06d8f commit c596c9b

File tree

8 files changed

+409
-290
lines changed

8 files changed

+409
-290
lines changed

console/atest-ui/src/assets/api-testing-mock-schema.json

Lines changed: 0 additions & 93 deletions
This file was deleted.

console/atest-ui/src/views/MockManager.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@ import { jsonLanguage } from "@codemirror/lang-json"
88
import { API } from './net';
99
import {useI18n} from "vue-i18n";
1010
import EditButton from '../components/EditButton.vue'
11-
import mockSchema from '../assets/api-testing-mock-schema.json';
1211
1312
const { t } = useI18n()
1413
15-
const mockschema = ref(mockSchema as any); // Type assertion to any for JSON schema
14+
const mockschema = ref({}); // Type assertion to any for JSON schema
1615
const jsonComplete = NewTemplateLangComplete(jsonLanguage)
1716
const headerComplete = NewHeaderLangComplete(jsonLanguage)
1817
18+
API.GetSchema('mock').then((schema) => {
19+
if (schema.success && schema.message !== '') {
20+
mockschema.value = JSON.parse(schema.message);
21+
}
22+
});
23+
1924
interface MockConfig {
2025
Config: string
2126
ConfigAsJSON: string
@@ -28,7 +33,10 @@ const mockConfig = ref({} as MockConfig);
2833
watch(mockConfig, (newValue) => {
2934
if (tabActive.value === 'json') {
3035
// convert JSON to YAML string
31-
newValue.Config = jsonToYaml(newValue.ConfigAsJSON);
36+
try {
37+
newValue.Config = jsonToYaml(newValue.ConfigAsJSON);
38+
} catch (e) {
39+
}
3240
} else {
3341
newValue.ConfigAsJSON = JSON.stringify(yaml.load(newValue.Config), null, 2);
3442
}

console/atest-ui/src/views/net.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16+
import { ca } from 'element-plus/es/locales.mjs';
1617
import { Cache } from './cache'
1718

1819
/**
@@ -117,6 +118,25 @@ function GetVersion(callback?: (v: AppVersion) => void) {
117118
.then(emptyOrDefault(callback))
118119
}
119120

121+
interface CommonResult {
122+
message: string
123+
success: boolean
124+
}
125+
126+
async function GetSchema(name: string, callback?: (v: CommonResult) => void) {
127+
const requestOptions = {
128+
method: 'GET',
129+
}
130+
if (callback) {
131+
return fetch(`/api/v1/schemas/${name}`, requestOptions)
132+
.then(DefaultResponseProcess)
133+
.then(emptyOrDefault(callback))
134+
} else {
135+
return fetch(`/api/v1/schemas/${name}`, requestOptions)
136+
.then(DefaultResponseProcess)
137+
}
138+
}
139+
120140
interface TestSuite {
121141
store: string
122142
name: string
@@ -915,7 +935,7 @@ const GetBinding = (name: string, callback: (d: any) => void | null) => {
915935

916936
export const API = {
917937
DefaultResponseProcess,
918-
GetVersion,
938+
GetVersion, GetSchema,
919939
CreateTestSuite, UpdateTestSuite, ImportTestSuite, GetTestSuite, DeleteTestSuite, ConvertTestSuite, DuplicateTestSuite, RenameTestSuite, GetTestSuiteYaml,
920940
CreateTestCase, UpdateTestCase, GetTestCase, ListTestCase, DeleteTestCase, DuplicateTestCase, RenameTestCase, RunTestCase, BatchRunTestCase,
921941
GetHistoryTestCaseWithResult, DeleteHistoryTestCase, GetHistoryTestCase, GetTestCaseAllHistory, DeleteAllHistoryTestCase, DownloadResponseFile,

pkg/server/remote_server.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/prometheus/client_golang/prometheus"
3939
"github.com/prometheus/client_golang/prometheus/promauto"
4040

41+
"github.com/linuxsuren/api-testing/docs"
4142
"github.com/linuxsuren/api-testing/pkg/util/home"
4243

4344
"github.com/linuxsuren/api-testing/pkg/mock"
@@ -434,6 +435,19 @@ func (s *server) RunTestSuite(srv Runner_RunTestSuiteServer) (err error) {
434435
}
435436
}
436437

438+
func (s *server) GetSchema(ctx context.Context, in *SimpleQuery) (result *CommonResult, err error) {
439+
result = &CommonResult{
440+
Success: true,
441+
}
442+
switch in.Name {
443+
case "core":
444+
result.Message = docs.Schema
445+
case "mock":
446+
result.Message = docs.MockSchema
447+
}
448+
return
449+
}
450+
437451
// GetVersion returns the version
438452
func (s *server) GetVersion(ctx context.Context, in *Empty) (reply *Version, err error) {
439453
reply = &Version{

0 commit comments

Comments
 (0)