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
- schema
- oas
- file
- information
- 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 48
- 238000013499 data model Methods 0.000 claims abstract description 103
- 238000010586 diagram Methods 0.000 claims description 93
- 238000004590 computer program Methods 0.000 claims description 13
- 230000008569 process Effects 0.000 claims description 9
- 239000000284 extract Substances 0.000 claims description 7
- 238000011161 development Methods 0.000 abstract description 7
- 238000012423 maintenance Methods 0.000 abstract description 6
- 238000012986 modification Methods 0.000 description 8
- 230000004048 modification Effects 0.000 description 8
- 230000004044 response Effects 0.000 description 8
- 238000012545 processing Methods 0.000 description 7
- 238000005516 engineering process Methods 0.000 description 5
- 230000003993 interaction Effects 0.000 description 4
- 230000003287 optical effect Effects 0.000 description 4
- 230000000694 effects Effects 0.000 description 3
- 238000013507 mapping Methods 0.000 description 3
- 230000002452 interceptive effect Effects 0.000 description 2
- 230000002093 peripheral effect Effects 0.000 description 2
- 238000007430 reference method Methods 0.000 description 2
- 230000003068 static effect Effects 0.000 description 2
- 238000010200 validation analysis Methods 0.000 description 2
- 238000007792 addition Methods 0.000 description 1
- 230000002776 aggregation Effects 0.000 description 1
- 238000004220 aggregation Methods 0.000 description 1
- 238000003491 array 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
- 230000008878 coupling Effects 0.000 description 1
- 238000010168 coupling process Methods 0.000 description 1
- 238000005859 coupling reaction Methods 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
- 230000006870 function Effects 0.000 description 1
- 230000010354 integration Effects 0.000 description 1
- 238000007726 management method Methods 0.000 description 1
- 238000004904 shortening Methods 0.000 description 1
- 238000012360 testing method Methods 0.000 description 1
- 238000012546 transfer 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
Description
技术领域Technical field
本申请涉及软件开发技术领域,具体而言,本申请涉及一种OAS Schema的生成方法、装置、设备及介质。This application relates to the technical field of software development. Specifically, this application relates to a method, device, equipment and medium for generating OAS Schema.
背景技术Background technique
随着现代社会科学技术的发展,计算机系统已经成为各行各业所不可缺少的工具,而在其中起着核心作用的,则是计算机软件系统。随着软件系统在各行各业的日益渗透,其变得日益庞大,自身的问题也是越来越严重。现在的一个应用,常常会由几十人编写几十万到几百万行代码来完成。另一方面,应用是在一个不断变化的动态环境中生存和发展的,因此,应用就需要不断地维护——即部分地改写应用的一部分或新增功能。With the development of science and technology in modern society, computer systems have become indispensable tools in all walks of life, and computer software systems play a core role in them. As software systems increasingly penetrate into all walks of life, they become increasingly larger and their own problems become more and more serious. Today's applications are often completed by dozens of people writing hundreds of thousands to millions of lines of code. On the other hand, applications survive and develop in an ever-changing dynamic environment. Therefore, applications require constant maintenance—that is, partial rewriting of parts of the application or new features.
在软件开发领域,随着应用规模的不断扩大,各个部分之间的集成和交互变得越来越复杂,要求也越来越高。RESTful(英文:Representational State Transfer,简称REST,REST指的是一组架构约束条件和原则。满足这些约束条件和原则的应用程序或设计就是RESTful)由于其特有的平台无关、编程语言无关、结构清晰、易于理解、扩展方便等特性,正在被越来越多的厂商使用。其中,OpenAPI Specification(OAS,接口定义规范)。也被称为Swagger规范,是一种用于描述和定义RESTful Web服务的标准规范。它提供了一种统一的方式来描述API(应用程序编程接口)的结构、操作和交互,使得开发人员、API提供者和消费者能够更好地理解和使用API。In the field of software development, as the scale of applications continues to expand, the integration and interaction between various parts become more and more complex and demanding. RESTful (English: Representational State Transfer, REST for short, REST refers to a set of architectural constraints and principles. Applications or designs that meet these constraints and principles are RESTful) due to its unique platform-independent, programming language-independent, and clear structure , easy to understand, easy to expand and other features, are being used by more and more manufacturers. Among them, OpenAPI Specification (OAS, interface definition specification). Also known as the Swagger specification, it is a standard specification for describing and defining RESTful web services. It provides a unified way to describe the structure, operation and interaction of APIs (Application Programming Interfaces), allowing developers, API providers and consumers to better understand and use APIs.
OAS Schema(OAS数据模型)在OAS中被广泛用于描述资源、请求参数和响应体的数据模型,通过OAS Schema可以定义资源的属性、数据类型、验证规则等,以确保API的请求和响应数据的准确性和一致性。然而,现有的OAS Schema是手工编写的,这需要花费大量的时间和精力,并且容易出现错误和与领域模型不一致的情况,导致需要多次修改和维护,降低了软件开发效率。OAS Schema (OAS data model) is widely used in OAS to describe the data model of resources, request parameters and response bodies. Through OAS Schema, you can define resource attributes, data types, validation rules, etc. to ensure API request and response data. accuracy and consistency. However, the existing OAS Schema is written manually, which takes a lot of time and effort, and is prone to errors and inconsistencies with the domain model, resulting in the need for multiple modifications and maintenance, which reduces software development efficiency.
发明内容Contents of the invention
本申请实施例提供了一种OAS Schema的生成方法、装置、设备及介质,可以解决现有的OAS Schema手工编写花费时间长,精力消耗大且容易出现错误和偏差问题。为了实现该目的,本申请实施例提供了如下几个方案。Embodiments of the present application provide an OAS Schema generation method, device, equipment, and medium, which can solve the existing problems that manual writing of OAS Schema takes a long time, consumes a lot of energy, and is prone to errors and deviations. In order to achieve this goal, the embodiments of this application provide the following solutions.
根据本申请实施例的一个方面,提供了一种OAS Schema的生成方法,该方法包括:According to one aspect of the embodiment of the present application, a method for generating OAS Schema is provided, which method includes:
解析类图文件,并从解析后的文件中获取与类相关的信息,所述信息包括与各个类分别对应的列表、类的属性以及类之间的关系信息;Parse the class diagram file, and obtain class-related information from the parsed file, where the information includes a list corresponding to each class, attributes of the class, and relationship information between classes;
根据所述与类相关的信息生成OAS的数据模型。Generate a data model of the OAS based on the class-related information.
在一个可能的实现方式中,所述解析类图文件,并从解析后的文件中获取与类相关的信息,包括:In a possible implementation, the class diagram file is parsed and class-related information is obtained from the parsed file, including:
调用预设的解析对象解析所述类图文件,得到可处理数据结构的目标文件,所述解析对象包括所述类图文件对应的解析器或库;Call a preset parsing object to parse the class diagram file to obtain a target file that can process the data structure. The parsing object includes a parser or library corresponding to the class diagram file;
从所述目标文件中提取与类相关的信息。Extract class-related information from the object file.
在一个可能的实现方式中,所述根据所述与类相关的信息生成OAS的数据模型,包括:In a possible implementation, generating an OAS data model based on the class-related information includes:
基于所述与类相关的信息调用预设OAS自动生成程序,生成数据模型,该数据模型中包括多个与类一一对应的Schema对象;Based on the information related to the class, call the preset OAS automatic generation program to generate a data model. The data model includes multiple Schema objects corresponding to the class one-to-one;
基于所述与类相关的信息确定所述数据模型中各Schema对象的第一信息;所述第一信息包括类名、类型以及属性列表的文本信息;Determine the first information of each Schema object in the data model based on the class-related information; the first information includes text information of class name, type and attribute list;
基于所述与类相关的信息确定所述数据模型中各Schema对象的第二信息,所述第二信息包括类的属性名称、数据类型、属性的约束以及与各类对应的Schema对象之间的引用关系对应的文本信息。The second information of each Schema object in the data model is determined based on the class-related information. The second information includes the attribute name, data type, attribute constraints of the class, and the relationship between the Schema objects corresponding to each type. Text information corresponding to the reference relationship.
在一个可能的实现方式中,所述基于所述与类相关的信息确定所述数据模型中各Schema对象的第一信息,包括:In a possible implementation, determining the first information of each Schema object in the data model based on the class-related information includes:
根据所述与类相关的信息在所述Schema对象的文本信息中定义类的名称、类型以及属性列表。The name, type and attribute list of the class are defined in the text information of the Schema object according to the class-related information.
在一个可能的实现方式中,所述基于所述与类相关的信息确定所述数据模型中各Schema对象的第二信息,包括:In a possible implementation, determining the second information of each Schema object in the data model based on the class-related information includes:
根据所述属性名称确定对应的Schema对象中类的属性名称、数据类型,并对所述Schema对象中属性的约束进行处理;Determine the attribute name and data type of the class in the corresponding Schema object according to the attribute name, and process the constraints of the attributes in the Schema object;
根据所述关系信息确定所述Schema对象之间的引用关系。Determine the reference relationship between the Schema objects based on the relationship information.
在一个可能的实现方式中,所述根据所述与类相关的信息生成OAS的数据模型,包括:In a possible implementation, generating an OAS data model based on the class-related information includes:
针对所述数据模型中的每个Schema对象生成对应的定义文件,保存所述定义文件和所述数据模型;Generate a corresponding definition file for each Schema object in the data model, and save the definition file and the data model;
或,根据数据模型中的每个Schema对象生成OAS文件,所述OAS文件包括每个Schema对象对应的定义。Or, generate an OAS file according to each Schema object in the data model, and the OAS file includes the definition corresponding to each Schema object.
在一个可能的实现方式中,所述方法,还包括:In a possible implementation, the method further includes:
检测所述类图文件是否发生变化,所述变化包括所述类图文件中类的新增、删除、修改中的至少一种;Detect whether the class diagram file has changed, and the changes include at least one of adding, deleting, and modifying classes in the class diagram file;
若确定所述类图文件发生变化,解析所述类图文件获取与类相关的信息,根据所述与类相关的信息更新已生成的数据模型或对新增的类生成新的数据模型,并同步更新已生成的OAS文件。If it is determined that the class diagram file has changed, parse the class diagram file to obtain class-related information, update the generated data model according to the class-related information or generate a new data model for the newly added class, and Synchronously update the generated OAS files.
本申请提供一种OAS Schema的生成装置,所述装置,包括:This application provides a device for generating OAS Schema. The device includes:
类图文件解析模块,用于解析类图文件解析类图文件,并从解析后的文件中获取与类相关的信息,所述信息包括与各个类分别对应的列表、类的属性以及类之间的关系信息;The class diagram file parsing module is used to parse the class diagram file, and obtain the class-related information from the parsed file. The information includes the list corresponding to each class, the attributes of the class, and the relationships between classes. relationship information;
数据模型生成模块,用于遍历所述与类相关的信息生成OAS的数据模型。A data model generation module is used to traverse the class-related information to generate a data model of the OAS.
本申请提供一种电子设备,包括存储器、处理器及存储在存储器上的计算机程序,其特征在于,所述处理器执行所述计算机程序以实现如上所述方法的步骤。The present application provides an electronic device, including a memory, a processor, and a computer program stored on the memory, wherein the processor executes the computer program to implement the steps of the above method.
根据本申请实施例的再一个方面,提供了一种计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如上所述方法的步骤。According to yet another aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the steps of the above method are implemented.
本申请实施例提供的技术方案带来的有益效果是:The beneficial effects brought by the technical solutions provided by the embodiments of this application are:
本申请提供的OAS Schema的生成方法解析类图文件,从解析后的文件中获取与类相关的信息,根据该信息中与各个类分别对应的列表、类的属性以及类之间的关系生成OASSchema。本申请实施例对类图文件进行解析,根据解析结果生成OAS Schema。因此,本申请实施例利用类图文件自动化生成OAS Schema,降低手动编写和维护的工作量,耗时短,提高了开发效率,并能够快速迭代和修改,减少OAS Schema与领域模型不一致的可能。The OAS Schema generation method provided by this application parses the class diagram file, obtains class-related information from the parsed file, and generates OAS Schema based on the list corresponding to each class in the information, the attributes of the class, and the relationship between classes. . The embodiment of this application parses the class diagram file and generates OAS Schema based on the parsing results. Therefore, the embodiment of the present application uses class diagram files to automatically generate OAS Schema, reducing the workload of manual writing and maintenance, shortening the time, improving development efficiency, and enabling rapid iteration and modification, reducing the possibility of inconsistency between the OAS Schema and the domain model.
附图说明Description of the drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对本申请实施例描述中所需要使用的附图作简单的介绍。In order to explain the technical solutions in the embodiments of the present application more clearly, the drawings needed to be used in the description of the embodiments of the present application will be briefly introduced below.
图1为本申请实施例提供的OAS Schema的生成方法的流程图;Figure 1 is a flow chart of the OAS Schema generation method provided by the embodiment of the present application;
图2为本申请提供的OAS Schema的生成方法另一实施例的流程图;Figure 2 is a flow chart of another embodiment of the OAS Schema generation method provided by this application;
图3为本申请OAS Schema的生成方法一实施例的序列图;Figure 3 is a sequence diagram of an embodiment of the OAS Schema generation method of this application;
图4为本申请实施例提供的用于生成OAS Schema的类图文件的示意图;Figure 4 is a schematic diagram of a class diagram file used to generate OAS Schema provided by an embodiment of the present application;
图5为本申请实施例提供的OAS Schema的生成装置的结构图;Figure 5 is a structural diagram of an OAS Schema generation device provided by an embodiment of the present application;
图6为本申请实施例提供的电子设备的结构图。Figure 6 is a structural diagram of an electronic device provided by an embodiment of the present application.
具体实施方式Detailed ways
下面结合本申请中的附图描述本申请的实施例。应理解,下面结合附图所阐述的实施方式,是用于解释本申请实施例的技术方案的示例性描述,对本申请实施例的技术方案不构成限制。The 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 in conjunction with the accompanying drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application, and do not limit the technical solutions of the embodiments of the present application.
本技术领域技术人员可以理解,除非特意声明,这里使用的单数形式“一”、“一个”、“所述”和“该”也可包括复数形式。应该进一步理解的是,本申请实施例所使用的术语“包括”以及“包含”是指相应特征可以实现为所呈现的特征、信息、数据、步骤、操作、元件和/或组件,但不排除实现为本技术领域所支持其他特征、信息、数据、步骤、操作、元件、组件和/或它们的组合等。应该理解,当我们称一个元件被“连接”或“耦接”到另一元件时,该一个元件可以直接连接或耦接到另一元件,也可以指该一个元件和另一元件通过中间元件建立连接关系。此外,这里使用的“连接”或“耦接”可以包括无线连接或无线耦接。这里使用的术语“和/或”指示该术语所限定的项目中的至少一个,例如“A和/或B”指示实现为“A”,或者实现为“A”,或者实现为“A和B”。Those skilled in the art will understand that, unless expressly stated otherwise, the singular forms "a", "an", "the" and "the" used herein may also include the plural form. It should be further understood that the terms "comprising" and "including" used in the embodiments of this application mean that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and/or components, but do not exclude Implementation is other features, information, data, steps, operations, elements, components and/or their combinations supported by the technical field. It should be understood that when we refer to an element being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element, or one element and the other element may be connected to the other element through intervening elements. Establish connections. Additionally, "connected" or "coupled" as used herein may include wireless connections or wireless couplings. The term "and/or" as used herein indicates at least one of the items defined by the term, for example, "A and/or B" indicates implemented as "A", or implemented as "A", or implemented as "A and B" ".
为使本发明的目的、技术方案和优点更加清楚,下面将结合附图对本发明实施方式做进一步的详细描述。In order to make the purpose, technical solutions and advantages of the present invention clearer, the embodiments of the present invention will be described in further detail below with reference to the accompanying drawings.
下面通过对几个示例性实施方式的描述,对本发明实施例的技术方案以及本发明的技术方案产生的技术效果进行说明。需要指出的是,下述实施方式之间可以相互参考、借鉴或结合,对于不同实施方式中相同的术语、相似的特征以及相似的实施步骤等,不再重复描述。The following describes the technical solutions of the embodiments of the present invention and the technical effects produced by the technical solutions of the present invention through the description of several exemplary embodiments. It should be noted that the following embodiments can be referred to, borrowed from, or combined with each other. The same terms, similar features, and similar implementation steps in different embodiments will not be repeatedly described.
OAS基于JSON或YAML格式,提供了一组结构化的规范和约定,用于定义API的各个方面,包括资源、路径、操作、参数、响应和安全性等。它的主要目标是使API文档易于理解、可读性强,并提供了一种交互式的方式来测试和调用API。Based on JSON or YAML format, OAS provides a set of structured specifications and conventions for defining various aspects of the API, including resources, paths, operations, parameters, responses, and security. Its main goal is to make API documentation easy to understand and readable, and to provide an interactive way to test and call APIs.
Schema在OAS中被广泛用于描述资源、请求参数和响应体的数据模型,通过Schema可以定义资源的属性、数据类型、验证规则等,以确保API的请求和响应数据的准确性和一致性。Schema is widely used in OAS to describe the data model of resources, request parameters and response bodies. Schema can be used to define resource attributes, data types, validation rules, etc. to ensure the accuracy and consistency of API request and response data.
在软件开发中,编写OAS的数据模型(Schema)是一个重要的任务。现有方案中,数据模型是手工编写的,然而手工编写数据模型存在以下问题。In software development, writing the OAS data model (Schema) is an important task. In the existing solution, the data model is written manually. However, there are the following problems in manually writing the data model.
1.错误和遗漏:手工编写数据模型容易出现错误和遗漏。人工操作容易犯错,可能会导致属性命名错误、数据类型错误或者缺少必要的字段。这些错误可能会导致API不能正确地解释或实现。1. Errors and omissions: Manually writing data models is prone to errors and omissions. Human errors are prone to errors, which may result in incorrectly named properties, wrong data types, or missing necessary fields. These errors may cause the API to not be interpreted or implemented correctly.
2.不一致性:在大型项目或团队中,手工编写Schema存在一致性的挑战。不同的开发人员可能有不同的编写风格和标准,导致Schema的格式和结构不一致。这使得维护和修改变得困难,并增加了理解和协作的难度。2. Inconsistency: In large projects or teams, there are consistency challenges in manually writing Schemas. Different developers may have different writing styles and standards, resulting in inconsistent format and structure of the Schema. This makes maintenance and modification difficult, and increases the difficulty of understanding and collaboration.
3.费时费力:手工编写Schema是一项耗时的任务。Schema可能包含大量的字段和复杂的数据类型,手动编写需要花费大量的时间和精力。此外,当领域模型发生更改时,手工更新和调整Schema也需要额外的时间和努力。3. Time-consuming and labor-intensive: Manually writing Schema is a time-consuming task. Schema may contain a large number of fields and complex data types, and manual writing requires a lot of time and effort. In addition, when the domain model changes, manually updating and adjusting the Schema also requires additional time and effort.
4.缺乏可靠性和扩展性:手工编写Schema缺乏自动化和可靠性。人工编写的Schema难以自动验证和检查,可能导致潜在的错误和问题无法及时发现。此外,当需要扩展和更新领域模型时,手工编写的Schema难以自动适应变化,可能需要进行大量的修改和调整。4. Lack of reliability and scalability: Manually written Schema lacks automation and reliability. Manually written Schema is difficult to automatically verify and check, which may result in potential errors and problems not being discovered 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.领域模型同步困难:手工编写的Schema与实际的领域模型之间的同步可能会存在困难。如果领域模型发生变化,需要手工更新Schema、API和领域模型以保持一致性,这需要额外的工作和管理。这可能导致API文档和实际领域模型之间的不一致,给用户和开发人员带来困惑。5. Difficulty in domain model synchronization: There may be difficulties in synchronization between the manually written Schema and the actual domain model. If the domain model changes, the Schema, API, and domain model need to be manually updated to maintain consistency, which requires additional work and management. This can lead to inconsistencies between the API documentation and the actual domain model, causing confusion for users and developers.
本申请提供的OAS Schema的生成方法、装置、设备以及存储介质,旨在解决现有技术中存在的至少一个技术问题。The OAS Schema generation method, device, equipment and storage medium provided by this application are intended to solve at least one technical problem existing in the existing technology.
本申请实施例中提供了一种OAS Schema的生成方法,应用该方法的设备可以为手机、电脑、服务器、云平台以及其他能够用于数据模型生成的设备。如图1所示,该OASSchema(下面简称数据模型)的生成方法包括步骤S101-S102。Embodiments of this application provide a method for generating OAS Schema. Devices applying this method can be mobile phones, computers, servers, cloud platforms, and other devices that can be used for data model generation. As shown in Figure 1, the generation method of the OASSchema (hereinafter referred to as the data model) includes steps S101-S102.
S101:解析类图文件,并从解析后的文件中获取与类相关的信息。S101: Parse the class diagram file and obtain class-related information from the parsed file.
可选地,类图文件可以为PlantUML类图文件,也可以为序列图、用例图、活动图以及其他基于PlantUML技术的用于描述类信息的文件。其中,PlantUML是一种开源的绘图工具,它允许用户使用简单的文本描述来生成各种类型的图表,如类图、时序图、用例图、活动图等。它采用了基于文本的标记语言,使得图表的创建过程更加简单和可维护。Optionally, the class diagram file can be a PlantUML class diagram file, or it can be a sequence diagram, use case diagram, activity diagram, or other files based on PlantUML technology for describing class information. Among them, PlantUML is an open source drawing tool that allows users to use simple text descriptions to generate various types of diagrams, such as class diagrams, sequence diagrams, use case diagrams, activity diagrams, etc. It uses a text-based markup language to make the chart creation process easier and maintainable.
可选地,在解析类图文件前,执行该生成方法的设备可以根据输入的文件选择指令确定需要解析的类图文件,也可以根据输入的指令开启生成数据模型的工具,将输入该工具的类图文件确定为需要解析的类图文件。还可以根据使用对象的查询操作或输入的网址等标识类图文件所在位置的信息获取类图文件。Optionally, before parsing the class diagram file, the device executing the generation method can determine the class diagram file that needs to be parsed according to the input file selection instruction, or can open a tool for generating the data model according to the input instruction, and input the data into the tool. The class diagram file is determined to be the class diagram file that needs to be parsed. The class diagram file can also be obtained based on information identifying the location of the class diagram file, such as a query operation using the object or an input URL.
可选地,获取类图文件后,调用预设的解析对象(一些解析工具)解析类图文件,其中该解析对象为解析器或库。Optionally, after obtaining the class diagram file, call a preset parsing object (some parsing tool) to parse the class diagram file, where the parsing object is a parser or library.
在一个实施例中,该解析对象包括PlantUML Parser、Puml2Json、PlantUML ClassDiagram Parser中的至少一种。In one embodiment, the parsing object includes at least one of PlantUML Parser, Puml2Json, and PlantUML ClassDiagram Parser.
可选地,与类相关的信息可以包括与各个类分别对应的列表、类的属性以及类之间的关系信息,该列表可以包括类名、类型等与类相关的信息。并且,为了便于后续处理通过预设的解析结构将类图文件解析为一种为可处理数据结构的目标文件。Optionally, the class-related information may include a list corresponding to each class, attributes of the class, and relationship information between classes. The list may include class names, types and other class-related information. Moreover, in order to facilitate subsequent processing, the class diagram file is parsed into a target file that is a processable data structure through a preset parsing structure.
在一个实施例中,可处理的数据结构可以为树形结构或JSON格式,该数据结构包括类名的列表、类的属性以及类的关系信息。该关系信息包括类之间的关系信息,如一对多的关系、一对一的关系、继承关系等。In one embodiment, the processable data structure may be a tree structure or JSON format, and the data structure includes a list of class names, attributes of the class, and relationship information of the class. The relationship information includes relationship information between classes, such as one-to-many relationship, one-to-one relationship, inheritance relationship, etc.
在一个示例中,关系信息如下:In one example, the relationship information is as follows:
Person "1" *-->"1..*" Address: personAddressPerson "1" *-->"1..*" Address: personAddress
其包括以下内容:It includes the following:
主类名称:PersonMain class name: Person
被关联类名称: AddressAssociated class name: Address
类之间的关系名称:personAddressRelationship name between classes: personAddress
关联的数量限制规则:一个人可以包含1到多个地址,一个地址只能属于一个人。Association quantity limit rules: A person can contain 1 to multiple addresses, and an address can only belong to one person.
S102:遍历与类相关的信息生成OAS的数据模型。S102: Traverse the class-related information to generate the OAS data model.
可选地,遍历与类相关的信息生成OAS的数据模型,包括:基于与类相关的信息调用预设OAS自动生成程序,生成数据模型,该数据模型中包括多个与类一一对应的Schema对象(类和Schema对象的数量一致);基于与类相关的信息确定数据模型中各Schema对象的第一信息;第一信息包括类名、类型以及属性列表对应的文本信息;基于与类相关的信息确定数据模型中各Schema对象的第二信息,第二信息包括数据模型的属性名称、数据类型、数据模型中属性的约束以及与各类对应的Schema对象之间的引用关系对应的文本信息。Optionally, traverse the class-related information to generate an OAS data model, including: calling a preset OAS automatic generation program based on the class-related information to generate a data model. The data model includes multiple Schemas corresponding to the class one-to-one. Objects (the number of classes and Schema objects is the same); determine the first information of each Schema object in the data model based on the information related to the class; the first information includes text information corresponding to the class name, type and attribute list; based on the class-related information The information determines the second information of each Schema object in the data model. The second information includes the attribute name of the data model, the data type, the constraints of the attributes in the data model, and the text information corresponding to the reference relationship between various corresponding Schema objects.
在一个实施例中,根据与类相关的信息创建对应的数据模型(即OAS Schema),该数据Schema对象包括多个Schema对象,并且利用该与类相关的信息定义每个Schema对象中类的名称、类型(object)以及属性。在完成定义后,获取类的属性名称,将该类型的信息映射到数据模型的Schema对象中,确定Schema对象的属性名称(如根据类的属性名称确定数据模型支持的数据类型,如字符串、数字、布尔值等)。并根据与类相关的信息相应处理属性的约束,如最大长度、枚举值等,根据解析结果中的关系信息相应设置Schema对象之间的引用关系。In one embodiment, a corresponding data model (ie, OAS Schema) is created based on class-related information. The data Schema object includes multiple Schema objects, and the class-related information is used to define the name of the class in each Schema object. , type (object) and attributes. After completing the definition, obtain the attribute name of the class, map this type of information to the Schema object of the data model, and determine the attribute name of the Schema object (such as determining the data type supported by the data model based on the attribute name of the class, such as string, numbers, Boolean values, etc.). And according to the information related to the class, the constraints of the attributes, such as maximum length, enumeration value, etc., are correspondingly processed, and the reference relationship between Schema objects is set accordingly according to the relationship information in the parsing result.
本申请实施例利用类图文件自动化生成OAS Schema,减少了手动编写和维护的工作量,耗时短,提高了开发效率,并能够快速迭代和修改,减少OAS Schema与领域模型不一致的可能。The embodiment of this application uses class diagram files to automatically generate OAS Schema, which reduces the workload of manual writing and maintenance, shortens the time consumption, improves development efficiency, and enables rapid iteration and modification, reducing the possibility of inconsistency between the OAS Schema and the domain model.
可选地,本申请还提出一种OAS Schema的生成方法,如图2-图4所示,该方法包括:Optionally, this application also proposes a method for generating OAS Schema, as shown in Figures 2-4. The method includes:
S201:调用预设的解析对象解析类图文件,得到可处理数据结构的目标文件。S201: Call the preset parsing object to parse the class diagram file and obtain a target file that can process the data structure.
可选地,使用对象输入类图文件,该类图文件为与数据模型相关的文件,包括数据模型相关的各个类的信息,设备接收该类图文件后,调用预设的解析对象解析该类图文件。其中,该解析对象包括PlantUML Parser、Puml2Json、PlantUML Class Diagram Parser中的至少一种。Optionally, use an object to input a class diagram file. The class diagram file is a file related to the data model, including information about each class related to the data model. After the device receives the class diagram file, it calls the preset parsing object to parse the class. Picture file. Wherein, the parsing object includes at least one of PlantUML Parser, Puml2Json, and PlantUML Class Diagram Parser.
可选地,设备可以获取输入的类图文件的名称、编号、格式以及其他能够标识解析对象的信息,根据该信息确定该类图文件对应的解析对象,调用该解析对象执行解析操作。Optionally, the device can obtain the name, number, format and other information that can identify the parsing object of the input class diagram file, determine the parsing object corresponding to the class diagram file based on the information, and call the parsing object to perform the parsing operation.
在一个实施例中,类图文件为PlantUML类图文件,接收该类图文件,并调用该类图文件对应的解析对象,得到该类图文件的解析结果。In one embodiment, the class diagram file is a PlantUML class diagram file. The class diagram file is received, and the parsing object corresponding to the class diagram file is called to obtain the parsing result of the class diagram file.
可选地,作为解析结果的目标文件使用可处理数据结构,该结构可根据实际需求和解析对象的类型进行设置,该可处理数据结构包括类的列表、类的属性信息以及类之间的关系信息。Optionally, the target file as the parsing result uses a processable data structure, which can be set according to actual needs and the type of the parsed object. The processable data structure includes a list of classes, attribute information of the classes, and relationships between classes. information.
在一个实施例中,可处理数据结构可以为树形结构、JSON格式中的任一种。In one embodiment, the processable data structure may be any of a tree structure and a JSON format.
S202:从目标文件中提取与类相关的信息。S202: Extract class-related information from the target file.
可选地,通过目标文件提取类的列表以及类的属性、关系信息。关系信息包括两个类之间的关系信息,比如一对多的关系,一对一的关系、继承关系等。Optionally, extract the list of classes and their attributes and relationship information from the target file. Relationship information includes relationship information between two classes, such as one-to-many relationship, one-to-one relationship, inheritance relationship, etc.
在一个实施例中,提取的与类相关的信息中关系信息为:Person "1" *-->"1..*"Address: personAddress,该关系信息包括以下内容:In one embodiment, the relationship information in the extracted class-related information is: Person "1" *-->"1..*"Address: personAddress, and the relationship information includes the following:
主类名称:PersonMain class name: Person
被关联类名称: AddressAssociated class name: Address
类之间的关系名称:personAddressRelationship name between classes: personAddress
关联的数量限制规则:一个人可以包含1到多个地址,一个地址只能属于一个人。Association quantity limit rules: A person can contain 1 to multiple addresses, and an address can only belong to one person.
可选地,在使用解析对象解析类图文件得到目标文件后,使用提取器提取与类相关的信息,该提取器根据目标文件的数据结构提取信息。Optionally, after using the parsing object to parse the class diagram file to obtain the target file, use an extractor to extract class-related information, and the extractor extracts information according to the data structure of the target file.
S203:基于与类相关的信息调用预设OAS自动生成程序,生成数据模型,基于与类相关的信息确定数据模型中各Schema对象的第一信息,基于与类相关的信息确定数据模型中各Schema对象的第二信息。S203: Call the preset OAS automatic generation program based on the information related to the class to generate the data model, determine the first information of each Schema object in the data model based on the information related to the class, and determine each Schema in the data model based on the information related to the class. Secondary information about the object.
可选地,第一信息包括类的名称、类型以及类的属性列表对应的文本信息,第二信息包括数据模型的属性名称、数据类型、属性的约束以及类对应的引用关系。其中,数据模型由多个Schema对象组成,通过对Schema对象相关的第一信息、第二信息的处理得到最终的数据模型。Optionally, the first information includes the name, type, and text information corresponding to the attribute list of the class, and the second information includes the attribute name, data type, attribute constraints of the data model, and the reference relationship corresponding to the class. Among them, the data model consists of multiple Schema objects, and the final data model is obtained by processing the first information and the second information related to the Schema objects.
可选地,基于与类相关的信息确定数据模型中各Schema对象的第一信息,包括:根据与类相关的信息在每个Schema对象的文本信息中定义类的名称、类型以及属性列表。Optionally, determining the first information of each Schema object in the data model based on the class-related information includes: defining the name, type, and attribute list of the class in the text information of each Schema object based on the class-related information.
在一个实施例中,目标文件中的每个类可以表示为一个OAS的Schema对象。根据提取的信息(可以为类的列表)创建对应的Schema对象,并在该Schema对象生成类的名称、类型(object)以及属性列表的文本信息。具体的,根据与类相关的信息,调用预设程序生成对应的Schema对象的文本内容,该文本内容包括类的名称、类型(object)以及属性,其中将类的名称作为Schema对象的名称。其中,预设程序可以为OAS自动生成程序。In one embodiment, each class in the target file can be represented as an OAS Schema object. Create a corresponding Schema object based on the extracted information (which can be a list of classes), and generate the text information of the class name, type (object), and attribute list in the Schema object. Specifically, according to the information related to the class, the preset program is called to generate the text content of the corresponding Schema object. The text content includes the name, type (object) and attributes of the class, where the name of the class is used as the name of the Schema object. Among them, the preset program can automatically generate programs for OAS.
具体的,基于上述实施例中与类相关的信息(其关系信息设为:Person "1" *-->"1..*" Address: personAddress)创建的一个Schema对象的定义如下:Specifically, the definition of a Schema object created based on the class-related information in the above embodiment (the relationship information is set to: Person "1" *-->"1..*" Address: personAddress) is as follows:
components:components:
schemas:schemas:
Person:Person:
type: object 这个类型目前都是固定的Object。type: object This type is currently fixed Object.
properties: 属性是指类的属性。properties: Properties refer to the attributes of the class.
id:ID:
type: stringtype: string
name:name:
type: stringtype: string
其中,除了生成Schema对象Person以及对应的文本信息,还生成Schema对象PersonAddress及PersonAddress对应的文本信息。Among them, in addition to generating Schema object Person and corresponding text information, Schema object PersonAddress and text information corresponding to PersonAddress are also generated.
在一个实施例中,可以使用Schema generator(模式生成器)创建类的定义和属性,并使用该模式生成器确定数据模型的属性名称以及属性的约束关系。In one embodiment, a Schema generator can be used to create class definitions and attributes, and the Schema generator can be used to determine the attribute names of the data model and the constraint relationships of the attributes.
可选地,基于与类相关的信息确定数据模型中各Schema对象的第二信息,包括:根据属性名称确定对应的Schema对象的属性名称、数据类型,并对属性的约束进行处理;根据关系信息确定Schema对象之间的引用关系。Optionally, determine the second information of each Schema object in the data model based on the information related to the class, including: determining the attribute name and data type of the corresponding Schema object according to the attribute name, and processing the constraints of the attributes; according to the relationship information Determine the reference relationship between Schema objects.
在一个实施例中,将类图文件中类的属性名称映射到对应的Schema对象中,以确定该Schema对象的属性名称。基于该属性名称确定该Schema对象支持的数据类型,如字符串、数字、布尔值等。同时,处理属性的约束,如最大长度、枚举值等。具体的,类图文件中的属性名称String对应到创建的Schema对象中为string,类图文件中的属性名称Long对应到Schema对象中属性名称为string等,根据预设的映射关系进行属性名称的映射。可以在使用程序(如OAS自动生成程序)生成Schema对象中属性相关的文本时根据映射关系进行替换。In one embodiment, the attribute names of the classes in the class diagram file are mapped to the corresponding Schema objects to determine the attribute names of the Schema objects. Determine the data types supported by the Schema object based on the attribute name, such as strings, numbers, Boolean values, etc. At the same time, handle constraints on attributes, such as maximum length, enumeration values, etc. Specifically, the attribute name String in the class diagram file corresponds to the created Schema object as string, the attribute name Long in the class diagram file corresponds to the attribute name in the Schema object as string, etc. The attribute names are determined according to the preset mapping relationship. mapping. It can be replaced based on the mapping relationship when using a program (such as the OAS automatic generation program) to generate text related to attributes in the Schema object.
在一个示例中:In an example:
PlantUML类图文件中的Person是这样的:The Person in the PlantUML class diagram file looks like this:
class Person<<Resource>>{class Person<<Resource>>{
{field}id: String{field}id: String
{field}name: String{field}name: String
}}
其中,属性名称为String,根据该属性名称相应定义Schema对象中的属性名称为:Among them, the attribute name is String, and the attribute name in the Schema object is defined accordingly according to the attribute name:
components:components:
schemas:schemas:
Person:Person:
type: objecttype: object
properties:properties:
id:ID:
type: stringtype: string
name:name:
type: stringtype: string
在另一个示例中,类图文件中属性名称为:{field}id: String,该类型对应的Schema对象中属性名称对应的描述文本则为:In another example, the attribute name in the class diagram file is: {field}id: String, and the description text corresponding to the attribute name in the Schema object corresponding to this type is:
properties:properties:
id:ID:
type: stringtype: string
可选地,因类图文件中类之间可能存在关联关系(如聚合、继承、关联等),在数据模型中可以使用引用($ref)来表示类之间的关联关系。根据类图中的关系信息,生成对应的引用关系,并在Schema对象中使用$ref进行引用。Optionally, because there may be associations between classes in the class diagram file (such as aggregation, inheritance, association, etc.), references ($ref) can be used in the data model to represent the associations between classes. Based on the relationship information in the class diagram, the corresponding reference relationship is generated and referenced using $ref in the Schema object.
在一个实施例中,使用Reference Handler(引用处理程序)获取类图文件中类之间的关系信息,根据该关系信息对应生成Schema对象之间的引用关系。In one embodiment, a Reference Handler (reference handler) is used to obtain relationship information between classes in the class diagram file, and reference relationships between Schema objects are correspondingly generated based on the relationship information.
可选地,为了实现对数据模型的存储调用以及实现OAS文件的快速生成,遍历与类相关的信息生成OAS的数据模型,包括:针对数据模型中的每个Schema对象生成对应的定义文件,保存定义文件和数据模型;或,根据数据模型中的每个Schema对象生成OAS文件,OAS文件包括每个Schema对象对应的定义。Optionally, in order to realize the storage call of the data model and the rapid generation of OAS files, traverse the class-related information to generate the OAS data model, including: generating a corresponding definition file for each Schema object in the data model, and saving Definition file and data model; or, generate an OAS file based on each Schema object in the data model. The OAS file includes the definition corresponding to each Schema object.
可选地,定义文件可以作为OAS文件的一部分,也可以相对于OAS文件独立保存,OAS文件保存该定义文件的引用方式。其中,该定义文件包括生成的Schema对象的定义,该定义包括用于对Schema对象进行增删改查等操作的接口的定义。Optionally, the definition file can be part of the OAS file, or can be saved independently from the OAS file, and the OAS file saves the reference method of the definition file. The definition file includes the definition of the generated Schema object, and the definition includes the definition of an interface for performing operations such as addition, deletion, modification, and query on the Schema object.
在一个实施例中,定义文件作为OAS文件的一部分,该OAS文件的示例如下:In one embodiment, the definition file is part of the OAS file. An example of the OAS file is as follows:
components:components:
schemas:schemas:
Person:Person:
type: objecttype: object
properties:properties:
id:ID:
type: stringtype: string
name:name:
type: stringtype: string
在另一个实施例中,定义文件单独保存为:Person_schemas.yaml:。相关的OAS文件为:Person_Management-v1.0.0.oas.yaml,该OAS文件还包括该定义文件的引用方式:In another embodiment, the definition file is saved separately as: Person_schemas.yaml:. The relevant OAS file is: Person_Management-v1.0.0.oas.yaml. The OAS file also includes the reference method of the definition file:
CuPerson:CuPerson:
type: objecttype: object
properties:properties:
id:ID:
type: stringtype: string
name:name:
type: stringtype: string
然后在Person_Management-v1.0.0.oas.yaml中进行引用:Then reference it in Person_Management-v1.0.0.oas.yaml:
paths:paths:
/persons:/persons:
get:get:
summary: Get all personssummary: Get all persons
responses:responses:
'200':'200':
description: A list of personsdescription: A list of persons
content:content:
application/json:application/json:
schema:Schema:
type: arraytype: array
items:items:
$ref: 'Person_schemas.yaml#/Person'$ref: 'Person_schemas.yaml#/Person'
可选地,保存定义文件时,若Schema对象的定义写入OAS文件,则只需保存该OAS文件,若数据模型的Schema对象单独保存,则需要同时保存相应的定义文件,如果每个Schema对象单独保存,则有多少Schema对象就有多少个定义文件。Optionally, when saving the definition file, if the definition of the Schema object is written to the OAS file, you only need to save the OAS file. If the Schema object of the data model is saved separately, the corresponding definition file needs to be saved at the same time. If each Schema object If saved separately, there will be as many definition files as there are Schema objects.
可选地,为了实现数据模型的快速迭代,检测类图文件是否发生变化,变化包括类图文件中类的新增、删除、修改中的至少一种;若确定类图文件发生变化,解析类图文件获取与类相关的信息,根据与类相关的信息生成新的数据模型。Optionally, in order to achieve rapid iteration of the data model, detect whether the class diagram file has changed. The changes include at least one of adding, deleting, and modifying classes in the class diagram file; if it is determined that the class diagram file has changed, parse the class diagram file. The graph file obtains class-related information and generates a new data model based on the class-related information.
下面结合图3对本申请的OAS Schema的生成方法作进一步说明。The OAS Schema generation method of this application will be further described below in conjunction with Figure 3.
如图3所示,使用者通过用户终端(如手机、电脑)提供PlantUML类图文件作为生成数据模型的文件。接收该类图文件后,使用预设的解析对象解析PlantUML类图文件,生成结构为可处理数据结构的目标文件。根据该数据结构从目标文件中提取类名、属性、关系信息。基于提取的信息对应生成数据模型的Schema对象,在Schema对象中创建类的定义和属性名称、数据类型,处理属性的约束,并对Schema对象之间的引用关系进行设置。数据模型的Schema对象创建完成后,向使用者返回生成的数据模型,保存该数据模型对应的OAS文件或定义文件。As shown in Figure 3, users provide PlantUML class diagram files as files for generating data models through user terminals (such as mobile phones and computers). After receiving the class diagram file, use the preset parsing object to parse the PlantUML class diagram file and generate a target file whose structure is a processable data structure. Extract class names, attributes, and relationship information from the target file according to the data structure. Generate a Schema object of the data model based on the extracted information, create class definitions, attribute names, and data types in the Schema object, process attribute constraints, and set reference relationships between Schema objects. 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.
在一个实施例中,PlantUML类图文件如图4所示,基于该类图文件生成的数据模型的示例为:In one embodiment, the PlantUML class diagram file is shown in Figure 4. An example of the data model generated based on the class diagram file is:
addresses:addresses:
type: arraytype: array
items:items:
$ref: '#/components/schemas/Address'$ref: '#/components/schemas/Address'
该数据模型很好地体现了PlantUML类图中一个人可以包含1到多个地址的关系。This data model well reflects the relationship in the PlantUML class diagram that a person can contain 1 to multiple addresses.
包括该数据模型的OpenAPI示例如下:An OpenAPI example that includes this data model is as follows:
openapi: 3.0.0openapi: 3.0.0
info:info:
title: Example APItitle: Example API
version: 1.0.0version: 1.0.0
paths:paths:
/persons:/persons:
get:get:
summary: Get all personssummary: Get all persons
responses:responses:
'200':'200':
description: Successful responsedescription: Successful response
content:content:
application/json:application/json:
schema:Schema:
type: arraytype: array
items:items:
$ref: '#/components/schemas/Person'$ref: '#/components/schemas/Person'
components:components:
schemas:schemas:
Person:Person:
type: objecttype: object
properties:properties:
id:ID:
type: stringtype: string
name:name:
type: stringtype: string
addresses:addresses:
type: arraytype: array
items:items:
$ref: '#/components/schemas/Address'$ref: '#/components/schemas/Address'
required:required:
- id-id
- name- name
Address:Address:
type: objecttype: object
properties:properties:
street:street:
type: stringtype: string
city:city:
type: stringtype: string
country:country:
type: stringtype: string
required:required:
- street- street
- city-city
- country-country
该OpenAPI示例定义了资源person相关的API接口,示例接口/persons获取所有Person的列表,返回内容是Person的列表,Person的定义引用Person Schema的定义,具体定于在本文件的 '#/components/schemas/Person'部分。This OpenAPI example defines the API interface related to the resource person. The example interface /persons obtains the list of all Persons, and the returned content is the list of Persons. The definition of Person refers to the definition of Person Schema, which is specified in '#/components/ of this file. schemas/Person' section.
在components的schemas部分定义了对象Person的schema,同时定义了Address以及Person和Address之间关系对象的schema。这些schema定义了对象的类型、名称、属性列表,对每个属性,定义了名称和类型。In the schemas part of components, the schema of the object Person is defined, and the schema of the Address and the relationship object between Person and Address are also defined. These schemas define the object's type, name, and attribute list. For each attribute, the name and type are defined.
components的schemas中定义的每个对象的schema,即本申请根据PlantUML类图自动生成的内容。The schema of each object defined in the schemas of components is what this application automatically generates based on the PlantUML class diagram.
区别于前述单独生成Schema对象并进行引用的方式,Person Schema还包含了对另一个数据模型Address Schema的引用。Different from the previous method of generating Schema objects separately and referencing them, Person Schema also contains a reference to another data model, Address Schema.
该示例展示了对Person Schema对象的查询接口(API)获取,通过该API可以查询获得所有person对象的列表,其中每个person对象的结构由Person Schema进行定义。This example shows the query interface (API) for obtaining Person Schema objects. Through this API, you can query and obtain a list of all person objects, where the structure of each person object is defined by Person Schema.
相比于现有技术,本申请的OAS Schema的生成方法具有以下优点:Compared with the existing technology, the OAS Schema generation method of this application has the following advantages:
1.提高开发效率:通过自动化生成OAS Schema,减少了手工编写和维护的工作量,提高了开发效率。1. Improve development efficiency: By automatically generating OAS Schema, the workload of manual writing and maintenance is reduced, and development efficiency is improved.
2.确保一致性:自动生成的OAS Schema与领域模型保持一致,避免了手动编写时可能出现的不一致性问题。2. Ensure consistency: The automatically generated OAS Schema is consistent with the domain model, avoiding inconsistencies that may occur when writing manually.
3.快速迭代和修改:由于基于PlantUML类图文件生成OAS Schema,可以轻松地进行迭代和修改,加快了开发过程。3. Rapid iteration and modification: Since OAS Schema is generated based on PlantUML class diagram files, iteration and modification can be easily carried out, speeding up the development process.
4.提高准确性:自动生成的OAS Schema的方式可以避免手动编写时可能出现的错误,提高了数据模型的准确性。4. Improve accuracy: The automatically generated OAS Schema method can avoid errors that may occur during manual writing and improve the accuracy of the data model.
需要说明的是,在本申请的可选实施例中,所涉及到的数据(如类图文件、数据模型、OAS Schema等数据),当本申请以上实施例运用到具体产品或技术中时,需要获得使用对象许可或者同意,且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准。也就是说,本申请实施例中如果涉及到与对象有关的数据,这些数据需要经由对象授权同意、且符合国家和地区的相关法律法规和标准的情况下获取的。It should be noted that in the optional embodiments of the present application, the data involved (such as class diagram files, data models, OAS Schema and other data), when the above embodiments of the present application are applied to specific products or technologies, It is necessary to obtain the permission or consent of the user, and the collection, use and processing of relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. That is to say, if the embodiments of this application involve data related to objects, these data need to be obtained with the authorization and consent of the objects and in compliance with relevant laws, regulations and standards of the country and region.
根据本申请的一个方面,本申请提供一种OAS Schema的生成装置,如图5所示,OASSchema的生成装置300包括类图文件解析模块310、数据模型生成模块320,其中,类图文件解析模块310,用于解析类图文件,并从解析后的文件中获取与类相关的信息,信息包括与各个类分别对应的列表、类的属性以及类之间的关系信息;数据模型生成模块320,用于根据与类相关的信息生成OAS的数据模型。According to one aspect of the present application, the present application provides an OAS Schema generation device. As shown in Figure 5, the OAS Schema generation device 300 includes a class diagram file parsing module 310 and a data model generation module 320, wherein the class diagram file parsing module 310, used to parse the class diagram file and obtain class-related information from the parsed file. The information includes a list corresponding to each class, attributes of the class, and relationship information between classes; data model generation module 320, Data model used to generate OAS based on class-related information.
可选地,解析类图文件,并从解析后的文件中获取与类相关的信息,包括:调用预设的解析对象解析类图文件,得到可处理数据结构的目标文件,解析对象包括类图文件对应的解析器或库;Optionally, parse the class diagram file and obtain class-related information from the parsed file, including: calling a preset parsing object to parse the class diagram file to obtain a target file that can process the data structure. The parsing object includes the class diagram. The parser or library corresponding to the file;
从目标文件中提取与类相关的信息,与类相关的信息包括类名、类的属性以及类的关系信息。Extract class-related information from the target file. Class-related information includes class name, class attributes, and class relationship information.
可选地,遍历与类相关的信息生成OAS的数据模型,包括:Optionally, traverse class-related information to generate an OAS data model, including:
基于与类相关的信息调用预设OAS自动生成程序,生成数据模型,该数据模型中包括多个与类一一对应的Schema对象;Based on the information related to the class, the preset OAS automatic generation program is called to generate a data model. The data model includes multiple Schema objects corresponding to the class one-to-one;
基于与类相关的信息确定数据模型中各Schema对象的第一信息;第一信息包括类名、类型以及属性列表的文本信息;Determine the first information of each Schema object in the data model based on the information related to the class; the first information includes text information of class name, type and attribute list;
基于与类相关的信息确定数据模型中各Schema对象的第二信息,第二信息包括数据模型的属性名称、数据类型、属性的约束以及与各类对应的Schema对象之间的引用关系对应的文本信息。The second information of each Schema object in the data model is determined based on the class-related information. The second information includes the attribute name, data type, attribute constraints of the data model, and the text corresponding to the reference relationship between various corresponding Schema objects. information.
可选地,基于与类相关的信息确定数据模型中各Schema对象的第一信息,包括:Optionally, determine the first information of each Schema object in the data model based on class-related information, including:
根据与类相关的信息在所述Schema对象的文本信息中定义类的名称、类型以及属性列表。The name, type and attribute list of the class are defined in the text information of the Schema object according to the information related to the class.
可选地,基于与类相关的信息确定数据模型中各Schema对象的第二信息,包括:根据属性名称确定对应的Schema对象中类的属性名称、数据类型,并对Schema对象中属性的约束进行处理;根据关系信息确定Schema对象之间的引用关系。Optionally, determining the second information of each Schema object in the data model based on the information related to the class includes: determining the attribute name and data type of the class in the corresponding Schema object based on the attribute name, and performing constraints on the attributes in the Schema object. Processing; determine the reference relationship between Schema objects based on the relationship information.
可选地,遍历与类相关的信息生成OAS的数据模型,包括:Optionally, traverse class-related information to generate an OAS data model, including:
针对数据模型中的每个Schema对象生成对应的定义文件,保存定义文件和数据模型;Generate a corresponding definition file for each Schema object in the data model, and save the definition file and data model;
或,根据数据模型中的每个Schema对象生成OAS文件,所述OAS文件包括每个Schema对象对应的定义。Or, generate an OAS file according to each Schema object in the data model, and the OAS file includes the definition corresponding to each Schema object.
可选地,还包括:检测类图文件是否发生变化,变化包括类图文件中类的新增、删除、修改中的至少一种;Optionally, the method also includes: detecting whether the class diagram file has changed, and the changes include at least one of adding, deleting, and modifying classes in the class diagram file;
若确定类图文件发生变化,解析类图文件获取与类相关的信息,根据所述与类相关的信息更新已生成的数据模型或对新增的类生成新的数据模型,并同步更新已生成的OAS文件。If it is determined that the class diagram file has changed, parse the class diagram file to obtain class-related information, update the generated data model based on the class-related information or generate a new data model for the newly added class, and synchronously update the generated data model. OAS file.
在一个可选实施例中,提供了一种电子设备,如图6所示,图6所示的电子设备4000包括:处理器4001和存储器4003。其中,处理器4001和存储器4003相连,如通过总线4002相连。可选地,电子设备4000还可以包括收发器4004,收发器4004可以用于该电子设备与其他电子设备之间的数据交互,如数据的发送和/或数据的接收等。需要说明的是,实际应用中收发器4004不限于一个,该电子设备4000的结构并不构成对本申请实施例的限定。In an optional embodiment, an electronic device is provided, as shown in Figure 6. The electronic device 4000 shown in Figure 6 includes: a processor 4001 and a memory 4003. Among them, the processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and/or data reception. It should be noted that in practical applications, the number of transceivers 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.
处理器4001可以是CPU(CentralProcessingUnit,中央处理器),通用处理器,DSP(DigitalSignalProcessor,数据信号处理器),ASIC(ApplicationSpecificIntegratedCircuit,专用集成电路),FPGA(FieldProgrammableGateArray,现场可编程门阵列)或者其他可编程逻辑器件、晶体管逻辑器件、硬件部件或者其任意组合。其可以实现或执行结合本申请公开内容所描述的各种示例性的逻辑方框,模块和电路。处理器4001也可以是实现计算功能的组合,例如包含一个或多个微处理器组合,DSP和微处理器的组合等。The processor 4001 can be a CPU (Central Processing Unit, central processing unit), a general-purpose processor, a DSP (Digital Signal Processor, a data signal processor), an ASIC (Application Specific Integrated Circuit, an application specific integrated circuit), an FPGA (Field Programmable Gate Array, a field programmable gate array) or other programmable gate arrays. Programmed logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute the various illustrative logical blocks, modules, and circuits described in connection with this disclosure. The processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, etc.
总线4002可包括一通路,在上述组件之间传送信息。总线4002可以是PCI(PeripheralComponentInterconnect,外设部件互连标准)总线或EISA(ExtendedIndustryStandardArchitecture,扩展工业标准结构)总线等。总线4002可以分为地址总线、数据总线、控制总线等。为便于表示,图中仅用一条粗线表示,但并不表示仅有一根总线或一种类型的总线。Bus 4002 may include a path that carries information between the above-mentioned components. The bus 4002 may be a PCI (Peripheral Component Interconnect, Peripheral Component Interconnect Standard) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The bus 4002 can be divided into an address bus, a data bus, a control bus, etc. For ease of presentation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
存储器4003可以是ROM(ReadOnlyMemory,只读存储器)或可存储静态信息和指令的其他类型的静态存储设备,RAM(RandomAccessMemory,随机存取存储器)或者可存储信息和指令的其他类型的动态存储设备,也可以是EEPROM(ElectricallyErasableProgrammableReadOnlyMemory,电可擦可编程只读存储器)、CD-ROM(CompactDiscReadOnlyMemory,只读光盘)或其他光盘存储、光碟存储(包括压缩光碟、激光碟、光碟、数字通用光碟、蓝光光碟等)、磁盘存储介质、其他磁存储设备或者能够用于携带或存储计算机程序并能够由计算机读取的任何其他介质,在此不做限定。The memory 4003 may be ROM (ReadOnlyMemory, read-only memory) or other types of static storage devices that can store static information and instructions, RAM (RandomAccessMemory, random access memory) or other types of dynamic storage devices that can store information and instructions, It can also be EEPROM (Electrically Erasable Programmable ReadOnly Memory), CD-ROM (CompactDiscReadOnlyMemory, read-only disc) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital versatile discs, Blu-ray discs etc.), disk storage media, other magnetic storage devices or any other media that can be used to carry or store computer programs and can be read by a computer, without limitation here.
存储器4003用于存储执行本申请实施例的计算机程序,并由处理器4001来控制执行。处理器4001用于执行存储器4003中存储的计算机程序,以实现前述方法实施例所示的步骤。The memory 4003 is used to store computer programs for executing embodiments of the present application, and is controlled by the processor 4001 for execution. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the steps shown in the foregoing method embodiments.
其中,电子设备可以是任何一种可与对象进行人机交互的电子产品,例如,个人计算机、平板电脑、智能手机、个人数字助理(PersonalDigitalAssistant,PDA)、游戏机、交互式网络电视(InternetProtocolTelevision,IPTV)、智能式穿戴式设备等。Among them, the electronic device can be any electronic product that can perform human-computer interaction with the object, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (Personal Digital Assistant, PDA), a game console, an interactive network television (Internet Protocol Television, IPTV), smart wearable devices, etc.
所述电子设备还可以包括网络设备和/或对象设备。其中,所述网络设备包括,但不限于单个网络服务器、多个网络服务器组成的服务器组或基于云计算(CloudComputing)的由大量主机或网络服务器构成的云。The electronic device may also include a network device and/or an object device. The network device includes, but is not limited to, a single network server, a server group composed of multiple network servers, or a cloud composed of a large number of hosts or network servers based on cloud computing (Cloud Computing).
所述电子设备所处的网络包括但不限于互联网、广域网、城域网、局域网、虚拟专用网络(VirtualPrivateNetwork,VPN)等。The network where the electronic device is located includes but is not limited to the Internet, wide area network, metropolitan area network, local area network, virtual private network (Virtual Private Network, VPN), etc.
本申请实施例提供了一种计算机可读存储介质,该计算机可读存储介质上存储有计算机程序,计算机程序被处理器执行时可实现前述方法实施例的步骤及相应内容。Embodiments of the present application provide a computer-readable storage medium. A computer program is stored on the computer-readable storage medium. When the computer program is executed by a processor, the steps and corresponding contents of the foregoing method embodiments can be implemented.
本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”、“第三”、“第四”、“1”、“2”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例能够以除图示或文字描述以外的顺序实施。The terms "first", "second", "third", "fourth", "1", "2", etc. (if present) in the description and claims of this application and the above-mentioned drawings are used for Distinguishes similar objects without necessarily describing a specific order or sequence. It is to be understood that the data so used are interchangeable under appropriate circumstances so that the embodiments of the application described herein can be practiced in other than the order illustrated or described.
应该理解的是,虽然本申请实施例的流程图中通过箭头指示各个操作步骤,但是这些步骤的实施顺序并不受限于箭头所指示的顺序。除非本文中有明确的说明,否则在本申请实施例的一些实施场景中,各流程图中的实施步骤可以按照需求以其他的顺序执行。此外,各流程图中的部分或全部步骤基于实际的实施场景,可以包括多个子步骤或者多个阶段。这些子步骤或者阶段中的部分或全部可以在同一时刻被执行,这些子步骤或者阶段中的每个子步骤或者阶段也可以分别在不同的时刻被执行。在执行时刻不同的场景下,这些子步骤或者阶段的执行顺序可以根据需求灵活配置,本申请实施例对此不限制。It should be understood that although each operation step is indicated by arrows in the flow chart of the embodiment of the present application, the order of implementation of these steps is not limited to the order indicated by the arrows. Unless otherwise specified herein, in some implementation scenarios of the embodiments of the present application, the implementation steps in each flowchart may be executed in other orders according to requirements. In addition, some or all of the steps in each flowchart are based on actual implementation scenarios and may include multiple sub-steps or multiple stages. Some or all of these sub-steps or stages may be executed at the same time, and each of these sub-steps or stages may also be executed at different times. In scenarios with different execution times, the execution order of these sub-steps or stages can be flexibly configured according to needs, and the embodiments of the present application do not limit this.
以上所述仅是本申请部分实施场景的可选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请的方案技术构思的前提下,采用基于本申请技术思想的其他类似实施手段,同样属于本申请实施例的保护范畴。The above are only optional implementation modes of some implementation scenarios of the present application. It should be pointed out that for those of ordinary skill in the technical field, without departing from the technical concept of the solution of the present application, adopting solutions based on the technical ideas of the present application Other similar implementation means also fall within the protection scope of the embodiments of this application.
Claims (10)
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 |
---|---|---|
WO2020000706A1 (en) | Database comparison-based interface testing method and system, device and storage medium | |
WO2021184725A1 (en) | User interface test method and apparatus, storage medium, and computer device | |
US9218269B2 (en) | Testing multiple target platforms | |
CN102279750B (en) | Iterative code generation method based on domain knowledge sharing | |
CN108345532A (en) | A kind of automatic test cases generation method and device | |
CN109522228B (en) | Interface automation test data construction method, device, platform and storage medium | |
CN111078555B (en) | Test file generation method, system, server and storage medium | |
CN108009087A (en) | Data library test method, device and computer-readable recording medium | |
CN104954453A (en) | Data mining REST service platform based on cloud computing | |
CN113032244B (en) | Interface test method, device, computer system and computer readable storage medium | |
CN111722839A (en) | Code generation method and device, electronic equipment and storage medium | |
CN101976188A (en) | OpenApi data automatic loading system oriented to AJAX protocol | |
CN111026670B (en) | Test case generation method, test case generation device and storage medium | |
CN113778897A (en) | Automatic test method, device, equipment and storage medium of interface | |
US20200293592A1 (en) | Methods and systems for browser extension used to generate relative xpath, absolute xpath and/or css selectors | |
CN114995859A (en) | Page hot updating method, device, equipment and storage medium | |
CN112650526B (en) | Method, device, electronic equipment and medium for detecting version consistency | |
CN114968817A (en) | Method, device, equipment and storage medium for evaluating code change influence range | |
CN112187713B (en) | Method, device, computer equipment and storage medium for message conversion | |
CN113485927A (en) | Test data generation method, device, equipment and storage medium | |
CN116414774A (en) | File migration method, device, equipment and storage medium | |
CN112860584B (en) | Workflow model-based testing method and device | |
CN113050935A (en) | Method and device for generating mixed object, computing equipment and computer readable storage medium | |
CN116755684A (en) | OAS Schema generation method, device, equipment and medium | |
CN116860636A (en) | Unit test code generation method, device, 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 |