CN116755684A - OAS Schema generation method, device, equipment and medium - Google Patents
OAS Schema generation method, device, equipment and medium Download PDFInfo
- Publication number
- CN116755684A CN116755684A CN202311031400.4A CN202311031400A CN116755684A CN 116755684 A CN116755684 A CN 116755684A CN 202311031400 A CN202311031400 A CN 202311031400A CN 116755684 A CN116755684 A CN 116755684A
- Authority
- CN
- China
- Prior art keywords
- class
- file
- information
- schema
- oas
- 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.)
- Granted
Links
- 238000000034 method Methods 0.000 title claims abstract description 38
- 238000013499 data model Methods 0.000 claims abstract description 102
- 238000004458 analytical method Methods 0.000 claims abstract description 24
- 238000010586 diagram Methods 0.000 claims description 53
- 238000012545 processing Methods 0.000 claims description 12
- 238000004590 computer program Methods 0.000 claims description 11
- 230000008859 change Effects 0.000 claims description 8
- 238000011161 development Methods 0.000 abstract description 8
- 238000012423 maintenance Methods 0.000 abstract description 6
- 238000004867 photoacoustic spectroscopy Methods 0.000 description 73
- 230000004044 response Effects 0.000 description 8
- 238000012986 modification Methods 0.000 description 6
- 230000004048 modification Effects 0.000 description 6
- 230000003993 interaction Effects 0.000 description 4
- 230000000694 effects Effects 0.000 description 3
- 238000005516 engineering process Methods 0.000 description 3
- 238000013507 mapping Methods 0.000 description 3
- 230000003287 optical effect Effects 0.000 description 3
- 238000007792 addition Methods 0.000 description 2
- 230000002452 interceptive effect Effects 0.000 description 2
- 230000008569 process Effects 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 238000012546 transfer Methods 0.000 description 2
- 238000010200 validation analysis Methods 0.000 description 2
- 230000002776 aggregation Effects 0.000 description 1
- 238000004220 aggregation Methods 0.000 description 1
- 238000013459 approach Methods 0.000 description 1
- 238000013475 authorization Methods 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 230000005540 biological transmission Effects 0.000 description 1
- 238000012217 deletion Methods 0.000 description 1
- 230000037430 deletion Effects 0.000 description 1
- 238000013461 design Methods 0.000 description 1
- 238000005265 energy consumption Methods 0.000 description 1
- 239000000284 extract Substances 0.000 description 1
- 230000010354 integration Effects 0.000 description 1
- 238000007726 management method Methods 0.000 description 1
- 230000002093 peripheral effect Effects 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/35—Creation or generation of source code model driven
- G06F8/355—Round-trip engineering
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/71—Version control; Configuration management
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/70—Software maintenance or management
- G06F8/74—Reverse engineering; Extracting design information from source code
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Security & Cryptography (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The application provides a method, a device, equipment and a storage medium for generating an OAS Schema, and relates to the technical field of software development. The method comprises the following steps: analyzing the class file, and acquiring information related to the class from the analyzed file; traversing information related to the class generates a data model of the OAS. The implementation of the application can analyze the class image file, automatically generate the OAS Schema according to the analysis result, specifically analyze the plant UML class image file, generate the OAS Schema according to the analysis result, and quickly generate the OAS file comprising interfaces for adding, deleting, modifying and checking the OAS Schema through the OAS Schema, thereby reducing the workload of manual writing and maintenance, having short time consumption, improving the development efficiency, and being capable of quickly iterating and modifying, and reducing the possibility of inconsistent OAS Schema and the field model.
Description
Technical Field
The application relates to the technical field of software development, in particular to a method, a device, equipment and a medium for generating an OAS Schema.
Background
With the development of modern social science and technology, computer systems have become an indispensable tool for various industries, and have played a central role in the development of computer software systems. As software systems become increasingly popular in various industries, their problems become increasingly large and serious themselves. One application today is often accomplished by tens of people writing hundreds of thousands to millions of lines of code. On the other hand, applications live and develop in a changing dynamic environment, and therefore, the applications need to be maintained constantly, i.e., partially rewritten over a portion of the application or new functionality.
In the field of software development, as the scale of applications is continuously enlarged, integration and interaction between various parts become more and more complex, and requirements are also higher and higher. RESTful (english: representational State Transfer, simply REST, REST refers to a set of architectural constraints and principles-an application or design that satisfies these constraints and principles is RESTful) is being used by an increasing number of manufacturers due to its unique platform-independent, programming language-independent, clear structure, easy understanding, ease of expansion, etc. Among them, openAPI Specification (OAS, interface definition specification). Also known as Swagger specification, is a standard specification for describing and defining RESTful Web services. It provides a uniform way to describe the structure, operation, and interactions of APIs (application programming interfaces) so that developers, API providers, and consumers can better understand and use APIs.
OAS Schema (OAS data model) is widely used in OAS to describe data models of resources, request parameters, and response bodies, through which attributes, data types, validation rules, etc. of resources can be defined to ensure accuracy and consistency of request and response data of an API. However, existing OAS schemas are written manually, which takes a lot of time and effort, and are prone to errors and inconsistencies with the domain model, resulting in multiple modifications and maintenance required, reducing software development efficiency.
Disclosure of Invention
The embodiment of the application provides a method, a device, equipment and a medium for generating an OAS Schema, which can solve the problems that the conventional manual programming of the OAS Schema takes a long time, is large in energy consumption and is easy to cause errors and deviations. In order to achieve the object, embodiments of the present application provide the following solutions.
According to an aspect of an embodiment of the present application, there is provided a method for generating an OAS Schema, including:
analyzing the class file, and acquiring information related to the classes from the analyzed file, wherein the information comprises a list corresponding to each class, attributes of the classes and relation information among the classes;
and generating a data model of the OAS according to the information related to the class.
In one possible implementation manner, the parsing the class file and obtaining information related to the class from the parsed file includes:
invoking a preset analysis object to analyze the class diagram file to obtain a target file with a processable data structure, wherein the analysis object comprises an analyzer or library corresponding to the class diagram file;
and extracting information related to the class from the target file.
In one possible implementation, the generating a data model of the OAS from the class-related information includes:
calling a preset OAS automatic generation program based on the information related to the class to generate a data model, wherein the data model comprises a plurality of Schema objects corresponding to the class one by one;
determining first information of each Schema object in the data model based on the information related to the class; the first information comprises text information of class names, types and attribute lists;
and determining second information of each Schema object in the data model based on the information related to the class, wherein the second information comprises attribute names, data types, constraints of the attributes of the class and text information corresponding to the reference relation between Schema objects corresponding to each class.
In one possible implementation manner, the determining, based on the information related to the class, first information of each Schema object in the data model includes:
and defining the name, type and attribute list of the class in the text information of the Schema object according to the information related to the class.
In one possible implementation manner, the determining, based on the information related to the class, second information of each Schema object in the data model includes:
determining the attribute name and the data type of the class in the corresponding Schema object according to the attribute name, and processing the constraint of the attribute in the Schema object;
and determining the reference relation between the Schema objects according to the relation information.
In one possible implementation, the generating a data model of the OAS from the class-related information includes:
generating a corresponding definition file aiming at each Schema object in the data model, and storing the definition file and the data model;
or generating an OAS file according to each Schema object in the data model, wherein the OAS file comprises a definition corresponding to each Schema object.
In one possible implementation, the method further includes:
detecting whether the class diagram file changes, wherein the change comprises at least one of adding, deleting and modifying classes in the class diagram file;
if the class file is determined to change, analyzing the class file to acquire information related to the class, updating the generated data model according to the information related to the class or generating a new data model for the newly added class, and synchronously updating the generated OAS file.
The application provides a generating device of an OAS Schema, which comprises the following components:
the class file analysis module is used for analyzing the class file and acquiring information related to the classes from the analyzed file, wherein the information comprises a list corresponding to each class, attributes of the classes and relation information among the classes;
and the data model generation module is used for traversing the information related to the class to generate a data model of the OAS.
The application provides an electronic device comprising a memory, a processor and a computer program stored on the memory, characterized in that the processor executes the computer program to carry out the steps of the method as described above.
According to a further aspect of embodiments of the present application, there is provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the method as described above.
The technical scheme provided by the embodiment of the application has the beneficial effects that:
the OAS Schema generation method provided by the application analyzes the class file, acquires the information related to the classes from the analyzed file, and generates the OAS Schema according to the list corresponding to each class, the attribute of the class and the relation between the classes in the information. The embodiment of the application analyzes the class diagram file and generates the OAS Schema according to the analysis result. Therefore, the embodiment of the application automatically generates the OAS Schema by using the image-like file, reduces the workload of manual writing and maintenance, has short time consumption, improves the development efficiency, can quickly iterate and modify, and reduces the possibility of inconsistent OAS Schema and the field model.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following description will simply refer to the drawings that are required to be used in the description of the embodiments of the present application.
FIG. 1 is a flow chart of a method for generating OAS Schema provided by an embodiment of the application;
FIG. 2 is a flow chart of another embodiment of a method for generating OAS schemas provided by the present application;
FIG. 3 is a sequence diagram of one embodiment of a method of generating an OAS scheme of the application;
FIG. 4 is a schematic diagram of class diagram files for generating OAS schemas provided by an embodiment of the present application;
FIG. 5 is a block diagram of an OAS Schema generation apparatus provided by an embodiment of the present application;
fig. 6 is a block diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Embodiments of the present application are described below with reference to the drawings in the present application. It should be understood that the embodiments described below with reference to the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application, and the technical solutions of the embodiments of the present application are not limited.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless expressly stated otherwise, as understood by those skilled in the art. It will be further understood that the terms "comprises" and "comprising," when used in this specification, specify the presence of stated features, information, data, steps, operations, elements, and/or components, but do not preclude the presence or addition of other features, information, data, steps, operations, elements, components, and/or groups thereof, all of which may be included in the present specification. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. The term "and/or" as used herein indicates at least one of the items defined by the term, e.g. "a and/or B" indicates implementation as "a", or as "a and B".
For the purpose of making the objects, technical solutions and advantages of the present application more apparent, the following detailed description of the embodiments of the present application will be given with reference to the accompanying drawings.
The technical solutions of the embodiments of the present application and technical effects produced by the technical solutions of the present application are described below by describing several exemplary embodiments. It should be noted that the following embodiments may be referred to, or combined with each other, and the description will not be repeated for the same terms, similar features, similar implementation steps, and the like in different embodiments.
OASs provide a structured set of specifications and conventions based on JSON or YAML formats for defining various aspects of APIs, including resources, paths, operations, parameters, responses, security, and the like. Its main objective is to make the API document easy to understand, readable and provide an interactive way to test and call APIs.
Schema is widely used in OAS to describe data models of resources, request parameters, and response volumes, through which attributes of resources, data types, validation rules, etc. can be defined to ensure accuracy and consistency of request and response data of APIs.
In software development, writing a data model (Schema) of an OAS is an important task. In the existing scheme, the data model is manually written, however, the manually written data model has the following problems.
1. Errors and omissions: manually writing data models is prone to errors and omissions. Manual operations are prone to make mistakes, which may result in incorrect naming of attributes, incorrect data types, or lack of necessary fields. These errors may cause the API to not interpret or implement properly.
2. Inconsistency: in large projects or teams, manually writing Schema presents a consistency challenge. Different developers may have different writing styles and standards, resulting in inconsistent Schema formats and structures. This makes maintenance and modification difficult and increases the difficulty of understanding and collaboration.
3. Time and effort are wasted: manually writing a Schema is a time consuming task. Schema may contain a large number of fields and complex data types, requiring a great deal of time and effort to manually write. Furthermore, when the domain model changes, additional time and effort are also required to manually update and adjust the Schema.
4. Lack of reliability and scalability: manually writing schemes lacks automation and reliability. Manually written schemas are difficult to automatically verify and check, potentially resulting in errors and problems that cannot be found in time. In addition, when the domain model needs to be extended and updated, the manually written Schema is difficult to automatically adapt to changes, and may require a large number of modifications and adjustments.
5. Domain model synchronization is difficult: synchronization between the manually written Schema and the actual domain model may present difficulties. If the domain model changes, the Schema, API and domain model need to be manually updated to maintain consistency, which requires additional effort and management. This can lead to inconsistencies between the API documents and the real world model, which can be confusing to users and developers.
The application provides a method, a device, equipment and a storage medium for generating an OAS scheme, which aim to solve at least one technical problem in the prior art.
The embodiment of the application provides a method for generating an OAS Schema, and equipment applying the method can be a mobile phone, a computer, a server, a cloud platform and other equipment capable of being used for generating a data model. As shown in FIG. 1, the method for generating the OAS Schema (hereinafter referred to as data model) includes steps S101-S102.
S101: and analyzing the class file, and acquiring information related to the class from the analyzed file.
Optionally, the class diagram file may be a plant uml class diagram file, or may be a sequence diagram, a use case diagram, an activity diagram, or other files for describing class information based on plant uml technology. Among them, plant uml is an open-source drawing tool that allows users to generate various types of charts, such as class charts, timing charts, usage charts, activity charts, etc., using simple text descriptions. The method adopts the text-based markup language, so that the creation process of the chart is simpler and maintainable.
Optionally, before analyzing the class image file, the device executing the generating method may determine the class image file to be analyzed according to the input file selection instruction, or may start a tool for generating a data model according to the input instruction, and determine the class image file input into the tool as the class image file to be analyzed. The class diagram file can also be obtained according to the information of the position of the identification class diagram file such as the query operation of the use object or the input website.
Optionally, after the class diagram file is acquired, a preset parsing object (some parsing tools) is called to parse the class diagram file, where the parsing object is a parser or a library.
In one embodiment, the parsing object includes at least one of plant UML Parser, puml2Json, plantUML Class Diagram Parser.
Alternatively, the information related to the class may include a list corresponding to each class, respectively, the list may include class name, type, and the like information related to the class, and relationship information between the classes. In addition, the class diagram file is resolved into a target file which is a processable data structure through a preset resolving structure in order to facilitate subsequent processing.
In one embodiment, the processable data structure may be in a tree structure or JSON format, which includes a list of class names, attributes of the classes, and relationship information of the classes. The relationship information includes relationship information between classes, such as one-to-many relationships, one-to-one relationships, inheritance relationships, and the like.
In one example, the relationship information is as follows:
Person "1" *-->"1..*" Address: personAddress
it comprises the following contents:
main class name: person
Associated class name: address (Address)
Relationship name between classes: personAddress
Associated number limit rules: a person may contain 1 to a plurality of addresses, one address belonging to only one person.
S102: traversing information related to the class generates a data model of the OAS.
Optionally, traversing the class-related information generates a data model of the OAS, comprising: calling a preset OAS automatic generation program based on the information related to the class to generate a data model, wherein the data model comprises a plurality of Schema objects (the number of the classes is consistent with that of the Schema objects) corresponding to the classes one by one; determining first information of each Schema object in the data model based on the information related to the class; the first information comprises text information corresponding to the class name, the type and the attribute list; and determining second information of each Schema object in the data model based on the information related to the class, wherein the second information comprises attribute names of the data model, data types, constraints of the attributes in the data model and text information corresponding to the reference relation between Schema objects corresponding to the classes.
In one embodiment, a corresponding data model (i.e., OAS Schema) is created from class-related information, the data Schema object comprising a plurality of Schema objects, and the class-related information is utilized to define the names, types (objects), and properties of the classes in each Schema object. After definition is completed, the attribute names of the classes are acquired, the information of the types is mapped into Schema objects of the data model, and the attribute names of the Schema objects are determined (for example, the data types supported by the data model, such as character strings, numbers, boolean values and the like, are determined according to the attribute names of the classes). And according to the constraint of corresponding processing attributes of the information related to the class, such as maximum length, enumeration value and the like, the quotation relationship between Schema objects is correspondingly set according to the relationship information in the analysis result.
The embodiment of the application automatically generates the OAS Schema by using the image-like file, reduces the workload of manual writing and maintenance, has short time consumption, improves the development efficiency, can quickly iterate and modify, and reduces the possibility of inconsistent OAS Schema and the field model.
Optionally, the application further provides a method for generating the OAS Schema, as shown in fig. 2-4, the method includes:
s201: and calling a preset analysis object analysis class file to obtain a target file capable of processing the data structure.
Optionally, an object is used to input a class diagram file, wherein the class diagram file is a file related to the data model, and comprises information of each class related to the data model, and after receiving the class diagram file, the equipment calls a preset analysis object to analyze the class diagram file. Wherein the parsing object comprises at least one of plant UML Parser, puml2Json, plantUML Class Diagram Parser.
Optionally, the device may obtain the name, number, format and other information capable of identifying the analysis object of the input class diagram file, determine the analysis object corresponding to the class diagram file according to the information, and call the analysis object to execute the analysis operation.
In one embodiment, the class diagram file is a plant UML class diagram file, the class diagram file is received, and an analysis object corresponding to the class diagram file is called to obtain an analysis result of the class diagram file.
Alternatively, the object file as the analysis result uses a processable data structure including a list of classes, attribute information of the classes, and relationship information between the classes, which can be set according to the actual requirements and the types of the analysis objects.
In one embodiment, the processable data structure may be any of a tree structure, JSON format.
S202: information related to the class is extracted from the object file.
Optionally, the list of classes and the attribute and relation information of the classes are extracted through the target file. The relationship information includes relationship information between two classes, such as one-to-many relationships, one-to-one relationships, inheritance relationships, and the like.
In one embodiment, the relationship information in the extracted class-related information is: person "1" - - > "1..:
main class name: person
Associated class name: address (Address)
Relationship name between classes: personAddress
Associated number limit rules: a person may contain 1 to a plurality of addresses, one address belonging to only one person.
Optionally, after the class map file is parsed to obtain the target file by using the parsing object, information related to the class is extracted by using an extractor, and the extractor extracts information according to a data structure of the target file.
S203: calling a preset OAS automatic generation program based on the information related to the class, generating a data model, determining first information of each Schema object in the data model based on the information related to the class, and determining second information of each Schema object in the data model based on the information related to the class.
Optionally, the first information includes a name of the class, a type of the class, and text information corresponding to an attribute list of the class, and the second information includes an attribute name of the data model, a data type, a constraint of the attribute, and a reference relationship corresponding to the class. The data model is composed of a plurality of Schema objects, and a final data model is obtained through processing first information and second information related to the Schema objects.
Optionally, determining the first information of each Schema object in the data model based on the information related to the class includes: the name, type and attribute list of the class are defined in the text information of each Schema object according to the information related to the class.
In one embodiment, each class in the target file may be represented as a Schema object of one OAS. Corresponding Schema objects are created according to the extracted information (a list of classes can be) and the names, types (objects) and text information of the attribute list of the classes are generated in the Schema objects. Specifically, according to the information related to the class, a preset program is called to generate text content of a corresponding Schema object, wherein the text content comprises the name, the type (object) and the attribute of the class, and the name of the class is taken as the name of the Schema object. The preset program may be an OAS auto-generation program.
Specifically, a Schema object created based on the class-related information (the relationship information is set to: person "1" - > "1.+ -. Address: personAddress) in the above embodiment is defined as follows:
components:
schemas:
Person:
type-Object this type is currently a fixed Object.
Properties refers to the properties of a class.
id:
type: string
name:
type: string
Besides generating the Schema object Person and the corresponding text information, the Schema object PersonAddress and the text information corresponding to the PersonAddress are also generated.
In one embodiment, schema generators (Schema generators) may be used to create definitions and attributes of classes and to determine attribute names for data models and constraint relationships for attributes.
Optionally, determining second information of each Schema object in the data model based on the information related to the class includes: determining the attribute name and the data type of the corresponding Schema object according to the attribute name, and processing the constraint of the attribute; and determining the reference relation between Schema objects according to the relation information.
In one embodiment, the attribute names of the classes in the class file are mapped to the corresponding Schema object to determine the attribute names of the Schema object. The data types supported by the Schema object, such as strings, numbers, boolean values, etc., are determined based on the attribute names. At the same time, constraints of the attributes, such as maximum length, enumerated values, etc., are handled. Specifically, the attribute name String in the class diagram file corresponds to String in the created Schema object, the attribute name Long in the class diagram file corresponds to String in the Schema object, and the like, and mapping of the attribute names is performed according to a preset mapping relationship. Replacement may be performed according to a mapping relationship when a program (e.g., an OAS auto-generator) is used to generate text related to attributes in a Schema object.
In one example:
person in the plant uml class diagram file is such that:
class Person<<Resource>>{
{field}id: String
{field}name: String
}
the attribute names are String, and the attribute names in the Schema object are correspondingly defined according to the attribute names:
components:
schemas:
Person:
type: object
properties:
id:
type: string
name:
type: string
in another example, the attribute names in the class diagram file are: { field } id: string, description text corresponding to the attribute name in the Schema object corresponding to the type is:
properties:
id:
type: string
alternatively, because there may be an association (e.g., aggregation, inheritance, association, etc.) between classes in a class file, a reference ($ref) may be used in the data model to represent the association between classes. According to the relation information in the class diagram, a corresponding reference relation is generated, and the reference is carried out in the Schema object by using $ref.
In one embodiment, reference Handler (reference handler) is used to obtain relationship information between classes in the class file, and a reference relationship between Schema objects is correspondingly generated according to the relationship information.
Optionally, to enable storage invocation of the data model and enable rapid generation of OAS files, traversing class-related information generates a data model of the OAS, including: generating a corresponding definition file aiming at each Schema object in the data model, and storing the definition file and the data model; or generating an OAS file according to each Schema object in the data model, wherein the OAS file comprises a definition corresponding to each Schema object.
Alternatively, the definition file may be part of the OAS file or may be stored separately from the OAS file, which stores a reference to the definition file. The definition file comprises definitions of the generated Schema objects, and the definitions comprise definitions of interfaces used for performing operations such as adding, deleting, modifying and the like on the Schema objects.
In one embodiment, the definition file is part of an OAS file, an example of which is as follows:
components:
schemas:
Person:
type: object
properties:
id:
type: string
name:
type: string
in another embodiment, the definition file is stored separately as: person_schema. Relevant OAS files are: person_management-v1.0.0.oas.yaml, the OAS file also includes a reference to the definition file:
CuPerson:
type: object
properties:
id:
type: string
name:
type: string
reference is then made in person_management-v1.0.0.oas.yaml:
paths:
/persons:
get:
summary: Get all persons
responses:
'200':
description: A list of persons
content:
application/json:
schema:
type: array
items:
$ref: 'Person_schemas.yaml#/Person'
optionally, when saving the definition file, if the definition of the Schema object is written into the OAS file, only the OAS file needs to be saved, if the Schema object of the data model is independently saved, the corresponding definition file needs to be saved at the same time, and if each Schema object is independently saved, how many Schema objects have how many definition files.
Optionally, in order to implement rapid iteration of the data model, detecting whether a class diagram file changes, where the change includes at least one of adding, deleting, and modifying classes in the class diagram file; if the image file of the class is determined to change, analyzing the image file of the class to acquire information related to the class, and generating a new data model according to the information related to the class.
The method of generating OAS Schema of the present application is further described below in conjunction with fig. 3.
As shown in fig. 3, a user provides a plant uml-type image file as a file for generating a data model through a user terminal (e.g., a mobile phone, a computer). After the class diagram file is received, the plant UML class diagram file is analyzed by using a preset analysis object, and a target file with a structure which can be used for processing the data structure is generated. Class name, attribute and relationship information are extracted from the target file according to the data structure. Based on the extracted information, a Schema object of the data model is correspondingly generated, definition and attribute names of classes, data types are created in the Schema object, constraint of the attributes is processed, and reference relations among the Schema objects are set. After the Schema object of the data model is created, the generated data model is returned to the user, and the OAS file or definition file corresponding to the data model is saved.
In one embodiment, a plant UML class diagram file is shown in FIG. 4, and examples of data models generated based on the class diagram file are:
addresses:
type: array
items:
$ref: '#/components/schemas/Address'
the data model best embodies the relationship that one person in the plant UML class diagram can contain from 1 to multiple addresses.
Examples of openapis that include the data model are as follows:
openapi: 3.0.0
info:
title: Example API
version: 1.0.0
paths:
/persons:
get:
summary: Get all persons
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Person'
components:
schemas:
Person:
type: object
properties:
id:
type: string
name:
type: string
addresses:
type: array
items:
$ref: '#/components/schemas/Address'
required:
- id
- name
Address:
type: object
properties:
street:
type: string
city:
type: string
country:
type: string
required:
- street
- city
- country
the OpenAPI example defines a resource Person-related API interface, and the example interface/Person obtains a list of all Person, the returned content is the list of Person, and the definition of Person refers to the definition of Person Schema, specifically in the '#/components/Schema/Person' section of this document.
The schema section of components defines the schema of the object Person, while defining the schema of Address and the relationship objects between Person and Address. These schemas define the type, name, list of attributes of the object, and for each attribute, name and type.
The schema of each object defined in the schema of components, i.e. the content automatically generated by the present application according to the plant UML class diagram.
The Person Schema also contains a reference to another data model Address Schema, unlike the previous approach of generating Schema objects separately and referencing them.
This example demonstrates a query interface (API) retrieval of Person Schema objects through which a list of all Person objects can be queried, where the structure of each Person object is defined by the Person Schema.
Compared with the prior art, the OAS Schema generation method has the following advantages:
1. development efficiency is improved: by automatically generating OAS Schema, the workload of manual writing and maintenance is reduced, and the development efficiency is improved.
2. Ensuring consistency: the OAS Schema generated automatically keeps consistent with the domain model, and the problem of inconsistency possibly occurring in manual writing is avoided.
3. Fast iteration and modification: because the OAS Schema is generated based on the plant UML-type image file, iteration and modification can be easily carried out, and the development process is quickened.
4. Accuracy is improved: the OAS Schema mode automatically generated can avoid possible errors in manual writing, and accuracy of the data model is improved.
It should be noted that, in the alternative embodiment of the present application, the related data (such as class diagram files, data models, OAS schemas, etc.) need to be licensed or agreed upon by the user when the above embodiment of the present application is applied to a specific product or technology, and the collection, use and processing of the related data need to comply with the relevant laws and regulations and standards of the relevant country and region. That is, in the embodiment of the present application, if data related to the subject is involved, the data needs to be obtained through the subject authorization consent and in accordance with the relevant laws and regulations and standards of the country and region.
According to an aspect of the present application, as shown in fig. 5, the generating device 300 of the OAS Schema includes a class file parsing module 310 and a data model generating module 320, where the class file parsing module 310 is configured to parse a class file, and obtain information related to the class from the parsed file, where the information includes a list corresponding to each class, attributes of the class, and relationship information between the classes; the data model generation module 320 is configured to generate a data model of the OAS based on the information related to the class.
Optionally, parsing the class file and obtaining information related to the class from the parsed file includes: invoking a preset analysis object to analyze the class image file to obtain a target file capable of processing the data structure, wherein the analysis object comprises an analyzer or library corresponding to the class image file;
information related to the class is extracted from the target file, and the information related to the class comprises class names, attributes of the class and relation information of the class.
Optionally, traversing the class-related information generates a data model of the OAS, comprising:
calling a preset OAS automatic generation program based on the information related to the class to generate a data model, wherein the data model comprises a plurality of Schema objects corresponding to the class one by one;
determining first information of each Schema object in the data model based on the information related to the class; the first information comprises text information of class names, types and attribute lists;
and determining second information of each Schema object in the data model based on the information related to the class, wherein the second information comprises attribute names, data types, constraints of the attributes of the data model and text information corresponding to the reference relation among Schema objects corresponding to the classes.
Optionally, determining the first information of each Schema object in the data model based on the information related to the class includes:
and defining the name, type and attribute list of the class in the text information of the Schema object according to the information related to the class.
Optionally, determining second information of each Schema object in the data model based on the information related to the class includes: determining the attribute name and the data type of the class in the corresponding Schema object according to the attribute name, and processing the constraint of the attribute in the Schema object; and determining the reference relation between Schema objects according to the relation information.
Optionally, traversing the class-related information generates a data model of the OAS, comprising:
generating a corresponding definition file aiming at each Schema object in the data model, and storing the definition file and the data model;
or generating an OAS file according to each Schema object in the data model, wherein the OAS file comprises a definition corresponding to each Schema object.
Optionally, the method further comprises: detecting whether the class diagram file changes, wherein the change comprises at least one of new addition, deletion and modification of classes in the class diagram file;
if the class file is determined to change, analyzing the class file to acquire information related to the class, updating the generated data model according to the information related to the class or generating a new data model for the newly added class, and synchronously updating the generated OAS file.
In an alternative embodiment, there is provided an electronic device, as shown in fig. 6, the electronic device 4000 shown in fig. 6 includes: a processor 4001 and a memory 4003. Wherein the processor 4001 is coupled to the memory 4003, such as via a bus 4002. Optionally, the electronic device 4000 may further comprise a transceiver 4004, the transceiver 4004 may be used for data interaction between the electronic device and other electronic devices, such as transmission of data and/or reception of data, etc. It should be noted that, in practical applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 is not limited to the embodiment of the present application.
The processor 4001 may be a CPU (central processing unit), a general purpose processor, a DSP (digital signal processor), an ASIC (application specific integrated circuit), an FPGA (field programmable gate array) or other programmable logic device, a transistor logic device, a hardware component, or any combination thereof. Which may implement or perform the various exemplary logic blocks, modules and circuits described in connection with this disclosure. The processor 4001 may also be a combination that implements computing functionality, e.g., comprising one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
Bus 4002 may include a path to transfer information between the aforementioned components. The bus 4002 may be a PCI (peripheral component interconnect) bus, an EISA (extended industrial standard architecture) bus, or the like. The bus 4002 can be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The memory 4003 may be a ROM (read only memory) or other type of static storage device that can store static information and instructions, a RAM (random access memory) or other type of dynamic storage device that can store information and instructions, an EEPROM (electrically erasable programmable read only memory), a CD-ROM (compact disc read only memory) or other optical disk storage, optical disk storage (including compact disc, laser disc, optical disc, digital versatile disc, blu-ray disc, etc.), magnetic disk storage media, other magnetic storage devices, or any other medium that can be used to carry or store a computer program and that can be read by a computer, without limitation.
The memory 4003 is used for storing a computer program for executing an embodiment of the present application, and is controlled to be executed by the processor 4001. The processor 4001 is configured to execute a computer program stored in the memory 4003 to realize the steps shown in the foregoing method embodiment.
The electronic device may be any electronic product that can perform man-machine interaction with an object, for example, a personal computer, a tablet computer, a smart phone, a personal digital assistant (PersonalDigitalAssistant, PDA), a game console, an interactive internet protocol television (InternetProtocolTelevision, IPTV), an intelligent wearable device, and the like.
The electronic device may also include a network device and/or an object device. Wherein the network device includes, but is not limited to, a single network server, a server group made up of multiple network servers, or a cloud based on cloud computing (CloudComputing) made up of a large number of hosts or network servers.
The network in which the electronic device is located includes, but is not limited to, the internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (VirtualPrivateNetwork, VPN), and the like.
Embodiments of the present application provide a computer readable storage medium having a computer program stored thereon, which when executed by a processor, implements the steps of the foregoing method embodiments and corresponding content.
The terms "first," "second," "third," "fourth," "1," "2," and the like in the description and in the claims and in the above figures, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate, such that the embodiments of the application described herein may be implemented in other sequences than those illustrated or otherwise described.
It should be understood that, although various operation steps are indicated by arrows in the flowcharts of the embodiments of the present application, the order in which these steps are implemented is not limited to the order indicated by the arrows. In some implementations of embodiments of the application, the implementation steps in the flowcharts may be performed in other orders as desired, unless explicitly stated herein. Furthermore, some or all of the steps in the flowcharts may include multiple sub-steps or multiple stages based on the actual implementation scenario. Some or all of these sub-steps or phases may be performed at the same time, or each of these sub-steps or phases may be performed at different times, respectively. In the case of different execution time, the execution sequence of the sub-steps or stages can be flexibly configured according to the requirement, which is not limited by the embodiment of the present application.
The foregoing is merely an optional implementation manner of some of the implementation scenarios of the present application, and it should be noted that, for those skilled in the art, other similar implementation manners based on the technical ideas of the present application are adopted without departing from the technical ideas of the scheme of the present application, and the implementation manner is also within the protection scope of the embodiments of the present application.
Claims (10)
1. A method for generating OAS Schema, comprising:
analyzing the class file, and acquiring information related to the classes from the analyzed file, wherein the information comprises a list corresponding to each class, attributes of the classes and relation information among the classes;
traversing the class-related information generates a data model of the OAS.
2. The method of claim 1, wherein parsing the class file and obtaining class-related information from the parsed file comprises:
invoking a preset analysis object to analyze the class diagram file to obtain a target file with a processable data structure, wherein the analysis object comprises an analyzer or library corresponding to the class diagram file;
and extracting information related to the class from the target file.
3. The method of claim 2, wherein said traversing the class-related information generates a data model of an OAS, comprising:
calling a preset OAS automatic generation program based on the information related to the class to generate a data model, wherein the data model comprises a plurality of Schema objects corresponding to the class one by one;
determining first information of each Schema object in the data model based on the information related to the class; the first information comprises text information of class names, types and attribute lists;
and determining second information of each Schema object in the data model based on the information related to the class, wherein the second information comprises attribute names, data types, constraints of the attributes of the class and text information corresponding to the reference relation between Schema objects corresponding to each class.
4. The method of claim 3, wherein determining first information for each Schema object in the data model based on the class-related information comprises:
and defining the name, type and attribute list of the class in the text information of the Schema object according to the information related to the class.
5. The method of claim 3, wherein determining second information for each Schema object in the data model based on the class-related information comprises:
determining the attribute name and the data type of the class in the corresponding Schema object according to the attribute name, and processing the constraint of the attribute in the Schema object;
and determining the reference relation between the Schema objects according to the relation information.
6. The method of claim 3, wherein said traversing the class-related information generates a data model of an OAS, comprising:
generating a corresponding definition file aiming at each Schema object in the data model, and storing the definition file and the data model;
or generating an OAS file according to each Schema object in the data model, wherein the OAS file comprises a definition corresponding to each Schema object.
7. The method according to claim 6, further comprising:
detecting whether the class diagram file changes, wherein the change comprises at least one of adding, deleting and modifying classes in the class diagram file;
if the class file is determined to change, analyzing the class file to acquire information related to the class, updating the generated data model according to the information related to the class or generating a new data model for the newly added class, and synchronously updating the generated OAS file.
8. An OAS scheme generation apparatus, the apparatus comprising:
the class file analysis module is used for analyzing the class file and acquiring information related to the class from the analyzed file, wherein the information comprises a list corresponding to each class, attributes of the class and relation information among the classes;
and the data model generation module is used for traversing the information related to the class to generate a data model of the OAS.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory, characterized in that the processor executes the computer program to carry out the steps of the method of any one of claims 1-7.
10. A computer readable storage medium, on which a computer program is stored, characterized in that the computer program, when being executed by a processor, implements the steps of the method according to any of claims 1-7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311031400.4A CN116755684B (en) | 2023-08-16 | 2023-08-16 | OAS Schema generation method, device, equipment and medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311031400.4A CN116755684B (en) | 2023-08-16 | 2023-08-16 | OAS Schema generation method, device, equipment and medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN116755684A true CN116755684A (en) | 2023-09-15 |
CN116755684B CN116755684B (en) | 2023-12-05 |
Family
ID=87951800
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311031400.4A Active CN116755684B (en) | 2023-08-16 | 2023-08-16 | OAS Schema generation method, device, equipment and medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116755684B (en) |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20040143819A1 (en) * | 2003-01-10 | 2004-07-22 | National Cheng Kung University | Generic software testing system and mechanism |
WO2014059207A1 (en) * | 2012-10-12 | 2014-04-17 | Baker Hughes Incorporated | Method and system to automatically generate use case sequence diagrams and class diagrams |
CN105630500A (en) * | 2015-12-25 | 2016-06-01 | 江苏东大金智信息系统有限公司 | CIM object model for data processing and programming frame thereof |
CN111950239A (en) * | 2020-08-07 | 2020-11-17 | 北京字节跳动网络技术有限公司 | Schema document generation method and device, computer equipment and medium |
CN114417064A (en) * | 2021-12-14 | 2022-04-29 | 深圳供电局有限公司 | Data processing method and device, computer equipment and storage medium |
US20230085956A1 (en) * | 2021-09-20 | 2023-03-23 | Salesforce, Inc. | System and Method for Semantic Metadata Extensions in API Governance using Validation Rulesets |
-
2023
- 2023-08-16 CN CN202311031400.4A patent/CN116755684B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20040143819A1 (en) * | 2003-01-10 | 2004-07-22 | National Cheng Kung University | Generic software testing system and mechanism |
WO2014059207A1 (en) * | 2012-10-12 | 2014-04-17 | Baker Hughes Incorporated | Method and system to automatically generate use case sequence diagrams and class diagrams |
CN105630500A (en) * | 2015-12-25 | 2016-06-01 | 江苏东大金智信息系统有限公司 | CIM object model for data processing and programming frame thereof |
CN111950239A (en) * | 2020-08-07 | 2020-11-17 | 北京字节跳动网络技术有限公司 | Schema document generation method and device, computer equipment and medium |
US20230085956A1 (en) * | 2021-09-20 | 2023-03-23 | Salesforce, Inc. | System and Method for Semantic Metadata Extensions in API Governance using Validation Rulesets |
CN114417064A (en) * | 2021-12-14 | 2022-04-29 | 深圳供电局有限公司 | Data processing method and device, computer equipment and storage medium |
Non-Patent Citations (1)
Title |
---|
段有胜;王虎;: "基于MDA的UML类模型转换XML Schema的方法", 信息技术与信息化, no. 02, pages 53 - 56 * |
Also Published As
Publication number | Publication date |
---|---|
CN116755684B (en) | 2023-12-05 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN109670053B (en) | Data object mapping method, device, equipment and computer readable storage medium | |
US9021440B1 (en) | System and method for automated test script generation | |
CN107122368B (en) | Data verification method and device and electronic equipment | |
US9043757B2 (en) | Identifying differences between source codes of different versions of a software when each source code is organized using incorporated files | |
US10445675B2 (en) | Confirming enforcement of business rules specified in a data access tier of a multi-tier application | |
CN111722839A (en) | Code generation method and device, electronic equipment and storage medium | |
CN117033249B (en) | Test case generation method and device, computer equipment and storage medium | |
US10534592B2 (en) | Template expressions for constraint-based systems | |
CN104461531A (en) | Implementing method for self-defined functions of reporting system | |
CN111125064B (en) | Method and device for generating database schema definition statement | |
CN113962597A (en) | Data analysis method and device, electronic equipment and storage medium | |
CN116755669A (en) | Low code development method and tool based on DSL language operation model | |
CN112860584B (en) | Workflow model-based testing method and device | |
CN108694172B (en) | Information output method and device | |
CN113238739A (en) | Plug-in development and data acquisition method, device, electronic equipment and medium | |
CN113050935A (en) | Method and device for generating mixed object, computing equipment and computer readable storage medium | |
CN116755684B (en) | OAS Schema generation method, device, equipment and medium | |
US11977473B2 (en) | Providing a pseudo language for manipulating complex variables of an orchestration flow | |
CN116860636A (en) | Unit test code generation method, device, equipment and storage medium | |
CN116414689A (en) | Interface parameter verification method and system based on reflection mechanism | |
CN117667884A (en) | Data migration method, device, equipment and storage medium | |
CN116466927A (en) | Code generation method, system, electronic device and storage medium for batch processing task | |
CN116185389A (en) | Code generation method and device, electronic equipment and medium | |
CN115543428A (en) | Simulated data generation method and device based on strategy template | |
CN114371886A (en) | Front-end frame assembly conversion method and device, computer equipment and storage medium |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |