io.github.justtimki:spring-cloud-contract-swagger

Spring Cloud Contract Swagger

License

License

Categories

Categories

Swagger Program Interface REST Frameworks
GroupId

GroupId

io.github.justtimki
ArtifactId

ArtifactId

spring-cloud-contract-swagger
Last Version

Last Version

1.2.13.RELEASE
Release Date

Release Date

Type

Type

jar
Description

Description

io.github.justtimki:spring-cloud-contract-swagger
Spring Cloud Contract Swagger
Project URL

Project URL

https://github.com/justtimki/spring-cloud-contract-swagger
Project Organization

Project Organization

Spring
Source Code Management

Source Code Management

https://github.com/justtimki/spring-cloud-contract-swagger/tree/master

Download spring-cloud-contract-swagger

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.justtimki/spring-cloud-contract-swagger/ -->
<dependency>
    <groupId>io.github.justtimki</groupId>
    <artifactId>spring-cloud-contract-swagger</artifactId>
    <version>1.2.13.RELEASE</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.justtimki/spring-cloud-contract-swagger/
implementation 'io.github.justtimki:spring-cloud-contract-swagger:1.2.13.RELEASE'
// https://jarcasting.com/artifacts/io.github.justtimki/spring-cloud-contract-swagger/
implementation ("io.github.justtimki:spring-cloud-contract-swagger:1.2.13.RELEASE")
'io.github.justtimki:spring-cloud-contract-swagger:jar:1.2.13.RELEASE'
<dependency org="io.github.justtimki" name="spring-cloud-contract-swagger" rev="1.2.13.RELEASE">
  <artifact name="spring-cloud-contract-swagger" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.justtimki', module='spring-cloud-contract-swagger', version='1.2.13.RELEASE')
)
libraryDependencies += "io.github.justtimki" % "spring-cloud-contract-swagger" % "1.2.13.RELEASE"
[io.github.justtimki/spring-cloud-contract-swagger "1.2.13.RELEASE"]

Dependencies

compile (9)

Group / Artifact Type Version
org.springframework : spring-context jar
org.springframework.cloud : spring-cloud-contract-converters jar
org.springframework.cloud : spring-cloud-contract-stub-runner jar
org.springframework.boot : spring-boot-starter-logging jar
org.codehaus.groovy : groovy jar 2.5.10
org.codehaus.groovy : groovy-nio jar 2.5.10
org.springframework.boot : spring-boot-autoconfigure-processor Optional jar
io.swagger.parser.v3 : swagger-parser jar 2.0.22
io.swagger.core.v3 : swagger-annotations jar 2.1.5

test (4)

Group / Artifact Type Version
org.spockframework : spock-core jar 1.3-groovy-2.5
org.springframework.boot : spring-boot-starter-test jar
info.solidsoft.spock : spock-global-unroll jar 0.5.1
org.springframework.cloud : spring-cloud-contract-wiremock jar

Project Modules

There are no modules declared in this project.

Maven Central Project Stats

Spring Cloud Contract Swagger

Converts Swagger files to contracts for Spring Cloud Contract

This project enables Spring Cloud Contract to parse Swagger API 2.0 specifications as Spring Cloud Contracts.

Usage

You can check out spring-cloud-contract-swagger-sample for examples.

Producer

To convert a Swagger file to a Spring Cloud Contract and to execute it against a Producer, add the spring-cloud-contract-maven-plugin as plugin and the converter spring-cloud-contract-swagger as plugin-dependency.

Consumer

For the consumer, add as dependencies the spring-cloud-starter-contract-stub-runner and the converter spring-cloud-contract-swagger.

Default Behaviour

Currently, Spring Cloud Contract Swagger generates default values for a Swagger document’s fields.

  • Boolean: true
  • Number: 1
  • Float/Double: 1.1
  • String: (the name of the String)

Custom Values

To set your own default values, you can use the x-example field in the parameters and responses section. In the definitions section, you can also use the x-example or the supported example field. You should avoid the default field, since the current Swagger parser (1.0.36) interprets numerical values of default fields as String. Regarding the order, the converter will first evaluate example, then x-example, and then default fields. If it does not find a predefined value, it will go all the way down to the primitive fields. The converter will only use the first response of a Swagger method entry.

Optional Parameters

If you do not want to pass an optional parameter (required: false) in a request, you can add x-ignore: true to this field.

Patterns

Pattern only work for request parameters. Your provided example values will be checked against the pattern.

Custom JSON Body

You can set the request and response body with a json string. For this, you have to place an x-example field next (on the same level) to the schema field. Use single ticks for your json string so you do not have to escape any quotes.

Also, you can reference external json files for the request and response by using the x-ref field. Just place the x-ref field next (on the same level) to the schema field. Use single ticks for the path, relative to the Swagger file.

Recommendation

If you are working in a project that restricts you to define your API with Swagger, this library is for you. Instead of defining your API and Groovy/JSON/YAML contracts, maintaining two separate documents, and risking inconsistency, you can maintain your API specification and contract in one document. This enables you to take at least partly benefit of CDC. The features of this are more restricted then by using proper contracts. However, if possible, you should go the way to define your API with contracts and let the Swagger documentation be generated by your Maven project. See more details at https://github.com/spring-cloud/spring-cloud-contract

If you decide to do contract testing with this project, you might have the choice to move gradually to Spring Cloud Contract with the Swagger Request Validator since Spring Cloud Contract generates WireMock stubs. This would enable you to add Groovy/JSON/YAML contracts and therefore test move scenarios. Thanks to Marcin Grzejszczak for this tip.

Further Information

Read the blog about Consumer Driven Contracts with Swagger for more information.

Versions

Version
1.2.13.RELEASE
1.2.12.RELEASE
1.2.11.RELEASE
1.2.10.RELEASE