Incompatibility with fiware/orion:2.0.0 - fiware

This is a question related with this issue
https://github.com/ging/fiware-cygnus/issues/6
I've deployed the iot stack with docker. These are the used containers:
fiware/orion:2.0.0
ging/fiware-cygnus:latest
ging/fiware-cygnus:latest
"Id": "sha256:b6baf1cbd18e6ba6ab5ec7d8e1d9c8a08bbc18b45037faa345e8465c890f454c",
"RepoTags": [ "ging/fiware-cygnus:latest" ],
"RepoDigests": [
"ging/fiware-cygnus#sha256:4fcf44666651ca63f1a74203bc12a7ffd9a1268f8d514dff1a83db269a1c6923"
],
"Created": "2018-10-17T15:52:19.749023834Z"
[And other containers not involved in the issue ...]
Currently the image fiware/orion:2.0.0 is sending the headers as follows.
--------------------------------------------------
Standard FlowFile Attributes
Key: 'entryDate'
Value: 'Wed Oct 31 12:15:25 UTC 2018'
Key: 'lineageStartDate'
Value: 'Wed Oct 31 12:15:25 UTC 2018'
Key: 'fileSize'
Value: '144'
FlowFile Attribute Map Content
Key: 'Accept'
Value: 'application/json'
Key: 'Content-Length'
Value: '144'
Key: 'Content-Type'
Value: 'application/json; charset=UTF-8'
Key: 'Fiware-Correlator'
Value: 'a5a196d6-dd06-11e8-8f35-0242ac1c0004'
Key: 'Fiware-Service'
Value: 'testService'
Key: 'Fiware-Servicepath'
Value: '/testPath'
Key: 'Host'
Value: 'cygnus:5050'
Key: 'Ngsiv2-AttrsFormat'
Value: 'normalized'
Key: 'User-Agent'
Value: 'orion/2.0.0 libcurl/7.29.0'
Key: 'filename'
Value: '102283488692700'
Key: 'path'
Value: './'
Key: 'restlistener.remote.source.host'
Value: '172.28.0.4'
Key: 'restlistener.remote.user.dn'
Value: 'none'
Key: 'restlistener.request.uri'
Value: '/v2/notify'
Key: 'uuid'
Value: 'b20ecd8d-7d6e-4edd-be39-242a1ae1cc49'
--------------------------------------------------
Specifically, the header "Fiware-Servicepath" does not match what is expected this line of code. "fiware-servicepath," Fiware-ServicePath "," fiware-servicepath"
And this causes the following error:
`2018-10-31 12:15:41,201 ERROR [Timer-Driven Process Thread-1] o.a.nifi.processors.ngsi.NGSIToMongo NGSIToMongo[id=8f96c89d-850a-3578-b512-2b3f5f4fdacd] java.lang.NullPointerException
I think that it is caused by this line
String fiwareServicePath = (flowFile.getAttribute("fiware-servicepath")==null) ? flowFile.getAttribute("Fiware-ServicePath"):flowFile.getAttribute("fiware-servicepath");
IN
fiware-cygnus/nifi-ngsi-bundle/nifi-ngsi-processors/src/main/java/org/apache/nifi/processors/ngsi/NGSI/utils/NGSIUtils.java

Related

how do I validate a JSON payload in OpenAPI 3.0 with Mule 4.4 Runtime

I need to develop a Mule API ( 4.4 Runtime ) with openapi: 3.0.0
The endpoint is a POST with the following request payload :
{
"Employee": {
"Address": {
"City": "a",
"Country": "aaa"
}
}
}
Here is the relevant section of the OpenAPI 3.0 spec :
openapi: "3.0.0"
paths:
/search:
post:
tags:
- SearchUser
summary: Search for Users
operationId: getUser
requestBody:
description: User Request Object
content:
application/json:
schema:
$ref: '#/components/schemas/RequestComp'
required: true
responses:
'200':
description: successful operation
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ResponseComp'
'400':
description: Bad request
content: {}
'404':
description: User not found
content: {}
'405':
description: Validation exception
content: {}
components:
schemas:
RequestComp:
type: object
properties:
Employee:
$ref: '#/components/schemas/EmployeeComp'
EmployeeComp:
type: object
properties:
Address:
$ref: '#/components/schemas/AddressComp'
AddressComp:
type: object
properties:
City:
type: string
required: true
nullable: false
minLength: 1
Country:
type: string
required: true
nullable: false
minLength: 1
ResponseComp:
type: object
properties:
City:
type: string
Country:
type: string
So I can validate individual elements like 'City' and 'Country' to not be null but how do I prevent following request ? ( presently its not being flagged as invalid : )
{
"Address": {
"City": "a",
"Country": "aaa"
}
}
You can define the Employee wrapper as a required property and also disallow unknown properties by adding additionalProperties: false. Note that required is not a property-level attribute, but an object-level attribute - it's a list of required properties.
components:
schemas:
RequestComp:
type: object
required: [Employee] # <-----
properties:
Employee:
$ref: '#/components/schemas/EmployeeComp'
additionalProperties: false # <-----
EmployeeComp:
type: object
properties:
Address:
$ref: '#/components/schemas/AddressComp'
additionalProperties: false # <-----
AddressComp:
type: object
required: [City, Country] # <-----
properties:
City:
type: string
# required: true # <-- remove this
nullable: false
minLength: 1
Country:
type: string
# required: true # <-- remove this
nullable: false
minLength: 1
additionalProperties: false # <-----

gridjs: server, how to map data for a simple json array

I'm a java-script newbee, that's why I struggle with the mapping of a simple json array, if it is a response from a server. I've tested it with static json, and it works as expected:
new gridjs.Grid({
columns: [{
id: 'dateTime',
name: 'Timestamp'
}, {
id: 'host',
name: 'Host'
}, {
id: 'ipv4',
name: 'IPv4'
}, {
id: 'ipv6',
name: 'IPv6'
}],
data: [
{"dateTime": "2021-12-02 03:11:30.501","host": "master.myhost.com","ipv4": "93.215.66.14", "ipv6": "2003:cc:2fff:9e4:2e91:abff:febf:d839"},
{"dateTime": "2021-12-02 03:44:29.494", "host": "test.myhost.com", "ipv4": "93.203.250.190", "ipv6": "n/a"},
]
}).render(document.getElementById("wrapper"));
But if the same json array is delivered by a server, I don't know how to define my data mapping. That's what I've tried:
new gridjs.Grid({
columns: [{
id: 'dateTime',
name: 'Timestamp'
}, {
id: 'host',
name: 'Host'
}, {
id: 'ipv4',
name: 'IPv4'
}, {
id: 'ipv6',
name: 'IPv6'
}],
server: {
url: "http://localhost:8080/info/zone-log",
then: data => data.map([data.dateTime, data.host, data.ipv4, data.ipv6])
}
}).render(document.getElementById("wrapper"));
I get the following error on the JS console: '[Grid.js] [ERROR]: TypeError: [...] is not a function'.
Can somebody explain me, how to do the data mapping correctly?
Edit
Server response:
curl -i http://localhost:8080/info/zone-log
HTTP/1.1 200 OK
Date: Tue, 01 Mar 2022 08:53:39 GMT
Content-Type: application/json
Transfer-Encoding: chunked
[{"dateTime":"2021-12-02 03:11:30.501","host":"master.myhost.com","ipv4":"93.215.66.14","ipv6":"2003:cc:2fff:9e4:2e91:abff:febf:d839"},{"dateTime":"2021-12-02 03:44:29.494","host":"ursa.myhost.com","ipv4":"93.203.250.190","ipv6":"n/a"}, ...}
java-script console log:
data
Array(191) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]
[0…99]
​​0: Object { dateTime: "2021-12-02 03:11:30.501", host: "master.myhost.com", ipv4: "93.215.66.14", … }
​​1: Object { dateTime: "2021-12-02 03:44:29.494", host: "ursa.myhost.com", ipv4: "93.203.250.190", … }
[Grid.js] [ERROR]: TypeError: [...] is not a function log.ts:12:21
Looks like data that you are getting is not an array. Hence data.map() is giving type error. Can you please console log the data and see what's coming?
new gridjs.Grid({
columns: [{
id: 'dateTime',
name: 'Timestamp'
}, {
id: 'host',
name: 'Host'
}, {
id: 'ipv4',
name: 'IPv4'
}, {
id: 'ipv6',
name: 'IPv6'
}],
server: {
url: "http://localhost:8080/info/zone-log",
then: data => {
console.log("data", data);
return data.map([data.dateTime, data.host, data.ipv4, data.ipv6])
}
}
}).render(document.getElementById("wrapper"));
Most probably the required array is inside another object in data.

Avoid additional fields in json apart from the fields defined in the swagger to fail the validation in WSO2 APIM 3.1.0

We are trying to validate a json in APIM 3.1.0 by defining the validation conditions in swagger definition and by enabling the schema validation under runtime configurations. PFA the Swagger definition.
When additional fields are passed in the request json apart from the fields defined in the swagger, the validation must fail or gateway should ignore those additional fields and shouldn't be passing it to the backend. But this is not happening currently, Could you please suggest us if we are missing anything here.
Sample Request JSON
Note : In this JSON, "test" field is an additional parameter sent in the request.
{​​​​​​​
"applicationId": "Test123_3211",
"name": "Bala krishna",
"dateOfBirth": "1981-04-11",
"gender": "FEMALE",
"phonenumber": "9039283630",
"altphonenumber": "9979979971",
"panCard": "AAAAV1234N",
"nomineeName": "Ramji Ambedkar",
"nomineeDOB": "1976-04-14",
"source": "ONLINE",
"process": "Canara HSBC",
"callDate": "2018-08-24",
"callTime": "17:00",
"merType": "VIDEOMER",
"instantCall": true,
"test": "abcd"
}​​​​​​​
Below is the swagger API :
swagger: "2.0"
info:
version: v1.0.0
title: MedicalBookAppointmentAPI
description: "This API is for booking medical appointments. \n\nSupported operations :\n\n\t1. Docs APP "
schemes:
https
http
produces:
application/json
paths:
/docs-app:
post:
summary: This API will be used to add cases and to schedule appointments.
description: This API will be used to add cases and to schedule appointments.
parameters:
- in: body
name: Payload
description: Request Body
required: true
schema:
$ref: "#/definitions/docs-app-request"
responses:
"200":
description: OK
schema:
$ref: "#/definitions/docs-app-response"
"400":
schema:
$ref: "#/definitions/book-appointment-api-error"
description: Bad Request. Invalid request or validation error.
"415":
schema:
$ref: "#/definitions/book-appointment-api-error"
description: " Unsupported Media Type. The entity of the request was in a not supported format."
"500":
schema:
$ref: "#/definitions/book-appointment-api-error"
description: Internal Server Error
produces:
- application/json
consumes:
- application/json
x-auth-type: "Application & Application User"
x-throttling-tier: Unlimited
definitions:
docs-app-request:
type: "object"
required:
- "applicationId"
- "process"
properties:
applicationId:
type: "string"
name:
type: "string"
dateOfBirth:
type: "string"
pattern: "^\d{​​​​​​​4}​​​​​​​-\d{​​​​​​​2}​​​​​​​-\d{​​​​​​​2}​​​​​​​$"
gender:
type: "string"
phonenumber:
type: "number"
altphonenumber:
type: "number"
panCard:
type: "string"
nomineeName:
type: "string"
nomineeDOB:
type: "string"
pattern: "^\d{​​​​​​​4}​​​​​​​-\d{​​​​​​​2}​​​​​​​-\d{​​​​​​​2}​​​​​​​$"
source:
type: "string"
process:
type: "string"
planDetails:
type: "string"
priorityStatus:
type: "string"
callDate:
type: "string"
pattern: "^\d{​​​​​​​4}​​​​​​​-\d{​​​​​​​2}​​​​​​​-\d{​​​​​​​2}​​​​​​​$"
callTime:
type: "string"
metaInfo:
type: "string"
instantCall:
type: "boolean"
merType:
type: "string"
enum:
- "TELEMER"
- "VIDEOMER"
- "OTHERS"
docs-app-response:
type: object
properties:
data:
type: object
properties:
approved:
type: boolean
isInternational:
type: boolean
id:
format: int64
type: integer
applicationId:
type: string
name:
type: string
dateOfBirth:
type: string
gender:
type: string
phonenumber:
type: string
altphonenumber:
type: string
panCard:
type: string
nomineeName:
type: string
nomineeDOB:
type: string
merType:
type: string
vendor:
type: string
updatedAt:
type: string
createdAt:
type: string
success:
type: integer
book-appointment-api-error:
title: Error object returned with HTTP status
type: object
properties:
fault:
type: object
properties:
code:
format: int64
type: integer
type:
type: string
message:
description: Error message.
type: string
description:
description: A detail description about the error message.
type: string
required:
- code
- message
You can use either additionalProperties or minProperties/maxProperties in the swagger file and restrict the additional properties in the payload.
If you know the property count to be limited then use minProperties/maxProperties
If you don't know the property count to be limited then use additionalProperties
For more details please refer https://m-saranki.medium.com/unboxing-json-schema-validator-320-2dd944dae6c0

Swagger-Editor empty response in client generated in HTML

I'm doing documentation for a project. On the website everything is showing correctly in the preview, though it is showing error "Resolver error Cannot read property '0' of undefined".
When generating client in html2 response schema is blank.
UPDATE: showing full code now.
I've tried cutting one level (Entity->EntityItem->EntityResponse to Entity->EntityResponse), error stopped, HTML still not showing full data.
openapi: 3.0.0
info:
description: not working
version: "1.0.0"
title: ...
contact:
email: work#pls.com
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
#====================================================================================
paths:
/search/nip/{nip}:
get:
operationId: nip?date
parameters:
- in: path
name: nip
required: true
schema:
type: string
minLength: 10
maxLength: 10
description: "Nip"
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityResponse'
'400':
description: ...
description: ...
/search/regon/{regon}:
get:
operationId: regon?date
parameters:
- in: path
name: regon
required: true
schema:
type: string
pattern: '^\d{9}$|^\d{14}$'
description: ...
example: '364760520'
description: Regon
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityResponse'
'400':
description: ...
description: ...
/search/bank-account/{bank-account}:
get:
operationId: bank-account?date
parameters:
- in: path
name: bank-account
required: true
schema:
type: string
minLength: 26
maxLength: 26
description: ...
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityListResponse'
'400':
description: ...
description: ...
/check/nip/{nip}/bank-account/{bank-account}:
get:
operationId: checkNip
parameters:
- in: path
name: nip
required: true
schema:
type: string
minLength: 10
maxLength: 10
description: "Nip"
- in: path
name: bank-account
required: true
schema:
type: string
minLength: 26
maxLength: 26
description: Numer rachunku bankowego
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityCheckResponse'
'400':
description: ...
description: ...
/check/regon/{regon}/bank-account/{bank-account}:
get:
operationId: checkRegon
parameters:
- in: path
name: regon
required: true
schema:
type: string
pattern: '^\d{9}$|^\d{14}$'
description: numer identyfikacyjny REGON
example: '364760520'
description: Regon
- in: path
name: bank-account
required: true
schema:
type: string
minLength: 26
maxLength: 26
description: ...
- in: query
name: date
required: true
schema:
type: string
format: date
example: '2019-05-17'
responses:
'200':
description: ...
content:
application/json:
schema:
$ref: '#/components/schemas/EntityCheckResponse'
'400':
description: ...
description: ...
#====================================================================================
components:
schemas:
EntityRequestBase:
properties:
data:
type: string
format: date
example: '2019-05-17'
bank-account:
type: array
items:
type: string
minLength: 26
maxLength: 26
example: '90249000050247256316596736'
nip:
type: string
minLength: 10
maxLength: 10
example: '1111111111'
regon:
type: string
pattern: '^\d{9}$|^\d{14}$'
description: |
...
example: '364760520'
pesel:
type: string
description: |
...
minLength: 11
maxLength: 11
example: '22222222222'
required:
- data
#====================================================================================
Exception:
properties:
message:
type: string
example: 'error message'
code:
type: integer
required:
- message
- code
#====================================================================================
Person:
properties:
firstName:
type: string
example: Jan
lastName:
type: string
example: Nowak
pesel:
$ref: '#/components/schemas/EntityRequestBase/properties/pesel'
nip:
type: string
minLength: 10
maxLength: 10
example: '1111111111'
#====================================================================================
EntityPerson:
allOf:
- $ref: '#/components/schemas/Person'
- properties:
companyName:
type: string
example: 'Nazwa firmy'
#====================================================================================
EntityCheck:
properties:
accountAssigned:
type: string
example: TAK
description: |
...
requestId:
type: string
example: 'd2n10-84df1a1'
#====================================================================================
Entity:
allOf:
- properties:
name:
type: string
example: 'ABC Jan Nowak'
description: |
...
nip:
type: string
minLength: 10
maxLength: 10
example: '1111111111'
statusVat:
type: string
enum:
- C
- Z
- P
example: Z
description: |
...
regon:
type: string
pattern: '^\d{9}$|^\d{14}$'
description: |
...
example: '364760520'
pesel:
$ref: '#/components/schemas/EntityRequestBase/properties/pesel'
krs:
type: string
example: '0000636771'
maxLength: 10
minLength: 10
description: |
...
residenceAddress:
type: string
example: 'ul/ Taka a Owaka 12 01- Warszawa'
description: |
...
workingAddress:
type: string
representatives:
type: array
items:
$ref: '#/components/schemas/Person'
description: |
...
authorizedClerks:
type: array
items:
$ref: '#/components/schemas/Person'
description: |
...
partners:
type: array
items:
$ref: '#/components/schemas/EntityPerson'
description: |
...
registrationLegalDate:
type: string
format: date
example: '2018-02-21'
registrationDenialDate:
type: string
format: date
example: '2019-02-21'
description: |
...
registrationDenialBasis:
type: string
example: 'Ustawa o podatku od towarów i usług art. 96'
description: |
...
restorationDate:
type: string
format: date
example: '2019-02-21'
description: |
...
restorationBasis:
type: string
example: 'Ustawa o podatku od towarów i usług art. 96'
description: |
...
accountNumbers:
type: array
items:
type: string
minLength: 26
maxLength: 26
example: '90249000050247256316596736'
hasVirtualAccounts:
type: boolean
example: true
description: |
...
required:
- name
#====================================================================================
EntityItem:
allOf:
- properties:
subject:
$ref: '#/components/schemas/Entity'
requestId:
type: string
example: 'd2n10-84df1a1'
#====================================================================================
EntityList:
allOf:
- properties:
subjects:
type: array
items:
$ref: '#/components/schemas/Entity'
description: |
...
requestId:
type: string
example: 'd2n10-84df1a1'
#====================================================================================
EntityResponse:
allOf:
- properties:
exception:
$ref: '#/components/schemas/Exception'
result:
$ref: '#/components/schemas/EntityItem'
EntityCheckResponse:
allOf:
- properties:
exception:
$ref: '#/components/schemas/Exception'
result:
$ref: '#/components/schemas/EntityCheck'
EntityListResponse:
allOf:
- properties:
exception:
$ref: '#/components/schemas/Exception'
result:
$ref: '#/components/schemas/EntityList'
The issue seems to be caused by the ? question mark in operation IDs:
operationId: nip?date
If you remove the question mark, HTML2 docs will include response schemas.
You can file a bug report in the Swagger Codegen repository at https://github.com/swagger-api/swagger-codegen/issues.
Found the solution, it was due to the misuse of "allOf", without them error stops and HTML is generated correctly. It only made sense in "Person", all the other cases were deleted.

Following swagger specifications, how can I define json of nested objects to yaml?

I am having a problem in defining the array of objects in swagger yaml. Swagger editor is giving an error everytime I try to define the type: array part of the yaml. I defined it, but it is not right as it is giving an error.
Following is the json I am trying to define in swagger yaml.
{
"CountryCombo": {
"options": {
"option": [{
"id": "GB",
"value": "GB Great Britain"
}, {
"id": "US",
"value": "US United States"
}, {
"id": "AD",
"value": "AD Andorra, Principality of"
}]
}
}
}
I defined this json into swagger yaml like this but it is giving an error:
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
- id:
type: string
description: GB
value:
type: string
description: GB Great Britain
- id:
type: string
description: US
value:
type: string
description: US United States
- id:
type: string
description: AD
value:
type: string
description: AD Andorra, Principality of
Can anyone suggest me how would I define this json in yaml following swagger specifications?
In a schema, you don't want to have the values, only the description of the values.
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
type: object
properties:
id:
type: string
value:
type: string
The above answer is also right but I already implemented this in my yaml. I found that I can also define array by creating another definition.
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
$ref: '#/definitions/Country_row'
Country_row:
type: object
properties:
id:
type: string
value:
type: string
The accepted answer cannot achieve the output desired the question. Swagger documentation on examples explains how to add multiple examples for an array of objects:
definitions:
ArrayOfCatalogItems:
type: array
items:
$ref: '#/definitions/CatalogItem'
example:
- id: 38
title: T-shirt
- id: 114
title: Phone
OP was actually on the right track, but made a syntactic mistake:
CountryCombo:
type: object
properties:
options:
type: object
properties:
option:
type: array
items:
- id:
type: string
value:
type: string
- id:
type: string
value:
type: string
- id:
type: string
value:
type: string
example:
- id: GB
value: GB Great Britain
- id: US
value: US United States
- id: AD
value: AD Andorra, Principles of