git.iko.soy/typeable/compaREST
on master help sign in
Fixed ProdCons value pairs in report (#112)

* Fixed ProdCons value pairs in report * normalizeProdConsOrientation -> orientProdCons * Applied fix to PathFragmentsDontMatch

commitd50b2ba645e8530a1a553921b9b32a58bb16bdb7 authoriko <ilyakooo0@gmail.com> dateFri 23 Jul 2021, 12:19 (5 years ago) parenta501f6e
11 files changed+280−22
fourmolu.yaml+8 src/OpenAPI/Checker/Subtree.hs+5 src/OpenAPI/Checker/Validate/Param.hs+3−2 src/OpenAPI/Checker/Validate/PathFragment.hs+1−1 src/OpenAPI/Checker/Validate/Schema/Issues.hs+26−15 test/golden/common/random-example/a.yaml+56 test/golden/common/random-example/b.yaml+58 test/golden/common/random-example/report.md+71 test/golden/common/random-example/trace-tree.yaml+48 test/golden/common/tuple-items/heterogeneous-length-mismatch/report.md+2−2 test/golden/common/tuple-items/homogeneous-length-mismatch/report.md+2−2
fourmolu.yamlnew file+8
@@ -0,0 +1,8 @@
1+indentation: 2
2+comma-style: leading # for lists, tuples etc. - can also be 'trailing'
3+record-brace-space: true # rec {x = 1} vs. rec{x = 1}
4+indent-wheres: true # 'false' means save space by only half-indenting the 'where' keyword
5+diff-friendly-import-export: false # 'false' uses Ormolu-style lists
6+respectful: true # don't be too opinionated about newlines etc.
7+haddock-style: single-line # '--' vs. '{-'
8+newlines-between-decls: 1 # number of newlines between top-level declarations
src/OpenAPI/Checker/Subtree.hs+5
@@ -18,6 +18,7 @@ module OpenAPI.Checker.Subtree
1818 , CompatFormula'
1919 , SemanticCompatFormula
2020 , ProdCons (..)
21+ , orientProdCons
2122 , swapProdCons
2223 , runCompatFormula
2324 , issueAt
@@ -110,6 +111,10 @@ data ProdCons a = ProdCons
110111 }
111112 deriving stock (Eq, Ord, Show, Functor, Foldable, Traversable)
112113
114+orientProdCons :: Orientation -> ProdCons x -> ProdCons x
115+orientProdCons Forward x = x
116+orientProdCons Backward (ProdCons p c) = ProdCons c p
117+
113118swapProdCons
114119 :: SwapEnvRoles xs
115120 => (HList xs -> ProdCons x -> CompatFormula' q AnIssue r a)
src/OpenAPI/Checker/Validate/Param.hs+3−2
@@ -66,7 +66,7 @@ instance Issuable 'PathFragmentLevel where
6666 ParamStyleMismatch
6767 | -- | One of schemas not presented
6868 ParamSchemaMismatch
69− | PathFragmentsDontMatch Text Text
69+ | PathFragmentsDontMatch (ProdCons Text)
7070 deriving stock (Eq, Ord, Show)
7171 issueIsUnsupported _ = False
7272 describeIssue _ ParamNameMismatch = para "The path fragments don't match."
@@ -77,7 +77,8 @@ instance Issuable 'PathFragmentLevel where
7777 describeIssue _ ParamPlaceIncompatible = para "Parameters in incompatible locations."
7878 describeIssue _ ParamStyleMismatch = para "Different parameter styles (encodings)."
7979 describeIssue _ ParamSchemaMismatch = para "Expected a schema, but didn't find one."
80− describeIssue _ (PathFragmentsDontMatch e a) = para $ "Parameter changed from " <> code e <> " to " <> code a <> "."
80+ describeIssue ori (PathFragmentsDontMatch (orientProdCons ori -> ProdCons e a)) =
81+ para $ "Parameter changed from " <> code e <> " to " <> code a <> "."
8182
8283instance Behavable 'PathFragmentLevel 'SchemaLevel where
8384 data Behave 'PathFragmentLevel 'SchemaLevel
src/OpenAPI/Checker/Validate/PathFragment.hs+1−1
@@ -74,6 +74,6 @@ instance Subtree PathFragmentParam where
7474 checkSemanticCompatibility _ beh (ProdCons (extract -> StaticPath x) (extract -> StaticPath y)) =
7575 if x == y
7676 then pure ()
77− else issueAt beh (PathFragmentsDontMatch x y)
77+ else issueAt beh (PathFragmentsDontMatch (ProdCons x y))
7878 checkSemanticCompatibility env beh prodCons = do
7979 checkCompatibility beh env (tracedPathFragmentParam <$> prodCons)
src/OpenAPI/Checker/Validate/Schema/Issues.hs+26−15
@@ -94,26 +94,32 @@ instance Issuable 'TypedSchemaLevel where
9494 describeIssue Backward (NoMatchingEnum v) = para "The following enum value has been removed:" <> showJSONValue v
9595 describeIssue Forward (NoMatchingMaximum b) = para $ "Upper bound has been added:" <> showBound b <> "."
9696 describeIssue Backward (NoMatchingMaximum b) = para $ "Upper bound has been removed:" <> showBound b <> "."
97− describeIssue _ (MatchingMaximumWeak (ProdCons p c)) = para $ "Upper bound changed from " <> showBound p <> " to " <> showBound c <> "."
97+ describeIssue ori (MatchingMaximumWeak (orientProdCons ori -> ProdCons p c)) =
98+ para $ "Upper bound changed from " <> showBound p <> " to " <> showBound c <> "."
9899 describeIssue Forward (NoMatchingMinimum b) = para $ "Lower bound has been added: " <> showBound b <> "."
99100 describeIssue Backward (NoMatchingMinimum b) = para $ "Lower bound has been removed: " <> showBound b <> "."
100− describeIssue _ (MatchingMinimumWeak (ProdCons p c)) = para $ "Lower bound changed from " <> showBound p <> " to " <> showBound c <> "."
101+ describeIssue ori (MatchingMinimumWeak (orientProdCons ori -> ProdCons p c)) =
102+ para $ "Lower bound changed from " <> showBound p <> " to " <> showBound c <> "."
101103 describeIssue Forward (NoMatchingMultipleOf n) = para $ "Value is now a multiple of " <> show' n <> "."
102104 describeIssue Backward (NoMatchingMultipleOf n) = para $ "Value is no longer a multiple of " <> show' n <> "."
103− describeIssue _ (MatchingMultipleOfWeak (ProdCons p c)) = para $ "Value changed from being a multiple of " <> show' p <> " to being a multiple of " <> show' c <> "."
105+ describeIssue ori (MatchingMultipleOfWeak (orientProdCons ori -> ProdCons p c)) =
106+ para $ "Value changed from being a multiple of " <> show' p <> " to being a multiple of " <> show' c <> "."
104107 describeIssue Forward (NoMatchingFormat f) = para $ "Format added: " <> code f <> "."
105108 describeIssue Backward (NoMatchingFormat f) = para $ "Format removed: " <> code f <> "."
106109 describeIssue Forward (NoMatchingMaxLength n) = para $ "Maximum length added: " <> show' n <> "."
107110 describeIssue Backward (NoMatchingMaxLength n) = para $ "Maximum length removed: " <> show' n <> "."
108− describeIssue _ (MatchingMaxLengthWeak (ProdCons p c)) = para $ "Maximum length of the string changed from " <> show' p <> " to " <> show' c <> "."
111+ describeIssue ori (MatchingMaxLengthWeak (orientProdCons ori -> ProdCons p c)) =
112+ para $ "Maximum length of the string changed from " <> show' p <> " to " <> show' c <> "."
109113 describeIssue Forward (NoMatchingMinLength n) = para $ "Minimum length of the string added: " <> show' n <> "."
110114 describeIssue Backward (NoMatchingMinLength n) = para $ "Minimum length of the string removed: " <> show' n <> "."
111− describeIssue _ (MatchingMinLengthWeak (ProdCons p c)) = para $ "Minimum length of the string changed from " <> show' p <> " to " <> show' c <> "."
115+ describeIssue ori (MatchingMinLengthWeak (orientProdCons ori -> ProdCons p c)) =
116+ para $ "Minimum length of the string changed from " <> show' p <> " to " <> show' c <> "."
112117 describeIssue Forward (NoMatchingPattern p) = para "Pattern (regular expression) added: " <> codeBlock p
113118 describeIssue Backward (NoMatchingPattern p) = para "Pattern (regular expression) removed: " <> codeBlock p
114119 describeIssue Forward NoMatchingItems = para "Array item schema has been added."
115120 describeIssue Backward NoMatchingItems = para "Array item schema has been removed."
116− describeIssue _ (TupleItemsLengthChanged (ProdCons p c)) = para $ "Tuple length changed from " <> show' p <> " to " <> show' c <> "."
121+ describeIssue ori (TupleItemsLengthChanged (orientProdCons ori -> ProdCons p c)) =
122+ para $ "Tuple length changed from " <> show' p <> " to " <> show' c <> "."
117123 describeIssue Forward ArrayToTuple = para "The array is now explicitly defined as a tuple."
118124 describeIssue Backward ArrayToTuple = para "The array is no longer explicitly defined as a tuple."
119125 describeIssue Forward TupleToArray = para "The array is no longer explicitly defined as a tuple."
@@ -122,10 +128,12 @@ instance Issuable 'TypedSchemaLevel where
122128 describeIssue Backward NoMatchingTupleItems = para "The array is no longer explicitly defined as a tuple."
123129 describeIssue Forward (NoMatchingMaxItems n) = para $ "Maximum length of the array has been added " <> show' n <> "."
124130 describeIssue Backward (NoMatchingMaxItems n) = para $ "Maximum length of the array has been removed " <> show' n <> "."
125− describeIssue _ (MatchingMaxItemsWeak (ProdCons p c)) = para $ "Maximum length of the array changed from " <> show' p <> " to " <> show' c <> "."
131+ describeIssue ori (MatchingMaxItemsWeak (orientProdCons ori -> ProdCons p c)) =
132+ para $ "Maximum length of the array changed from " <> show' p <> " to " <> show' c <> "."
126133 describeIssue Forward (NoMatchingMinItems n) = para $ "Minimum length of the array added: " <> show' n <> "."
127134 describeIssue Backward (NoMatchingMinItems n) = para $ "Minimum length of the array removed: " <> show' n <> "."
128− describeIssue _ (MatchingMinItemsWeak (ProdCons p c)) = para $ "Minimum length of the array changed from " <> show' p <> " to " <> show' c <> "."
135+ describeIssue ori (MatchingMinItemsWeak (orientProdCons ori -> ProdCons p c)) =
136+ para $ "Minimum length of the array changed from " <> show' p <> " to " <> show' c <> "."
129137 describeIssue Forward NoMatchingUniqueItems = para "Items are now required to be unique."
130138 describeIssue Backward NoMatchingUniqueItems = para "Items are no longer required to be unique."
131139 describeIssue Forward NoMatchingProperties = para "Property added."
@@ -134,17 +142,20 @@ instance Issuable 'TypedSchemaLevel where
134142 describeIssue Backward NoAdditionalProperties = para "Additional properties have been added."
135143 describeIssue Forward (NoMatchingMaxProperties n) = para $ "Maximum number of properties has been added: " <> show' n <> "."
136144 describeIssue Backward (NoMatchingMaxProperties n) = para $ "Maximum number of properties has been removed: " <> show' n <> "."
137− describeIssue _ (MatchingMaxPropertiesWeak (ProdCons p c)) = para $ "Maximum number of properties has changed from " <> show' p <> " to " <> show' c <> "."
145+ describeIssue ori (MatchingMaxPropertiesWeak (orientProdCons ori -> ProdCons p c)) =
146+ para $ "Maximum number of properties has changed from " <> show' p <> " to " <> show' c <> "."
138147 describeIssue Forward (NoMatchingMinProperties n) = para $ "Minimum number of properties added: " <> show' n <> "."
139148 describeIssue Backward (NoMatchingMinProperties n) = para $ "Minimum number of properties removed: " <> show' n <> "."
140− describeIssue _ (MatchingMinPropertiesWeak (ProdCons p c)) = para $ "Minimum number of properties has changed from " <> show' p <> " to " <> show' c <> "."
149+ describeIssue ori (MatchingMinPropertiesWeak (orientProdCons ori -> ProdCons p c)) =
150+ para $ "Minimum number of properties has changed from " <> show' p <> " to " <> show' c <> "."
141151 describeIssue _ (NoMatchingCondition mPart conds) =
142152 para
143− (case mPart of
144− Nothing -> "Could not verify that the following conditions hold (please file a bug if you see this):"
145− Just locPart ->
146− "In cases where " <> showPartition locPart
147− <> " – could not verify that the following conditions hold (please file a bug if you see this):")
153+ ( case mPart of
154+ Nothing -> "Could not verify that the following conditions hold (please file a bug if you see this):"
155+ Just locPart ->
156+ "In cases where " <> showPartition locPart
157+ <> " – could not verify that the following conditions hold (please file a bug if you see this):"
158+ )
148159 <> bulletList ((\(SomeCondition c) -> showCondition c) <$> conds)
149160 describeIssue Forward TypeBecomesEmpty = para "The type has been removed."
150161 describeIssue Backward TypeBecomesEmpty = para "The type has been added."
test/golden/common/random-example/a.yamlnew file+56
@@ -0,0 +1,56 @@
1+openapi: "3.0.0"
2+info:
3+ version: 1.0.0
4+ title: Swagger Petstore
5+ license:
6+ name: MIT
7+servers:
8+ - url: https://example.com
9+paths:
10+ /pets:
11+ get:
12+ parameters:
13+ - name: limit
14+ in: query
15+ required: false
16+ schema:
17+ type: integer
18+ maximum: 20
19+ responses:
20+ "200":
21+ description: ""
22+ headers:
23+ x-next:
24+ schema:
25+ type: string
26+ content:
27+ application/json:
28+ schema:
29+ $ref: "#/components/schemas/Pets"
30+ post:
31+ requestBody:
32+ content:
33+ application/json:
34+ schema:
35+ $ref: "#/components/schemas/Pet"
36+ responses:
37+ "201":
38+ description: ""
39+components:
40+ schemas:
41+ Pet:
42+ type: object
43+ required:
44+ - id
45+ - name
46+ properties:
47+ id:
48+ type: integer
49+ name:
50+ type: string
51+ minLength: 3
52+ maxLength: 10
53+ Pets:
54+ type: array
55+ items:
56+ $ref: "#/components/schemas/Pet"
test/golden/common/random-example/b.yamlnew file+58
@@ -0,0 +1,58 @@
1+openapi: "3.0.0"
2+info:
3+ version: 1.1.0
4+ title: Swagger Petstore
5+ license:
6+ name: MIT
7+servers:
8+ - url: https://example.com
9+paths:
10+ /pets:
11+ get:
12+ parameters:
13+ - name: limit
14+ in: query
15+ required: false
16+ schema:
17+ type: integer
18+ maximum: 30
19+ responses:
20+ "200":
21+ description: ""
22+ headers:
23+ x-next:
24+ schema:
25+ type: string
26+ content:
27+ application/json:
28+ schema:
29+ $ref: "#/components/schemas/Pets"
30+ post:
31+ requestBody:
32+ content:
33+ application/json:
34+ schema:
35+ $ref: "#/components/schemas/Pet"
36+ responses:
37+ "201":
38+ description: ""
39+components:
40+ schemas:
41+ Pet:
42+ type: object
43+ required:
44+ - id
45+ - name
46+ properties:
47+ id:
48+ type: integer
49+ name:
50+ type: string
51+ minLength: 1
52+ maxLength: 15
53+ weight:
54+ type: integer
55+ Pets:
56+ type: array
57+ items:
58+ $ref: "#/components/schemas/Pet"
test/golden/common/random-example/report.mdnew file+71
@@ -0,0 +1,71 @@
1+# Summary
2+
3+| [⚠️ Breaking changes](#breaking-changes) | [🙆 Non-breaking changes](#non-breaking-changes) | 🤷 Unsupported feature changes |
4+|------------------------------------------|-------------------------------------------------|-------------------------------|
5+| 5 | 6 | 0 |
6+
7+# <span id="breaking-changes"></span>⚠️ Breaking changes
8+
9+## **GET** /pets
10+
11+### 📱⬅️ JSON Response – 200
12+
13+#### `$[*].name(String)`
14+
15+1. Maximum length of the string changed from 10 to 15.
16+
17+2. Minimum length of the string changed from 3 to 1.
18+
19+## **POST** /pets
20+
21+### 📱➡️ JSON Request
22+
23+#### `$.weight`
24+
25+1. Values are now limited to the following types:
26+
27+ - Number
28+
29+2. The property was previously implicitly described by the catch-all
30+ "additional properties" case. It is now explicitly defined.
31+
32+#### `$.weight(Number)`
33+
34+Value is now a multiple of 1.0.
35+
36+# <span id="non-breaking-changes"></span>🙆 Non-breaking changes
37+
38+## **GET** /pets
39+
40+### Parameter limit
41+
42+#### JSON Schema
43+
44+##### `$(Number)`
45+
46+Upper bound changed from 20.0 inclusive to 30.0 inclusive.
47+
48+### 📱⬅️ JSON Response – 200
49+
50+#### `$[*].weight`
51+
52+1. Values are now limited to the following types:
53+
54+ - Number
55+
56+2. The property was previously implicitly described by the catch-all
57+ "additional properties" case. It is now explicitly defined.
58+
59+#### `$[*].weight(Number)`
60+
61+Value is now a multiple of 1.0.
62+
63+## **POST** /pets
64+
65+### 📱➡️ JSON Request
66+
67+#### `$.name(String)`
68+
69+1. Maximum length of the string changed from 10 to 15.
70+
71+2. Minimum length of the string changed from 3 to 1.
test/golden/common/random-example/trace-tree.yamlnew file+48
@@ -0,0 +1,48 @@
1+breakingChanges:
2+ AtPath "/pets":
3+ InOperation GetMethod:
4+ WithStatusCode 200:
5+ ResponsePayload:
6+ PayloadSchema:
7+ OfType Array:
8+ InItems:
9+ OfType Object:
10+ InProperty "name":
11+ OfType String:
12+ - MatchingMaxLengthWeak (ProdCons {producer = 15, consumer = 10})
13+ - MatchingMinLengthWeak (ProdCons {producer = 1, consumer = 3})
14+ InOperation PostMethod:
15+ InRequest:
16+ InPayload:
17+ PayloadSchema:
18+ OfType Object:
19+ InProperty "weight":
20+ - TypesRestricted [Number]
21+ - AdditionalToProperty
22+ - OfType Number: NoMatchingMultipleOf 1.0
23+nonBreakingChanges:
24+ AtPath "/pets":
25+ InOperation GetMethod:
26+ WithStatusCode 200:
27+ ResponsePayload:
28+ PayloadSchema:
29+ OfType Array:
30+ InItems:
31+ OfType Object:
32+ InProperty "weight":
33+ - TypesRestricted [Number]
34+ - AdditionalToProperty
35+ - OfType Number: NoMatchingMultipleOf 1.0
36+ InParam "limit":
37+ InParamSchema:
38+ OfType Number: MatchingMaximumWeak (ProdCons {producer = Inclusive 30.0,
39+ consumer = Inclusive 20.0})
40+ InOperation PostMethod:
41+ InRequest:
42+ InPayload:
43+ PayloadSchema:
44+ OfType Object:
45+ InProperty "name":
46+ OfType String:
47+ - MatchingMaxLengthWeak (ProdCons {producer = 15, consumer = 10})
48+ - MatchingMinLengthWeak (ProdCons {producer = 1, consumer = 3})
test/golden/common/tuple-items/heterogeneous-length-mismatch/report.md+2−2
@@ -18,7 +18,7 @@ Tuple length changed from 3 to 2.
1818
1919#### `$(Array)`
2020
21−Tuple length changed from 2 to 3.
21+Tuple length changed from 3 to 2.
2222
2323# <span id="non-breaking-changes"></span>🙆 Non-breaking changes
2424
@@ -28,7 +28,7 @@ Tuple length changed from 2 to 3.
2828
2929#### `$(Array)`
3030
31−Tuple length changed from 2 to 3.
31+Tuple length changed from 3 to 2.
3232
3333### 📱⬅️ JSON Response – 200
3434
test/golden/common/tuple-items/homogeneous-length-mismatch/report.md+2−2
@@ -34,7 +34,7 @@ Minimum length of the array changed from 2 to 3.
3434
3535#### `$(Array)`
3636
37−1. Tuple length changed from 3 to 2.
37+1. Tuple length changed from 2 to 3.
3838
39392. The array is no longer explicitly defined as a tuple.
4040
@@ -62,7 +62,7 @@ The array is no longer explicitly defined as a tuple.
6262
6363#### `$(Array)`
6464
65−1. Tuple length changed from 3 to 2.
65+1. Tuple length changed from 2 to 3.
6666
67672. The array is no longer explicitly defined as a tuple.
6868