Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into special_paging

* 'master' of https://github.com/Azure/autorest.testserver:
  add test for error deserialization in op with param name 'models' (#234)
  add test for first response no items, second response with items (#235)
  • Loading branch information
iscai-msft committed Nov 11, 2020
2 parents 0201487 + 5b70058 commit 58582b6
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 18 deletions.
4 changes: 2 additions & 2 deletions legacy/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ var coverage = {
"intError":0,
"stringError":0,
"animalNotFoundError":0,
"linkNotFoundError":0
"linkNotFoundError":0,
};

// view engine setup
Expand Down Expand Up @@ -557,7 +557,7 @@ app.use('/parameterGrouping', new parameterGrouping(azurecoverage).router);
app.use('/validation', new validation(coverage).router);
app.use('/customUri', new customUri(coverage).router);
app.use('/extensibleEnums', new extensibleEnums(coverage).router);
app.use('/errorStatusCodes', new errorStatusCodes(coverage).router);
app.use('/errorStatusCodes', new errorStatusCodes(coverage, optionalCoverage).router);
app.use('/additionalProperties', new additionalProperties(coverage).router);
app.use('/mediatypes', new mediatypes(coverage).router);
app.use('/xml', new xml(coverage).router);
Expand Down
13 changes: 12 additions & 1 deletion legacy/routes/errorStatusCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ var animalNotFoundError = {
};


var pathitem = function(coverage) {
var pathitem = function(coverage, optionalCoverage) {
optionalCoverage['sendErrorWithParamNameModels'] = 0;
router.post('/Pets/doSomething/:whatAction', function(req, res, next) {
var whatAction = req.params.whatAction;
console.log('Inside action: "' + whatAction +'"\n');
Expand Down Expand Up @@ -95,6 +96,16 @@ var pathitem = function(coverage) {
res.status(402).end("That's all folks!!");
}
});

router.post('/Pets/hasModelsParam', function(req, res, next) {
models_param = req.query['models']
if (models_param == 'value1') {
res.status(500).json(sadCasper);
optionalCoverage['sendErrorWithParamNameModels']++;
} else {
utils.send400(res, next, "The value of input param models is " + models_param + " and not the client default value of 'value1'");
}
});
}

pathitem.prototype.router = router;
Expand Down
13 changes: 13 additions & 0 deletions legacy/routes/paging.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var paging = function(coverage) {
coverage['PagingCustomUrlPartialNextLink'] = 0;
coverage["PagingCustomUrlPartialOperationNextLink"] = 0;
coverage["PagingReturnModelWithXMSClientName"] = 0;
coverage["PagingFirstResponseEmpty"] = 0;

router.get('/noitemname', function(req, res, next) {
coverage["PagingNoItemName"]++;
Expand Down Expand Up @@ -206,6 +207,18 @@ var paging = function(coverage) {
res.status(200).json({ "values" : [ {"properties":{"id": 1, "name": "Product" }}]});
});

router.get('/firstResponseEmpty/:pagenumber', function(req, res, next) {
if (req.params.pagenumber == 1) {
res.status(200).json({ "values" : [], "nextLink":"/paging/firstResponseEmpty/2"});
} else if(req.params.pagenumber == 2) {
coverage["PagingFirstResponseEmpty"]++;
res.status(200).json({ "value" : [ {"properties":{"id": 1, "name": "Product" }}]});
} else {
res.status(400).end("Incorrect page number " + req.params.pagenumber + ". Needs to be either 1 for the initial call, or 2 for the final call");
}
});


/*** PAGEABLE LROs ***/
router.post('/multiple/lro', function (req, res, next) {
var pollingUri = 'http://localhost:' + utils.getPort() + '/paging/multiple/lro/200';
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@microsoft.azure/autorest.testserver",
"version": "2.10.63",
"version": "2.10.64",
"main": "./legacy/startup/www.js",
"bin": {
"start-autorest-express": "./.scripts/start-autorest-express.js",
Expand Down
18 changes: 18 additions & 0 deletions swagger/paging.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@
}
}
},
"/paging/firstResponseEmpty/1": {
"get": {
"x-ms-pageable": { "nextLinkName": "nextLink" },
"operationId": "Paging_firstResponseEmpty",
"description": "A paging operation whose first response's items list is empty, but still returns a next link. Second (and final) call, will give you an items list of 1.",
"responses": {
"200": {
"description": "First call returns an empty items list, second (and final) call returns an items list of length 1.",
"schema": {
"$ref": "#/definitions/ProductResultValue"
}
},
"default": {
"description": "Unexpected error"
}
}
}
},
"/paging/multiple": {
"get": {
"x-ms-pageable": { "nextLinkName": "nextLink", "itemName": "values" },
Expand Down
55 changes: 41 additions & 14 deletions swagger/xms-error-responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
"schemes": [
"http"
],
"produces": [
"application/json"
],
"consumes": [
"application/json"
],
"paths": {
"/errorStatusCodes/Pets/{petId}/GetPet": {
"get": {
Expand Down Expand Up @@ -57,13 +63,7 @@
"default": {
"description": "default stuff"
}
},
"produces": [
"application/json"
],
"consumes": [
"application/json"
]
}
}
},
"/errorStatusCodes/Pets/doSomething/{whatAction}": {
Expand Down Expand Up @@ -99,14 +99,41 @@
"$ref": "#/definitions/PetActionError"
}
}
},
"produces": [
"application/json"
],
"consumes": [
"application/json"
]
}
}
},
"/errorStatusCodes/Pets/hasModelsParam": {
"post": {
"operationId": "Pet_HasModelsParam",
"description": "Ensure you can correctly deserialize the returned PetActionError and deserialization doesn't conflict with the input param name 'models'",
"parameters": [
{
"name": "models",
"in": "query",
"type": "string",
"x-ms-client-default": "value1",
"description": "Make sure model deserialization doesn't conflict with this param name, which has input name 'models'. Use client default value in call"
}
],
"responses": {
"200": {
"description": "OK. We will be returning an error though"
},
"500": {
"description": "Will return error. Make sure the error can be correctly deserialized",
"schema": {
"$ref": "#/definitions/PetActionError"
},
"x-ms-error-response": true
},
"default": {
"description": "Default",
"schema": {
"$ref": "#/definitions/PetActionError"
}
}
}
}
}
},
"definitions": {
Expand Down

0 comments on commit 58582b6

Please sign in to comment.