Created PMR 83084,442,000
Thanks.
-----Original Message-----
From: WEB400 [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Nadir Amra
Sent: Monday, June 05, 2017 6:14 PM
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] RFE Swagger & _LENGTH
Yes, seems to be a defect. If you can open a PMR, that would be good. If
not, let me know. Working on a fix.
From: Mitch Gallman <mgallman@xxxxxxxxxxxx>
To: "Web Enabling the IBM i (AS/400 and iSeries)"
<web400@xxxxxxxxxxxx>
Date: 06/05/2017 03:43 PM
Subject: Re: [WEB400] RFE Swagger & _LENGTH
Sent by: "WEB400" <web400-bounces@xxxxxxxxxxxx>
We are on HTTP Group level 6 (one behind). Will work towards getting it updated.
Here is a sample service program along with the swagger document generated. I am wrapping input and the option to detect field lengths is selected.
---( Service Program )---
**FREE
ctl-opt nomain;
ctl-opt pgminfo(*pcml:*module:*dclcase);
//==============================================================================
// Get Example in a result set from a Post //==============================================================================
dcl-proc exampleRequest export;
//----------------------------------------------------------------------------
// Incoming Parameter List
//----------------------------------------------------------------------------
dcl-pi *n;
userId char(10) const;
request likeds(t_exampleRequest) const;
httpStatus int(10);
status char(15);
message char(250);
response likeds(t_exampleResponse);
end-pi;
//----------------------------------------------------------------------------
// Template of the Request Input Parameter
//----------------------------------------------------------------------------
dcl-ds t_exampleRequest template qualified;
companyCode char(4);
end-ds;
//----------------------------------------------------------------------------
// Template of the Response Output Parameter
//----------------------------------------------------------------------------
dcl-ds t_exampleResponse template qualified;
resultSet_LENGTH int(10);
resultSet likeds(t_exampleResults) dim(30000);
end-ds;
dcl-ds t_exampleResults template;
Id zoned(20);
name char(10);
description char(50);
end-ds;
// SQL Result Set to overlay the outgoing parameter
// SQL only supports one level or nesting thus response.resultSet is not allowed
// as a valid target of the FETCH INTO statement
dcl-s rsPtr pointer inz;
dcl-ds resultSet likeds(t_exampleResults) dim(30000) based(rsPtr);
//----------------------------------------------------------------------------
// Run-time variables
//----------------------------------------------------------------------------
dcl-s isAbnormalEnd ind inz;
// Set the SQL Result set pointer to the incoming parameter
// Since SQL-Into doesn't support more than one level of
// nesting in a data structure
rsPtr = %addr(response.resultSet);
// Reset Output Parameters
clear httpStatus;
clear status;
clear message;
clear response;
// Fill-in the Result set based on the user's authority/role
exec sql
declare csrExample cursor for
select
1,
'Example',
'An Example'
from
sysibm/sysdummy1
;
exec sql
open csrExample;
if sqlState > '02000';
httpStatus = 500;
status = 'error';
message = 'Failed opening resultSet: Example Cursor';
return;
endif;
exec sql
fetch csrExample for 30000 rows into :resultSet;
if sqlState > '02000';
httpStatus = 500;
status = 'error';
message = 'Failed fetching resultSet: Example Cursor';
return;
endif;
// Set the number of results to be returned
response.resultSet_length = sqler3;
// Return OK or No Content based on the number of results
if response.resultSet_length > 0;
httpStatus = 200;
status = 'success';
else;
httpStatus = 204;
status = 'success';
message = 'No Data';
endif;
return;
on-exit isAbnormalEnd;
if isAbnormalEnd;
httpStatus = 500;
status = 'error';
message = 'Unexpected Error';
return;
endif;
end-proc;
---( Swagger.IO generated )---
{
"swagger": "2.0",
"info": {
"title": "example APIs",
"description": "APIs available for example",
"version": "1.0.0"
},
"host": "xxxxxxxxxxxxxxxxxx",
"schemes": [ "https" ],
"basePath": "/web/services/example",
"tags": [
{
"name": "example APIs",
"description": "APIs available for example"
}
],
"definitions": {
"t_exampleResults": {
"type": "object",
"properties": {
"Id": {
"type": "number"
},
"name": {
"type": "string",
"maxLength": 10
},
"description": {
"type": "string",
"maxLength": 50
}
}
},
"t_exampleResponse": {
"type": "object",
"properties": {
"resultSet_LENGTH": {
"type": "integer",
"format": "int32"
},
"resultSet": {
"type": "array",
"maxItems": 30000,
"items": {
"$ref": "#/definitions/t_exampleResults"
}
}
}
},
"t_exampleRequest": {
"type": "object",
"properties": {
"companyCode": {
"type": "string",
"maxLength": 4
}
}
},
"exampleRequestInput": {
"type": "object",
"properties": {
"userId": {
"type": "string",
"maxLength": 10
},
"request": {
"type": "object",
"$ref": "#/definitions/t_exampleRequest"
}
}
},
"exampleRequestResult": {
"type": "object",
"properties": {
"status": {
"type": "string",
"maxLength": 15
},
"message": {
"type": "string",
"maxLength": 250
},
"response": {
"type": "object",
"$ref": "#/definitions/t_exampleResponse"
}
}
}
},
"paths": {
"/request": {
"post": {
"tags": [
"example APIs"
],
"operationId": "exampleRequest",
"consumes": [
"*/*"
],
"produces": [
"application/xml",
"application/json"
],
"parameters": [
{
"name": "body",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/exampleRequestInput"
}
}
],
"responses": {
"200": {
"description": "Successful operation",
"schema": {
"$ref": "#/definitions/exampleRequestResult"
}
}
}
}
}
}
}
-----Original Message-----
From: WEB400 [mailto:web400-bounces@xxxxxxxxxxxx] On Behalf Of Nadir Amra
Sent: Monday, June 05, 2017 4:07 PM
To: Web Enabling the IBM i (AS/400 and iSeries)
Subject: Re: [WEB400] RFE Swagger & _LENGTH
Also forgot to mention that you should ensure you have latest HTTP group PTF and when deploying a web service, you need to ensure the "Detect filed lengths" box is selected.
From: "Nadir Amra" <amra@xxxxxxxxxx>
To: "Web Enabling the IBM i \(AS/400 and iSeries\)"
<web400@xxxxxxxxxxxx>
Date: 06/05/2017 02:59 PM
Subject: Re: [WEB400] RFE Swagger & _LENGTH
Sent by: "WEB400" <web400-bounces@xxxxxxxxxxxx>
Hi Mitch,
I would need to see an example. xxxxx_LENGTH will not be in swagger only if there is a subsequent array field with name xxxxx.
From: Mitch Gallman <mgallman@xxxxxxxxxxxx>
To: "Web Enabling the IBM i (AS/400 and iSeries)"
<web400@xxxxxxxxxxxx>
Date: 06/05/2017 02:40 PM
Subject: [WEB400] RFE Swagger & _LENGTH
Sent by: "WEB400" <web400-bounces@xxxxxxxxxxxx>
I noticed the swagger.json generated contains the _LENGTH fields that are
not returned in the payload.
Created an RFE
https://www.ibm.com/developerworks/rfe/execute?use_case=viewRfe&CR_ID=106070
Mitch Gallman | U.S. Xpress, Inc.
IBM i Applications Developer
As an Amazon Associate we earn from qualifying purchases.