CN117873561A - Method and device for generating sample data based on OAS Schema - Google Patents

Method and device for generating sample data based on OAS Schema Download PDF

Info

Publication number
CN117873561A
CN117873561A CN202410258224.6A CN202410258224A CN117873561A CN 117873561 A CN117873561 A CN 117873561A CN 202410258224 A CN202410258224 A CN 202410258224A CN 117873561 A CN117873561 A CN 117873561A
Authority
CN
China
Prior art keywords
sample data
schema
display area
client
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202410258224.6A
Other languages
Chinese (zh)
Inventor
张联华
王首峰
欧阳晔
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Asiainfo Technologies China Inc
Original Assignee
Asiainfo Technologies China Inc
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Asiainfo Technologies China Inc filed Critical Asiainfo Technologies China Inc
Priority to CN202410258224.6A priority Critical patent/CN117873561A/en
Publication of CN117873561A publication Critical patent/CN117873561A/en
Pending legal-status Critical Current

Links

Landscapes

  • User Interface Of Digital Computer (AREA)

Abstract

The invention provides a method and a device for generating sample data based on an OAS Schema, wherein the method comprises the following steps: displaying a foreground main interface comprising at least a schema tab page and a display area, the schema tab page comprising a schema defined in the OAS; when the target schema is detected to be selected, generating basic sample data according to the structure of the target schema; displaying the basic sample data in a display area; configuring sample data information of any operation endpoint corresponding to the target schema in response to configuration operation in the display area; when the operation of generating sample data is detected, final OAS sample data is generated based on sample data information of an operation endpoint corresponding to the target schema. The OAS sample data can be automatically generated without relying on manpower, the efficiency of producing the sample data is improved, the correctness of the sample data is ensured, and the normal use of the API is further ensured.

Description

