Skip to content

Commit 1d1d938

Browse files
authored
fix(parameters): applied extra schema validation to parameters (#166)
* fix(parameters): applied extra schema validation to parameters This PR applies an extra jsonschema validation to expanded parameters. Whenever a parameter is provided as a $ref, jsonschema validation works at the level of the unexpanded parameter only. It is indeed valid to declare a parameter as a json reference. The issue is that the expanded content of this parameter definition is subject only to "extra rules" (uniqueness, etc) and not to the basic jsonschema rules (e.g. allowed and required properties). An example is provided by go-swagger/go-swagger#2527. It seems that this situation never occured before go-swagger/go-swagger#2527 because the "parameters" section to which shared parameters normally point to is always fully expanded. In the case of a $ref to a schema in "definition", the invalid content of the $ref incorrectly passes validation. * fixes #165 * contributes go-swagger/go-swagger#2527 Signed-off-by: Frederic BIDON <[email protected]> * added unit test to assert that no duplicate messages are spewed out Signed-off-by: Frederic BIDON <[email protected]> --------- Signed-off-by: Frederic BIDON <[email protected]>
1 parent dd1b7cd commit 1d1d938

10 files changed

+1680
-87
lines changed

fixtures/bugs/2527/swagger-fixed.yml

+285
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
swagger: '2.0'
2+
info:
3+
title: Exchange Automator 2
4+
version: '1.0'
5+
description: Exchange trading automator. Internal only service.
6+
host: localhost
7+
basePath: /api/v1
8+
securityDefinitions:
9+
ApiKeyAuth:
10+
name: X-API-Key
11+
description: 'API keys are all predefined for all internal services'
12+
type: apiKey
13+
in: header
14+
security:
15+
- ApiKeyAuth: []
16+
schemes:
17+
- https
18+
consumes:
19+
- application/json
20+
produces:
21+
- application/json
22+
responses:
23+
401:
24+
description: Not authorized
25+
schema:
26+
$ref: '#/definitions/Error'
27+
422:
28+
description: Unprocessable entity
29+
schema:
30+
$ref: '#/definitions/Error'
31+
503:
32+
description: Service temporarily unavailable
33+
schema:
34+
$ref: '#/definitions/Error'
35+
tags:
36+
- name: Currency exchange rate
37+
description: Get exchange currency rate info
38+
- name: Deposit
39+
- name: Trading
40+
parameters:
41+
Exchange:
42+
name: exchange
43+
in: query
44+
type: string
45+
enum: [kraken, globitex, binance, cex]
46+
description: Exchange Id
47+
definitions:
48+
Exchange:
49+
type: string
50+
enum: [kraken, globitex, binance, cex]
51+
description: Exchange Id
52+
CurrencyRate:
53+
type: object
54+
properties:
55+
exchange:
56+
type: string
57+
timestamp:
58+
description: Most likely near to current moment
59+
type: integer
60+
format: int64
61+
source:
62+
type: string
63+
description: Source currency ticker
64+
target:
65+
type: string
66+
description: Target currency ticker
67+
rate:
68+
type: number
69+
format: double
70+
sourceAmount:
71+
type: number
72+
format: double
73+
targetAmount:
74+
type: number
75+
format: double
76+
Deposit:
77+
type: object
78+
description: Field list is not final, will be added during development
79+
properties:
80+
exchange:
81+
$ref: '#/definitions/Exchange'
82+
accountId:
83+
type: string
84+
format: uuid
85+
txId:
86+
description: Transaction Id
87+
type: string
88+
clientId:
89+
description: Client Id, identified via external system, after receiving
90+
ticker:
91+
type: string
92+
amount:
93+
type: number
94+
format: double
95+
ExchangeOrder:
96+
type: object
97+
required:
98+
- exchange
99+
- incomingTxId
100+
- source
101+
- target
102+
- sourceAmount
103+
properties:
104+
id:
105+
type: string
106+
description: Created order Id
107+
type:
108+
type: string
109+
description: defaults to 'market'
110+
enum: [market, limit]
111+
exchange:
112+
$ref: '#/definitions/Exchange'
113+
incomingTxId:
114+
type: string
115+
description: Incoming deposit transaction id
116+
source:
117+
type: string
118+
target:
119+
type: string
120+
sourceAmount:
121+
type: number
122+
format: double
123+
targetAmount:
124+
description: Target currency amount after or during exchange processing. Total of transactions amounts
125+
type: number
126+
format: double
127+
status:
128+
type: string
129+
enum: [pending, processing, executed]
130+
transactions:
131+
type: array
132+
items:
133+
type: string
134+
135+
Error:
136+
type: object
137+
required:
138+
- message
139+
properties:
140+
message:
141+
type: string
142+
description: Error description
143+
paths:
144+
/swagger.yml:
145+
get:
146+
description: Returns swagger api specs
147+
tags:
148+
- Swagger
149+
responses:
150+
200:
151+
description: Swagger specs contents
152+
/exchange_rate:
153+
get:
154+
description: Returns currency exchange rate. If both sourceAmount and targetAmount is provided, targetAmount will be ignored.
155+
tags:
156+
- Currency exchange rate
157+
parameters:
158+
- name: exchange
159+
description: Exchange to query
160+
in: query
161+
type: string
162+
required: true
163+
- name: source
164+
description: Source currency to be converted from
165+
in: query
166+
type: string
167+
required: true
168+
- name: target
169+
description: Target currency to be converted to
170+
in: query
171+
type: string
172+
required: true
173+
- name: sourceAmount
174+
description: If set, returns target currency amount, selling this amount of source currency, default 1
175+
in: query
176+
type: number
177+
format: double
178+
- name: targetAmount
179+
description: If set, returns source currency amount, buying this amount of target currency
180+
in: query
181+
type: number
182+
format: double
183+
responses:
184+
200:
185+
description: Currency rate object
186+
schema:
187+
$ref: '#/definitions/CurrencyRate'
188+
401:
189+
$ref: '#/responses/401'
190+
422:
191+
$ref: '#/responses/422'
192+
503:
193+
$ref: '#/responses/503'
194+
/deposits:
195+
get:
196+
description: Returns deposits list across all exchanges
197+
tags:
198+
- Deposit
199+
parameters:
200+
- name: accountId
201+
description: Filter by account ID
202+
in: query
203+
type: string
204+
format: uuid
205+
- $ref: '#/parameters/Exchange'
206+
- name: status
207+
description: Filter by deposit transaction status
208+
type: string
209+
in: query
210+
enum: [pending, mempool, something, else]
211+
responses:
212+
200:
213+
description: Deposit list
214+
schema:
215+
type: object
216+
properties:
217+
deposits:
218+
type: array
219+
items:
220+
$ref: '#/definitions/Deposit'
221+
401:
222+
$ref: '#/responses/401'
223+
/exchange_order/{exchangeOrderId}:
224+
get:
225+
description: Returns exchange order
226+
tags:
227+
- Trading
228+
parameters:
229+
- name: exchangeOrderId
230+
in: path
231+
type: string
232+
required: true
233+
responses:
234+
200:
235+
description: Exchange order
236+
schema:
237+
$ref: '#/definitions/ExchangeOrder'
238+
401:
239+
$ref: '#/responses/401'
240+
/exchange_order:
241+
post:
242+
description: Creates a currency exchange order, depending on order type, might be async
243+
tags:
244+
- Trading
245+
parameters:
246+
- name: X-Idempotency-Token
247+
description: Client generated idempotency token for operation deduplication
248+
in: header
249+
type: string
250+
required: true
251+
- name: exchangeOrder
252+
in: body
253+
required: true
254+
schema:
255+
type: object
256+
required:
257+
- exchange
258+
- incomingTxId
259+
- source
260+
- target
261+
- sourceAmount
262+
properties:
263+
type:
264+
type: string
265+
description: defaults to 'market'
266+
enum: [market, limit]
267+
exchange:
268+
$ref: '#/definitions/Exchange'
269+
incomingTxId:
270+
type: string
271+
description: Incoming deposit transaction id
272+
source:
273+
type: string
274+
target:
275+
type: string
276+
sourceAmount:
277+
type: number
278+
format: double
279+
responses:
280+
200:
281+
description: Exchange order
282+
schema:
283+
$ref: '#/definitions/ExchangeOrder'
284+
401:
285+
$ref: '#/responses/401'

0 commit comments

Comments
 (0)