•  


GitHub - sngular/scc-multiapi-converter: SCC Verifier MultiApi Converter allows us to use Spring Cloud Contract to generate contracts from an OpenApi yaml or AsyncApi yaml document
Skip to content

SCC Verifier MultiApi Converter allows us to use Spring Cloud Contract to generate contracts from an OpenApi yaml or AsyncApi yaml document

License

Notifications You must be signed in to change notification settings

sngular/scc-multiapi-converter

Folders and files

Name Name
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Codacy Badge Maven Central

SCC Verifier MultiApi Converter

?? Summary

SCC Verifier MultiApi Converter allows us to use Spring Cloud Contract to generate contracts from an OpenApi yaml document or an AsyncApi document. This plugin will detect automatically what contract needs to be generated

Here is the documentation for these technologies:

?? Getting Started

In order to get this plugin working, you need the following things installed in your computer:

  • Java 11 Version
  • Maven

After you have these installed, you need to add the Spring Cloud Contract Maven Plugin in your pom.xml file and extend it with this Converter as a Dependency. Here is an easy example of a basic configuration:

<
plugin
>
  <
groupId
>org.springframework.cloud</
groupId
>
  <
artifactId
>spring-cloud-contract-maven-plugin</
artifactId
>
  <
version
>3.0.0</
version
>
  <
extensions
>true</
extensions
>
  <
configuration
>
    <
packageWithBaseClasses
>com.sngular.challenge.gameserver.baseclasses</
packageWithBaseClasses
>
    <
contractsDirectory
>${project.basedir}/src/main/resources/api</
contractsDirectory
>
  </
configuration
>
  <
dependencies
>
    <
dependency
>
      <
groupId
>com.sngular</
groupId
>
      <
artifactId
>scc-multiapi-converter</
artifactId
>
      <
version
>3.4.1</
version
>
      <
scope
>compile</
scope
>
    </
dependency
>
  </
dependencies
>
</
plugin
>

??????? Usage

Inside the configuration tag, you must declare the contractsDirectory tag. In this tag you must specify the directory that contains the OpenApi/AsyncApi Yamls.

Also, we recommend specifying the baseClassForTests tag. This tag indicates the base class from which the autogenerated test will be extended. This class must be a test class of the producer part in which only a call to the producer method will be made, which is necessary for the test of the producer of the autogenerated class.

Once you specify this in your pom.xml you must use the command: mvn clean install . This will generate the stubs necessary for the contract testing generation under the stubs folder.

It will also generate the ContractVerifierTest class for the producer and consumer tests for your Messaging Api and your Rest Api, in addition to the corresponding yml files with the contracts of both, inside target in the package where your baseClassForTests is located. If you want to change where your contracts will be located you must use the basePackageForTests tag in the pom.xml.

If you need more control over the settings of your project, you can use all the Configuration Options that Spring Cloud Contract Maven Plugin has. These configuration options can be checked in the official documentation webpage under 4.2.7 Section: Spring Cloud Contract Verifier Setup .

?? Writing Ymls

This plugin supports most of the OpenApi/Swagger and AsyncApi, but there are a couple of things that must be noted:

  • Using OpenApi/AsyncApi´s example label in the parameters/schemas will check in our contracts that the response is equal to the example value instead of using a Regex.
  • OpenApi : Since 2.4.0 version, we support the definition of parameters in both Path and Operation object, but you can only define it in one of them. ???? We use the Option resolver from OpenApi which will override the Operation parameters if you have a parameter defined in the Path.
  • Please be aware that writing an example must be the same type as indicated in the file, otherwise your contract will break.

This is an easy example of a small YAML for OpenApi that will work with our plugin:

---
openapi
: 
"
3.0.0
"

info
:
  
version
: 
1.0.0

  title
: 
Sngular Challenge Game Server

  description
: 
Test File for SCC MultiApi Plugin.

  contact
:
    
name
: 
Sngular

    url
: 
sngular.com

    email
: 
os3@sngular.com

  license
:
    
name
: 
MPL 2.0

servers
:
- 
url
: 
http://localhost:8080/v1

paths
:
  
/games
:
    
summary
: 
Hola

    get
:
      
summary
: 
List all available games

      description
: 
Test File for SCC MultiApi Plugin.

      tags
:
      - 
games

      operationId
: 
listGames

      responses
:
        
'
200
'
:
          
description
: 
A paged array of games

          content
:
            
application/json
:
              
schema
:
                
$ref
: 
"
#/components/schemas/Game
"

components
:
  
schemas
:
    
Game
:
      
type
: 
object

      properties
:
        
player
:
          
$ref
: 
"
#/components/schemas/Player
"

    Player
:
      
type
: 
object

      properties
:
        
name
:
          
$ref
: 
"
#/components/schemas/Name
"

    Name
:
      
type
: 
object

      properties
:
        
firstname
:
          
type
: 
string

          example
: 
John

        lastname
:
          
type
: 
string

          example
: 
Doe

tags
:
- 
name
: 
games

  description
: 
Test description for SCC MultiApi Plugin.

And here, there is an example of a YAML file for the AsyncApi side:

asyncapi
: 
"
2.3.0
"

info
:
  
title
: 
Order Service

  version
: 
1.0.0

  description
: 
Order management Service

  contact
:
    
name
: 
Sngular

    url
: 
http://www.asyncapi.org/support

    email
: 
os3@sngular.com

    license
:
      
name
: 
MPL 2.0

channels
:
  
orderCreated
:
    
publish
:
      
operationId
: 
"
publishOperation
"

      message
:
        
$ref
: 
'
#/components/messages/OrderCreated
'

    description
: 
Operation that will produce an OrderCreated object

  createOrder
:
    
subscribe
:
      
operationId
: 
"
subscribeOperation
"

      message
:
        
$ref
: 
'
#/components/messages/CreateOrder
'

    description
: 
Operation that will consume an CreateOrder object

components
:
  
messages
:
    
OrderCreated
:
      
payload
:
        
$ref
: 
'
#/components/schemas/Order
'

    CreateOrder
:
      
payload
:
        
$ref
: 
'
#/components/schemas/Order
'

  schemas
:
    
Order
:
      
type
: 
object

      properties
:
        
tableNumber
:
          
type
: 
integer

          format
: 
int32

          example
: 
1

        clientRef
:
          
type
: 
integer

          format
: 
int32

          example
: 
432

?? Current Limitations

Currently, this plugin has some limitations that will be addressed in the future. In order to make it work, we must follow some rules:

OpenApi implementation :

  • Some OpenApi functionalities are not implemented yet, such as creating example objects, instead you must use the example tag in every property of the object.
  • Due to the OpenApi Parser code, when you use a $ref that points to an external file, there are some limitations when using $ref again in that same file.

Async Api implementation :

  • This plugin doesn't allow the use of AllOfs, OneOfs and AnyOfs.
  • Support for generating contracts from avro files.
  • Some AsyncApi functionalities are not implemented yet, such as creating example objects, instead you must use the example tag in every property of the object.

?? RoadMap

  • Add implementation to support AllOfs, AnyOfs and OneOfs in AsyncApi.
  • Add support for generating contracts from avro files.
  • Further investigation for OpenApi/AsyncApi and Spring Cloud Contract possibilities.
  • More testing and fixing possible bugs that may occur in the future.
  • Get rid of the OpenApi parser in order to control our own code.
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본