Method and device for generating sample data based on OAS Schema
Technical Field
The invention relates to the technical field of APIs, in particular to a method and a device for generating sample data based on an OAS Schema.
Background
OpenAPI Specification (OAS, interface definition specification) sample data (samples) may be used as an example to expose request and response data to facilitate better understanding of the use and intended data formats of the application programming interface (Application Programming Interface, API) by developers and users.
Currently, the manual writing of exemples is often relied on by developers; however, on one hand, manually writing exemples easily causes problems of missing attributes, containing error data, format errors and the like, which can lead to the fact that the API cannot be used normally; on the other hand, writing exemples manually takes a lot of time, and the efficiency of producing exemples is low.
Disclosure of Invention
In view of this, the embodiment of the invention provides a method and a device for generating sample data based on OAS Schema, so as to solve the problems that APIs cannot be used normally and efficiency of producing samples is low due to the manual writing of samples.
In order to achieve the above object, the embodiment of the present invention provides the following technical solutions:
the first aspect of the embodiment of the invention discloses a method for generating sample data based on an OAS Schema, which comprises the following steps:
displaying a foreground main interface, wherein the foreground main interface at least comprises a data model schema label page and a display area, and the schema label page comprises at least one schema defined in an interface definition specification (OAS);
when the target schema in the schema label page is detected to be selected, generating basic sample data according to the structure of the target schema, wherein the target schema is any schema in the schema label page;
Displaying the basic sample data in the display area, wherein the basic sample data at least comprises sample data information of any operation endpoint corresponding to the target schema;
responding to configuration operation in the display area, and configuring sample data information of any operation endpoint corresponding to the target schema;
and when the operation of generating the sample data is detected, generating final OAS sample data based on the sample data information of the operation endpoint corresponding to the target schema.
Preferably, when detecting that the target schema in the schema label page is selected, generating basic sample data according to the structure of the target schema includes:
when the target schema in the schema label page is detected to be selected, determining attributes in sample data according to the structure of the target schema;
obtaining sample data values corresponding to the attributes;
and generating basic sample data based on the sample data values corresponding to the attributes.
Preferably, the target schema is a client schema, and the display area includes a first display area and a second display area;
displaying the basic sample data in the display area, including:
Displaying sample data information of each client in the basic sample data in the first display area;
when the fact that the target client in the first display area is selected is detected, sample data information of any operation endpoint corresponding to the target client in the basic sample data is displayed in the second display area, and the target client is any client in the first display area.
Preferably, in response to a configuration operation in the display area, configuring sample data information of any operation endpoint corresponding to the target schema includes:
responding to configuration operation of a user in the second display area, configuring sample data information of any operation endpoint corresponding to the target client, wherein any operation endpoint corresponding to the target client is any one or combination of the following: list operation endpoint, get operation endpoint, post operation endpoint, and patch operation endpoint.
Preferably, the sample data information of the client at least comprises a client ID, a client name and an address list;
displaying sample data information of each client in the basic sample data in the first display area, including:
displaying a client list in the first display area, wherein the client list comprises client IDs and client names of various clients;
And when detecting that the target client in the first display area is selected, displaying an address list of the target client in the first display area, wherein the target client is any client in the client list.
Preferably, after generating the final OAS sample data, further comprising:
the final OAS sample data is saved to an OAS file or the final OAS sample data is saved to another file that can be referenced by the OAS file.
The second aspect of the embodiment of the invention discloses a device for generating sample data based on OAS Schema, which comprises:
the first display unit is used for displaying a foreground main interface, wherein the foreground main interface at least comprises a data model schema label page and a display area, and the schema label page comprises at least one schema defined in an interface definition specification (OAS);
the first generation unit is used for generating basic sample data according to the structure of the target schema when the target schema in the schema label page is detected to be selected, wherein the target schema is any schema in the schema label page;
the second display unit is used for displaying the basic sample data in the display area, wherein the basic sample data at least comprises sample data information of any operation endpoint corresponding to the target schema;
The configuration unit is used for responding to the configuration operation in the display area and configuring sample data information of any operation endpoint corresponding to the target schema;
and the second generating unit is used for generating final OAS sample data based on the sample data information of the operation endpoint corresponding to the target schema when the operation of generating the sample data is detected.
Preferably, the first generating unit includes:
the determining module is used for determining the attribute in the sample data according to the structure of the target schema when the target schema in the schema label page is detected to be selected;
the acquisition module is used for acquiring sample data values corresponding to the attributes;
and the generation module is used for generating basic sample data based on the sample data values corresponding to the attributes.
Preferably, the target schema is a client schema, and the display area includes a first display area and a second display area; the second display unit includes:
the first display module is used for displaying sample data information of each client in the basic sample data in the first display area;
and the second display module is used for displaying sample data information of any operation endpoint corresponding to the target client in the basic sample data in the second display area when detecting that the target client in the first display area is selected, wherein the target client is any client in the first display area.
Preferably, the configuration unit is specifically configured to: responding to configuration operation of a user in the second display area, configuring sample data information of any operation endpoint corresponding to the target client, wherein any operation endpoint corresponding to the target client is any one or combination of the following: list operation endpoint, get operation endpoint, post operation endpoint, and patch operation endpoint.
Based on the method and the device for generating sample data based on OAS Schema provided by the embodiment of the invention, the method comprises the following steps: displaying a foreground main interface, wherein the foreground main interface at least comprises a schema label page and a display area, and the schema label page comprises at least one schema defined in an OAS; when the target schema in the schema label page is detected to be selected, generating basic sample data according to the structure of the target schema; displaying the basic sample data in a display area; configuring sample data information of any operation endpoint corresponding to the target schema in response to configuration operation in the display area; when the operation of generating sample data is detected, final OAS sample data is generated based on sample data information of an operation endpoint corresponding to the target schema. In the scheme, basic sample data is generated according to the structure of the target schema selected by the user, the basic sample data is displayed, and the user can configure sample data information of any operation endpoint corresponding to the target schema. After configuration is completed, final OAS sample data is automatically generated based on sample data information of an operation endpoint corresponding to the target schema, the OAS sample data can be automatically generated without relying on manpower, the efficiency of producing the sample data is improved, the correctness of the sample data is ensured, and the normal use of an API is further ensured.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings that are required to be used in the embodiments or the description of the prior art will be briefly described below, and it is obvious that the drawings in the following description are only embodiments of the present invention, and that other drawings can be obtained according to the provided drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a method for generating sample data based on OAS Schema provided by an embodiment of the invention;
FIG. 2 is a first exemplary diagram of a foreground main interface provided by an embodiment of the present invention;
FIG. 3 is an exemplary diagram of a structure of a client schema provided in an embodiment of the present invention;
FIG. 4 (a) is an exemplary diagram of final samples corresponding to a customer schema provided by an embodiment of the present invention; FIG. 4 (b) is another exemplary diagram of final samples corresponding to a customer schema provided by an embodiment of the present invention;
FIG. 5 is a second exemplary diagram of a foreground main interface provided by an embodiment of the present invention;
FIG. 6 is a diagram showing an example of text content of a customer_list provided by an embodiment of the present invention;
FIG. 7 is a third exemplary diagram of a foreground main interface provided by an embodiment of the present invention;
FIG. 8 (a) is a diagram illustrating mapping definition information of a post operation endpoint corresponding to a request and a response according to an embodiment of the present invention; FIG. 8 (b) is an example diagram of examples generated in the request definition of a post operation endpoint; FIG. 8 (c) is an example diagram of examples generated in the response definition of a post operation endpoint;
FIG. 9 is a fourth exemplary diagram of a foreground main interface provided by an embodiment of the present invention;
FIG. 10 (a) is an exemplary diagram of a request samples of a patch operation endpoint provided by an embodiment of the present invention; FIG. 10 (b) is an exemplary diagram of response samples of a patch operation endpoint provided by an embodiment of the present invention;
FIG. 11 is a fifth exemplary diagram of a foreground main interface provided by an embodiment of the present invention;
FIG. 12 (a) is a diagram illustrating another example of a request samples of a patch operation endpoint according to an embodiment of the present invention; FIG. 12 (b) is a diagram illustrating another example of response samples of a patch operation endpoint according to an embodiment of the present invention;
FIG. 13 is a sixth exemplary diagram of a foreground main interface provided by an embodiment of the present invention;
FIG. 14 (a) is a diagram illustrating another example of a request examples of a patch operation endpoint according to an embodiment of the present invention; FIG. 14 (b) is a diagram illustrating another example of response samples of a patch operation endpoint according to an embodiment of the present invention;
FIG. 15 is an exemplary diagram of defining the contents of requests and responses in requestBody and response provided by an embodiment of the present invention;
FIG. 16 is an exemplary diagram of response content of 200customer_list provided by an embodiment of the present invention;
FIG. 17 is an overall flowchart of a method for generating sample data based on OAS Schema, provided by an embodiment of the invention;
fig. 18 is a block diagram of an apparatus for generating sample data based on OAS Schema according to an embodiment of the present invention.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
In this application, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Note that OpenAPI Specification (OAS, interface definition specification), also referred to as swagger specification, is a standard specification for describing and defining RESTful Web services; OASs provide a uniform way to describe the structure, operation, and interactions of APIs so that developers, API providers, and consumers can better understand and use APIs.
OASs provide a set of structured specifications and conventions based on JSON or YAML formats for defining various aspects of API resources, paths, operations, parameters, responses, and security, with the primary objective of making API documents easy to understand, readable, and providing an interactive way to test and call APIs.
Data models (schemas) are widely used in OASs to describe resources, request parameters, and response volumes, through which attributes of the resources, data types, validation rules, etc. can be defined, thereby ensuring the accuracy and consistency of the request and response data of the API.
Sample data (samples) of OASs may be used as an example to expose request and response data to facilitate a better understanding of application programming interfaces (Application Programming Interface, APIs) usage and expected data formats by developers and users; these examples may be simulated, randomly generated, or actual data samples to demonstrate how the request and expected response content is constructed.
Application of OAS samples has the following benefits:
benefit one, explicit data structure: the schema in the API definition describes the structure and attributes of the data, but these descriptions may be relatively abstract, examples provide specific examples of data, help the developer understand the meaning, type and format of each attribute more clearly, and reduce the developer's misunderstanding of the API data format.
Benefit two, exemplary request construction: the user of the API needs to know how to construct the request, and by way of example the request enables the developer to know the parameters, format and correct location of the request, thereby constructing the request correctly, and thus improving the usability of the API.
Benefit three, expected response display: examples show the structure and content of the response, which helps the developer to expect the data they will get and to better parse and process the response.
Fourth, standardize the usage mode: through examples, users of the API can follow standard usage patterns, thereby avoiding format errors of requests and responses, ensuring consistency of request and response data, and reducing risks of data errors.
Fifth, accelerate development: examples can help developers to develop, test and integrate based on examples without guessing the format of requests and responses, reduce learning costs, quickly start up, and speed up development processes, thereby improving development efficiency.
Six benefits, the test of being convenient for: the examples can be used for test case construction to ensure that the API can function correctly under various conditions.
The above are benefits with respect to applying exemples of OAS; in software development, writing an example of an API is a very important task. The inventor finds that the current examples of the API are manually written by a developer, and many contents of the examples of the API are repeated, so that the manual writing not only requires a great deal of time and effort, but also is easy to cause errors and inconsistencies; in general, the manner in which examples are written manually has the following problems:
problem one, inconsistency: different developers may write examples in different ways, which may result in inconsistent data formats and content in examples, thereby increasing the difficulty of understanding between developers.
Problem two, omission and error: hand written exemples may miss certain attributes or data or contain erroneous data, resulting in a failure to call an API or an inaccurate result.
Problem three, difficult to maintain: when OAS schemes change, the manually written exemples need to be manually updated, which may cause the exemples to be inconsistent with the actual OAS schemes, resulting in misunderstanding by the developer.
Fourth, time and effort are wasted: hand writing exemples takes a lot of time and effort, especially for complex data structures and APIs with multiple operating endpoints (List, get, etc.), multiple access forms (application/json, application/merge-latch+ json, application/json-latch+ json, application/json-latch-query+json), and a lot of repeated exemples data need to be manually changed.
Problem five, poor readability: manually written examples can become lengthy and unintelligible, particularly for complex objects that contain multiple attributes and associations.
Problem six, format error: manually writing exemples may result in format errors, such as forgetting to add commas, quotation marks, etc., resulting in incorrect resolution of requests and responses.
In order to solve the problems, the scheme provides a method and a device for generating sample data based on an OAS Schema, wherein basic sample data is generated according to a structure of a target Schema selected by a user, the basic sample data is displayed, and the user can configure sample data information of any operation endpoint corresponding to the target Schema. After configuration is completed, final OAS sample data is automatically generated based on sample data information of an operation endpoint corresponding to the target schema, the OAS sample data can be automatically generated without relying on manpower, the efficiency of producing the sample data is improved, the correctness of the sample data is ensured, and the normal use of an API is further ensured.
The scheme can be suitable for any software development project which needs to use the OAS to provide Restful to access the API, particularly in a large project or a multi-person cooperation project, the development and test efficiency can be remarkably improved, and the availability of the API is improved. The present embodiment will be described in detail with reference to the following examples.
Referring to fig. 1, a flowchart of a method for generating sample data based on OAS Schema according to an embodiment of the present invention is shown, where the method includes:
step S101: and displaying a foreground main interface.
In the specific implementation process of step S101, when a user (i.e., an operator) needs to write sample data (samples), the user opens a foreground main interface; at this time, when an operation of opening the foreground main interface is detected, the foreground main interface is displayed, and at least contains a schema tag page (TAB page) containing at least one schema defined in OAS and a display area. The user may select a schema for which sample data is to be configured in the schema tab page of the foreground main interface.
For example, as can be seen in the first example diagram of the foreground main interface shown in fig. 2, the foreground main interface includes a schema tab, a display area, a "determine generation" control, and so on; the schema tag page contains customer schema (referred to as customer schema) and order schema defined in the OAS, which the user can select for configuration of sample data.
Step S102: when the target schema in the schema label page is detected to be selected, basic sample data is generated according to the structure of the target schema.
It should be noted that the target schema is any schema in the schema tag page, and specifically, the target schema is a schema selected by the user.
In the specific implementation process of step S102, when it is detected that the target schema in the schema label page is selected, the examples data generation service is called to automatically generate basic sample data, so that a user can select and edit the basic sample data according to the requirements of different APIs in the foreground main interface.
In some embodiments, the specific implementation manner of generating the basic sample data is: the method comprises the steps of determining the attribute in sample data according to the structure of a target schema, specifically, finding the attribute and the attribute category in the sample data (samples) according to the structure of the target schema, wherein the structure of the target schema at least comprises a class name, an attribute type and the like.
For example, fig. 3 shows an exemplary diagram of the structure of the Customer schema, and for the definition of '#/components/schema/Customer' as shown in fig. 3, it can be seen from the structure of the Customer schema shown in fig. 3 that the sample data includes contents such as a Customer ID, a Customer name (name), an Address list (addresses), etc., and according to the structure of the addresses referenced by the addresses, ID, street, city, postcode information of one to a plurality of addresses should be included in the samples.
Obtaining sample data values (namely sample values) corresponding to all the attributes in the sample data; basic sample data (also referred to as basic samples data) is generated based on sample data values corresponding to respective attributes in the sample data.
To better explain the examples data generation service, the workflow of the examples data generation service is explained by the following processes A1 to A3.
A1, finding out the attribute and attribute category in the sample data according to the structure of the target schema.
A2, circulating each found attribute to generate a sample data value of each attribute. And respectively calling the corresponding type of sample data generating method to generate corresponding sample data values for different types of attributes.
For example: for the attribute of the ID type, the unique number can be generated in sequence to obtain the corresponding sample data value, or the UUID can be adopted to generate the unique number to obtain the corresponding sample data value; for the character string type, corresponding character strings can be randomly generated to obtain corresponding sample data values; for the creation date, the current date may be selected to obtain a corresponding sample data value; in practical application, different generation strategies can be configured through a configuration method.
A3, for a specific field, accessing a database to randomly search or conditionally search the proper basic sample data; for example: for names, a library of pre-defined names may be queried to use the appropriate name as the base sample data.
In summary, the sample values corresponding to each attribute in the samples may be automatically generated by the system, and the basic sample data composed of the automatically generated sample values may be displayed in the foreground main interface for editing and selecting by the user.
Step S103: and displaying the basic sample data in a display area.
In the process of implementing step S103 specifically, after the basic sample data is generated according to the structure of the target schema, the basic sample data is displayed in the display area of the foreground main interface, where the displayed basic sample data at least includes sample data information of any operation endpoint corresponding to the target schema, that is, at least sample data information of any operation endpoint corresponding to the target schema is displayed in the display area, and similarly, according to the actual situation of the target schema, other information than sample data information of the operation endpoint may be displayed in the display area.
Step S104: and configuring sample data information of any operation endpoint corresponding to the target schema in response to the configuration operation in the display area.
In the specific implementation process of step S104, after at least displaying sample data information of any operation endpoint corresponding to the target schema in the display area, the user may configure the sample data information displayed in the display area; and configuring sample data information of any operation endpoint corresponding to the target schema in response to the configuration operation in the display area.
Step S105: when the operation of generating sample data is detected, final OAS sample data is generated based on sample data information of an operation endpoint corresponding to the target schema.
In the specific implementation process of step S105, after the user configures sample data information of any operation endpoint corresponding to the target schema, the user confirms that the configuration information is correct, and then can generate final OAS sample data through operation; when the operation of generating sample data is detected, final OAS sample data is generated based on sample data information of an operation endpoint corresponding to the target schema.
For example, as can be seen in connection with the first example diagram of the foreground main interface shown in FIG. 2, after confirming that the configuration information is correct, the user may click on the "determine generate" control, thereby generating final OAS sample data corresponding to the target schema.
In some embodiments, after the final OAS sample data is generated, the final OAS sample data is saved to the OAS file or the final OAS sample data is saved to another file that can be referenced by the OAS file.
That is, after the final samples are generated, the final samples may be saved with the OAS file, the samples may be saved as another file separately and the file referenced in the OAS file, which may help to maintain the cleanliness and maintainability of the OAS file.
For example: assuming that the target schema is a customer schema, the final samples corresponding to the customer schema are generated in the above manner, and the specific content is shown in fig. 4 (a).
"customer_sample" may also be saved in json format, and the details of "customer_sample" when saved in json format are shown in FIG. 4 (b). The reference definition is made in the samples of components of OAS files in the following manner:
“components:
examples:
customer_example:
$ref: ./path/to/customer_example.json”。
next, use the examples of this reference elsewhere in the OAS file, such as in requestBodes or responses, with specific reference to the following:
“requestBodies:
Customer_post:
description: The customer to be created
content:
application/json:
schema:
$ref: '#/components/schemas/Customer'
examples:
customer_create_example:
$ref: '#/components/examples/customer_example'”。
in the embodiment of the invention, the basic sample data is generated according to the structure of the target schema selected by the user, the basic sample data is displayed, and the user can configure the sample data information of any operation endpoint corresponding to the target schema. After configuration is completed, final OAS sample data is automatically generated based on sample data information of an operation endpoint corresponding to the target schema, the OAS sample data can be automatically generated without relying on manpower, the efficiency of producing the sample data is improved, the correctness of the sample data is ensured, and the normal use of an API is further ensured.
It will be appreciated that the schema tag page contains various schemas, such as customer schemas (referred to as customer schemas) and order schemas, defined in the OAS; when the user selects a different schema (the selected schema is the target schema) in the schema tab page, the information displayed in the display area of the foreground main interface is different.
In some embodiments, the target schema is a client schema, the display area includes a first display area and a second display area, and the specific manner of displaying the basic sample data in the display area is: displaying sample data information of each client in the basic sample data in a first display area; when the target client in the first display area is detected to be selected, sample data information of any operation endpoint corresponding to the target client in the basic sample data is displayed in the second display area, and the target client is any client in the first display area.
It can be understood that when the target schema is the client schema, the sample data information of the client at least includes a client ID, a client name and an address list; the specific way of displaying the sample data information of each client in the basic sample data in the first display area is as follows: displaying a client list in a first display area, the client list comprising client IDs and client names of respective clients; when it is detected that the target client in the first display area is selected, displaying an address list of the target client in the first display area, wherein the target client is any client in the client list.
Correspondingly, when the target schema is the client schema, the specific mode of configuring the sample data information of any operation endpoint corresponding to the target schema is as follows: responding to configuration operation of a user in the second display area, configuring sample data information of any operation endpoint corresponding to a target client, wherein any operation endpoint corresponding to the target client is any one or combination of the following: list operation endpoint, get operation endpoint, post operation endpoint, and patch operation endpoint.
To better explain how the present solution generates final OAS sample data, the following is used to explain the target schema as the customer schema (customer schema).
As can be seen from the second exemplary diagram of the foreground main interface provided in FIG. 5, the leftmost schema TAB page (TAB page) of the foreground main interface displays all of the schemas (customer and order) defined in the OAS; the user can select the schema for editing on the foreground main interface and generate the examples of the schema corresponding to different operation endpoints; the user selects "customer" in the foreground main interface shown in FIG. 5.
After the user selects the customer schema in fig. 5, more than two customers are automatically generated for selection by different examples, that is, a customer list is displayed in the first display area, and the customer category includes two customers with customer ID 1 and customer ID 2 (John Doe and John Smith); according to the definition of the example schema, each client may have a plurality of addresses, so that after one client is selected (the selected client is the target client), the address list of the target client is displayed in the first display area; the user selects a client with a client ID of 1 in fig. 5, so that a list of addresses of John Doe, two addresses of John Doe, is displayed in the first display area. The second display area (right half) in fig. 5 may be used to configure sample data information (samples information) of all operation endpoints corresponding to the customer schema, where all operation endpoints corresponding to the customer schema include a list operation endpoint (LIST response examples), a GET operation endpoint (GET samples), a POST operation endpoint (POST samples), and a latch operation endpoint (path samples); the user may click on the tab corresponding to each operation endpoint on the second display area in fig. 5 to configure the samples information of each operation endpoint (also referred to as a method), and the following explains how to configure the samples information of the list operation endpoint, the get operation endpoint, the post operation endpoint, and the patch operation endpoint, respectively.
Description of examples information about configuration list operation endpoints:
the second display area in fig. 5 currently displays response samples information of the List operation endpoint, and List operation is to query and return a List of all clients, so that the second display area displays information of two clients and the information of the two clients is selected by default, namely the two clients are returned by default; if it is not necessary to return a certain client as an example, the left-hand "v" may be clicked in the client table (including the client ID and the client name) displayed in the second display area to cancel the client, and then the returned response information will not include a certain line of client information from which "v" was cancelled. Similarly, the second display area also includes an address table, where the address table includes a plurality of addresses of a client, and which addresses of the client need to be returned can be selected or cancelled by clicking "v" on the left side of the address table in the second display area.
Edit Customer Examples and Edit Customer Address Examples show all information of the selected customer and all information of the customer's selected address; it is thus possible to select at Edit Customer Examples and Edit Customer Address Examples which properties of the client or of the address should be included in the responding example, and if some properties are not wanted to be included in the responding example, the "left" v "of the properties not wanted to be included in the responding example may be deselected.
If the object attribute value generated by the system needs to be modified, the corresponding attribute value can be edited; after confirming the configuration information, the user may click on the "determine generate" control in FIG. 5, generating the final samples in the OAS. According to the configuration information in the second display area of fig. 5, the text content of the generated final text_list of samples is shown in fig. 6. Note that, the address information of John Smith with the client ID of 2 is not shown in the second display area shown in fig. 5, and the address information of John Smith is shown in the second display area when the second client needs to be clicked to switch to the second client in the actual configuration.
The above is a related description of example information configuring list operation endpoints.
Description of examples information about configuration post operation endpoints:
as can be seen from the third exemplary diagram of the foreground main interface shown in fig. 7, the second display area in the foreground main interface shown in fig. 7 is currently displaying the samples information that is the post operation endpoint.
The mapping definition information of the post operation endpoint (post method) corresponding to the request and the response is shown in fig. 8 (a), and specifically, the contents enclosed by the rectangular frame in fig. 8 (a) are shown in detail.
The user clicks the "determine generate" control, which generates the final samples in the OAS. According to the configuration information in the second display area of fig. 7, the specific content of examples in the request definition of the generated post operation endpoint is shown in fig. 8 (b), and the specific content of examples in the response definition of the generated post operation endpoint is shown in fig. 8 (c).
The above is a related description about the examples information configuring the post operation endpoint.
Description of examples information about configuration patch operation endpoints:
the patch operation endpoint (patch method) supports different request formats, such as application/json, application/merge-patch+ json, application/json-patch+ json, application/json-patch-query+json and the like, and the request contents of the different formats are different; modifying the contents such as the client name can be performed by the respective request formats described above.
As can be seen from the fourth exemplary diagram of the foreground main interface shown in FIG. 9, the customer name may be modified by the application/json request format; the configuration information after the client name is modified according to the request format of application/json shown in fig. 9, and the specific content of the generated request examples is shown in fig. 10 (a); the specific contents of the generated response samples are shown in fig. 10 (b), and the corresponding client name in the specific contents of the response samples shown in fig. 10 (b) should be changed to "Stone Doe", and other information is unchanged.
As can be seen from the fifth exemplary diagram of the foreground main interface shown in FIG. 11, the customer name may be modified by the request format application/json-patch+json, with the interface display differing in the need to select the corresponding operation (op); the configuration information after the client name is modified according to the request format of application/json-patch+json shown in fig. 11, and the specific content of the generated request examples is shown in fig. 12 (a); the specific content of the generated response samples is shown in fig. 12 (b), and the corresponding client name in the specific content of the response samples shown in fig. 12 (b) should be changed to "James Doe", and other information is unchanged.
As can be seen from the sixth exemplary diagram of the foreground main interface shown in fig. 13, the postal code of the first address of the client 1 may be modified by using the request format of application/json-patch-query+json, requiring selection of the corresponding operation (op), selection of the ID of the client address as the query parameter, selection of the postal code of the client and modification to what needs to be modified.
Modifying the post-zip configuration information of the first address of the client 1 according to the request format of application/json-patch-query+json shown in fig. 13, and the specific content of the generated request samples is shown in fig. 14 (a); the specific content of the generated response samples is shown in fig. 14 (b), and the postal code of the first address of the corresponding customer in the specific content of the response samples shown in fig. 14 (b) should be changed from original 12345 to 23456, and other information is unchanged.
The above is a related description of the examples information configuring the patch operation endpoint.
In combination with the above, taking customer schema as an example, the implementation idea of the scheme is as follows: for each operation endpoint (method) in the OAS, it can be seen in connection with the example diagram of defining the contents of the request and response in the requestBody and response shown in fig. 15 that if the request contents or the response contents are of the object type, the contents of the request and response are uniformly defined in the requestBody and response and referenced; the list returned by the get method to the customer in FIG. 15 is a response to the object type, all of which are defined by referencing the definition of '#/components/responses/200 customer_list'.
Request contents are defined in components/requestBodies, components/response parts define response contents, the response contents of 200customer_list are shown in fig. 16, the schema of 200customer_list in fig. 16 defines the response contents as a definition referring to '#/components/schema/Customer', and the examples part describes a list of returned client information, two client objects are returned in fig. 16, and the examples contents in fig. 16 are automatically generated according to the schema, and the main generation manner can be seen from the contents of the above embodiments, and will not be repeated herein.
In summary, the overall flow chart of the present solution is shown in fig. 17, and fig. 17 contains 1-10 steps.
1. All schemes are listed on the TAB page.
2. The user selects a schema on the TAB page.
3. The basic sample data (basic sample data) is automatically generated by calling the samples data generation service.
4. Basic samples data are displayed.
5. The user selects an API method/endpoint (i.e., an operating endpoint).
6. Configuration request samples data.
7. The configuration is responsive to sample data.
8. Other API methods/endpoints are selected and configured.
9. Other schemas are selected and configured.
10. OAS samples are generated.
Compared with the existing manual writing mode of exemples, the scheme has the following advantages:
the method has the advantages that firstly, development efficiency is improved: by automatically generating OAS samples, the workload of manual writing and maintenance is reduced, and the development efficiency is improved.
Second, ensure the uniformity: the OAS samples generated automatically are consistent with the Schema, so that the problem of inconsistency possibly occurring during manual writing is avoided, and the consistency of a plurality of samples with similar operations is ensured.
Advantage three, fast iteration and modification: iteration and modification can be easily performed, and the development process is quickened.
Fourth, improve the accuracy: the OAS samples generated automatically can avoid possible errors in manual writing, and accuracy of the data model is improved.
Fifth, support the disposable generation of multiple samples data.
Six, generation of example data in multiple request formats supporting Patch.
The method has the advantages that the multiple personalized example data generation method is flexibly supported through configuration by the example data generation service.
And the method has the advantage that selection and configuration of the samples data are more flexible and convenient through the selection and configuration of the foreground main interface.
The example content generated, advantage nine, may be placed either directly in the OAS file or in a separate file and referenced in the OAS file.
Corresponding to the method for generating sample data based on OAS Schema provided in the embodiment of the present invention, referring to fig. 18, the embodiment of the present invention further provides a structural block diagram of an apparatus for generating sample data based on OAS Schema, where the apparatus includes: a first display unit 100, a first generation unit 200, a second display unit 300, a configuration unit 400, a second generation unit 500;
a first display unit 100, configured to display a foreground main interface, where the foreground main interface includes at least a schema tag page and a display area, and the schema tag page includes at least one schema defined in the OAS.
The first generating unit 200 is configured to generate, when it is detected that the target schema in the schema tag page is selected, basic sample data according to a structure of the target schema, where the target schema is any schema in the schema tag page.
The second display unit 300 is configured to display, in the display area, basic sample data, where the basic sample data includes at least sample data information of any operation endpoint corresponding to the target schema.
And a configuration unit 400, configured to configure sample data information of any operation endpoint corresponding to the target schema in response to a configuration operation in the display area.
In a specific implementation, the configuration unit 400 is specifically configured to: responding to configuration operation of a user in the second display area, configuring sample data information of any operation endpoint corresponding to a target client, wherein any operation endpoint corresponding to the target client is any one or combination of the following: list operation endpoint, get operation endpoint, post operation endpoint, and patch operation endpoint.
The second generating unit 500 is configured to generate final OAS sample data based on sample data information of an operation endpoint corresponding to the target schema when an operation for generating sample data is detected.
In the embodiment of the invention, the basic sample data is generated according to the structure of the target schema selected by the user, the basic sample data is displayed, and the user can configure the sample data information of any operation endpoint corresponding to the target schema. After configuration is completed, final OAS sample data is automatically generated based on sample data information of an operation endpoint corresponding to the target schema, the OAS sample data can be automatically generated without relying on manpower, the efficiency of producing the sample data is improved, the correctness of the sample data is ensured, and the normal use of an API is further ensured.
Preferably, in conjunction with the content shown in fig. 18, the first generating unit 200 includes a determining module, an obtaining module, and a generating module, where the execution principle of each module is as follows:
and the determining module is used for determining the attribute in the sample data according to the structure of the target schema when the target schema in the schema label page is detected to be selected.
The acquisition module is used for acquiring the sample data value corresponding to each attribute.
And the generation module is used for generating basic sample data based on the sample data values corresponding to the attributes.
Preferably, in connection with the content shown in fig. 18, the target schema is a client schema, and the display area includes a first display area and a second display area; the second display unit 300 includes a first display module and a second display module, and the execution principle of each module is as follows:
and the first display module is used for displaying sample data information of each client in the basic sample data in the first display area.
In a specific implementation, the sample data information of the client at least comprises a client ID, a client name and an address list; the first display module is specifically configured to: displaying a client list in a first display area, wherein the client list comprises client IDs and client names of various clients; when the target client in the first display area is detected to be selected, the address list of the target client is displayed in the first display area, and the target client is any client in the client list.
And the second display module is used for displaying sample data information of any operation endpoint corresponding to the target client in the basic sample data in the second display area when the target client in the first display area is detected to be selected, wherein the target client is any client in the first display area.
Preferably, in combination with the content shown in fig. 18, the apparatus further includes:
and a storage unit for storing the final OAS sample data in the OAS file or storing the final OAS sample data in other files that can be referenced by the OAS file.
In summary, the embodiments of the present invention provide a method and an apparatus for generating sample data based on OAS Schema, which generate basic sample data according to a structure of a target Schema selected by a user, and display the basic sample data, and the user may configure sample data information of any operation endpoint corresponding to the target Schema. After configuration is completed, final OAS sample data is automatically generated based on sample data information of an operation endpoint corresponding to the target schema, the OAS sample data can be automatically generated without relying on manpower, the efficiency of producing the sample data is improved, the correctness of the sample data is ensured, and the normal use of an API is further ensured.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for a system or system embodiment, since it is substantially similar to a method embodiment, the description is relatively simple, with reference to the description of the method embodiment being made in part. The systems and system embodiments described above are merely illustrative, wherein the elements illustrated as separate elements may or may not be physically separate, and the elements shown as elements may or may not be physical elements, may be located in one place, or may be distributed over a plurality of network elements. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment. Those of ordinary skill in the art will understand and implement the present invention without undue burden.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. A method of generating sample data based on OAS Schema, the method comprising:
displaying a foreground main interface, wherein the foreground main interface at least comprises a data model schema label page and a display area, and the schema label page comprises at least one schema defined in an interface definition specification (OAS);
when the target schema in the schema label page is detected to be selected, generating basic sample data according to the structure of the target schema, wherein the target schema is any schema in the schema label page;
displaying the basic sample data in the display area, wherein the basic sample data at least comprises sample data information of any operation endpoint corresponding to the target schema;
Responding to configuration operation in the display area, and configuring sample data information of any operation endpoint corresponding to the target schema;
and when the operation of generating the sample data is detected, generating final OAS sample data based on the sample data information of the operation endpoint corresponding to the target schema.
2. The method of claim 1, wherein generating basic sample data from a structure of a target schema in the schema tag page when it is detected that the target schema is selected comprises:
when the target schema in the schema label page is detected to be selected, determining attributes in sample data according to the structure of the target schema;
obtaining sample data values corresponding to the attributes;
and generating basic sample data based on the sample data values corresponding to the attributes.
3. The method of claim 1, wherein the target schema is a customer schema, and the display area comprises a first display area and a second display area;
displaying the basic sample data in the display area, including:
displaying sample data information of each client in the basic sample data in the first display area;
When the fact that the target client in the first display area is selected is detected, sample data information of any operation endpoint corresponding to the target client in the basic sample data is displayed in the second display area, and the target client is any client in the first display area.
4. The method of claim 3, wherein configuring sample data information of any operation endpoint corresponding to the target schema in response to a configuration operation in the display area comprises:
responding to configuration operation of a user in the second display area, configuring sample data information of any operation endpoint corresponding to the target client, wherein any operation endpoint corresponding to the target client is any one or combination of the following: list operation endpoint, get operation endpoint, post operation endpoint, and patch operation endpoint.
5. A method according to claim 3, wherein the sample data information of the client comprises at least a client ID, a client name and an address list;
displaying sample data information of each client in the basic sample data in the first display area, including:
displaying a client list in the first display area, wherein the client list comprises client IDs and client names of various clients;
And when detecting that the target client in the first display area is selected, displaying an address list of the target client in the first display area, wherein the target client is any client in the client list.
6. The method of any one of claims 1-5, further comprising, after generating final OAS sample data:
the final OAS sample data is saved to an OAS file or the final OAS sample data is saved to another file that can be referenced by the OAS file.
7. An apparatus for generating sample data based on OAS Schema, the apparatus comprising:
the first display unit is used for displaying a foreground main interface, wherein the foreground main interface at least comprises a data model schema label page and a display area, and the schema label page comprises at least one schema defined in an interface definition specification (OAS);
the first generation unit is used for generating basic sample data according to the structure of the target schema when the target schema in the schema label page is detected to be selected, wherein the target schema is any schema in the schema label page;
the second display unit is used for displaying the basic sample data in the display area, wherein the basic sample data at least comprises sample data information of any operation endpoint corresponding to the target schema;
The configuration unit is used for responding to the configuration operation in the display area and configuring sample data information of any operation endpoint corresponding to the target schema;
and the second generating unit is used for generating final OAS sample data based on the sample data information of the operation endpoint corresponding to the target schema when the operation of generating the sample data is detected.
8. The apparatus of claim 7, wherein the first generation unit comprises:
the determining module is used for determining the attribute in the sample data according to the structure of the target schema when the target schema in the schema label page is detected to be selected;
the acquisition module is used for acquiring sample data values corresponding to the attributes;
and the generation module is used for generating basic sample data based on the sample data values corresponding to the attributes.
9. The apparatus of claim 7, wherein the target schema is a customer schema, and wherein the display area comprises a first display area and a second display area; the second display unit includes:
the first display module is used for displaying sample data information of each client in the basic sample data in the first display area;
And the second display module is used for displaying sample data information of any operation endpoint corresponding to the target client in the basic sample data in the second display area when detecting that the target client in the first display area is selected, wherein the target client is any client in the first display area.
10. The apparatus according to claim 9, wherein the configuration unit is specifically configured to: responding to configuration operation of a user in the second display area, configuring sample data information of any operation endpoint corresponding to the target client, wherein any operation endpoint corresponding to the target client is any one or combination of the following: list operation endpoint, get operation endpoint, post operation endpoint, and patch operation endpoint.
CN202410258224.6A 2024-03-07 2024-03-07 Method and device for generating sample data based on OAS Schema Pending CN117873561A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202410258224.6A CN117873561A (en) 2024-03-07 2024-03-07 Method and device for generating sample data based on OAS Schema

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202410258224.6A CN117873561A (en) 2024-03-07 2024-03-07 Method and device for generating sample data based on OAS Schema

