{"id":18264998,"url":"https://github.com/springframeworkguru/spring-cloud-contract-oa3","last_synced_at":"2025-04-04T21:31:14.495Z","repository":{"id":36191579,"uuid":"142465000","full_name":"springframeworkguru/spring-cloud-contract-oa3","owner":"springframeworkguru","description":"Spring Cloud Contract Open API 3.0","archived":false,"fork":false,"pushed_at":"2022-04-24T18:52:13.000Z","size":185,"stargazers_count":65,"open_issues_count":18,"forks_count":38,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-04-13T18:53:16.510Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/springframeworkguru.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-26T16:13:35.000Z","updated_at":"2023-10-03T20:32:58.000Z","dependencies_parsed_at":"2022-07-29T21:09:39.606Z","dependency_job_id":null,"html_url":"https://github.com/springframeworkguru/spring-cloud-contract-oa3","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springframeworkguru%2Fspring-cloud-contract-oa3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springframeworkguru%2Fspring-cloud-contract-oa3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springframeworkguru%2Fspring-cloud-contract-oa3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/springframeworkguru%2Fspring-cloud-contract-oa3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/springframeworkguru","download_url":"https://codeload.github.com/springframeworkguru/spring-cloud-contract-oa3/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223158928,"owners_count":17097375,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-05T11:16:43.626Z","updated_at":"2024-11-05T11:16:44.364Z","avatar_url":"https://github.com/springframeworkguru.png","language":"Groovy","readme":"# Spring Cloud Contract OpenAPI 3.0 Contract Converter\n\n[![Gitter chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/spring-cloud-contract-oa3/Lobby)\n\n[![CircleCI](https://circleci.com/gh/springframeworkguru/spring-cloud-contract-oa3.svg?style=svg)](https://circleci.com/gh/springframeworkguru/spring-cloud-contract-oa3)\n\n![QualityGate](https://sonarcloud.io/api/project_badges/measure?project=guru.springframework%3Aspring-cloud-contract-oa3\u0026metric=alert_status)\n## OpenAPI 3.0 Converter\n\nThe [OpenAPI Specification (OAS)](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md) defines a\nstandard, language-agnostic interface to RESTful APIs which allows both humans and computers to discover and understand \nthe capabilities of the service without access to source code, documentation, or through network traffic inspection. \nWhen properly defined, a consumer can understand and interact with the remote service with a minimal amount of \nimplementation logic.\n\nAn OpenAPI definition can then be used by documentation generation tools to display the API, code generation tools to\ngenerate servers and clients in various programming languages, testing tools, and many other use cases.\n\n## Example Project\nA complete working example project using Open API 3.0 to define contracts for Spring Cloud Contract is available \n[here on GitHub](https://github.com/springframeworkguru/sccoa3-fraud-example).\n\nThis project is a copy of the fraud API example commonly used in the standalone examples. The above example implements \nthe same producer, client, and contracts (defined in YAML) from the [standalone YAML example](https://github.com/springframeworkguru/sccoa3-fraud-example). \n\n## Usage\n### Maven\nTo enable this plugin, you will need to add the OA3 converter jar to your Spring Boot project as follows.\n\n1. Configure your project to use [Spring Cloud Contract](https://cloud.spring.io/spring-cloud-static/spring-cloud-contract/2.1.0.RELEASE/single/spring-cloud-contract.html#maven-project).\n\n2. Add to your maven dependencies: \n    ```xml\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.springframework.cloud\u003c/groupId\u003e\n        \u003cartifactId\u003espring-cloud-starter-contract-verifier\u003c/artifactId\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.springframework.boot\u003c/groupId\u003e\n        \u003cartifactId\u003espring-boot-starter-test\u003c/artifactId\u003e\n        \u003cscope\u003etest\u003c/scope\u003e\n    \u003c/dependency\u003e\n    ```\n3. The artifact also needs to be added to the Maven Plugin:\n\n```xml\n    \u003cplugin\u003e\n        \u003cgroupId\u003eorg.springframework.cloud\u003c/groupId\u003e\n        \u003cartifactId\u003espring-cloud-contract-maven-plugin\u003c/artifactId\u003e\n        \u003cversion\u003e${spring-cloud-contract.version}\u003c/version\u003e\n        \u003cextensions\u003etrue\u003c/extensions\u003e\n        \u003cconfiguration\u003e\n            \u003cpackageWithBaseClasses\u003ecom.example.fraud\u003c/packageWithBaseClasses\u003e\n        \u003c/configuration\u003e\n        \u003cdependencies\u003e\n        \u003c!--needed to include oa3 converter--\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eguru.springframework\u003c/groupId\u003e\n            \u003cartifactId\u003espring-cloud-contract-oa3\u003c/artifactId\u003e\n            \u003cversion\u003e2.0.1\u003c/version\u003e\n            \u003c/dependency\u003e\n        \u003c/dependencies\u003e\n    \u003c/plugin\u003e\n```\n\n##  Defining Contracts in OpenAPI\n\nNatively, OpenAPI does a great job of describing an API in a holistic manner.\n\nOpenAPI, however, does not define API interactions. Within the native OpenAPI specification, it is not possible to\ndefine request / response pairs. To define a contract, you need to define the API and the specific details of a\nrequest, and the expected response.\n\nThe Open API Specification defines a number of extension points in the API. These extension points may be used to\ndefine details about request / response pairs.\n\nComplete details of OpenAPI 3.x extensions can be\nfound [here](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#specificationExtensions).\n\nIn general, most OpenAPI schema objects may be extended using objects using a property with starts with 'x-'. The extension\nproperty is an object, which provides the necessary flexibility to define interactions.\n\nThe below snippet shows the definition of two contracts by extending the\n[Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#operationObject) of the OA3 specification.\n\n\n```yaml\npaths:\n    /fraudcheck:\n        put:\n            summary: Perform Fraud Check\n            x-contracts:\n            - contractId: 1\n              name: Should Mark Client as Fraud\n              priority: 1\n            - contractId: 2\n              name: Should Not Mark Client as Fraud\n```\n\nThe OA3 extension objects are used to define request / response pairs. *While* the OA3 objects are used to define\nthe API itself. Where ever possible, the _DRY Principle_ is followed (Don't Repeat Yourself).\n\nFor example:\n\n* *Path*: Source - OA3\n* *HTTP Method*: Source - OA3\n* *Parameter Value for Interaction*: Source - OA3 Extension\n* *Request Body for Interaction*: Source - OA3 Extension\n\n`x-contracts` -  This is the root extension object used to define contracts. This object will always expect a list of objects. Each object in\nthe list will have a `contractId` property.\n\nThe `x-contracts` object may be applied to:\n\n* [Operation Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#operationObject) - Used to define\nindividual contacts, and header level information for contracts.\n\n* [Parameter Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#parameterObject) - Define Parameter\n (path, query, header, cookie) Values for interactions.\n\n* [Request Body](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#requestBodyObject) - Define the request\nbody for interaction.\n\n* [Response Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#responseObject) - Define\nexpected response for given interaction.\n\n### OA3 Extensions for Spring Cloud Contract\nUnder the covers, the converter is converting from the OA3 object format, to the `YamlContract` object of Spring Cloud Contract.\nThis is then converted to a `Contract` object using the same converter used by Spring Cloud Contract for it's \nYAML DSL.\n\nThe YAML DSL of Spring Cloud Contract is very robust. Please review the capabilities of the YAML DSL in the official \n[Spring Cloud Contract documentation](https://cloud.spring.io/spring-cloud-contract/multi/multi__contract_dsl.html#_common_top_level_elements).\n\nAs much as practical, the object properties and names follow the YAML DSL of Spring Cloud Contract. \n#### Operation Object Extension\n\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"x-contracts\": {\n      \"type\": \"array\",\n      \"items\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"contractId\": {\n              \"type\": \"integer\"\n            },\n            \"name\": {\n              \"type\": \"string\"\n            },\n            \"description\": {\n              \"type\": \"string\"\n            },\n            \"label\": {\n              \"type\": \"string\"\n            },\n            \"priority\": {\n              \"type\": \"integer\"\n            },\n            \"ignored\": {\n              \"type\": \"boolean\"\n            },\n            \"contractPath\": {\n              \"type\": \"string\"\n            }\n          },\n          \"required\": [\n            \"contractId\",\n            \"name\",\n            \"description\",\n            \"label\",\n            \"priority\",\n            \"ignored\",\n            \"contractPath\"\n          ]\n        },\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"contractId\": {\n              \"type\": \"integer\"\n            },\n            \"name\": {\n              \"type\": \"string\"\n            },\n            \"description\": {\n              \"type\": \"string\"\n            },\n            \"label\": {\n              \"type\": \"string\"\n            },\n            \"priority\": {\n              \"type\": \"integer\"\n            },\n            \"contractPath\": {\n              \"type\": \"string\"\n            }\n          },\n          \"required\": [\n            \"contractId\",\n            \"description\"\n          ]\n        }\n      ]\n    }\n  },\n  \"required\": [\n    \"x-contracts\"\n  ]\n}\n```\n#### Parameter Object Extension\nNote: Query Parameters maybe defined on the Parameter object, or within the parameter element of the Request Body extension.\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"x-contracts\": {\n      \"type\": \"array\",\n      \"items\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"contractId\": {\n              \"type\": \"integer\"\n            },\n            \"value\": {\n              \"type\": \"string\"\n            },\n            \"matchers\": {\n              \"type\": \"array\",\n              \"items\": [\n                {\n                  \"type\": \"object\",\n                  \"properties\": {\n                    \"type\": {\n                      \"type\": \"string\"\n                    },\n                    \"value\": {\n                      \"type\": \"string\"\n                    }\n                  },\n                  \"required\": []\n                }\n              ]\n            }\n          },\n          \"required\": [\n            \"contractId\",\n            \"value\"\n          ]\n        }\n      ]\n    }\n  },\n  \"required\": [\n    \"x-contracts\"\n  ]\n}\n```\n#### Request Body Extension\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"x-contracts\": {\n      \"type\": \"array\",\n      \"items\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"contractId\": {\n              \"type\": \"integer\"\n            },\n            \"request\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"queryParameters\": {\n                  \"type\": \"array\",\n                  \"items\": [\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"key\": {\n                          \"type\": \"string\"\n                        },\n                        \"value\": {\n                          \"type\": \"integer\"\n                        }\n                      },\n                      \"required\": [\n                        \"key\",\n                        \"value\"\n                      ]\n                    }\n                  ]\n                }\n              },\n              \"required\": []\n            },\n            \"headers\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"Header-key\": {\n                  \"type\": \"string\"\n                }\n              },\n              \"required\": [\n                \"Header-key\"\n              ]\n            },\n            \"body\": {\n              \"type\": \"object\"\n            },\n            \"multipart\": {\n              \"type\": \"object\",\n                \"named\": {\n                  \"type\": \"array\",\n                  \"items\": [\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"paramName\": {\n                          \"type\": \"string\"\n                        },\n                        \"fileName\": {\n                          \"type\": \"string\"\n                        },\n                        \"fileContent\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": [\n                        \"paramName\",\n                        \"fileName\",\n                        \"fileContent\"\n                      ]\n                    }\n                  ]\n                }\n              },\n              \"required\": [\n                \"params\",\n                \"named\"\n              ]\n            },\n            \"matchers\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"headers\": {\n                  \"type\": \"array\",\n                  \"items\": [\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"key\": {\n                          \"type\": \"string\"\n                        },\n                        \"regex\": {\n                          \"type\": \"string\"\n                        },\n                        \"predefined\": {\n                          \"type\": \"string\"\n                        },\n                        \"command\": {\n                          \"type\": \"string\"\n                        },\n                        \"type\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": []\n                    }\n                  ]\n                },\n                \"body\": {\n                  \"type\": \"array\",\n                  \"items\": [\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"path\": {\n                          \"type\": \"string\"\n                        },\n                        \"type\": {\n                          \"type\": \"string\"\n                        },\n                        \"predefined\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": []\n                    },\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"path\": {\n                          \"type\": \"string\"\n                        },\n                        \"type\": {\n                          \"type\": \"string\"\n                        },\n                        \"predefined\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": []\n                    },\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"path\": {\n                          \"type\": \"string\"\n                        },\n                        \"type\": {\n                          \"type\": \"string\"\n                        },\n                        \"predefined\": {\n                          \"type\": \"string\"\n                        },\n                        \"value\": {\n                          \"type\": \"string\"\n                        },\n                        \"minOccurrence\": {\n                          \"type\": \"integer\"\n                        },\n                        \"maxOccurrence\": {\n                          \"type\": \"integer\"\n                        },\n                        \"regexType\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": []\n                    }\n                  ]\n                },\n                \"queryParameters\": {\n                  \"type\": \"array\",\n                  \"items\": [\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"key\": {\n                          \"type\": \"string\"\n                        },\n                        \"type\": {\n                          \"type\": \"string\"\n                        },\n                        \"value\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": []\n                    }\n                  ]\n                },\n                \"cookies\": {\n                  \"type\": \"array\",\n                  \"items\": [\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"key\": {\n                          \"type\": \"string\"\n                        },\n                        \"regex\": {\n                          \"type\": \"string\"\n                        },\n                        \"predefined\": {\n                          \"type\": \"string\"\n                        },\n                        \"command\": {\n                          \"type\": \"string\"\n                        },\n                        \"type\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": [\n                        \"key\",\n                        \"regex\",\n                        \"predefined\",\n                        \"command\",\n                        \"type\"\n                      ]\n                    }\n                  ]\n                },\n                \"multipart\": {\n                  \"type\": \"object\",\n                  \"properties\": {\n                    \"params\": {\n                      \"type\": \"array\",\n                      \"items\": [\n                        {\n                          \"type\": \"object\",\n                          \"properties\": {\n                            \"key\": {\n                              \"type\": \"string\"\n                            },\n                            \"regex\": {\n                              \"type\": \"string\"\n                            },\n                            \"predefined\": {\n                              \"type\": \"string\"\n                            },\n                            \"command\": {\n                              \"type\": \"string\"\n                            },\n                            \"type\": {\n                              \"type\": \"string\"\n                            }\n                          },\n                          \"required\": []\n                        }\n                      ]\n                    },\n                    \"named\": {\n                      \"type\": \"array\",\n                      \"items\": [\n                        {\n                          \"type\": \"object\",\n                          \"properties\": {\n                            \"paramName\": {\n                              \"type\": \"string\"\n                            },\n                            \"fileName\": {\n                              \"type\": \"object\",\n                              \"properties\": {\n                                \"regex\": {\n                                  \"type\": \"string\"\n                                },\n                                \"perfefined\": {\n                                  \"type\": \"string\"\n                                }\n                              },\n                              \"required\": []\n                            },\n                            \"fileContent\": {\n                              \"type\": \"object\",\n                              \"properties\": {\n                                \"regex\": {\n                                  \"type\": \"string\"\n                                },\n                                \"perfefined\": {\n                                  \"type\": \"string\"\n                                }\n                              },\n                              \"required\": [ ]\n                            },\n                            \"contentType\": {\n                              \"type\": \"object\",\n                              \"properties\": {\n                                \"regex\": {\n                                  \"type\": \"string\"\n                                },\n                                \"perfefined\": {\n                                  \"type\": \"string\"\n                                }\n                              },\n                              \"required\": [ ]\n                            }\n                          },\n                          \"required\": []\n                        }\n                      ]\n                    }\n                  },\n                  \"required\": [\n                    \"params\",\n                    \"named\"\n                  ]\n                }\n              },\n              \"required\": []\n            }\n          },\n          \"required\": []\n        }\n      ]\n    }\n  },\n  \"required\": [\n    \"x-contracts\"\n  ]\n}\n```\n\n#### Response Object Extension\n```json\n{\n  \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n  \"type\": \"object\",\n  \"properties\": {\n    \"x-contracts\": {\n      \"type\": \"array\",\n      \"items\": [\n        {\n          \"type\": \"object\",\n          \"properties\": {\n            \"contractId\": {\n              \"type\": \"integer\"\n            },\n            \"headers\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"HeaderKey\": {\n                  \"type\": \"string\"\n                }\n              },\n              \"required\": [\n                \"HeaderKey\"\n              ]\n            },\n            \"body\": {\n              \"type\": \"object\"\n            },\n            \"cookies\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"key\": {\n                  \"type\": \"string\"\n                }\n              },\n              \"required\": [\n                \"key\"\n              ]\n            },\n            \"assyc\": {\n              \"type\": \"boolean\"\n            },\n            \"fixedDelayMilliseconds\": {\n              \"type\": \"integer\"\n            },\n            \"matchers\": {\n              \"type\": \"object\",\n              \"properties\": {\n                \"headers\": {\n                  \"type\": \"array\",\n                  \"items\": [\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"key\": {\n                          \"type\": \"string\"\n                        },\n                        \"regex\": {\n                          \"type\": \"string\"\n                        },\n                        \"command\": {\n                          \"type\": \"string\"\n                        },\n                        \"predefined\": {\n                          \"type\": \"string\"\n                        },\n                        \"regexType\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": []\n                    }\n                  ]\n                },\n                \"body\": {\n                  \"type\": \"array\",\n                  \"items\": [\n                    {\n                      \"type\": \"object\",\n                      \"properties\": {\n                        \"path\": {\n                          \"type\": \"string\"\n                        },\n                        \"type\": {\n                          \"type\": \"string\"\n                        },\n                        \"predefined\": {\n                          \"type\": \"string\"\n                        },\n                        \"value\": {\n                          \"type\": \"string\"\n                        },\n                        \"minOccurrence\": {\n                          \"type\": \"integer\"\n                        },\n                        \"maxOccurrence\": {\n                          \"type\": \"integer\"\n                        },\n                        \"regexType\": {\n                          \"type\": \"string\"\n                        }\n                      },\n                      \"required\": []\n                    }\n                  ]\n                },\n                \"cookies\": {\n                  \"type\": \"object\",\n                  \"properties\": {\n                    \"key\": {\n                      \"type\": \"string\"\n                    },\n                    \"regex\": {\n                      \"type\": \"string\"\n                    },\n                    \"command\": {\n                      \"type\": \"string\"\n                    },\n                    \"predefined\": {\n                      \"type\": \"string\"\n                    },\n                    \"regexType\": {\n                      \"type\": \"string\"\n                    }\n                  },\n                  \"required\": []\n                }\n              },\n              \"required\": []\n            }\n          },\n          \"required\": [\n            \"contractId\"]\n        }\n      ]\n    }\n  },\n  \"required\": [\n    \"x-contracts\"\n  ]\n}\n```\n\n### Example Contract Definition\n\nConsider the following example:\n\n```yaml\nopenapi: 3.0.0\ninfo:\n    description: Spring Cloud Contract Verifier Http Server OA3 Sample\n    version: \"1.0.0\"\n    title: Fraud Service API\npaths:\n    /fraudcheck:\n        put:\n            summary: Perform Fraud Check\n            x-contracts:\n            - contractId: 1\n              name: Should Mark Client as Fraud\n              priority: 1\n            - contractId: 2\n              name: Should Not Mark Client as Fraud\n            requestBody:\n                content:\n                    application/json:\n                        schema:\n                            type: object\n                            properties:\n                                \"client.id\":\n                                    type: integer\n                                loanAmount:\n                                    type: integer\n                x-contracts:\n                - contractId: 1\n                  body:\n                      \"client.id\": 1234567890\n                      loanAmount: 99999\n                  matchers:\n                      body:\n                      - path: $.['client.id']\n                        type: by_regex\n                        value: \"[0-9]{10}\"\n                - contractId: 2\n                  body:\n                      \"client.id\": 1234567890\n                      loanAmount: 123.123\n                  matchers:\n                      body:\n                      - path: $.['client.id']\n                        type: by_regex\n                        value: \"[0-9]{10}\"\n            responses:\n                '200':\n                    description: created ok\n                    content:\n                        application/json:\n                            schema:\n                                type: object\n                                properties:\n                                    fraudCheckStatus:\n                                        type: string\n                                    \"rejection.reason\":\n                                        type: string\n                    x-contracts:\n                    - contractId: 1\n                      body:\n                          fraudCheckStatus: \"FRAUD\"\n                          \"rejection.reason\": \"Amount too high\"\n                      headers:\n                          Content-Type: application/json;charset=UTF-8\n                    - contractId: 2\n                      body:\n                          fraudCheckStatus: \"OK\"\n                          \"rejection.reason\": null\n                      headers:\n                          Content-Type: application/json;charset=UTF-8\n                      matchers:\n                          body:\n                          - path: $.['rejection.reason']\n                            type: by_command\n                            value: assertThatRejectionReasonIsNull($it)\n    /frauds:\n        get:\n            x-contracts:\n            - contractId: 3\n              name: should return all frauds - should count all frauds\n            responses:\n                '200':\n                    description: okay\n                    content:\n                        application/json:\n                            schema:\n                                type: object\n                                properties:\n                                    count:\n                                        type: integer\n                    x-contracts:\n                    - contractId: 3\n                      body:\n                          count: 200\n    /drunks:\n        get:\n            x-contracts:\n            - contractId: 6\n              name: drunk frauds\n            responses:\n                '200':\n                    description: okay\n                    content:\n                        application/json:\n                            schema:\n                                type: object\n                                properties:\n                                    count:\n                                        type: integer\n                    x-contracts:\n                    - contractId: 6\n                      body:\n                          count: 100\n```\n\n#### Define Contract Headers\n\nTwo Contracts are defined in the Operation Object:\n\n```yaml\n        put:\n            summary: Perform Fraud Check\n            x-contracts:\n            - contractId: 1\n              name: Should Mark Client as Fraud\n              priority: 1\n            - contractId: 2\n              name: Should Not Mark Client as Fraud\n```\n\n#### Define Expected Request for Contacts\n\nIn the Request Body Object, the details for the expected request for each contract are given:\n\n```yaml\n            requestBody:\n                content:\n                    application/json:\n                        schema:\n                            type: object\n                            properties:\n                                \"client.id\":\n                                    type: integer\n                                loanAmount:\n                                    type: integer\n                x-contracts:\n                - contractId: 1\n                  body:\n                      \"client.id\": 1234567890\n                      loanAmount: 99999\n                  matchers:\n                      body:\n                      - path: $.['client.id']\n                        type: by_regex\n                        value: \"[0-9]{10}\"\n                - contractId: 2\n                  body:\n                      \"client.id\": 1234567890\n                      loanAmount: 123.123\n                  matchers:\n                      body:\n                      - path: $.['client.id']\n                        type: by_regex\n                        value: \"[0-9]{10}\"\n```\n\n*Note:* Notice how `x-contracts` is a list, with two objects, each of which has a `contractId` property.\nThe `contractId` property is matched to the `contractId` property in other sections of the document.\n\n#### Define Expected Responses for Each Contract\n\nThe expected response for each contract, is defined on the\nhttps://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#responseObject[Response Object].\n\nIn this example, two responses are defined for the HTTP status of 200.\n\n```yaml\n            responses:\n                '200':\n                    description: created ok\n                    content:\n                        application/json:\n                            schema:\n                                type: object\n                                properties:\n                                    fraudCheckStatus:\n                                        type: string\n                                    \"rejection.reason\":\n                                        type: string\n                    x-contracts:\n                    - contractId: 1\n                      body:\n                          fraudCheckStatus: \"FRAUD\"\n                          \"rejection.reason\": \"Amount too high\"\n                      headers:\n                          Content-Type: application/json;charset=UTF-8\n                    - contractId: 2\n                      body:\n                          fraudCheckStatus: \"OK\"\n                          \"rejection.reason\": null\n                      headers:\n                          Content-Type: application/json;charset=UTF-8\n                      matchers:\n                          body:\n                          - path: $.['rejection.reason']\n                            type: by_command\n                            value: assertThatRejectionReasonIsNull($it)\n```\n\n### Advanced Example\n\nFollowing is a more advanced example showing how to incorporate query parameters, cookies, header values, and\nmore detailed response properties.\n\n```yaml\nopenapi: \"3.0.0\"\ninfo:\n  version: 1.0.0\n  title: SCC\npaths:\n  /foo:\n    put:\n        x-contracts:\n            - contractId: 1\n              description: Some description\n              name: some name\n              priority: 8\n              ignored: true\n        parameters:\n          - name: a\n            in: query\n            schema:\n                type: string\n            x-contracts:\n                - contractId: 1\n                  value: b\n          - name: b\n            in: query\n            schema:\n                type: string\n            x-contracts:\n                - contractId: 1\n                  value: c\n          - name: foo\n            in: header\n            schema:\n                type: string\n            x-contracts:\n                - contractId: 1\n                  value: bar\n          - name: fooReq\n            in: header\n            schema:\n                type: string\n            x-contracts:\n                - contractId: 1\n                  value: baz\n          - name: foo\n            in: cookie\n            schema:\n              type: string\n            x-contracts:\n                - contractId: 1\n                  value: bar\n          - name: fooReq\n            in: cookie\n            schema:\n              type: string\n            x-contracts:\n                - contractId: 1\n                  value: baz\n        requestBody:\n            content:\n                application/json:\n                    schema:\n                      properties:\n                        foo:\n                          type: string\n            x-contracts:\n                - contractId: 1\n                  body:\n                    foo: bar\n                  matchers:\n                      body:\n                        - path: $.foo\n                          type: by_regex\n                          value: bar\n                      headers:\n                        - key: foo\n                          regex: bar\n        responses:\n            '200':\n                description: the response\n                content:\n                    application/json:\n                        schema:\n                            properties:\n                              foo:\n                                type: string\n                x-contracts:\n                    - contractId: 1\n                      headers:\n                        foo2: bar\n                        foo3: foo33\n                        fooRes: baz\n                      body:\n                        foo2: bar\n                        foo3: baz\n                        nullValue: null\n                      matchers:\n                        body:\n                          - path: $.foo2\n                            type: by_regex\n                            value: bar\n                          - path: $.foo3\n                            type: by_command\n                            value: executeMe($it)\n                          - path: $.nullValue\n                            type: by_null\n                            value: null\n                        headers:\n                          - key: foo2\n                            regex: bar\n                          - key: foo3\n                            command: andMeToo($it)\n                        cookies:\n                          - key: foo2\n                            regex: bar\n                          - key: foo3\n                            predefined:\n```\n\n### OA3 YAML Syntax\nThe [YAML DSL for Spring Cloud Contract](https://cloud.spring.io/spring-cloud-contract/multi/multi__contract_dsl.html#contract-matchers) defines a number of advanced features (regx, matchers, json path, etc).\nThese features should work with the OA3 DSL by using the same YAML syntax.\n\n# License\n\nThe Spring Cloud Contract OpenAPI 3.0 Contract Converter is released under version 2.0 of the [Apache License](http://www.apache.org/licenses/LICENSE-2.0).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringframeworkguru%2Fspring-cloud-contract-oa3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspringframeworkguru%2Fspring-cloud-contract-oa3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspringframeworkguru%2Fspring-cloud-contract-oa3/lists"}