Publications (1)

Publication Number Publication Date
CN117873561A true CN117873561A (en) 2024-04-12

Family

ID=90590298

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202410258224.6A Pending CN117873561A (en) 2024-03-07 2024-03-07 Method and device for generating sample data based on OAS Schema

Country Status (1)

Country Link
CN (1) CN117873561A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112700295A (en) * 2019-10-22 2021-04-23 北京邮电大学 Data product metadata providing device and method
US20220012426A1 (en) * 2019-08-07 2022-01-13 Jurgen Ziemer Configurable Ontology to Data model Transformation
CN114036183A (en) * 2021-11-24 2022-02-11 杭州安恒信息技术股份有限公司 Data ETL processing method, device, equipment and medium
CN114661715A (en) * 2022-03-21 2022-06-24 中国工商银行股份有限公司 Database data processing method and device, storage medium and electronic equipment
CN115934537A (en) * 2022-12-06 2023-04-07 中国工商银行股份有限公司 Interface test tool generation method, device, equipment, medium and product
CN116955674A (en) * 2023-09-20 2023-10-27 杭州悦数科技有限公司 Method and web device for generating graph database statement through LLM

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20220012426A1 (en) * 2019-08-07 2022-01-13 Jurgen Ziemer Configurable Ontology to Data model Transformation
CN112700295A (en) * 2019-10-22 2021-04-23 北京邮电大学 Data product metadata providing device and method
CN114036183A (en) * 2021-11-24 2022-02-11 杭州安恒信息技术股份有限公司 Data ETL processing method, device, equipment and medium
CN114661715A (en) * 2022-03-21 2022-06-24 中国工商银行股份有限公司 Database data processing method and device, storage medium and electronic equipment
CN115934537A (en) * 2022-12-06 2023-04-07 中国工商银行股份有限公司 Interface test tool generation method, device, equipment, medium and product
CN116955674A (en) * 2023-09-20 2023-10-27 杭州悦数科技有限公司 Method and web device for generating graph database statement through LLM

Similar Documents

Publication Publication Date Title
JP6916403B2 (en) Specifying and applying logical validation rules to data
CA2639549C (en) Data mapping design tool
US8479093B2 (en) Metamodel-based automatic report generation
US8819075B2 (en) Facilitation of extension field usage based on reference field usage
US20100153150A1 (en) Software for business adaptation catalog modeling
CN108762743B (en) Data table operation code generation method and device
CA2639548C (en) Data mapping document design system
KR20080083324A (en) Identifying design issues in electronic forms
CN107578217B (en) Working electronic flow autonomous generation method and device and office management system
US11556702B2 (en) Orchestration of crud operations for a hierarchical web service data model in a spreadsheet
US20060047723A1 (en) Custom database system and method of building the same
US8606762B2 (en) Data quality administration framework
US10372760B2 (en) Building queries directed to objects hosted on clouds
CN110825395B (en) Multi-plug-in layered deployment system, device and medium
EP3113016A1 (en) Tracing dependencies between development artifacts in a development project
US10417234B2 (en) Data flow modeling and execution
US20100011018A1 (en) Custom database system and method of building the same
CN114116745A (en) Interface change identification and display method, device, equipment and medium
CN111045660A (en) Method, device and storage medium for verifying tax declaration data on network
CN117873561A (en) Method and device for generating sample data based on OAS Schema
US20230195792A1 (en) Database management methods and associated apparatus
US10949327B2 (en) Manipulation of complex variables in orchestration applications
US20080022258A1 (en) Custom database system and method of building and operating the same
US8631393B2 (en) Custom database system and method of building and operating the same
JP6677809B2 (en) Adapter generation apparatus and method

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination